OCT 1. 增加权限管理测试用例框架
This commit is contained in:
parent
f4934f365d
commit
3fd2ce5e44
|
@ -2,12 +2,16 @@ package com.cmhi.cf.authentication.pojo.po;
|
|||
|
||||
import com.houkunlin.system.dict.starter.json.DictText;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Schema(name = "资源权限信息")
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ResPermInfo {
|
||||
@Schema(description = "资源id")
|
||||
private Long id;
|
||||
|
|
|
@ -154,9 +154,7 @@ public class HelperUtils {
|
|||
|
||||
private static Type createRespType(Class<?>[] c) {
|
||||
if (c.length == 1) {
|
||||
return JsonParameterizedType.make(ProtocolResp.class,
|
||||
new Type[] {c[0]},
|
||||
ProtocolResp.class.getDeclaringClass());
|
||||
return createRespType(c[0]);
|
||||
}
|
||||
|
||||
Stack<Class<?>> st = new Stack<>();
|
||||
|
|
|
@ -8,11 +8,13 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
|||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Schema(name = "系统操作日志详细信息")
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonPropertyOrder({"id", "requestHeaders", "request", "result", "status", "message"})
|
||||
public class OperationLogDetails extends BaseRespStatus {
|
||||
|
@ -28,11 +30,6 @@ public class OperationLogDetails extends BaseRespStatus {
|
|||
@Schema(description = "操作返回结果")
|
||||
private String result;
|
||||
|
||||
public OperationLogDetails() {
|
||||
this.setStatus(ErrorCode.ERR_OK.getCode());
|
||||
this.setMessage(new String[] {ErrorCode.ERR_OK.getDescription()});
|
||||
}
|
||||
|
||||
public OperationLogDetails(Long id, ErrorCode error) {
|
||||
this.id = id;
|
||||
this.setStatus(error.getCode());
|
||||
|
|
|
@ -3,9 +3,11 @@ package com.cmhi.cf.restapi.pojo.vo;
|
|||
import com.cmhi.cf.restapi.pojo.base.BaseRespStatus;
|
||||
import com.cmhi.cf.restapi.pojo.po.OperationLogDetails;
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -13,6 +15,8 @@ import java.util.List;
|
|||
@Data
|
||||
@JsonPropertyOrder({"operationLog", "status", "message"})
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class OperationLogDetailsResp extends BaseRespStatus {
|
||||
private List<OperationLogDetails> operationLog;
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -5,6 +5,7 @@ import com.cmhi.cf.authentication.pojo.vo.LoginResp;
|
|||
import com.cmhi.cf.misc.HelperUtils;
|
||||
import com.cmhi.cf.restapi.config.ProtoCryptoType;
|
||||
import com.cmhi.cf.restapi.config.ProtocolConfigure;
|
||||
import com.cmhi.cf.restapi.pojo.base.BaseRespStatus;
|
||||
import com.cmhi.cf.restapi.pojo.dto.ProtocolReq;
|
||||
import com.cmhi.cf.restapi.pojo.vo.ProtocolResp;
|
||||
import com.cmhi.cf.restapi.service.ProtocolSecurityService;
|
||||
|
@ -155,4 +156,12 @@ public abstract class TestBaseAuthentication {
|
|||
Assertions.assertNotNull(str);
|
||||
Assertions.assertFalse(str.isEmpty());
|
||||
}
|
||||
|
||||
public <T extends BaseRespStatus> void AssertValidCommonResp(T resp) {
|
||||
Assertions.assertNotNull(resp);
|
||||
Assertions.assertNotNull(resp.getStatus());
|
||||
Assertions.assertNotNull(resp.getMessage());
|
||||
Assertions.assertNotEquals(resp.getMessage().length, 0);
|
||||
Assertions.assertEquals(resp.getStatus(), ErrorCode.ERR_OK.getCode());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.cmhi.cf.controller;
|
||||
|
||||
import com.cmhi.cf.common.ErrorCode;
|
||||
import com.cmhi.cf.common.TestBaseAuthentication;
|
||||
import com.cmhi.cf.restapi.pojo.vo.VersionResp;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
|
@ -18,12 +17,8 @@ public class CommonFrameworkApiTest extends TestBaseAuthentication {
|
|||
@Test
|
||||
void testGetVersion() throws Exception {
|
||||
VersionResp resp = (VersionResp) performanceRestful(RequestMethod.GET, null, "/api/version", new Class[]{VersionResp.class});
|
||||
Assertions.assertNotNull(resp);
|
||||
AssertValidCommonResp(resp);
|
||||
Assertions.assertNotNull(resp.getVersion());
|
||||
Assertions.assertNotNull(resp.getStatus());
|
||||
Assertions.assertNotNull(resp.getMessage());
|
||||
Assertions.assertNotEquals(resp.getMessage().length, 0);
|
||||
Assertions.assertEquals(resp.getStatus(), ErrorCode.ERR_OK.getCode());
|
||||
|
||||
Assertions.assertNotNull(resp.getVersion().getTagName());
|
||||
AssertValidString(resp.getVersion().getCommitId());
|
||||
|
@ -36,12 +31,8 @@ public class CommonFrameworkApiTest extends TestBaseAuthentication {
|
|||
@Test
|
||||
void testGetVersionV2() throws Exception {
|
||||
VersionResp resp = (VersionResp) performanceRestful(RequestMethod.POST, null, "/api/version", new Class[]{VersionResp.class});
|
||||
Assertions.assertNotNull(resp);
|
||||
AssertValidCommonResp(resp);
|
||||
Assertions.assertNotNull(resp.getVersion());
|
||||
Assertions.assertNotNull(resp.getStatus());
|
||||
Assertions.assertNotNull(resp.getMessage());
|
||||
Assertions.assertNotEquals(resp.getMessage().length, 0);
|
||||
Assertions.assertEquals(resp.getStatus(), ErrorCode.ERR_OK.getCode());
|
||||
|
||||
Assertions.assertNotNull(resp.getVersion().getTagName());
|
||||
AssertValidString(resp.getVersion().getCommitId());
|
||||
|
|
|
@ -3,23 +3,35 @@ package com.cmhi.cf.controller;
|
|||
import com.cmhi.cf.common.ErrorCode;
|
||||
import com.cmhi.cf.common.TestBaseAuthentication;
|
||||
import com.cmhi.cf.restapi.pojo.base.BasePageResultResp;
|
||||
import com.cmhi.cf.restapi.pojo.dto.OperationLogDetailsReq;
|
||||
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.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;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ExtendWith({SpringExtension.class})
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
|
||||
@Transactional
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
public class OperationLogApiTest extends TestBaseAuthentication {
|
||||
private final List<Long> optIdArray = new ArrayList<>();
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void testGetSummary() throws Exception {
|
||||
final long pageSize = 10L;
|
||||
final long pageNumber = 1L;
|
||||
|
@ -33,11 +45,7 @@ public class OperationLogApiTest extends TestBaseAuthentication {
|
|||
new Class[] {BasePageResultResp.class, OperationLogSummary.class});
|
||||
Assertions.assertNotNull(obj);
|
||||
BasePageResultResp<?> resp = (BasePageResultResp<?>) obj;
|
||||
Assertions.assertNotNull(resp);
|
||||
Assertions.assertNotNull(resp.getStatus());
|
||||
Assertions.assertNotNull(resp.getMessage());
|
||||
Assertions.assertNotEquals(resp.getMessage().length, 0);
|
||||
Assertions.assertEquals(resp.getStatus(), ErrorCode.ERR_OK.getCode());
|
||||
AssertValidCommonResp(resp);
|
||||
|
||||
Assertions.assertNotNull(resp.getItems());
|
||||
Assertions.assertFalse(resp.getItems().getItems().isEmpty());
|
||||
|
@ -65,16 +73,32 @@ public class OperationLogApiTest extends TestBaseAuthentication {
|
|||
AssertValidString(o.getRequestIp());
|
||||
AssertValidString(o.getHttpMethod());
|
||||
AssertValidString(o.getHttpPath());
|
||||
|
||||
optIdArray.add(o.getId());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void testGetDetails() throws Exception {
|
||||
Assertions.assertFalse(optIdArray.isEmpty());
|
||||
|
||||
}
|
||||
OperationLogDetailsReq req = new OperationLogDetailsReq(optIdArray);
|
||||
|
||||
@Test
|
||||
void testGetDetails_OperationLogServiceReturnsNoItems() throws Exception {
|
||||
Object obj = performanceRestful(RequestMethod.POST, req, "/api/operation/details",
|
||||
new Class[] {OperationLogDetailsResp.class});
|
||||
Assertions.assertNotNull(obj);
|
||||
OperationLogDetailsResp resp = (OperationLogDetailsResp) obj;
|
||||
AssertValidCommonResp(resp);
|
||||
Assertions.assertNotNull(resp.getOperationLog());
|
||||
Assertions.assertFalse(resp.getOperationLog().isEmpty());
|
||||
|
||||
resp.getOperationLog().forEach(k -> {
|
||||
Assertions.assertEquals(k.getStatus(), ErrorCode.ERR_OK.getCode());
|
||||
AssertValidString(k.getRequest());
|
||||
AssertValidString(k.getResult());
|
||||
AssertValidString(k.getRequestHeaders());
|
||||
Assertions.assertNotNull(k.getId());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,97 @@
|
|||
package com.cmhi.cf.controller;
|
||||
|
||||
import com.cmhi.cf.authentication.pojo.vo.UserResPermInfoResp;
|
||||
import com.cmhi.cf.common.TestBaseAuthentication;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
@ExtendWith({SpringExtension.class})
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
|
||||
@Transactional
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class PermissionManagerApiTest extends TestBaseAuthentication {
|
||||
@Test
|
||||
void testGetCurrentUserResourcePermission() throws Exception {
|
||||
UserResPermInfoResp resp = (UserResPermInfoResp) performanceRestful(RequestMethod.GET, null, "/api/permission/resourcePermission",
|
||||
new Class[] {UserResPermInfoResp.class});
|
||||
AssertValidCommonResp(resp);
|
||||
Assertions.assertNotNull(resp.getResPermission());
|
||||
AssertValidString(resp.getUserId());
|
||||
AssertValidString(resp.getUsername());
|
||||
|
||||
Assertions.assertFalse(resp.getResPermission().isEmpty());
|
||||
|
||||
resp.getResPermission().forEach(k -> {
|
||||
Assertions.assertNotNull(k.getId());
|
||||
AssertValidString(k.getHttpMethod());
|
||||
AssertValidString(k.getPath());
|
||||
AssertValidString(k.getName());
|
||||
Assertions.assertNotNull(k.getResTypeId());
|
||||
Assertions.assertNotNull(k.getEnable());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetCurrentUserResourcePermission_AuthUsersServiceReturnsNull() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetCurrentUserResourcePermission_UserServiceReturnsNoItems() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetUserResourcePermission() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetUserResourcePermission_UserServiceGetAccountUserByUidReturnsNull() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetUserResourcePermission_UserServiceGetUserResourcePermReturnsNoItems() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetAllRoles() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetAllRoles_RoleMapperReturnsNoItems() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRegisterResource() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRegisterResource_UserServiceReturnsNoItems() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRemoveResourceById() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRemoveResourceById_UserServiceReturnsNoItems() throws Exception {
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue