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 com.houkunlin.system.dict.starter.json.DictText;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
@Schema(name = "资源权限信息")
|
@Schema(name = "资源权限信息")
|
||||||
@Data
|
@Data
|
||||||
@Builder
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
public class ResPermInfo {
|
public class ResPermInfo {
|
||||||
@Schema(description = "资源id")
|
@Schema(description = "资源id")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
|
@ -154,9 +154,7 @@ public class HelperUtils {
|
||||||
|
|
||||||
private static Type createRespType(Class<?>[] c) {
|
private static Type createRespType(Class<?>[] c) {
|
||||||
if (c.length == 1) {
|
if (c.length == 1) {
|
||||||
return JsonParameterizedType.make(ProtocolResp.class,
|
return createRespType(c[0]);
|
||||||
new Type[] {c[0]},
|
|
||||||
ProtocolResp.class.getDeclaringClass());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Stack<Class<?>> st = new Stack<>();
|
Stack<Class<?>> st = new Stack<>();
|
||||||
|
|
|
@ -8,11 +8,13 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
@Schema(name = "系统操作日志详细信息")
|
@Schema(name = "系统操作日志详细信息")
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
@JsonPropertyOrder({"id", "requestHeaders", "request", "result", "status", "message"})
|
@JsonPropertyOrder({"id", "requestHeaders", "request", "result", "status", "message"})
|
||||||
public class OperationLogDetails extends BaseRespStatus {
|
public class OperationLogDetails extends BaseRespStatus {
|
||||||
|
@ -28,11 +30,6 @@ public class OperationLogDetails extends BaseRespStatus {
|
||||||
@Schema(description = "操作返回结果")
|
@Schema(description = "操作返回结果")
|
||||||
private String result;
|
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) {
|
public OperationLogDetails(Long id, ErrorCode error) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.setStatus(error.getCode());
|
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.base.BaseRespStatus;
|
||||||
import com.cmhi.cf.restapi.pojo.po.OperationLogDetails;
|
import com.cmhi.cf.restapi.pojo.po.OperationLogDetails;
|
||||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -13,6 +15,8 @@ import java.util.List;
|
||||||
@Data
|
@Data
|
||||||
@JsonPropertyOrder({"operationLog", "status", "message"})
|
@JsonPropertyOrder({"operationLog", "status", "message"})
|
||||||
@Builder
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
public class OperationLogDetailsResp extends BaseRespStatus {
|
public class OperationLogDetailsResp extends BaseRespStatus {
|
||||||
private List<OperationLogDetails> operationLog;
|
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.misc.HelperUtils;
|
||||||
import com.cmhi.cf.restapi.config.ProtoCryptoType;
|
import com.cmhi.cf.restapi.config.ProtoCryptoType;
|
||||||
import com.cmhi.cf.restapi.config.ProtocolConfigure;
|
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.dto.ProtocolReq;
|
||||||
import com.cmhi.cf.restapi.pojo.vo.ProtocolResp;
|
import com.cmhi.cf.restapi.pojo.vo.ProtocolResp;
|
||||||
import com.cmhi.cf.restapi.service.ProtocolSecurityService;
|
import com.cmhi.cf.restapi.service.ProtocolSecurityService;
|
||||||
|
@ -155,4 +156,12 @@ public abstract class TestBaseAuthentication {
|
||||||
Assertions.assertNotNull(str);
|
Assertions.assertNotNull(str);
|
||||||
Assertions.assertFalse(str.isEmpty());
|
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;
|
package com.cmhi.cf.controller;
|
||||||
|
|
||||||
import com.cmhi.cf.common.ErrorCode;
|
|
||||||
import com.cmhi.cf.common.TestBaseAuthentication;
|
import com.cmhi.cf.common.TestBaseAuthentication;
|
||||||
import com.cmhi.cf.restapi.pojo.vo.VersionResp;
|
import com.cmhi.cf.restapi.pojo.vo.VersionResp;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
@ -18,12 +17,8 @@ public class CommonFrameworkApiTest extends TestBaseAuthentication {
|
||||||
@Test
|
@Test
|
||||||
void testGetVersion() throws Exception {
|
void testGetVersion() throws Exception {
|
||||||
VersionResp resp = (VersionResp) performanceRestful(RequestMethod.GET, null, "/api/version", new Class[]{VersionResp.class});
|
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.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());
|
Assertions.assertNotNull(resp.getVersion().getTagName());
|
||||||
AssertValidString(resp.getVersion().getCommitId());
|
AssertValidString(resp.getVersion().getCommitId());
|
||||||
|
@ -36,12 +31,8 @@ public class CommonFrameworkApiTest extends TestBaseAuthentication {
|
||||||
@Test
|
@Test
|
||||||
void testGetVersionV2() throws Exception {
|
void testGetVersionV2() throws Exception {
|
||||||
VersionResp resp = (VersionResp) performanceRestful(RequestMethod.POST, null, "/api/version", new Class[]{VersionResp.class});
|
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.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());
|
Assertions.assertNotNull(resp.getVersion().getTagName());
|
||||||
AssertValidString(resp.getVersion().getCommitId());
|
AssertValidString(resp.getVersion().getCommitId());
|
||||||
|
|
|
@ -3,23 +3,35 @@ package com.cmhi.cf.controller;
|
||||||
import com.cmhi.cf.common.ErrorCode;
|
import com.cmhi.cf.common.ErrorCode;
|
||||||
import com.cmhi.cf.common.TestBaseAuthentication;
|
import com.cmhi.cf.common.TestBaseAuthentication;
|
||||||
import com.cmhi.cf.restapi.pojo.base.BasePageResultResp;
|
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.dto.OperationLogReq;
|
||||||
import com.cmhi.cf.restapi.pojo.po.OperationLogSummary;
|
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.Assertions;
|
||||||
|
import org.junit.jupiter.api.MethodOrderer;
|
||||||
|
import org.junit.jupiter.api.Order;
|
||||||
import org.junit.jupiter.api.Test;
|
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.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ExtendWith({SpringExtension.class})
|
@ExtendWith({SpringExtension.class})
|
||||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
|
||||||
@Transactional
|
@Transactional
|
||||||
|
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||||
|
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||||
public class OperationLogApiTest extends TestBaseAuthentication {
|
public class OperationLogApiTest extends TestBaseAuthentication {
|
||||||
|
private final List<Long> optIdArray = new ArrayList<>();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Order(1)
|
||||||
void testGetSummary() throws Exception {
|
void testGetSummary() throws Exception {
|
||||||
final long pageSize = 10L;
|
final long pageSize = 10L;
|
||||||
final long pageNumber = 1L;
|
final long pageNumber = 1L;
|
||||||
|
@ -33,11 +45,7 @@ public class OperationLogApiTest extends TestBaseAuthentication {
|
||||||
new Class[] {BasePageResultResp.class, OperationLogSummary.class});
|
new Class[] {BasePageResultResp.class, OperationLogSummary.class});
|
||||||
Assertions.assertNotNull(obj);
|
Assertions.assertNotNull(obj);
|
||||||
BasePageResultResp<?> resp = (BasePageResultResp<?>) obj;
|
BasePageResultResp<?> resp = (BasePageResultResp<?>) obj;
|
||||||
Assertions.assertNotNull(resp);
|
AssertValidCommonResp(resp);
|
||||||
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.getItems());
|
Assertions.assertNotNull(resp.getItems());
|
||||||
Assertions.assertFalse(resp.getItems().getItems().isEmpty());
|
Assertions.assertFalse(resp.getItems().getItems().isEmpty());
|
||||||
|
@ -65,16 +73,32 @@ public class OperationLogApiTest extends TestBaseAuthentication {
|
||||||
AssertValidString(o.getRequestIp());
|
AssertValidString(o.getRequestIp());
|
||||||
AssertValidString(o.getHttpMethod());
|
AssertValidString(o.getHttpMethod());
|
||||||
AssertValidString(o.getHttpPath());
|
AssertValidString(o.getHttpPath());
|
||||||
|
|
||||||
|
optIdArray.add(o.getId());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Order(2)
|
||||||
void testGetDetails() throws Exception {
|
void testGetDetails() throws Exception {
|
||||||
|
Assertions.assertFalse(optIdArray.isEmpty());
|
||||||
|
|
||||||
}
|
OperationLogDetailsReq req = new OperationLogDetailsReq(optIdArray);
|
||||||
|
|
||||||
@Test
|
Object obj = performanceRestful(RequestMethod.POST, req, "/api/operation/details",
|
||||||
void testGetDetails_OperationLogServiceReturnsNoItems() throws Exception {
|
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