This is an automated email from the ASF dual-hosted git repository.

xiaoyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git


The following commit(s) were added to refs/heads/master by this push:
     new 5ed30ca7d #4029 api improve unit test case (#4168)
5ed30ca7d is described below

commit 5ed30ca7daa1cc4ac799bad7488be837e9708c9f
Author: zhengpeng <[email protected]>
AuthorDate: Wed Nov 9 23:09:09 2022 +0800

    #4029 api improve unit test case (#4168)
---
 .../apache/shenyu/admin/mapper/ApiMapperTest.java  | 38 ++++++++++++++++++++--
 .../apache/shenyu/admin/mapper/TagMapperTest.java  | 11 +++++++
 .../shenyu/admin/service/ApiServiceTest.java       | 18 ----------
 3 files changed, 46 insertions(+), 21 deletions(-)

diff --git 
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/ApiMapperTest.java 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/ApiMapperTest.java
index ce75f8dc6..1206587d3 100644
--- 
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/ApiMapperTest.java
+++ 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/ApiMapperTest.java
@@ -19,13 +19,19 @@ package org.apache.shenyu.admin.mapper;
 
 import org.apache.shenyu.admin.AbstractSpringIntegrationTest;
 import org.apache.shenyu.admin.model.entity.ApiDO;
+import org.apache.shenyu.admin.model.page.PageParameter;
+import org.apache.shenyu.admin.model.query.ApiQuery;
 import org.apache.shenyu.common.utils.UUIDUtils;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
 import javax.annotation.Resource;
 import java.sql.Timestamp;
+import java.util.Collections;
+import java.util.List;
 
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.greaterThan;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 
@@ -75,7 +81,7 @@ public final class ApiMapperTest extends 
AbstractSpringIntegrationTest {
         this.apiDO.setVersion("V0.02");
         this.apiDO.setRpcType("dubbo1");
         this.apiDO.setState(1);
-        final int count = apiMapper.updateByPrimaryKeySelective(this.apiDO);
+        int count = apiMapper.updateByPrimaryKeySelective(this.apiDO);
         assertEquals(1, count);
     }
 
@@ -90,16 +96,42 @@ public final class ApiMapperTest extends 
AbstractSpringIntegrationTest {
         this.apiDO.setRpcType("dubbo2");
         this.apiDO.setState(2);
         this.apiDO.setApiSource(3);
-        final int count = apiMapper.updateByPrimaryKeySelective(this.apiDO);
+        int count = apiMapper.updateByPrimaryKeySelective(this.apiDO);
         assertEquals(1, count);
     }
 
+    @Test
+    public void testSelectByQuery() {
+        ApiQuery query = new ApiQuery();
+        query.setState(0);
+        query.setApiPath("/demo/findById");
+        query.setPageParameter(new PageParameter(1, 10));
+        List<ApiDO> apiDOS = apiMapper.selectByQuery(query);
+        assertThat(apiDOS.size(), greaterThan(0));
+    }
+
+    @Test
+    public void testSelectByIds() {
+        List<String> strings = Collections.singletonList(apiDO.getId());
+        List<ApiDO> apiDOS = apiMapper.selectByIds(strings);
+        assertThat(apiDOS.size(), greaterThan(0));
+    }
+
     @Test
     public void testDeleteByPrimaryKey() {
-        final int count = apiMapper.deleteByPrimaryKey(this.apiDO.getId());
+        int count = apiMapper.deleteByPrimaryKey(this.apiDO.getId());
         assertEquals(1, count);
     }
 
+    @Test
+    public void testDeleteByIds() {
+        ApiDO newApiDO = buildApiDO();
+        apiMapper.insertSelective(newApiDO);
+        List<String> ids = Collections.singletonList(newApiDO.getId());
+        int deleteRows = apiMapper.deleteByIds(ids);
+        assertEquals(1, deleteRows);
+    }
+
     private ApiDO buildApiDO() {
         Timestamp now = new Timestamp(System.currentTimeMillis());
         ApiDO apiDO = new ApiDO();
diff --git 
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/TagMapperTest.java 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/TagMapperTest.java
index daab80431..99cafe84a 100644
--- 
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/TagMapperTest.java
+++ 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/TagMapperTest.java
@@ -20,6 +20,7 @@ package org.apache.shenyu.admin.mapper;
 import com.google.common.collect.Lists;
 import java.sql.Timestamp;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import javax.annotation.Resource;
 import org.apache.shenyu.admin.AbstractSpringIntegrationTest;
@@ -139,6 +140,16 @@ public final class TagMapperTest extends 
AbstractSpringIntegrationTest {
         assertEquals(deleteCnt, 1);
     }
 
+    @Test
+    public void testSelectByIds() {
+        TagDO record = buildTagDO();
+        int count = tagMapper.insertSelective(record);
+        assertEquals(count, 1);
+        List<String> ids = Collections.singletonList(record.getId());
+        List<TagDO> tagDOS = tagMapper.selectByIds(ids);
+        assertThat(tagDOS.size(), greaterThan(0));
+    }
+
     private TagDO buildTagDO() {
         Timestamp now = new Timestamp(System.currentTimeMillis());
         String id = UUIDUtils.getInstance().generateShortUuid();
diff --git 
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/ApiServiceTest.java
 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/ApiServiceTest.java
index 2ea6b411d..4abcaae7e 100644
--- 
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/ApiServiceTest.java
+++ 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/ApiServiceTest.java
@@ -122,24 +122,6 @@ public final class ApiServiceTest {
         return apiDO;
     }
 
-    private ApiVO buildApiVO(final String id) {
-        return ApiVO.builder()
-                .id(id)
-                .contextPath("string")
-                .apiPath("string")
-                .httpMethod(0)
-                .consume("string")
-                .produce("string")
-                .version("string")
-                .rpcType("string")
-                .state(0)
-                .apiOwner("string")
-                .apiDesc("string")
-                .apiSource(0)
-                .document("document")
-                .build();
-    }
-
     private void testCreate() {
         ApiDTO apiDTO = buildApiDTO("");
         assertEquals(ShenyuResultMessage.CREATE_SUCCESS, 
this.apiService.createOrUpdate(apiDTO));

Reply via email to