Compare commits
3 Commits
3fd2ce5e44
...
e4aeb9b3cf
Author | SHA1 | Date |
---|---|---|
黄昕 | e4aeb9b3cf | |
黄昕 | d38a21094e | |
黄昕 | 8f314bcf79 |
|
@ -5,6 +5,7 @@ import com.cmhi.cf.restapi.pojo.base.BaseRespStatus;
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
@ -12,6 +13,7 @@ import lombok.NoArgsConstructor;
|
||||||
@Schema(name = "资源操作结果")
|
@Schema(name = "资源操作结果")
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
@Data
|
@Data
|
||||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
@JsonPropertyOrder({"rid", "path", "resTypeId", "httpMethod", "status", "message"})
|
@JsonPropertyOrder({"rid", "path", "resTypeId", "httpMethod", "status", "message"})
|
||||||
|
|
|
@ -6,14 +6,18 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import jakarta.validation.constraints.Size;
|
import jakarta.validation.constraints.Size;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Schema(name = "资源信息")
|
@Schema(name = "资源信息")
|
||||||
@Data
|
@Data
|
||||||
@Builder
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
public class ResourceInfo {
|
public class ResourceInfo {
|
||||||
@Schema(description = "资源路径")
|
@Schema(description = "资源路径")
|
||||||
@NotNull(message = "path 资源 URL 不能为 NULL", groups = ValidGroups.ResourceInfoValid.class)
|
@NotNull(message = "path 资源 URL 不能为 NULL", groups = ValidGroups.ResourceInfoValid.class)
|
||||||
|
|
|
@ -4,9 +4,11 @@ import com.cmhi.cf.database.authentication.entity.Role;
|
||||||
import com.cmhi.cf.restapi.pojo.base.BaseRespStatus;
|
import com.cmhi.cf.restapi.pojo.base.BaseRespStatus;
|
||||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||||
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.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -15,6 +17,8 @@ import java.util.List;
|
||||||
@Data
|
@Data
|
||||||
@Builder
|
@Builder
|
||||||
@JsonPropertyOrder({"roles", "status", "message"})
|
@JsonPropertyOrder({"roles", "status", "message"})
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
public class GetRoleResp extends BaseRespStatus {
|
public class GetRoleResp extends BaseRespStatus {
|
||||||
@Schema(description = "当前用户组")
|
@Schema(description = "当前用户组")
|
||||||
private List<Role> roles;
|
private List<Role> roles;
|
||||||
|
|
|
@ -5,7 +5,9 @@ import com.mybatisflex.annotation.Id;
|
||||||
import com.mybatisflex.annotation.KeyType;
|
import com.mybatisflex.annotation.KeyType;
|
||||||
import com.mybatisflex.annotation.Table;
|
import com.mybatisflex.annotation.Table;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 权限(Role)表实体类
|
* 权限(Role)表实体类
|
||||||
|
@ -16,6 +18,8 @@ import lombok.Data;
|
||||||
@Data
|
@Data
|
||||||
@Schema(name = "Role", description = "权限")
|
@Schema(name = "Role", description = "权限")
|
||||||
@Table("rbac_role")
|
@Table("rbac_role")
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
public class Role {
|
public class Role {
|
||||||
/**
|
/**
|
||||||
* id
|
* id
|
||||||
|
|
|
@ -212,11 +212,17 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||||
.enable(k.getAuthorize())
|
.enable(k.getAuthorize())
|
||||||
.build()));
|
.build()));
|
||||||
|
|
||||||
res = resDataMapper.selectAll().stream().filter(
|
res = resDataMapper.selectAllWithRelations().stream().filter(
|
||||||
k -> roleRes.stream().noneMatch(m -> m.getResources().getPath().equals(k.getPath()))).toList();
|
k -> roleRes.stream().noneMatch(m -> m.getResources().getPath().equals(k.getPath()))).toList();
|
||||||
|
|
||||||
res.forEach(k -> result.add(ResPermInfo.builder().id(k.getId()).name(k.getName()).path(k.getPath()).httpMethod(
|
res.forEach(k -> result.add(ResPermInfo.builder()
|
||||||
k.getHttpMethod()).enable(false).build()));
|
.id(k.getId())
|
||||||
|
.name(k.getName())
|
||||||
|
.path(k.getPath())
|
||||||
|
.httpMethod(k.getHttpMethod())
|
||||||
|
.resTypeId(k.getResType().getTypeId())
|
||||||
|
.enable(false)
|
||||||
|
.build()));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -253,11 +259,17 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||||
.enable(k.getAuthorize())
|
.enable(k.getAuthorize())
|
||||||
.build()));
|
.build()));
|
||||||
|
|
||||||
res = resDataMapper.selectAll().stream().filter(
|
res = resDataMapper.selectAllWithRelations().stream().filter(
|
||||||
k -> roleRes.stream().noneMatch(m -> m.getResources().getPath().equals(k.getPath()))).toList();
|
k -> roleRes.stream().noneMatch(m -> m.getResources().getPath().equals(k.getPath()))).toList();
|
||||||
|
|
||||||
res.forEach(k -> result.add(ResPermInfo.builder().id(k.getId()).name(k.getName()).path(k.getPath()).httpMethod(
|
res.forEach(k -> result.add(ResPermInfo.builder()
|
||||||
k.getHttpMethod()).enable(false).build()));
|
.id(k.getId())
|
||||||
|
.name(k.getName())
|
||||||
|
.path(k.getPath())
|
||||||
|
.resTypeId(k.getResType().getTypeId())
|
||||||
|
.httpMethod(k.getHttpMethod())
|
||||||
|
.enable(false)
|
||||||
|
.build()));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
package com.cmhi.cf.restapi.config;
|
package com.cmhi.cf.restapi.config;
|
||||||
|
|
||||||
import com.cmhi.cf.common.BaseEnum;
|
import com.cmhi.cf.common.BaseEnum;
|
||||||
|
import com.houkunlin.system.dict.starter.DictEnum;
|
||||||
|
import com.houkunlin.system.dict.starter.json.DictType;
|
||||||
|
|
||||||
public enum ProtoCryptoType implements BaseEnum {
|
@DictType(value = "ProtoCryptoType", comment = "协议加密类型")
|
||||||
|
public enum ProtoCryptoType implements BaseEnum, DictEnum<Integer> {
|
||||||
CRYPTO_NONE(0, "不加密"),
|
CRYPTO_NONE(0, "不加密"),
|
||||||
CRYPTO_BASE64(1, "Base64编码"),
|
CRYPTO_BASE64(1, "Base64编码"),
|
||||||
CRYPTO_AES128(2, "AES128加密"),
|
CRYPTO_AES128(2, "AES128加密"),
|
||||||
|
@ -27,6 +30,11 @@ public enum ProtoCryptoType implements BaseEnum {
|
||||||
return this.code;
|
return this.code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTitle() {
|
||||||
|
return this.readme;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return this.readme;
|
return this.readme;
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
import com.cmhi.cf.controller.CommonFrameworkApiTest;
|
import com.cmhi.cf.controller.CommonFrameworkApiTest;
|
||||||
import com.cmhi.cf.controller.OperationLogApiTest;
|
import com.cmhi.cf.controller.OperationLogApiTest;
|
||||||
|
import com.cmhi.cf.controller.PermissionManagerApiTest;
|
||||||
import org.junit.jupiter.api.DisplayName;
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.platform.suite.api.SelectClasses;
|
import org.junit.platform.suite.api.SelectClasses;
|
||||||
import org.junit.platform.suite.api.Suite;
|
import org.junit.platform.suite.api.Suite;
|
||||||
|
|
||||||
@SelectClasses({CommonFrameworkApiTest.class, OperationLogApiTest.class})
|
@SelectClasses({CommonFrameworkApiTest.class,
|
||||||
|
OperationLogApiTest.class,
|
||||||
|
PermissionManagerApiTest.class})
|
||||||
@DisplayName("接口集成测试")
|
@DisplayName("接口集成测试")
|
||||||
@Suite
|
@Suite
|
||||||
public class IntegrationTestSuite {
|
public class IntegrationTestSuite {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.cmhi.cf.controller;
|
||||||
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;
|
||||||
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
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;
|
||||||
|
@ -15,6 +16,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
@Transactional
|
@Transactional
|
||||||
public class CommonFrameworkApiTest extends TestBaseAuthentication {
|
public class CommonFrameworkApiTest extends TestBaseAuthentication {
|
||||||
@Test
|
@Test
|
||||||
|
@DisplayName("获取版本信息")
|
||||||
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});
|
||||||
AssertValidCommonResp(resp);
|
AssertValidCommonResp(resp);
|
||||||
|
@ -29,6 +31,7 @@ public class CommonFrameworkApiTest extends TestBaseAuthentication {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisplayName("获取版本信息(POST)")
|
||||||
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});
|
||||||
AssertValidCommonResp(resp);
|
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.po.OperationLogSummary;
|
||||||
import com.cmhi.cf.restapi.pojo.vo.OperationLogDetailsResp;
|
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.DisplayName;
|
||||||
import org.junit.jupiter.api.MethodOrderer;
|
import org.junit.jupiter.api.MethodOrderer;
|
||||||
import org.junit.jupiter.api.Order;
|
import org.junit.jupiter.api.Order;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
@ -32,6 +33,7 @@ public class OperationLogApiTest extends TestBaseAuthentication {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(1)
|
@Order(1)
|
||||||
|
@DisplayName("获取操作日志摘要(分页)")
|
||||||
void testGetSummary() throws Exception {
|
void testGetSummary() throws Exception {
|
||||||
final long pageSize = 10L;
|
final long pageSize = 10L;
|
||||||
final long pageNumber = 1L;
|
final long pageNumber = 1L;
|
||||||
|
@ -80,6 +82,7 @@ public class OperationLogApiTest extends TestBaseAuthentication {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(2)
|
@Order(2)
|
||||||
|
@DisplayName("获取操作日志详情")
|
||||||
void testGetDetails() throws Exception {
|
void testGetDetails() throws Exception {
|
||||||
Assertions.assertFalse(optIdArray.isEmpty());
|
Assertions.assertFalse(optIdArray.isEmpty());
|
||||||
|
|
||||||
|
|
|
@ -1,25 +1,46 @@
|
||||||
package com.cmhi.cf.controller;
|
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;
|
import com.cmhi.cf.authentication.pojo.vo.UserResPermInfoResp;
|
||||||
|
import com.cmhi.cf.common.ErrorCode;
|
||||||
import com.cmhi.cf.common.TestBaseAuthentication;
|
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.Assertions;
|
||||||
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.jupiter.api.MethodOrderer;
|
import org.junit.jupiter.api.MethodOrderer;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.TestInstance;
|
import org.junit.jupiter.api.TestInstance;
|
||||||
import org.junit.jupiter.api.TestMethodOrder;
|
import org.junit.jupiter.api.TestMethodOrder;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
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.UUID;
|
||||||
|
|
||||||
@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)
|
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.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;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisplayName("获取当前用户资源信息")
|
||||||
void testGetCurrentUserResourcePermission() throws Exception {
|
void testGetCurrentUserResourcePermission() throws Exception {
|
||||||
UserResPermInfoResp resp = (UserResPermInfoResp) performanceRestful(RequestMethod.GET, null, "/api/permission/resourcePermission",
|
UserResPermInfoResp resp = (UserResPermInfoResp) performanceRestful(RequestMethod.GET, null, "/api/permission/resourcePermission",
|
||||||
new Class[] {UserResPermInfoResp.class});
|
new Class[] {UserResPermInfoResp.class});
|
||||||
|
@ -41,57 +62,163 @@ class PermissionManagerApiTest extends TestBaseAuthentication {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testGetCurrentUserResourcePermission_AuthUsersServiceReturnsNull() throws Exception {
|
@DisplayName("获取用户资源信息")
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testGetCurrentUserResourcePermission_UserServiceReturnsNoItems() throws Exception {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testGetUserResourcePermission() throws Exception {
|
void testGetUserResourcePermission() throws Exception {
|
||||||
|
User user = userService.getAccountUserByName("admin");
|
||||||
|
Assertions.assertNotNull(user);
|
||||||
|
AssertValidString(user.getUid());
|
||||||
|
UserResPermInfoResp resp = (UserResPermInfoResp) performanceRestful(RequestMethod.POST, new UserIdReq(user.getUid()),
|
||||||
|
"/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
|
@Test
|
||||||
void testGetUserResourcePermission_UserServiceGetAccountUserByUidReturnsNull() throws Exception {
|
@DisplayName("不存在的用户获取资源信息")
|
||||||
|
void testGetUserResourcePermission_UserServiceGetAccountUserByUidReturnsNull() {
|
||||||
|
User user = userService.getAccountUserByUid("ff99fd68-14bf-4fd6-9320-bab85839245c");
|
||||||
|
Assertions.assertNull(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisplayName("获取用户资源信息, 当前用户无资源")
|
||||||
void testGetUserResourcePermission_UserServiceGetUserResourcePermReturnsNoItems() throws Exception {
|
void testGetUserResourcePermission_UserServiceGetUserResourcePermReturnsNoItems() throws Exception {
|
||||||
|
User user = userService.getAccountUserByName("guest");
|
||||||
|
Assertions.assertNotNull(user);
|
||||||
|
AssertValidString(user.getUid());
|
||||||
|
UserResPermInfoResp resp = (UserResPermInfoResp) performanceRestful(RequestMethod.POST, new UserIdReq(user.getUid()),
|
||||||
|
"/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());
|
||||||
|
Assertions.assertFalse(k.getEnable());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisplayName("获取当前所有用户组")
|
||||||
void testGetAllRoles() throws Exception {
|
void testGetAllRoles() throws Exception {
|
||||||
|
GetRoleResp resp = (GetRoleResp) performanceRestful(RequestMethod.GET, null, "/api/permission/allRoles",
|
||||||
}
|
new Class[] {GetRoleResp.class});
|
||||||
|
AssertValidCommonResp(resp);
|
||||||
@Test
|
Assertions.assertNotNull(resp.getRoles());
|
||||||
void testGetAllRoles_RoleMapperReturnsNoItems() throws Exception {
|
Assertions.assertFalse(resp.getRoles().isEmpty());
|
||||||
|
resp.getRoles().forEach(k -> {
|
||||||
}
|
Assertions.assertNotNull(k.getId());
|
||||||
|
AssertValidString(k.getDescription());
|
||||||
@Test
|
Assertions.assertNotNull(k.getName());
|
||||||
void testRegisterResource() throws Exception {
|
Assertions.assertNotNull(k.getAvailable());
|
||||||
|
});
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testRegisterResource_UserServiceReturnsNoItems() throws Exception {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testRemoveResourceById() throws Exception {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisplayName("删除不存在的资源")
|
||||||
void testRemoveResourceById_UserServiceReturnsNoItems() throws Exception {
|
void testRemoveResourceById_UserServiceReturnsNoItems() throws Exception {
|
||||||
|
List<String> rid = new ArrayList<>();
|
||||||
|
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
rid.add(UUID.randomUUID().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
IdArrayReq req = new IdArrayReq(rid);
|
||||||
|
|
||||||
|
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());
|
||||||
|
|
||||||
|
resp.getResult().forEach(k -> {
|
||||||
|
Assertions.assertEquals(k.getStatus(), ErrorCode.ERR_NOSUCHITEM.getCode());
|
||||||
|
Assertions.assertNotNull(k.getRid());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@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
|
||||||
|
@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