OCT 1. 增加集成测试用例名称显示
This commit is contained in:
parent
d38a21094e
commit
e4aeb9b3cf
|
@ -6,14 +6,18 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
|||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Schema(name = "资源信息")
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ResourceInfo {
|
||||
@Schema(description = "资源路径")
|
||||
@NotNull(message = "path 资源 URL 不能为 NULL", groups = ValidGroups.ResourceInfoValid.class)
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
import com.cmhi.cf.controller.CommonFrameworkApiTest;
|
||||
import com.cmhi.cf.controller.OperationLogApiTest;
|
||||
import com.cmhi.cf.controller.PermissionManagerApiTest;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.platform.suite.api.SelectClasses;
|
||||
import org.junit.platform.suite.api.Suite;
|
||||
|
||||
@SelectClasses({CommonFrameworkApiTest.class, OperationLogApiTest.class})
|
||||
@SelectClasses({CommonFrameworkApiTest.class,
|
||||
OperationLogApiTest.class,
|
||||
PermissionManagerApiTest.class})
|
||||
@DisplayName("接口集成测试")
|
||||
@Suite
|
||||
public class IntegrationTestSuite {
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.cmhi.cf.controller;
|
|||
import com.cmhi.cf.common.TestBaseAuthentication;
|
||||
import com.cmhi.cf.restapi.pojo.vo.VersionResp;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
@ -15,6 +16,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
|||
@Transactional
|
||||
public class CommonFrameworkApiTest extends TestBaseAuthentication {
|
||||
@Test
|
||||
@DisplayName("获取版本信息")
|
||||
void testGetVersion() throws Exception {
|
||||
VersionResp resp = (VersionResp) performanceRestful(RequestMethod.GET, null, "/api/version", new Class[]{VersionResp.class});
|
||||
AssertValidCommonResp(resp);
|
||||
|
@ -29,6 +31,7 @@ public class CommonFrameworkApiTest extends TestBaseAuthentication {
|
|||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("获取版本信息(POST)")
|
||||
void testGetVersionV2() throws Exception {
|
||||
VersionResp resp = (VersionResp) performanceRestful(RequestMethod.POST, null, "/api/version", new Class[]{VersionResp.class});
|
||||
AssertValidCommonResp(resp);
|
||||
|
|
|
@ -8,6 +8,7 @@ import com.cmhi.cf.restapi.pojo.dto.OperationLogReq;
|
|||
import com.cmhi.cf.restapi.pojo.po.OperationLogSummary;
|
||||
import com.cmhi.cf.restapi.pojo.vo.OperationLogDetailsResp;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -32,6 +33,7 @@ public class OperationLogApiTest extends TestBaseAuthentication {
|
|||
|
||||
@Test
|
||||
@Order(1)
|
||||
@DisplayName("获取操作日志摘要(分页)")
|
||||
void testGetSummary() throws Exception {
|
||||
final long pageSize = 10L;
|
||||
final long pageNumber = 1L;
|
||||
|
@ -80,6 +82,7 @@ public class OperationLogApiTest extends TestBaseAuthentication {
|
|||
|
||||
@Test
|
||||
@Order(2)
|
||||
@DisplayName("获取操作日志详情")
|
||||
void testGetDetails() throws Exception {
|
||||
Assertions.assertFalse(optIdArray.isEmpty());
|
||||
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package com.cmhi.cf.controller;
|
||||
|
||||
import com.cmhi.cf.authentication.pojo.dto.IdArrayReq;
|
||||
import com.cmhi.cf.authentication.pojo.dto.RegisterResourceReq;
|
||||
import com.cmhi.cf.authentication.pojo.dto.UserIdReq;
|
||||
import com.cmhi.cf.authentication.pojo.po.ResourceInfo;
|
||||
import com.cmhi.cf.authentication.pojo.vo.GetRoleResp;
|
||||
import com.cmhi.cf.authentication.pojo.vo.RegisterResourceResp;
|
||||
import com.cmhi.cf.authentication.pojo.vo.UserResPermInfoResp;
|
||||
|
@ -10,8 +12,8 @@ import com.cmhi.cf.common.TestBaseAuthentication;
|
|||
import com.cmhi.cf.database.authentication.entity.User;
|
||||
import com.cmhi.cf.database.authentication.service.UserService;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
@ -31,12 +33,14 @@ import java.util.UUID;
|
|||
@Transactional
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class PermissionManagerApiTest extends TestBaseAuthentication {
|
||||
public class PermissionManagerApiTest extends TestBaseAuthentication {
|
||||
private final List<String> addResUid = new ArrayList<>();
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
private UserService userService;
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
@DisplayName("获取当前用户资源信息")
|
||||
void testGetCurrentUserResourcePermission() throws Exception {
|
||||
UserResPermInfoResp resp = (UserResPermInfoResp) performanceRestful(RequestMethod.GET, null, "/api/permission/resourcePermission",
|
||||
new Class[] {UserResPermInfoResp.class});
|
||||
|
@ -58,7 +62,7 @@ class PermissionManagerApiTest extends TestBaseAuthentication {
|
|||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
@DisplayName("获取用户资源信息")
|
||||
void testGetUserResourcePermission() throws Exception {
|
||||
User user = userService.getAccountUserByName("admin");
|
||||
Assertions.assertNotNull(user);
|
||||
|
@ -84,14 +88,14 @@ class PermissionManagerApiTest extends TestBaseAuthentication {
|
|||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
@DisplayName("不存在的用户获取资源信息")
|
||||
void testGetUserResourcePermission_UserServiceGetAccountUserByUidReturnsNull() {
|
||||
User user = userService.getAccountUserByUid("ff99fd68-14bf-4fd6-9320-bab85839245c");
|
||||
Assertions.assertNull(user);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
@DisplayName("获取用户资源信息, 当前用户无资源")
|
||||
void testGetUserResourcePermission_UserServiceGetUserResourcePermReturnsNoItems() throws Exception {
|
||||
User user = userService.getAccountUserByName("guest");
|
||||
Assertions.assertNotNull(user);
|
||||
|
@ -118,7 +122,7 @@ class PermissionManagerApiTest extends TestBaseAuthentication {
|
|||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
@DisplayName("获取当前所有用户组")
|
||||
void testGetAllRoles() throws Exception {
|
||||
GetRoleResp resp = (GetRoleResp) performanceRestful(RequestMethod.GET, null, "/api/permission/allRoles",
|
||||
new Class[] {GetRoleResp.class});
|
||||
|
@ -134,7 +138,7 @@ class PermissionManagerApiTest extends TestBaseAuthentication {
|
|||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@DisplayName("删除不存在的资源")
|
||||
void testRemoveResourceById_UserServiceReturnsNoItems() throws Exception {
|
||||
List<String> rid = new ArrayList<>();
|
||||
|
||||
|
@ -144,9 +148,9 @@ class PermissionManagerApiTest extends TestBaseAuthentication {
|
|||
|
||||
IdArrayReq req = new IdArrayReq(rid);
|
||||
|
||||
RegisterResourceResp resp = (RegisterResourceResp)performanceRestful(RequestMethod.DELETE, req,
|
||||
"/api/permission/resource",
|
||||
new Class[] {RegisterResourceResp.class});
|
||||
RegisterResourceResp resp = (RegisterResourceResp) performanceRestful(RequestMethod.DELETE, req,
|
||||
"/api/permission/resource",
|
||||
new Class[] {RegisterResourceResp.class});
|
||||
AssertValidCommonResp(resp);
|
||||
Assertions.assertNotNull(resp.getResult());
|
||||
Assertions.assertEquals(resp.getResult().size(), rid.size());
|
||||
|
@ -158,14 +162,63 @@ class PermissionManagerApiTest extends TestBaseAuthentication {
|
|||
}
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
@DisplayName("注册新资源")
|
||||
void testRegisterResource() throws Exception {
|
||||
addResUid.clear();
|
||||
List<ResourceInfo> resList = new ArrayList<>();
|
||||
resList.add(ResourceInfo.builder()
|
||||
.path("/api/custom/show")
|
||||
.name("show")
|
||||
.resTypeId(0)
|
||||
.httpMethod(new ArrayList<>() {{add("POST");}})
|
||||
.build());
|
||||
|
||||
resList.add(ResourceInfo.builder()
|
||||
.path("/api/custom/List")
|
||||
.name("List")
|
||||
.resTypeId(1)
|
||||
.httpMethod(new ArrayList<>() {{add("PUT");}})
|
||||
.build());
|
||||
|
||||
RegisterResourceReq req = RegisterResourceReq.builder()
|
||||
.resources(resList)
|
||||
.build();
|
||||
|
||||
RegisterResourceResp resp = (RegisterResourceResp) performanceRestful(RequestMethod.PUT, req,
|
||||
"/api/permission/resource",
|
||||
new Class[] {RegisterResourceResp.class});
|
||||
|
||||
AssertValidCommonResp(resp);
|
||||
Assertions.assertNotNull(resp.getResult());
|
||||
Assertions.assertEquals(resp.getResult().size(), resList.size());
|
||||
|
||||
resp.getResult().forEach(k -> {
|
||||
AssertValidCommonResp(k);
|
||||
AssertValidString(k.getRid());
|
||||
AssertValidString(k.getPath());
|
||||
AssertValidString(k.getHttpMethod());
|
||||
Assertions.assertNotNull(k.getResTypeId());
|
||||
addResUid.add(k.getRid());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(11)
|
||||
@DisplayName("删除资源")
|
||||
void testRemoveResourceById() throws Exception {
|
||||
testRegisterResource();
|
||||
IdArrayReq req = new IdArrayReq(addResUid);
|
||||
|
||||
RegisterResourceResp resp = (RegisterResourceResp) performanceRestful(RequestMethod.DELETE, req,
|
||||
"/api/permission/resource",
|
||||
new Class[] {RegisterResourceResp.class});
|
||||
AssertValidCommonResp(resp);
|
||||
Assertions.assertNotNull(resp.getResult());
|
||||
Assertions.assertEquals(resp.getResult().size(), addResUid.size());
|
||||
|
||||
resp.getResult().forEach(k -> {
|
||||
AssertValidCommonResp(k);
|
||||
AssertValidString(k.getRid());
|
||||
Assertions.assertTrue(addResUid.contains(k.getRid()));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue