Compare commits
2 Commits
09d32a7796
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| bb5937c5b7 | |||
| 454e444632 |
@@ -40,7 +40,7 @@ public class CacheUtils {
|
|||||||
// 只阻塞当前数据加载线程,其他线程返回旧值
|
// 只阻塞当前数据加载线程,其他线程返回旧值
|
||||||
.refreshAfterWrite(duration)
|
.refreshAfterWrite(duration)
|
||||||
// 通过 asyncReloading 实现全异步加载,包括 refreshAfterWrite 被阻塞的加载线程
|
// 通过 asyncReloading 实现全异步加载,包括 refreshAfterWrite 被阻塞的加载线程
|
||||||
.build(CacheLoader.asyncReloading(loader, Executors.newCachedThreadPool())); // TODO 芋艿:可能要思考下,未来要不要做成可配置
|
.build(CacheLoader.asyncReloading(loader, Executors.newCachedThreadPool())); // TODO 鹭鹭:可能要思考下,未来要不要做成可配置
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ public class DeptDataPermissionRule implements DataPermissionRule {
|
|||||||
Expression deptExpression = buildDeptExpression(tableName,tableAlias, deptDataPermission.getDeptIds());
|
Expression deptExpression = buildDeptExpression(tableName,tableAlias, deptDataPermission.getDeptIds());
|
||||||
Expression userExpression = buildUserExpression(tableName, tableAlias, deptDataPermission.getSelf(), loginUser.getId());
|
Expression userExpression = buildUserExpression(tableName, tableAlias, deptDataPermission.getSelf(), loginUser.getId());
|
||||||
if (deptExpression == null && userExpression == null) {
|
if (deptExpression == null && userExpression == null) {
|
||||||
// TODO 芋艿:获得不到条件的时候,暂时不抛出异常,而是不返回数据
|
// TODO 鹭鹭:获得不到条件的时候,暂时不抛出异常,而是不返回数据
|
||||||
log.warn("[getExpression][LoginUser({}) Table({}/{}) DeptDataPermission({}) 构建的条件为空]",
|
log.warn("[getExpression][LoginUser({}) Table({}/{}) DeptDataPermission({}) 构建的条件为空]",
|
||||||
JsonUtils.toJsonString(loginUser), tableName, tableAlias, JsonUtils.toJsonString(deptDataPermission));
|
JsonUtils.toJsonString(loginUser), tableName, tableAlias, JsonUtils.toJsonString(deptDataPermission));
|
||||||
// throw new NullPointerException(String.format("LoginUser(%d) Table(%s/%s) 构建的条件为空",
|
// throw new NullPointerException(String.format("LoginUser(%d) Table(%s/%s) 构建的条件为空",
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ public class TenantJobAspect {
|
|||||||
// 逐个租户,执行 Job
|
// 逐个租户,执行 Job
|
||||||
Map<Long, String> results = new ConcurrentHashMap<>();
|
Map<Long, String> results = new ConcurrentHashMap<>();
|
||||||
tenantIds.parallelStream().forEach(tenantId -> {
|
tenantIds.parallelStream().forEach(tenantId -> {
|
||||||
// TODO 芋艿:先通过 parallel 实现并行;1)多个租户,是一条执行日志;2)异常的情况
|
// TODO 鹭鹭:先通过 parallel 实现并行;1)多个租户,是一条执行日志;2)异常的情况
|
||||||
TenantUtils.execute(tenantId, () -> {
|
TenantUtils.execute(tenantId, () -> {
|
||||||
try {
|
try {
|
||||||
Object result = joinPoint.proceed();
|
Object result = joinPoint.proceed();
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ import static cn.iocoder.lyzsys.framework.web.core.util.WebFrameworkUtils.HEADER
|
|||||||
* {@link HandlerMethodArgumentResolver}.
|
* {@link HandlerMethodArgumentResolver}.
|
||||||
*
|
*
|
||||||
* 针对 rabbitmq-spring 和 kafka-spring,不存在合适的拓展点,可以实现 Consumer 消费前,读取 Header 中的 tenant-id 设置到 {@link TenantContextHolder} 中
|
* 针对 rabbitmq-spring 和 kafka-spring,不存在合适的拓展点,可以实现 Consumer 消费前,读取 Header 中的 tenant-id 设置到 {@link TenantContextHolder} 中
|
||||||
* TODO 芋艿:持续跟进,看看有没新的拓展点
|
* TODO 鹭鹭:持续跟进,看看有没新的拓展点
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import org.springframework.context.annotation.Bean;
|
|||||||
@ConditionalOnProperty(prefix = "lyzsys.tracer", value = "enable", matchIfMissing = true)
|
@ConditionalOnProperty(prefix = "lyzsys.tracer", value = "enable", matchIfMissing = true)
|
||||||
public class LyzsysTracerAutoConfiguration {
|
public class LyzsysTracerAutoConfiguration {
|
||||||
|
|
||||||
// TODO @芋艿:skywalking 不兼容最新的 opentracing 版本。同时,opentracing 也停止了维护,尬住了!后续换 opentelemetry 即可!
|
// TODO @鹭鹭:skywalking 不兼容最新的 opentracing 版本。同时,opentracing 也停止了维护,尬住了!后续换 opentelemetry 即可!
|
||||||
// @Bean
|
// @Bean
|
||||||
// public BizTraceAspect bizTracingAop() {
|
// public BizTraceAspect bizTracingAop() {
|
||||||
// return new BizTraceAspect(tracer());
|
// return new BizTraceAspect(tracer());
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ public abstract class AbstractRedisStreamMessageListener<T extends AbstractRedis
|
|||||||
this.onMessage(messageObj);
|
this.onMessage(messageObj);
|
||||||
// ack 消息消费完成
|
// ack 消息消费完成
|
||||||
redisMQTemplate.getRedisTemplate().opsForStream().acknowledge(group, message);
|
redisMQTemplate.getRedisTemplate().opsForStream().acknowledge(group, message);
|
||||||
// TODO 芋艿:需要额外考虑以下几个点:
|
// TODO 鹭鹭:需要额外考虑以下几个点:
|
||||||
// 1. 处理异常的情况
|
// 1. 处理异常的情况
|
||||||
// 2. 发送日志;以及事务的结合
|
// 2. 发送日志;以及事务的结合
|
||||||
// 3. 消费日志;以及通用的幂等性
|
// 3. 消费日志;以及通用的幂等性
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ public class IdTypeEnvironmentPostProcessor implements EnvironmentPostProcessor
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 设置 Quartz JobStore 对应的 Driver
|
// 设置 Quartz JobStore 对应的 Driver
|
||||||
// TODO 芋艿:暂时没有找到特别合适的地方,先放在这里
|
// TODO 鹭鹭:暂时没有找到特别合适的地方,先放在这里
|
||||||
setJobStoreDriverIfPresent(environment, dbType);
|
setJobStoreDriverIfPresent(environment, dbType);
|
||||||
|
|
||||||
// 如果非 NONE,则不进行处理
|
// 如果非 NONE,则不进行处理
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ public class QueryWrapperX<T> extends QueryWrapper<T> {
|
|||||||
/**
|
/**
|
||||||
* 设置只返回最后一条
|
* 设置只返回最后一条
|
||||||
*
|
*
|
||||||
* TODO 芋艿:不是完美解,需要在思考下。如果使用多数据源,并且数据源是多种类型时,可能会存在问题:实现之返回一条的语法不同
|
* TODO 鹭鹭:不是完美解,需要在思考下。如果使用多数据源,并且数据源是多种类型时,可能会存在问题:实现之返回一条的语法不同
|
||||||
*
|
*
|
||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ public class DesensitizeTest {
|
|||||||
DesensitizeDemo d = JsonUtils.parseObject(JsonUtils.toJsonString(desensitizeDemo), DesensitizeDemo.class);
|
DesensitizeDemo d = JsonUtils.parseObject(JsonUtils.toJsonString(desensitizeDemo), DesensitizeDemo.class);
|
||||||
// 断言
|
// 断言
|
||||||
assertNotNull(d);
|
assertNotNull(d);
|
||||||
assertEquals("芋***", d.getNickname());
|
assertEquals("l****", d.getNickname());
|
||||||
assertEquals("998800********31", d.getBankCard());
|
assertEquals("998800********31", d.getBankCard());
|
||||||
assertEquals("粤A6***6", d.getCarLicense());
|
assertEquals("粤A6***6", d.getCarLicense());
|
||||||
assertEquals("0108*****22", d.getFixedPhone());
|
assertEquals("0108*****22", d.getFixedPhone());
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import static cn.iocoder.lyzsys.framework.common.util.date.DateUtils.FORMAT_YEAR
|
|||||||
@Data
|
@Data
|
||||||
public class Demo02CategoryListReqVO {
|
public class Demo02CategoryListReqVO {
|
||||||
|
|
||||||
@Schema(description = "名字", example = "芋艿")
|
@Schema(description = "名字", example = "鹭鹭")
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@Schema(description = "父级编号", example = "6080")
|
@Schema(description = "父级编号", example = "6080")
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ public class Demo02CategoryRespVO {
|
|||||||
@ExcelProperty("编号")
|
@ExcelProperty("编号")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
|
@Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "鹭鹭")
|
||||||
@ExcelProperty("名字")
|
@ExcelProperty("名字")
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ public class Demo02CategorySaveReqVO {
|
|||||||
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10304")
|
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10304")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
|
@Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "鹭鹭")
|
||||||
@NotEmpty(message = "名字不能为空")
|
@NotEmpty(message = "名字不能为空")
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import static cn.iocoder.lyzsys.framework.common.util.date.DateUtils.FORMAT_YEAR
|
|||||||
@Data
|
@Data
|
||||||
public class Demo03StudentErpPageReqVO extends PageParam {
|
public class Demo03StudentErpPageReqVO extends PageParam {
|
||||||
|
|
||||||
@Schema(description = "名字", example = "芋艿")
|
@Schema(description = "名字", example = "鹭鹭")
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@Schema(description = "性别")
|
@Schema(description = "性别")
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ public class Demo03StudentErpRespVO {
|
|||||||
@ExcelProperty("编号")
|
@ExcelProperty("编号")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
|
@Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "鹭鹭")
|
||||||
@ExcelProperty("名字")
|
@ExcelProperty("名字")
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ public class Demo03StudentErpSaveReqVO {
|
|||||||
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8525")
|
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8525")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
|
@Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "鹭鹭")
|
||||||
@NotEmpty(message = "名字不能为空")
|
@NotEmpty(message = "名字不能为空")
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import static cn.iocoder.lyzsys.framework.common.util.date.DateUtils.FORMAT_YEAR
|
|||||||
@Data
|
@Data
|
||||||
public class Demo03StudentInnerPageReqVO extends PageParam {
|
public class Demo03StudentInnerPageReqVO extends PageParam {
|
||||||
|
|
||||||
@Schema(description = "名字", example = "芋艿")
|
@Schema(description = "名字", example = "鹭鹭")
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@Schema(description = "性别")
|
@Schema(description = "性别")
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ public class Demo03StudentInnerRespVO {
|
|||||||
@ExcelProperty("编号")
|
@ExcelProperty("编号")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
|
@Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "鹭鹭")
|
||||||
@ExcelProperty("名字")
|
@ExcelProperty("名字")
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ public class Demo03StudentInnerSaveReqVO {
|
|||||||
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8525")
|
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8525")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
|
@Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "鹭鹭")
|
||||||
@NotEmpty(message = "名字不能为空")
|
@NotEmpty(message = "名字不能为空")
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import static cn.iocoder.lyzsys.framework.common.util.date.DateUtils.FORMAT_YEAR
|
|||||||
@Data
|
@Data
|
||||||
public class Demo03StudentNormalPageReqVO extends PageParam {
|
public class Demo03StudentNormalPageReqVO extends PageParam {
|
||||||
|
|
||||||
@Schema(description = "名字", example = "芋艿")
|
@Schema(description = "名字", example = "鹭鹭")
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@Schema(description = "性别")
|
@Schema(description = "性别")
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ public class Demo03StudentNormalRespVO {
|
|||||||
@ExcelProperty("编号")
|
@ExcelProperty("编号")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
|
@Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "鹭鹭")
|
||||||
@ExcelProperty("名字")
|
@ExcelProperty("名字")
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ public class Demo03StudentNormalSaveReqVO {
|
|||||||
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8525")
|
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8525")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
|
@Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "鹭鹭")
|
||||||
@NotEmpty(message = "名字不能为空")
|
@NotEmpty(message = "名字不能为空")
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
|||||||
@@ -193,7 +193,7 @@ public class CodegenBuilder {
|
|||||||
}
|
}
|
||||||
// name
|
// name
|
||||||
if (StrUtil.endWithIgnoreCase(column.getJavaField(), "name")) {
|
if (StrUtil.endWithIgnoreCase(column.getJavaField(), "name")) {
|
||||||
column.setExample(randomEle(new String[]{"张三", "李四", "王五", "赵六", "芋艿"}));
|
column.setExample(randomEle(new String[]{"张三", "李四", "王五", "赵六", "鹭鹭"}));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// status
|
// status
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ public class CodegenServiceImplTest extends BaseDbUnitTest {
|
|||||||
TableInfo tableInfo = mock(TableInfo.class);
|
TableInfo tableInfo = mock(TableInfo.class);
|
||||||
when(databaseTableService.getTable(eq(1L), eq("t_yunai")))
|
when(databaseTableService.getTable(eq(1L), eq("t_yunai")))
|
||||||
.thenReturn(tableInfo);
|
.thenReturn(tableInfo);
|
||||||
when(tableInfo.getComment()).thenReturn("芋艿");
|
when(tableInfo.getComment()).thenReturn("鹭鹭");
|
||||||
// mock 方法(TableInfo fields)
|
// mock 方法(TableInfo fields)
|
||||||
TableField field01 = mock(TableField.class);
|
TableField field01 = mock(TableField.class);
|
||||||
when(field01.getComment()).thenReturn("主键");
|
when(field01.getComment()).thenReturn("主键");
|
||||||
@@ -134,7 +134,7 @@ public class CodegenServiceImplTest extends BaseDbUnitTest {
|
|||||||
assertServiceException(() -> codegenService.validateTableInfo(tableInfo),
|
assertServiceException(() -> codegenService.validateTableInfo(tableInfo),
|
||||||
CODEGEN_TABLE_INFO_TABLE_COMMENT_IS_NULL);
|
CODEGEN_TABLE_INFO_TABLE_COMMENT_IS_NULL);
|
||||||
// 情况三
|
// 情况三
|
||||||
when(tableInfo.getComment()).thenReturn("芋艿");
|
when(tableInfo.getComment()).thenReturn("鹭鹭");
|
||||||
assertServiceException(() -> codegenService.validateTableInfo(tableInfo),
|
assertServiceException(() -> codegenService.validateTableInfo(tableInfo),
|
||||||
CODEGEN_IMPORT_COLUMNS_NULL);
|
CODEGEN_IMPORT_COLUMNS_NULL);
|
||||||
// 情况四
|
// 情况四
|
||||||
@@ -247,7 +247,7 @@ public class CodegenServiceImplTest extends BaseDbUnitTest {
|
|||||||
TableInfo tableInfo = mock(TableInfo.class);
|
TableInfo tableInfo = mock(TableInfo.class);
|
||||||
when(databaseTableService.getTable(eq(1L), eq("t_yunai")))
|
when(databaseTableService.getTable(eq(1L), eq("t_yunai")))
|
||||||
.thenReturn(tableInfo);
|
.thenReturn(tableInfo);
|
||||||
when(tableInfo.getComment()).thenReturn("芋艿");
|
when(tableInfo.getComment()).thenReturn("鹭鹭");
|
||||||
// mock 方法(TableInfo fields)
|
// mock 方法(TableInfo fields)
|
||||||
TableField field01 = mock(TableField.class);
|
TableField field01 = mock(TableField.class);
|
||||||
when(field01.getComment()).thenReturn("主键");
|
when(field01.getComment()).thenReturn("主键");
|
||||||
@@ -322,7 +322,7 @@ public class CodegenServiceImplTest extends BaseDbUnitTest {
|
|||||||
// mock 数据
|
// mock 数据
|
||||||
CodegenTableDO tableDO = randomPojo(CodegenTableDO.class, o -> {
|
CodegenTableDO tableDO = randomPojo(CodegenTableDO.class, o -> {
|
||||||
o.setTableName("t_yunai");
|
o.setTableName("t_yunai");
|
||||||
o.setTableComment("芋艿");
|
o.setTableComment("鹭鹭");
|
||||||
o.setClassName("SystemYunai");
|
o.setClassName("SystemYunai");
|
||||||
o.setCreateTime(buildTime(2021, 3, 10));
|
o.setCreateTime(buildTime(2021, 3, 10));
|
||||||
}).setScene(CodegenSceneEnum.ADMIN.getScene());
|
}).setScene(CodegenSceneEnum.ADMIN.getScene());
|
||||||
@@ -338,7 +338,7 @@ public class CodegenServiceImplTest extends BaseDbUnitTest {
|
|||||||
// 准备参数
|
// 准备参数
|
||||||
CodegenTablePageReqVO reqVO = new CodegenTablePageReqVO();
|
CodegenTablePageReqVO reqVO = new CodegenTablePageReqVO();
|
||||||
reqVO.setTableName("yunai");
|
reqVO.setTableName("yunai");
|
||||||
reqVO.setTableComment("芋");
|
reqVO.setTableComment("鹭");
|
||||||
reqVO.setClassName("Yunai");
|
reqVO.setClassName("Yunai");
|
||||||
reqVO.setCreateTime(buildBetweenTime(2021, 3, 1, 2021, 3, 31));
|
reqVO.setCreateTime(buildBetweenTime(2021, 3, 1, 2021, 3, 31));
|
||||||
|
|
||||||
@@ -539,10 +539,10 @@ public class CodegenServiceImplTest extends BaseDbUnitTest {
|
|||||||
// mock 方法
|
// mock 方法
|
||||||
TableInfo tableInfo01 = mock(TableInfo.class);
|
TableInfo tableInfo01 = mock(TableInfo.class);
|
||||||
when(tableInfo01.getName()).thenReturn("t_yunai");
|
when(tableInfo01.getName()).thenReturn("t_yunai");
|
||||||
when(tableInfo01.getComment()).thenReturn("芋艿");
|
when(tableInfo01.getComment()).thenReturn("鹭鹭");
|
||||||
TableInfo tableInfo02 = mock(TableInfo.class);
|
TableInfo tableInfo02 = mock(TableInfo.class);
|
||||||
when(tableInfo02.getName()).thenReturn("t_yunai_02");
|
when(tableInfo02.getName()).thenReturn("t_yunai_02");
|
||||||
when(tableInfo02.getComment()).thenReturn("芋艿_02");
|
when(tableInfo02.getComment()).thenReturn("鹭鹭_02");
|
||||||
when(databaseTableService.getTableList(eq(dataSourceConfigId), eq(name), eq(comment)))
|
when(databaseTableService.getTableList(eq(dataSourceConfigId), eq(name), eq(comment)))
|
||||||
.thenReturn(ListUtil.toList(tableInfo01, tableInfo02));
|
.thenReturn(ListUtil.toList(tableInfo01, tableInfo02));
|
||||||
// mock 数据
|
// mock 数据
|
||||||
@@ -557,7 +557,7 @@ public class CodegenServiceImplTest extends BaseDbUnitTest {
|
|||||||
// 断言
|
// 断言
|
||||||
assertEquals(1, result.size());
|
assertEquals(1, result.size());
|
||||||
assertEquals("t_yunai", result.get(0).getName());
|
assertEquals("t_yunai", result.get(0).getName());
|
||||||
assertEquals("芋艿", result.get(0).getComment());
|
assertEquals("鹭鹭", result.get(0).getComment());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ public class ConfigServiceImplTest extends BaseDbUnitTest {
|
|||||||
public void testGetConfigPage() {
|
public void testGetConfigPage() {
|
||||||
// mock 数据
|
// mock 数据
|
||||||
ConfigDO dbConfig = randomConfigDO(o -> { // 等会查询到
|
ConfigDO dbConfig = randomConfigDO(o -> { // 等会查询到
|
||||||
o.setName("芋艿");
|
o.setName("鹭鹭");
|
||||||
o.setConfigKey("yunai");
|
o.setConfigKey("yunai");
|
||||||
o.setType(ConfigTypeEnum.SYSTEM.getType());
|
o.setType(ConfigTypeEnum.SYSTEM.getType());
|
||||||
o.setCreateTime(buildTime(2021, 2, 1));
|
o.setCreateTime(buildTime(2021, 2, 1));
|
||||||
@@ -163,7 +163,7 @@ public class ConfigServiceImplTest extends BaseDbUnitTest {
|
|||||||
configMapper.insert(cloneIgnoreId(dbConfig, o -> o.setCreateTime(buildTime(2021, 1, 1))));
|
configMapper.insert(cloneIgnoreId(dbConfig, o -> o.setCreateTime(buildTime(2021, 1, 1))));
|
||||||
// 准备参数
|
// 准备参数
|
||||||
ConfigPageReqVO reqVO = new ConfigPageReqVO();
|
ConfigPageReqVO reqVO = new ConfigPageReqVO();
|
||||||
reqVO.setName("艿");
|
reqVO.setName("鹭");
|
||||||
reqVO.setKey("nai");
|
reqVO.setKey("nai");
|
||||||
reqVO.setType(ConfigTypeEnum.SYSTEM.getType());
|
reqVO.setType(ConfigTypeEnum.SYSTEM.getType());
|
||||||
reqVO.setCreateTime(buildBetweenTime(2021, 1, 15, 2021, 2, 15));
|
reqVO.setCreateTime(buildBetweenTime(2021, 1, 15, 2021, 2, 15));
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ public class JobLogServiceImplTest extends BaseDbUnitTest {
|
|||||||
assertEquals(1, count);
|
assertEquals(1, count);
|
||||||
List<JobLogDO> logs = jobLogMapper.selectList();
|
List<JobLogDO> logs = jobLogMapper.selectList();
|
||||||
assertEquals(1, logs.size());
|
assertEquals(1, logs.size());
|
||||||
// TODO @芋艿:createTime updateTime 被屏蔽,仅 win11 会复现,建议后续修复。
|
// TODO @鹭鹭:createTime updateTime 被屏蔽,仅 win11 会复现,建议后续修复。
|
||||||
assertPojoEquals(log02, logs.get(0), "createTime", "updateTime");
|
assertPojoEquals(log02, logs.get(0), "createTime", "updateTime");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ public class ApiAccessLogServiceImplTest extends BaseDbUnitTest {
|
|||||||
assertEquals(1, count);
|
assertEquals(1, count);
|
||||||
List<ApiAccessLogDO> logs = apiAccessLogMapper.selectList();
|
List<ApiAccessLogDO> logs = apiAccessLogMapper.selectList();
|
||||||
assertEquals(1, logs.size());
|
assertEquals(1, logs.size());
|
||||||
// TODO @芋艿:createTime updateTime 被屏蔽,仅 win11 会复现,建议后续修复。
|
// TODO @鹭鹭:createTime updateTime 被屏蔽,仅 win11 会复现,建议后续修复。
|
||||||
assertPojoEquals(log02, logs.get(0), "createTime", "updateTime");
|
assertPojoEquals(log02, logs.get(0), "createTime", "updateTime");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -157,7 +157,7 @@ public class ApiErrorLogServiceImplTest extends BaseDbUnitTest {
|
|||||||
assertEquals(1, count);
|
assertEquals(1, count);
|
||||||
List<ApiErrorLogDO> logs = apiErrorLogMapper.selectList();
|
List<ApiErrorLogDO> logs = apiErrorLogMapper.selectList();
|
||||||
assertEquals(1, logs.size());
|
assertEquals(1, logs.size());
|
||||||
// TODO @芋艿:createTime updateTime 被屏蔽,仅 win11 会复现,建议后续修复。
|
// TODO @鹭鹭:createTime updateTime 被屏蔽,仅 win11 会复现,建议后续修复。
|
||||||
assertPojoEquals(log02, logs.get(0), "createTime", "updateTime");
|
assertPojoEquals(log02, logs.get(0), "createTime", "updateTime");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ public class AuthRegisterReqVO extends CaptchaVerificationReqVO {
|
|||||||
@Size(min = 4, max = 30, message = "用户账号长度为 4-30 个字符")
|
@Size(min = 4, max = 30, message = "用户账号长度为 4-30 个字符")
|
||||||
private String username;
|
private String username;
|
||||||
|
|
||||||
@Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
|
@Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "鹭鹭")
|
||||||
@NotBlank(message = "用户昵称不能为空")
|
@NotBlank(message = "用户昵称不能为空")
|
||||||
@Size(max = 30, message = "用户昵称长度不能超过 30 个字符")
|
@Size(max = 30, message = "用户昵称长度不能超过 30 个字符")
|
||||||
private String nickname;
|
private String nickname;
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ public class OperateLogRespVO implements VO {
|
|||||||
@Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
@Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||||
@Trans(type = TransType.SIMPLE, target = AdminUserDO.class, fields = "nickname", ref = "userName")
|
@Trans(type = TransType.SIMPLE, target = AdminUserDO.class, fields = "nickname", ref = "userName")
|
||||||
private Long userId;
|
private Long userId;
|
||||||
@Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
|
@Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "鹭鹭")
|
||||||
@ExcelProperty("操作人")
|
@ExcelProperty("操作人")
|
||||||
private String userName;
|
private String userName;
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ public class MailTemplatePageReqVO extends PageParam {
|
|||||||
@Schema(description = "标识,模糊匹配", example = "code_1024")
|
@Schema(description = "标识,模糊匹配", example = "code_1024")
|
||||||
private String code;
|
private String code;
|
||||||
|
|
||||||
@Schema(description = "名称,模糊匹配", example = "芋头")
|
@Schema(description = "名称,模糊匹配", example = "鹭筑")
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@Schema(description = "账号编号", example = "2048")
|
@Schema(description = "账号编号", example = "2048")
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ public class MailTemplateRespVO {
|
|||||||
@Schema(description = "发送的邮箱账号编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
@Schema(description = "发送的邮箱账号编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||||
private Long accountId;
|
private Long accountId;
|
||||||
|
|
||||||
@Schema(description = "发送人名称", example = "芋头")
|
@Schema(description = "发送人名称", example = "鹭筑")
|
||||||
private String nickname;
|
private String nickname;
|
||||||
|
|
||||||
@Schema(description = "标题", requiredMode = Schema.RequiredMode.REQUIRED, example = "注册成功")
|
@Schema(description = "标题", requiredMode = Schema.RequiredMode.REQUIRED, example = "注册成功")
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ public class MailTemplateSaveReqVO {
|
|||||||
@NotNull(message = "发送的邮箱账号编号不能为空")
|
@NotNull(message = "发送的邮箱账号编号不能为空")
|
||||||
private Long accountId;
|
private Long accountId;
|
||||||
|
|
||||||
@Schema(description = "发送人名称", example = "芋头")
|
@Schema(description = "发送人名称", example = "鹭筑")
|
||||||
private String nickname;
|
private String nickname;
|
||||||
|
|
||||||
@Schema(description = "标题", requiredMode = Schema.RequiredMode.REQUIRED, example = "注册成功")
|
@Schema(description = "标题", requiredMode = Schema.RequiredMode.REQUIRED, example = "注册成功")
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ public class NotifyMessageRespVO {
|
|||||||
@Schema(description = "模板编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "test_01")
|
@Schema(description = "模板编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "test_01")
|
||||||
private String templateCode;
|
private String templateCode;
|
||||||
|
|
||||||
@Schema(description = "模版发送人名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
|
@Schema(description = "模版发送人名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "鹭鹭")
|
||||||
private String templateNickname;
|
private String templateNickname;
|
||||||
|
|
||||||
@Schema(description = "模版内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "测试内容")
|
@Schema(description = "模版内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "测试内容")
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ public class OAuth2UserInfoRespVO {
|
|||||||
@Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
@Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@Schema(description = "用户账号", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
|
@Schema(description = "用户账号", requiredMode = Schema.RequiredMode.REQUIRED, example = "鹭鹭")
|
||||||
private String username;
|
private String username;
|
||||||
|
|
||||||
@Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "lyz")
|
@Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "lyz")
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import javax.validation.constraints.Size;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class OAuth2UserUpdateReqVO {
|
public class OAuth2UserUpdateReqVO {
|
||||||
|
|
||||||
@Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
|
@Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "鹭鹭")
|
||||||
@Size(max = 30, message = "用户昵称长度不能超过 30 个字符")
|
@Size(max = 30, message = "用户昵称长度不能超过 30 个字符")
|
||||||
private String nickname;
|
private String nickname;
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ public class SocialUserRespVO {
|
|||||||
@Schema(description = "原始 Token 数据,一般是 JSON 格式", requiredMode = Schema.RequiredMode.REQUIRED, example = "{}")
|
@Schema(description = "原始 Token 数据,一般是 JSON 格式", requiredMode = Schema.RequiredMode.REQUIRED, example = "{}")
|
||||||
private String rawTokenInfo;
|
private String rawTokenInfo;
|
||||||
|
|
||||||
@Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
|
@Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "鹭鹭")
|
||||||
private String nickname;
|
private String nickname;
|
||||||
|
|
||||||
@Schema(description = "用户头像", example = "https://www.iocoder.cn/xxx.png")
|
@Schema(description = "用户头像", example = "https://www.iocoder.cn/xxx.png")
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ public class TenantPageReqVO extends PageParam {
|
|||||||
@Schema(description = "租户名", example = "lyz")
|
@Schema(description = "租户名", example = "lyz")
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@Schema(description = "联系人", example = "芋艿")
|
@Schema(description = "联系人", example = "鹭鹭")
|
||||||
private String contactName;
|
private String contactName;
|
||||||
|
|
||||||
@Schema(description = "联系手机", example = "15601691300")
|
@Schema(description = "联系手机", example = "15601691300")
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ public class TenantRespVO {
|
|||||||
@ExcelProperty("租户名")
|
@ExcelProperty("租户名")
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@Schema(description = "联系人", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
|
@Schema(description = "联系人", requiredMode = Schema.RequiredMode.REQUIRED, example = "鹭鹭")
|
||||||
@ExcelProperty("联系人")
|
@ExcelProperty("联系人")
|
||||||
private String contactName;
|
private String contactName;
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ public class TenantSaveReqVO {
|
|||||||
@NotNull(message = "租户名不能为空")
|
@NotNull(message = "租户名不能为空")
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@Schema(description = "联系人", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
|
@Schema(description = "联系人", requiredMode = Schema.RequiredMode.REQUIRED, example = "鹭鹭")
|
||||||
@NotNull(message = "联系人不能为空")
|
@NotNull(message = "联系人不能为空")
|
||||||
private String contactName;
|
private String contactName;
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ public class UserProfileRespVO {
|
|||||||
@Schema(description = "用户账号", requiredMode = Schema.RequiredMode.REQUIRED, example = "lyzsys")
|
@Schema(description = "用户账号", requiredMode = Schema.RequiredMode.REQUIRED, example = "lyzsys")
|
||||||
private String username;
|
private String username;
|
||||||
|
|
||||||
@Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
|
@Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "鹭鹭")
|
||||||
private String nickname;
|
private String nickname;
|
||||||
|
|
||||||
@Schema(description = "用户邮箱", example = "lyzsys@iocoder.cn")
|
@Schema(description = "用户邮箱", example = "lyzsys@iocoder.cn")
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import javax.validation.constraints.Size;
|
|||||||
@Data
|
@Data
|
||||||
public class UserProfileUpdateReqVO {
|
public class UserProfileUpdateReqVO {
|
||||||
|
|
||||||
@Schema(description = "用户昵称", example = "芋艿")
|
@Schema(description = "用户昵称", example = "鹭鹭")
|
||||||
@Size(max = 30, message = "用户昵称长度不能超过 30 个字符")
|
@Size(max = 30, message = "用户昵称长度不能超过 30 个字符")
|
||||||
private String nickname;
|
private String nickname;
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ public class UserRespVO{
|
|||||||
@ExcelProperty("用户名称")
|
@ExcelProperty("用户名称")
|
||||||
private String username;
|
private String username;
|
||||||
|
|
||||||
@Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
|
@Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "鹭鹭")
|
||||||
@ExcelProperty("用户昵称")
|
@ExcelProperty("用户昵称")
|
||||||
private String nickname;
|
private String nickname;
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ public class UserSaveReqVO {
|
|||||||
@DiffLogField(name = "用户账号")
|
@DiffLogField(name = "用户账号")
|
||||||
private String username;
|
private String username;
|
||||||
|
|
||||||
@Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
|
@Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "鹭鹭")
|
||||||
@Size(max = 30, message = "用户昵称长度不能超过30个字符")
|
@Size(max = 30, message = "用户昵称长度不能超过30个字符")
|
||||||
@DiffLogField(name = "用户昵称")
|
@DiffLogField(name = "用户昵称")
|
||||||
private String nickname;
|
private String nickname;
|
||||||
|
|||||||
@@ -10,14 +10,14 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JustAuth 配置类 TODO 芋艿:等 justauth 1.4.1 版本发布!!!
|
* JustAuth 配置类 TODO 鹭鹭:等 justauth 1.4.1 版本发布!!!
|
||||||
*
|
*
|
||||||
* @author lyz源码
|
* @author lyz源码
|
||||||
*/
|
*/
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
public class LyzsysJustAuthConfiguration {
|
public class LyzsysJustAuthConfiguration {
|
||||||
|
|
||||||
@Bean(name = "authRequestFactory2") // TODO @芋艿:等 justauth1.4.1 发布,可以去掉
|
@Bean(name = "authRequestFactory2") // TODO @鹭鹭:等 justauth1.4.1 发布,可以去掉
|
||||||
@ConditionalOnProperty(
|
@ConditionalOnProperty(
|
||||||
prefix = "justauth",
|
prefix = "justauth",
|
||||||
value = {"enabled"},
|
value = {"enabled"},
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
// TODO @芋艿:等官方发布 1.4.1!!!
|
// TODO @鹭鹭:等官方发布 1.4.1!!!
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* AuthRequest工厂类
|
* AuthRequest工厂类
|
||||||
|
|||||||
@@ -62,8 +62,8 @@ public class SmsCodeServiceImpl implements SmsCodeService {
|
|||||||
lastSmsCode.getTodayIndex() >= smsCodeProperties.getSendMaximumQuantityPerDay()) { // 超过当天发送的上限。
|
lastSmsCode.getTodayIndex() >= smsCodeProperties.getSendMaximumQuantityPerDay()) { // 超过当天发送的上限。
|
||||||
throw exception(SMS_CODE_EXCEED_SEND_MAXIMUM_QUANTITY_PER_DAY);
|
throw exception(SMS_CODE_EXCEED_SEND_MAXIMUM_QUANTITY_PER_DAY);
|
||||||
}
|
}
|
||||||
// TODO 芋艿:提升,每个 IP 每天可发送数量
|
// TODO 鹭鹭:提升,每个 IP 每天可发送数量
|
||||||
// TODO 芋艿:提升,每个 IP 每小时可发送数量
|
// TODO 鹭鹭:提升,每个 IP 每小时可发送数量
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建验证码记录
|
// 创建验证码记录
|
||||||
|
|||||||
@@ -1,352 +0,0 @@
|
|||||||
package cn.iocoder.lyzsys.module.system.service.dict;
|
|
||||||
|
|
||||||
import cn.iocoder.lyzsys.framework.common.enums.CommonStatusEnum;
|
|
||||||
import cn.iocoder.lyzsys.framework.common.pojo.PageResult;
|
|
||||||
import cn.iocoder.lyzsys.framework.common.util.collection.ArrayUtils;
|
|
||||||
import cn.iocoder.lyzsys.framework.test.core.ut.BaseDbUnitTest;
|
|
||||||
import cn.iocoder.lyzsys.module.system.controller.admin.dict.vo.data.DictDataPageReqVO;
|
|
||||||
import cn.iocoder.lyzsys.module.system.controller.admin.dict.vo.data.DictDataSaveReqVO;
|
|
||||||
import cn.iocoder.lyzsys.module.system.dal.dataobject.dict.DictDataDO;
|
|
||||||
import cn.iocoder.lyzsys.module.system.dal.dataobject.dict.DictTypeDO;
|
|
||||||
import cn.iocoder.lyzsys.module.system.dal.mysql.dict.DictDataMapper;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
|
||||||
import org.springframework.context.annotation.Import;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
import static cn.iocoder.lyzsys.framework.common.util.object.ObjectUtils.cloneIgnoreId;
|
|
||||||
import static cn.iocoder.lyzsys.framework.test.core.util.AssertUtils.assertPojoEquals;
|
|
||||||
import static cn.iocoder.lyzsys.framework.test.core.util.AssertUtils.assertServiceException;
|
|
||||||
import static cn.iocoder.lyzsys.framework.test.core.util.RandomUtils.*;
|
|
||||||
import static cn.iocoder.lyzsys.module.system.enums.ErrorCodeConstants.*;
|
|
||||||
import static java.util.Collections.singletonList;
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
@Import(DictDataServiceImpl.class)
|
|
||||||
public class DictDataServiceImplTest extends BaseDbUnitTest {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private DictDataServiceImpl dictDataService;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private DictDataMapper dictDataMapper;
|
|
||||||
@MockBean
|
|
||||||
private DictTypeService dictTypeService;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetDictDataList() {
|
|
||||||
// mock 数据
|
|
||||||
DictDataDO dictDataDO01 = randomDictDataDO().setDictType("yunai").setSort(2)
|
|
||||||
.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
|
||||||
dictDataMapper.insert(dictDataDO01);
|
|
||||||
DictDataDO dictDataDO02 = randomDictDataDO().setDictType("yunai").setSort(1)
|
|
||||||
.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
|
||||||
dictDataMapper.insert(dictDataDO02);
|
|
||||||
DictDataDO dictDataDO03 = randomDictDataDO().setDictType("yunai").setSort(3)
|
|
||||||
.setStatus(CommonStatusEnum.DISABLE.getStatus());
|
|
||||||
dictDataMapper.insert(dictDataDO03);
|
|
||||||
DictDataDO dictDataDO04 = randomDictDataDO().setDictType("yunai2").setSort(3)
|
|
||||||
.setStatus(CommonStatusEnum.DISABLE.getStatus());
|
|
||||||
dictDataMapper.insert(dictDataDO04);
|
|
||||||
// 准备参数
|
|
||||||
Integer status = CommonStatusEnum.ENABLE.getStatus();
|
|
||||||
String dictType = "yunai";
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
List<DictDataDO> dictDataDOList = dictDataService.getDictDataList(status, dictType);
|
|
||||||
// 断言
|
|
||||||
assertEquals(2, dictDataDOList.size());
|
|
||||||
assertPojoEquals(dictDataDO02, dictDataDOList.get(0));
|
|
||||||
assertPojoEquals(dictDataDO01, dictDataDOList.get(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetDictDataPage() {
|
|
||||||
// mock 数据
|
|
||||||
DictDataDO dbDictData = randomPojo(DictDataDO.class, o -> { // 等会查询到
|
|
||||||
o.setLabel("芋艿");
|
|
||||||
o.setDictType("yunai");
|
|
||||||
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
|
||||||
});
|
|
||||||
dictDataMapper.insert(dbDictData);
|
|
||||||
// 测试 label 不匹配
|
|
||||||
dictDataMapper.insert(cloneIgnoreId(dbDictData, o -> o.setLabel("艿")));
|
|
||||||
// 测试 dictType 不匹配
|
|
||||||
dictDataMapper.insert(cloneIgnoreId(dbDictData, o -> o.setDictType("nai")));
|
|
||||||
// 测试 status 不匹配
|
|
||||||
dictDataMapper.insert(cloneIgnoreId(dbDictData, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus())));
|
|
||||||
// 准备参数
|
|
||||||
DictDataPageReqVO reqVO = new DictDataPageReqVO();
|
|
||||||
reqVO.setLabel("芋");
|
|
||||||
reqVO.setDictType("yunai");
|
|
||||||
reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
PageResult<DictDataDO> pageResult = dictDataService.getDictDataPage(reqVO);
|
|
||||||
// 断言
|
|
||||||
assertEquals(1, pageResult.getTotal());
|
|
||||||
assertEquals(1, pageResult.getList().size());
|
|
||||||
assertPojoEquals(dbDictData, pageResult.getList().get(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetDictData() {
|
|
||||||
// mock 数据
|
|
||||||
DictDataDO dbDictData = randomDictDataDO();
|
|
||||||
dictDataMapper.insert(dbDictData);
|
|
||||||
// 准备参数
|
|
||||||
Long id = dbDictData.getId();
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
DictDataDO dictData = dictDataService.getDictData(id);
|
|
||||||
// 断言
|
|
||||||
assertPojoEquals(dbDictData, dictData);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testCreateDictData_success() {
|
|
||||||
// 准备参数
|
|
||||||
DictDataSaveReqVO reqVO = randomPojo(DictDataSaveReqVO.class,
|
|
||||||
o -> o.setStatus(randomCommonStatus()))
|
|
||||||
.setId(null); // 防止 id 被赋值
|
|
||||||
// mock 方法
|
|
||||||
when(dictTypeService.getDictType(eq(reqVO.getDictType()))).thenReturn(randomDictTypeDO(reqVO.getDictType()));
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
Long dictDataId = dictDataService.createDictData(reqVO);
|
|
||||||
// 断言
|
|
||||||
assertNotNull(dictDataId);
|
|
||||||
// 校验记录的属性是否正确
|
|
||||||
DictDataDO dictData = dictDataMapper.selectById(dictDataId);
|
|
||||||
assertPojoEquals(reqVO, dictData, "id");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testUpdateDictData_success() {
|
|
||||||
// mock 数据
|
|
||||||
DictDataDO dbDictData = randomDictDataDO();
|
|
||||||
dictDataMapper.insert(dbDictData);// @Sql: 先插入出一条存在的数据
|
|
||||||
// 准备参数
|
|
||||||
DictDataSaveReqVO reqVO = randomPojo(DictDataSaveReqVO.class, o -> {
|
|
||||||
o.setId(dbDictData.getId()); // 设置更新的 ID
|
|
||||||
o.setStatus(randomCommonStatus());
|
|
||||||
});
|
|
||||||
// mock 方法,字典类型
|
|
||||||
when(dictTypeService.getDictType(eq(reqVO.getDictType()))).thenReturn(randomDictTypeDO(reqVO.getDictType()));
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
dictDataService.updateDictData(reqVO);
|
|
||||||
// 校验是否更新正确
|
|
||||||
DictDataDO dictData = dictDataMapper.selectById(reqVO.getId()); // 获取最新的
|
|
||||||
assertPojoEquals(reqVO, dictData);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testDeleteDictData_success() {
|
|
||||||
// mock 数据
|
|
||||||
DictDataDO dbDictData = randomDictDataDO();
|
|
||||||
dictDataMapper.insert(dbDictData);// @Sql: 先插入出一条存在的数据
|
|
||||||
// 准备参数
|
|
||||||
Long id = dbDictData.getId();
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
dictDataService.deleteDictData(id);
|
|
||||||
// 校验数据不存在了
|
|
||||||
assertNull(dictDataMapper.selectById(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testValidateDictDataExists_success() {
|
|
||||||
// mock 数据
|
|
||||||
DictDataDO dbDictData = randomDictDataDO();
|
|
||||||
dictDataMapper.insert(dbDictData);// @Sql: 先插入出一条存在的数据
|
|
||||||
|
|
||||||
// 调用成功
|
|
||||||
dictDataService.validateDictDataExists(dbDictData.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testValidateDictDataExists_notExists() {
|
|
||||||
assertServiceException(() -> dictDataService.validateDictDataExists(randomLongId()), DICT_DATA_NOT_EXISTS);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testValidateDictTypeExists_success() {
|
|
||||||
// mock 方法,数据类型被禁用
|
|
||||||
String type = randomString();
|
|
||||||
when(dictTypeService.getDictType(eq(type))).thenReturn(randomDictTypeDO(type));
|
|
||||||
|
|
||||||
// 调用, 成功
|
|
||||||
dictDataService.validateDictTypeExists(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testValidateDictTypeExists_notExists() {
|
|
||||||
assertServiceException(() -> dictDataService.validateDictTypeExists(randomString()), DICT_TYPE_NOT_EXISTS);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testValidateDictTypeExists_notEnable() {
|
|
||||||
// mock 方法,数据类型被禁用
|
|
||||||
String dictType = randomString();
|
|
||||||
when(dictTypeService.getDictType(eq(dictType))).thenReturn(
|
|
||||||
randomPojo(DictTypeDO.class, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus())));
|
|
||||||
|
|
||||||
// 调用, 并断言异常
|
|
||||||
assertServiceException(() -> dictDataService.validateDictTypeExists(dictType), DICT_TYPE_NOT_ENABLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testValidateDictDataValueUnique_success() {
|
|
||||||
// 调用,成功
|
|
||||||
dictDataService.validateDictDataValueUnique(randomLongId(), randomString(), randomString());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testValidateDictDataValueUnique_valueDuplicateForCreate() {
|
|
||||||
// 准备参数
|
|
||||||
String dictType = randomString();
|
|
||||||
String value = randomString();
|
|
||||||
// mock 数据
|
|
||||||
dictDataMapper.insert(randomDictDataDO(o -> {
|
|
||||||
o.setDictType(dictType);
|
|
||||||
o.setValue(value);
|
|
||||||
}));
|
|
||||||
|
|
||||||
// 调用,校验异常
|
|
||||||
assertServiceException(() -> dictDataService.validateDictDataValueUnique(null, dictType, value),
|
|
||||||
DICT_DATA_VALUE_DUPLICATE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testValidateDictDataValueUnique_valueDuplicateForUpdate() {
|
|
||||||
// 准备参数
|
|
||||||
Long id = randomLongId();
|
|
||||||
String dictType = randomString();
|
|
||||||
String value = randomString();
|
|
||||||
// mock 数据
|
|
||||||
dictDataMapper.insert(randomDictDataDO(o -> {
|
|
||||||
o.setDictType(dictType);
|
|
||||||
o.setValue(value);
|
|
||||||
}));
|
|
||||||
|
|
||||||
// 调用,校验异常
|
|
||||||
assertServiceException(() -> dictDataService.validateDictDataValueUnique(id, dictType, value),
|
|
||||||
DICT_DATA_VALUE_DUPLICATE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetDictDataCountByDictType() {
|
|
||||||
// mock 数据
|
|
||||||
dictDataMapper.insert(randomDictDataDO(o -> o.setDictType("yunai")));
|
|
||||||
dictDataMapper.insert(randomDictDataDO(o -> o.setDictType("tudou")));
|
|
||||||
dictDataMapper.insert(randomDictDataDO(o -> o.setDictType("yunai")));
|
|
||||||
// 准备参数
|
|
||||||
String dictType = "yunai";
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
long count = dictDataService.getDictDataCountByDictType(dictType);
|
|
||||||
// 校验
|
|
||||||
assertEquals(2L, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testValidateDictDataList_success() {
|
|
||||||
// mock 数据
|
|
||||||
DictDataDO dictDataDO = randomDictDataDO().setStatus(CommonStatusEnum.ENABLE.getStatus());
|
|
||||||
dictDataMapper.insert(dictDataDO);
|
|
||||||
// 准备参数
|
|
||||||
String dictType = dictDataDO.getDictType();
|
|
||||||
List<String> values = singletonList(dictDataDO.getValue());
|
|
||||||
|
|
||||||
// 调用,无需断言
|
|
||||||
dictDataService.validateDictDataList(dictType, values);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testValidateDictDataList_notFound() {
|
|
||||||
// 准备参数
|
|
||||||
String dictType = randomString();
|
|
||||||
List<String> values = singletonList(randomString());
|
|
||||||
|
|
||||||
// 调用, 并断言异常
|
|
||||||
assertServiceException(() -> dictDataService.validateDictDataList(dictType, values), DICT_DATA_NOT_EXISTS);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testValidateDictDataList_notEnable() {
|
|
||||||
// mock 数据
|
|
||||||
DictDataDO dictDataDO = randomDictDataDO().setStatus(CommonStatusEnum.DISABLE.getStatus());
|
|
||||||
dictDataMapper.insert(dictDataDO);
|
|
||||||
// 准备参数
|
|
||||||
String dictType = dictDataDO.getDictType();
|
|
||||||
List<String> values = singletonList(dictDataDO.getValue());
|
|
||||||
|
|
||||||
// 调用, 并断言异常
|
|
||||||
assertServiceException(() -> dictDataService.validateDictDataList(dictType, values),
|
|
||||||
DICT_DATA_NOT_ENABLE, dictDataDO.getLabel());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetDictData_dictType() {
|
|
||||||
// mock 数据
|
|
||||||
DictDataDO dictDataDO = randomDictDataDO().setDictType("yunai").setValue("1");
|
|
||||||
dictDataMapper.insert(dictDataDO);
|
|
||||||
DictDataDO dictDataDO02 = randomDictDataDO().setDictType("yunai").setValue("2");
|
|
||||||
dictDataMapper.insert(dictDataDO02);
|
|
||||||
// 准备参数
|
|
||||||
String dictType = "yunai";
|
|
||||||
String value = "1";
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
DictDataDO dbDictData = dictDataService.getDictData(dictType, value);
|
|
||||||
// 断言
|
|
||||||
assertEquals(dictDataDO, dbDictData);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testParseDictData() {
|
|
||||||
// mock 数据
|
|
||||||
DictDataDO dictDataDO = randomDictDataDO().setDictType("yunai").setLabel("1");
|
|
||||||
dictDataMapper.insert(dictDataDO);
|
|
||||||
DictDataDO dictDataDO02 = randomDictDataDO().setDictType("yunai").setLabel("2");
|
|
||||||
dictDataMapper.insert(dictDataDO02);
|
|
||||||
// 准备参数
|
|
||||||
String dictType = "yunai";
|
|
||||||
String label = "1";
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
DictDataDO dbDictData = dictDataService.parseDictData(dictType, label);
|
|
||||||
// 断言
|
|
||||||
assertEquals(dictDataDO, dbDictData);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ========== 随机对象 ==========
|
|
||||||
|
|
||||||
@SafeVarargs
|
|
||||||
private static DictDataDO randomDictDataDO(Consumer<DictDataDO>... consumers) {
|
|
||||||
Consumer<DictDataDO> consumer = (o) -> {
|
|
||||||
o.setStatus(randomCommonStatus()); // 保证 status 的范围
|
|
||||||
};
|
|
||||||
return randomPojo(DictDataDO.class, ArrayUtils.append(consumer, consumers));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成一个有效的字典类型
|
|
||||||
*
|
|
||||||
* @param type 字典类型
|
|
||||||
* @return DictTypeDO 对象
|
|
||||||
*/
|
|
||||||
private static DictTypeDO randomDictTypeDO(String type) {
|
|
||||||
return randomPojo(DictTypeDO.class, o -> {
|
|
||||||
o.setType(type);
|
|
||||||
o.setStatus(CommonStatusEnum.ENABLE.getStatus()); // 保证 status 是开启
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,271 +0,0 @@
|
|||||||
package cn.iocoder.lyzsys.module.system.service.dict;
|
|
||||||
|
|
||||||
import cn.iocoder.lyzsys.framework.common.enums.CommonStatusEnum;
|
|
||||||
import cn.iocoder.lyzsys.framework.common.pojo.PageResult;
|
|
||||||
import cn.iocoder.lyzsys.framework.common.util.collection.ArrayUtils;
|
|
||||||
import cn.iocoder.lyzsys.framework.test.core.ut.BaseDbUnitTest;
|
|
||||||
import cn.iocoder.lyzsys.module.system.controller.admin.dict.vo.type.DictTypePageReqVO;
|
|
||||||
import cn.iocoder.lyzsys.module.system.controller.admin.dict.vo.type.DictTypeSaveReqVO;
|
|
||||||
import cn.iocoder.lyzsys.module.system.dal.dataobject.dict.DictTypeDO;
|
|
||||||
import cn.iocoder.lyzsys.module.system.dal.mysql.dict.DictTypeMapper;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
|
||||||
import org.springframework.context.annotation.Import;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
import static cn.hutool.core.util.RandomUtil.randomEle;
|
|
||||||
import static cn.iocoder.lyzsys.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime;
|
|
||||||
import static cn.iocoder.lyzsys.framework.common.util.date.LocalDateTimeUtils.buildTime;
|
|
||||||
import static cn.iocoder.lyzsys.framework.common.util.object.ObjectUtils.cloneIgnoreId;
|
|
||||||
import static cn.iocoder.lyzsys.framework.test.core.util.AssertUtils.assertPojoEquals;
|
|
||||||
import static cn.iocoder.lyzsys.framework.test.core.util.AssertUtils.assertServiceException;
|
|
||||||
import static cn.iocoder.lyzsys.framework.test.core.util.RandomUtils.*;
|
|
||||||
import static cn.iocoder.lyzsys.module.system.enums.ErrorCodeConstants.*;
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
@Import(DictTypeServiceImpl.class)
|
|
||||||
public class DictTypeServiceImplTest extends BaseDbUnitTest {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private DictTypeServiceImpl dictTypeService;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private DictTypeMapper dictTypeMapper;
|
|
||||||
@MockBean
|
|
||||||
private DictDataService dictDataService;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetDictTypePage() {
|
|
||||||
// mock 数据
|
|
||||||
DictTypeDO dbDictType = randomPojo(DictTypeDO.class, o -> { // 等会查询到
|
|
||||||
o.setName("yunai");
|
|
||||||
o.setType("芋艿");
|
|
||||||
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
|
||||||
o.setCreateTime(buildTime(2021, 1, 15));
|
|
||||||
});
|
|
||||||
dictTypeMapper.insert(dbDictType);
|
|
||||||
// 测试 name 不匹配
|
|
||||||
dictTypeMapper.insert(cloneIgnoreId(dbDictType, o -> o.setName("tudou")));
|
|
||||||
// 测试 type 不匹配
|
|
||||||
dictTypeMapper.insert(cloneIgnoreId(dbDictType, o -> o.setType("土豆")));
|
|
||||||
// 测试 status 不匹配
|
|
||||||
dictTypeMapper.insert(cloneIgnoreId(dbDictType, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus())));
|
|
||||||
// 测试 createTime 不匹配
|
|
||||||
dictTypeMapper.insert(cloneIgnoreId(dbDictType, o -> o.setCreateTime(buildTime(2021, 1, 1))));
|
|
||||||
// 准备参数
|
|
||||||
DictTypePageReqVO reqVO = new DictTypePageReqVO();
|
|
||||||
reqVO.setName("nai");
|
|
||||||
reqVO.setType("艿");
|
|
||||||
reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
|
||||||
reqVO.setCreateTime(buildBetweenTime(2021, 1, 10, 2021, 1, 20));
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
PageResult<DictTypeDO> pageResult = dictTypeService.getDictTypePage(reqVO);
|
|
||||||
// 断言
|
|
||||||
assertEquals(1, pageResult.getTotal());
|
|
||||||
assertEquals(1, pageResult.getList().size());
|
|
||||||
assertPojoEquals(dbDictType, pageResult.getList().get(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetDictType_id() {
|
|
||||||
// mock 数据
|
|
||||||
DictTypeDO dbDictType = randomDictTypeDO();
|
|
||||||
dictTypeMapper.insert(dbDictType);
|
|
||||||
// 准备参数
|
|
||||||
Long id = dbDictType.getId();
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
DictTypeDO dictType = dictTypeService.getDictType(id);
|
|
||||||
// 断言
|
|
||||||
assertNotNull(dictType);
|
|
||||||
assertPojoEquals(dbDictType, dictType);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetDictType_type() {
|
|
||||||
// mock 数据
|
|
||||||
DictTypeDO dbDictType = randomDictTypeDO();
|
|
||||||
dictTypeMapper.insert(dbDictType);
|
|
||||||
// 准备参数
|
|
||||||
String type = dbDictType.getType();
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
DictTypeDO dictType = dictTypeService.getDictType(type);
|
|
||||||
// 断言
|
|
||||||
assertNotNull(dictType);
|
|
||||||
assertPojoEquals(dbDictType, dictType);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testCreateDictType_success() {
|
|
||||||
// 准备参数
|
|
||||||
DictTypeSaveReqVO reqVO = randomPojo(DictTypeSaveReqVO.class,
|
|
||||||
o -> o.setStatus(randomEle(CommonStatusEnum.values()).getStatus()))
|
|
||||||
.setId(null); // 避免 id 被赋值
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
Long dictTypeId = dictTypeService.createDictType(reqVO);
|
|
||||||
// 断言
|
|
||||||
assertNotNull(dictTypeId);
|
|
||||||
// 校验记录的属性是否正确
|
|
||||||
DictTypeDO dictType = dictTypeMapper.selectById(dictTypeId);
|
|
||||||
assertPojoEquals(reqVO, dictType, "id");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testUpdateDictType_success() {
|
|
||||||
// mock 数据
|
|
||||||
DictTypeDO dbDictType = randomDictTypeDO();
|
|
||||||
dictTypeMapper.insert(dbDictType);// @Sql: 先插入出一条存在的数据
|
|
||||||
// 准备参数
|
|
||||||
DictTypeSaveReqVO reqVO = randomPojo(DictTypeSaveReqVO.class, o -> {
|
|
||||||
o.setId(dbDictType.getId()); // 设置更新的 ID
|
|
||||||
o.setStatus(randomEle(CommonStatusEnum.values()).getStatus());
|
|
||||||
});
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
dictTypeService.updateDictType(reqVO);
|
|
||||||
// 校验是否更新正确
|
|
||||||
DictTypeDO dictType = dictTypeMapper.selectById(reqVO.getId()); // 获取最新的
|
|
||||||
assertPojoEquals(reqVO, dictType);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testDeleteDictType_success() {
|
|
||||||
// mock 数据
|
|
||||||
DictTypeDO dbDictType = randomDictTypeDO();
|
|
||||||
dictTypeMapper.insert(dbDictType);// @Sql: 先插入出一条存在的数据
|
|
||||||
// 准备参数
|
|
||||||
Long id = dbDictType.getId();
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
dictTypeService.deleteDictType(id);
|
|
||||||
// 校验数据不存在了
|
|
||||||
assertNull(dictTypeMapper.selectById(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testDeleteDictType_hasChildren() {
|
|
||||||
// mock 数据
|
|
||||||
DictTypeDO dbDictType = randomDictTypeDO();
|
|
||||||
dictTypeMapper.insert(dbDictType);// @Sql: 先插入出一条存在的数据
|
|
||||||
// 准备参数
|
|
||||||
Long id = dbDictType.getId();
|
|
||||||
// mock 方法
|
|
||||||
when(dictDataService.getDictDataCountByDictType(eq(dbDictType.getType()))).thenReturn(1L);
|
|
||||||
|
|
||||||
// 调用, 并断言异常
|
|
||||||
assertServiceException(() -> dictTypeService.deleteDictType(id), DICT_TYPE_HAS_CHILDREN);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetDictTypeList() {
|
|
||||||
// 准备参数
|
|
||||||
DictTypeDO dictTypeDO01 = randomDictTypeDO();
|
|
||||||
dictTypeMapper.insert(dictTypeDO01);
|
|
||||||
DictTypeDO dictTypeDO02 = randomDictTypeDO();
|
|
||||||
dictTypeMapper.insert(dictTypeDO02);
|
|
||||||
// mock 方法
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
List<DictTypeDO> dictTypeDOList = dictTypeService.getDictTypeList();
|
|
||||||
// 断言
|
|
||||||
assertEquals(2, dictTypeDOList.size());
|
|
||||||
assertPojoEquals(dictTypeDO01, dictTypeDOList.get(0));
|
|
||||||
assertPojoEquals(dictTypeDO02, dictTypeDOList.get(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testValidateDictDataExists_success() {
|
|
||||||
// mock 数据
|
|
||||||
DictTypeDO dbDictType = randomDictTypeDO();
|
|
||||||
dictTypeMapper.insert(dbDictType);// @Sql: 先插入出一条存在的数据
|
|
||||||
|
|
||||||
// 调用成功
|
|
||||||
dictTypeService.validateDictTypeExists(dbDictType.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testValidateDictDataExists_notExists() {
|
|
||||||
assertServiceException(() -> dictTypeService.validateDictTypeExists(randomLongId()), DICT_TYPE_NOT_EXISTS);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testValidateDictTypeUnique_success() {
|
|
||||||
// 调用,成功
|
|
||||||
dictTypeService.validateDictTypeUnique(randomLongId(), randomString());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testValidateDictTypeUnique_valueDuplicateForCreate() {
|
|
||||||
// 准备参数
|
|
||||||
String type = randomString();
|
|
||||||
// mock 数据
|
|
||||||
dictTypeMapper.insert(randomDictTypeDO(o -> o.setType(type)));
|
|
||||||
|
|
||||||
// 调用,校验异常
|
|
||||||
assertServiceException(() -> dictTypeService.validateDictTypeUnique(null, type),
|
|
||||||
DICT_TYPE_TYPE_DUPLICATE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testValidateDictTypeUnique_valueDuplicateForUpdate() {
|
|
||||||
// 准备参数
|
|
||||||
Long id = randomLongId();
|
|
||||||
String type = randomString();
|
|
||||||
// mock 数据
|
|
||||||
dictTypeMapper.insert(randomDictTypeDO(o -> o.setType(type)));
|
|
||||||
|
|
||||||
// 调用,校验异常
|
|
||||||
assertServiceException(() -> dictTypeService.validateDictTypeUnique(id, type),
|
|
||||||
DICT_TYPE_TYPE_DUPLICATE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testValidateDictTypNameUnique_success() {
|
|
||||||
// 调用,成功
|
|
||||||
dictTypeService.validateDictTypeNameUnique(randomLongId(), randomString());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testValidateDictTypeNameUnique_nameDuplicateForCreate() {
|
|
||||||
// 准备参数
|
|
||||||
String name = randomString();
|
|
||||||
// mock 数据
|
|
||||||
dictTypeMapper.insert(randomDictTypeDO(o -> o.setName(name)));
|
|
||||||
|
|
||||||
// 调用,校验异常
|
|
||||||
assertServiceException(() -> dictTypeService.validateDictTypeNameUnique(null, name),
|
|
||||||
DICT_TYPE_NAME_DUPLICATE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testValidateDictTypeNameUnique_nameDuplicateForUpdate() {
|
|
||||||
// 准备参数
|
|
||||||
Long id = randomLongId();
|
|
||||||
String name = randomString();
|
|
||||||
// mock 数据
|
|
||||||
dictTypeMapper.insert(randomDictTypeDO(o -> o.setName(name)));
|
|
||||||
|
|
||||||
// 调用,校验异常
|
|
||||||
assertServiceException(() -> dictTypeService.validateDictTypeNameUnique(id, name),
|
|
||||||
DICT_TYPE_NAME_DUPLICATE);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ========== 随机对象 ==========
|
|
||||||
|
|
||||||
@SafeVarargs
|
|
||||||
private static DictTypeDO randomDictTypeDO(Consumer<DictTypeDO>... consumers) {
|
|
||||||
Consumer<DictTypeDO> consumer = (o) -> {
|
|
||||||
o.setStatus(randomEle(CommonStatusEnum.values()).getStatus()); // 保证 status 的范围
|
|
||||||
};
|
|
||||||
return randomPojo(DictTypeDO.class, ArrayUtils.append(consumer, consumers));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -271,7 +271,7 @@ public class MailSendServiceImplTest extends BaseMockitoUnitTest {
|
|||||||
public void testDoSendMail_success() {
|
public void testDoSendMail_success() {
|
||||||
try (final MockedStatic<MailUtil> mailUtilMock = mockStatic(MailUtil.class)) {
|
try (final MockedStatic<MailUtil> mailUtilMock = mockStatic(MailUtil.class)) {
|
||||||
// 准备参数
|
// 准备参数
|
||||||
MailSendMessage message = randomPojo(MailSendMessage.class, o -> o.setNickname("芋艿"));
|
MailSendMessage message = randomPojo(MailSendMessage.class, o -> o.setNickname("鹭鹭"));
|
||||||
// mock 方法(获得邮箱账号)
|
// mock 方法(获得邮箱账号)
|
||||||
MailAccountDO account = randomPojo(MailAccountDO.class, o -> o.setMail("7685@qq.com"));
|
MailAccountDO account = randomPojo(MailAccountDO.class, o -> o.setMail("7685@qq.com"));
|
||||||
when(mailAccountService.getMailAccountFromCache(eq(message.getAccountId())))
|
when(mailAccountService.getMailAccountFromCache(eq(message.getAccountId())))
|
||||||
@@ -281,7 +281,7 @@ public class MailSendServiceImplTest extends BaseMockitoUnitTest {
|
|||||||
String messageId = randomString();
|
String messageId = randomString();
|
||||||
mailUtilMock.when(() -> MailUtil.send(
|
mailUtilMock.when(() -> MailUtil.send(
|
||||||
argThat(mailAccount -> {
|
argThat(mailAccount -> {
|
||||||
assertEquals("芋艿 <7685@qq.com>", mailAccount.getFrom());
|
assertEquals("鹭鹭 <7685@qq.com>", mailAccount.getFrom());
|
||||||
assertTrue(mailAccount.isAuth());
|
assertTrue(mailAccount.isAuth());
|
||||||
assertEquals(account.getUsername(), mailAccount.getUser());
|
assertEquals(account.getUsername(), mailAccount.getUser());
|
||||||
assertArrayEquals(account.getPassword().toCharArray(), mailAccount.getPass().toCharArray());
|
assertArrayEquals(account.getPassword().toCharArray(), mailAccount.getPass().toCharArray());
|
||||||
@@ -304,7 +304,7 @@ public class MailSendServiceImplTest extends BaseMockitoUnitTest {
|
|||||||
public void testDoSendMail_exception() {
|
public void testDoSendMail_exception() {
|
||||||
try (MockedStatic<MailUtil> mailUtilMock = mockStatic(MailUtil.class)) {
|
try (MockedStatic<MailUtil> mailUtilMock = mockStatic(MailUtil.class)) {
|
||||||
// 准备参数
|
// 准备参数
|
||||||
MailSendMessage message = randomPojo(MailSendMessage.class, o -> o.setNickname("芋艿"));
|
MailSendMessage message = randomPojo(MailSendMessage.class, o -> o.setNickname("鹭鹭"));
|
||||||
// mock 方法(获得邮箱账号)
|
// mock 方法(获得邮箱账号)
|
||||||
MailAccountDO account = randomPojo(MailAccountDO.class, o -> o.setMail("7685@qq.com"));
|
MailAccountDO account = randomPojo(MailAccountDO.class, o -> o.setMail("7685@qq.com"));
|
||||||
when(mailAccountService.getMailAccountFromCache(eq(message.getAccountId())))
|
when(mailAccountService.getMailAccountFromCache(eq(message.getAccountId())))
|
||||||
@@ -313,7 +313,7 @@ public class MailSendServiceImplTest extends BaseMockitoUnitTest {
|
|||||||
// mock 方法(发送邮件)
|
// mock 方法(发送邮件)
|
||||||
Exception e = new NullPointerException("啦啦啦");
|
Exception e = new NullPointerException("啦啦啦");
|
||||||
mailUtilMock.when(() -> MailUtil.send(argThat(mailAccount -> {
|
mailUtilMock.when(() -> MailUtil.send(argThat(mailAccount -> {
|
||||||
assertEquals("芋艿 <7685@qq.com>", mailAccount.getFrom());
|
assertEquals("鹭鹭 <7685@qq.com>", mailAccount.getFrom());
|
||||||
assertTrue(mailAccount.isAuth());
|
assertTrue(mailAccount.isAuth());
|
||||||
assertEquals(account.getUsername(), mailAccount.getUser());
|
assertEquals(account.getUsername(), mailAccount.getUser());
|
||||||
assertArrayEquals(account.getPassword().toCharArray(), mailAccount.getPass().toCharArray());
|
assertArrayEquals(account.getPassword().toCharArray(), mailAccount.getPass().toCharArray());
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ public class NotifyTemplateServiceImplTest extends BaseDbUnitTest {
|
|||||||
public void testGetNotifyTemplatePage() {
|
public void testGetNotifyTemplatePage() {
|
||||||
// mock 数据
|
// mock 数据
|
||||||
NotifyTemplateDO dbNotifyTemplate = randomPojo(NotifyTemplateDO.class, o -> { // 等会查询到
|
NotifyTemplateDO dbNotifyTemplate = randomPojo(NotifyTemplateDO.class, o -> { // 等会查询到
|
||||||
o.setName("芋头");
|
o.setName("鹭筑");
|
||||||
o.setCode("test_01");
|
o.setCode("test_01");
|
||||||
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||||
o.setCreateTime(buildTime(2022, 2, 3));
|
o.setCreateTime(buildTime(2022, 2, 3));
|
||||||
@@ -123,7 +123,7 @@ public class NotifyTemplateServiceImplTest extends BaseDbUnitTest {
|
|||||||
notifyTemplateMapper.insert(cloneIgnoreId(dbNotifyTemplate, o -> o.setCreateTime(buildTime(2022, 1, 5))));
|
notifyTemplateMapper.insert(cloneIgnoreId(dbNotifyTemplate, o -> o.setCreateTime(buildTime(2022, 1, 5))));
|
||||||
// 准备参数
|
// 准备参数
|
||||||
NotifyTemplatePageReqVO reqVO = new NotifyTemplatePageReqVO();
|
NotifyTemplatePageReqVO reqVO = new NotifyTemplatePageReqVO();
|
||||||
reqVO.setName("芋");
|
reqVO.setName("鹭");
|
||||||
reqVO.setCode("est_01");
|
reqVO.setCode("est_01");
|
||||||
reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||||
reqVO.setCreateTime(buildBetweenTime(2022, 2, 1, 2022, 2, 5));
|
reqVO.setCreateTime(buildBetweenTime(2022, 2, 1, 2022, 2, 5));
|
||||||
|
|||||||
@@ -211,7 +211,7 @@ public class OAuth2ApproveServiceImplTest extends BaseDbUnitTest {
|
|||||||
List<OAuth2ApproveDO> result = oauth2ApproveService.getApproveList(userId, userType, clientId);
|
List<OAuth2ApproveDO> result = oauth2ApproveService.getApproveList(userId, userType, clientId);
|
||||||
// 断言
|
// 断言
|
||||||
assertEquals(1, result.size());
|
assertEquals(1, result.size());
|
||||||
// TODO @芋艿:expiresTime 被屏蔽,仅 win11 会复现,建议后续修复。
|
// TODO @鹭鹭:expiresTime 被屏蔽,仅 win11 会复现,建议后续修复。
|
||||||
assertPojoEquals(approve, result.get(0), "expiresTime");
|
assertPojoEquals(approve, result.get(0), "expiresTime");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ class OAuth2CodeServiceImplTest extends BaseDbUnitTest {
|
|||||||
scopes, redirectUri, state);
|
scopes, redirectUri, state);
|
||||||
// 断言
|
// 断言
|
||||||
OAuth2CodeDO dbCodeDO = oauth2CodeMapper.selectByCode(codeDO.getCode());
|
OAuth2CodeDO dbCodeDO = oauth2CodeMapper.selectByCode(codeDO.getCode());
|
||||||
// TODO @芋艿:expiresTime 被屏蔽,仅 win11 会复现,建议后续修复。
|
// TODO @鹭鹭:expiresTime 被屏蔽,仅 win11 会复现,建议后续修复。
|
||||||
assertPojoEquals(codeDO, dbCodeDO, "expiresTime", "createTime", "updateTime", "deleted");
|
assertPojoEquals(codeDO, dbCodeDO, "expiresTime", "createTime", "updateTime", "deleted");
|
||||||
assertEquals(userId, codeDO.getUserId());
|
assertEquals(userId, codeDO.getUserId());
|
||||||
assertEquals(userType, codeDO.getUserType());
|
assertEquals(userType, codeDO.getUserType());
|
||||||
@@ -93,7 +93,7 @@ class OAuth2CodeServiceImplTest extends BaseDbUnitTest {
|
|||||||
|
|
||||||
// 调用
|
// 调用
|
||||||
OAuth2CodeDO result = oauth2CodeService.consumeAuthorizationCode(code);
|
OAuth2CodeDO result = oauth2CodeService.consumeAuthorizationCode(code);
|
||||||
// TODO @芋艿:expiresTime 被屏蔽,仅 win11 会复现,建议后续修复。
|
// TODO @鹭鹭:expiresTime 被屏蔽,仅 win11 会复现,建议后续修复。
|
||||||
assertPojoEquals(codeDO, result, "expiresTime");
|
assertPojoEquals(codeDO, result, "expiresTime");
|
||||||
assertNull(oauth2CodeMapper.selectByCode(code));
|
assertNull(oauth2CodeMapper.selectByCode(code));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ public class OAuth2TokenServiceImplTest extends BaseDbAndRedisUnitTest {
|
|||||||
OAuth2AccessTokenDO accessTokenDO = oauth2TokenService.createAccessToken(userId, userType, clientId, scopes);
|
OAuth2AccessTokenDO accessTokenDO = oauth2TokenService.createAccessToken(userId, userType, clientId, scopes);
|
||||||
// 断言访问令牌
|
// 断言访问令牌
|
||||||
OAuth2AccessTokenDO dbAccessTokenDO = oauth2AccessTokenMapper.selectByAccessToken(accessTokenDO.getAccessToken());
|
OAuth2AccessTokenDO dbAccessTokenDO = oauth2AccessTokenMapper.selectByAccessToken(accessTokenDO.getAccessToken());
|
||||||
// TODO @芋艿:expiresTime 被屏蔽,仅 win11 会复现,建议后续修复。
|
// TODO @鹭鹭:expiresTime 被屏蔽,仅 win11 会复现,建议后续修复。
|
||||||
assertPojoEquals(accessTokenDO, dbAccessTokenDO, "expiresTime", "createTime", "updateTime", "deleted");
|
assertPojoEquals(accessTokenDO, dbAccessTokenDO, "expiresTime", "createTime", "updateTime", "deleted");
|
||||||
assertEquals(userId, accessTokenDO.getUserId());
|
assertEquals(userId, accessTokenDO.getUserId());
|
||||||
assertEquals(userType, accessTokenDO.getUserType());
|
assertEquals(userType, accessTokenDO.getUserType());
|
||||||
@@ -89,7 +89,7 @@ public class OAuth2TokenServiceImplTest extends BaseDbAndRedisUnitTest {
|
|||||||
assertFalse(DateUtils.isExpired(accessTokenDO.getExpiresTime()));
|
assertFalse(DateUtils.isExpired(accessTokenDO.getExpiresTime()));
|
||||||
// 断言访问令牌的缓存
|
// 断言访问令牌的缓存
|
||||||
OAuth2AccessTokenDO redisAccessTokenDO = oauth2AccessTokenRedisDAO.get(accessTokenDO.getAccessToken());
|
OAuth2AccessTokenDO redisAccessTokenDO = oauth2AccessTokenRedisDAO.get(accessTokenDO.getAccessToken());
|
||||||
// TODO @芋艿:expiresTime 被屏蔽,仅 win11 会复现,建议后续修复。
|
// TODO @鹭鹭:expiresTime 被屏蔽,仅 win11 会复现,建议后续修复。
|
||||||
assertPojoEquals(accessTokenDO, redisAccessTokenDO, "expiresTime", "createTime", "updateTime", "deleted");
|
assertPojoEquals(accessTokenDO, redisAccessTokenDO, "expiresTime", "createTime", "updateTime", "deleted");
|
||||||
// 断言刷新令牌
|
// 断言刷新令牌
|
||||||
OAuth2RefreshTokenDO refreshTokenDO = oauth2RefreshTokenMapper.selectList().get(0);
|
OAuth2RefreshTokenDO refreshTokenDO = oauth2RefreshTokenMapper.selectList().get(0);
|
||||||
@@ -180,14 +180,14 @@ public class OAuth2TokenServiceImplTest extends BaseDbAndRedisUnitTest {
|
|||||||
assertNull(oauth2AccessTokenRedisDAO.get(accessTokenDO.getAccessToken()));
|
assertNull(oauth2AccessTokenRedisDAO.get(accessTokenDO.getAccessToken()));
|
||||||
// 断言,新的访问令牌
|
// 断言,新的访问令牌
|
||||||
OAuth2AccessTokenDO dbAccessTokenDO = oauth2AccessTokenMapper.selectByAccessToken(newAccessTokenDO.getAccessToken());
|
OAuth2AccessTokenDO dbAccessTokenDO = oauth2AccessTokenMapper.selectByAccessToken(newAccessTokenDO.getAccessToken());
|
||||||
// TODO @芋艿:expiresTime 被屏蔽,仅 win11 会复现,建议后续修复。
|
// TODO @鹭鹭:expiresTime 被屏蔽,仅 win11 会复现,建议后续修复。
|
||||||
assertPojoEquals(newAccessTokenDO, dbAccessTokenDO, "expiresTime", "createTime", "updateTime", "deleted");
|
assertPojoEquals(newAccessTokenDO, dbAccessTokenDO, "expiresTime", "createTime", "updateTime", "deleted");
|
||||||
assertPojoEquals(newAccessTokenDO, refreshTokenDO, "id", "expiresTime", "createTime", "updateTime", "deleted",
|
assertPojoEquals(newAccessTokenDO, refreshTokenDO, "id", "expiresTime", "createTime", "updateTime", "deleted",
|
||||||
"creator", "updater");
|
"creator", "updater");
|
||||||
assertFalse(DateUtils.isExpired(newAccessTokenDO.getExpiresTime()));
|
assertFalse(DateUtils.isExpired(newAccessTokenDO.getExpiresTime()));
|
||||||
// 断言,新的访问令牌的缓存
|
// 断言,新的访问令牌的缓存
|
||||||
OAuth2AccessTokenDO redisAccessTokenDO = oauth2AccessTokenRedisDAO.get(newAccessTokenDO.getAccessToken());
|
OAuth2AccessTokenDO redisAccessTokenDO = oauth2AccessTokenRedisDAO.get(newAccessTokenDO.getAccessToken());
|
||||||
// TODO @芋艿:expiresTime 被屏蔽,仅 win11 会复现,建议后续修复。
|
// TODO @鹭鹭:expiresTime 被屏蔽,仅 win11 会复现,建议后续修复。
|
||||||
assertPojoEquals(newAccessTokenDO, redisAccessTokenDO, "expiresTime", "createTime", "updateTime", "deleted");
|
assertPojoEquals(newAccessTokenDO, redisAccessTokenDO, "expiresTime", "createTime", "updateTime", "deleted");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,10 +203,10 @@ public class OAuth2TokenServiceImplTest extends BaseDbAndRedisUnitTest {
|
|||||||
// 调用
|
// 调用
|
||||||
OAuth2AccessTokenDO result = oauth2TokenService.getAccessToken(accessToken);
|
OAuth2AccessTokenDO result = oauth2TokenService.getAccessToken(accessToken);
|
||||||
// 断言
|
// 断言
|
||||||
// TODO @芋艿:expiresTime 被屏蔽,仅 win11 会复现,建议后续修复。
|
// TODO @鹭鹭:expiresTime 被屏蔽,仅 win11 会复现,建议后续修复。
|
||||||
assertPojoEquals(accessTokenDO, result, "expiresTime", "createTime", "updateTime", "deleted",
|
assertPojoEquals(accessTokenDO, result, "expiresTime", "createTime", "updateTime", "deleted",
|
||||||
"creator", "updater");
|
"creator", "updater");
|
||||||
// TODO @芋艿:expiresTime 被屏蔽,仅 win11 会复现,建议后续修复。
|
// TODO @鹭鹭:expiresTime 被屏蔽,仅 win11 会复现,建议后续修复。
|
||||||
assertPojoEquals(accessTokenDO, oauth2AccessTokenRedisDAO.get(accessToken), "expiresTime", "createTime", "updateTime", "deleted",
|
assertPojoEquals(accessTokenDO, oauth2AccessTokenRedisDAO.get(accessToken), "expiresTime", "createTime", "updateTime", "deleted",
|
||||||
"creator", "updater");
|
"creator", "updater");
|
||||||
}
|
}
|
||||||
@@ -261,7 +261,7 @@ public class OAuth2TokenServiceImplTest extends BaseDbAndRedisUnitTest {
|
|||||||
// 调研,并断言
|
// 调研,并断言
|
||||||
OAuth2AccessTokenDO result = oauth2TokenService.getAccessToken(accessToken);
|
OAuth2AccessTokenDO result = oauth2TokenService.getAccessToken(accessToken);
|
||||||
// 断言
|
// 断言
|
||||||
// TODO @芋艿:expiresTime 被屏蔽,仅 win11 会复现,建议后续修复。
|
// TODO @鹭鹭:expiresTime 被屏蔽,仅 win11 会复现,建议后续修复。
|
||||||
assertPojoEquals(accessTokenDO, result, "expiresTime", "createTime", "updateTime", "deleted",
|
assertPojoEquals(accessTokenDO, result, "expiresTime", "createTime", "updateTime", "deleted",
|
||||||
"creator", "updater");
|
"creator", "updater");
|
||||||
}
|
}
|
||||||
@@ -284,7 +284,7 @@ public class OAuth2TokenServiceImplTest extends BaseDbAndRedisUnitTest {
|
|||||||
oauth2RefreshTokenMapper.insert(refreshTokenDO);
|
oauth2RefreshTokenMapper.insert(refreshTokenDO);
|
||||||
// 调用
|
// 调用
|
||||||
OAuth2AccessTokenDO result = oauth2TokenService.removeAccessToken(accessTokenDO.getAccessToken());
|
OAuth2AccessTokenDO result = oauth2TokenService.removeAccessToken(accessTokenDO.getAccessToken());
|
||||||
// TODO @芋艿:expiresTime 被屏蔽,仅 win11 会复现,建议后续修复。
|
// TODO @鹭鹭:expiresTime 被屏蔽,仅 win11 会复现,建议后续修复。
|
||||||
assertPojoEquals(accessTokenDO, result, "expiresTime", "createTime", "updateTime", "deleted",
|
assertPojoEquals(accessTokenDO, result, "expiresTime", "createTime", "updateTime", "deleted",
|
||||||
"creator", "updater");
|
"creator", "updater");
|
||||||
// 断言数据
|
// 断言数据
|
||||||
@@ -323,7 +323,7 @@ public class OAuth2TokenServiceImplTest extends BaseDbAndRedisUnitTest {
|
|||||||
// 断言
|
// 断言
|
||||||
assertEquals(1, pageResult.getTotal());
|
assertEquals(1, pageResult.getTotal());
|
||||||
assertEquals(1, pageResult.getList().size());
|
assertEquals(1, pageResult.getList().size());
|
||||||
// TODO @芋艿:expiresTime 被屏蔽,仅 win11 会复现,建议后续修复。
|
// TODO @鹭鹭:expiresTime 被屏蔽,仅 win11 会复现,建议后续修复。
|
||||||
assertPojoEquals(dbAccessToken, pageResult.getList().get(0), "expiresTime");
|
assertPojoEquals(dbAccessToken, pageResult.getList().get(0), "expiresTime");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,331 +0,0 @@
|
|||||||
package cn.iocoder.lyzsys.module.system.service.permission;
|
|
||||||
|
|
||||||
import cn.iocoder.lyzsys.framework.common.enums.CommonStatusEnum;
|
|
||||||
import cn.iocoder.lyzsys.framework.test.core.ut.BaseDbUnitTest;
|
|
||||||
import cn.iocoder.lyzsys.module.system.controller.admin.permission.vo.menu.MenuListReqVO;
|
|
||||||
import cn.iocoder.lyzsys.module.system.controller.admin.permission.vo.menu.MenuSaveVO;
|
|
||||||
import cn.iocoder.lyzsys.module.system.dal.dataobject.permission.MenuDO;
|
|
||||||
import cn.iocoder.lyzsys.module.system.dal.mysql.permission.MenuMapper;
|
|
||||||
import cn.iocoder.lyzsys.module.system.enums.permission.MenuTypeEnum;
|
|
||||||
import cn.iocoder.lyzsys.module.system.service.tenant.TenantService;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
|
||||||
import org.springframework.context.annotation.Import;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import static cn.iocoder.lyzsys.framework.common.util.collection.SetUtils.asSet;
|
|
||||||
import static cn.iocoder.lyzsys.framework.common.util.object.ObjectUtils.cloneIgnoreId;
|
|
||||||
import static cn.iocoder.lyzsys.framework.test.core.util.AssertUtils.assertPojoEquals;
|
|
||||||
import static cn.iocoder.lyzsys.framework.test.core.util.AssertUtils.assertServiceException;
|
|
||||||
import static cn.iocoder.lyzsys.framework.test.core.util.RandomUtils.*;
|
|
||||||
import static cn.iocoder.lyzsys.module.system.dal.dataobject.permission.MenuDO.ID_ROOT;
|
|
||||||
import static cn.iocoder.lyzsys.module.system.enums.ErrorCodeConstants.*;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
|
||||||
import static org.mockito.ArgumentMatchers.argThat;
|
|
||||||
import static org.mockito.Mockito.doNothing;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
|
|
||||||
@Import(MenuServiceImpl.class)
|
|
||||||
public class MenuServiceImplTest extends BaseDbUnitTest {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private MenuServiceImpl menuService;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private MenuMapper menuMapper;
|
|
||||||
|
|
||||||
@MockBean
|
|
||||||
private PermissionService permissionService;
|
|
||||||
@MockBean
|
|
||||||
private TenantService tenantService;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testCreateMenu_success() {
|
|
||||||
// mock 数据(构造父菜单)
|
|
||||||
MenuDO menuDO = buildMenuDO(MenuTypeEnum.MENU,
|
|
||||||
"parent", 0L);
|
|
||||||
menuMapper.insert(menuDO);
|
|
||||||
Long parentId = menuDO.getId();
|
|
||||||
// 准备参数
|
|
||||||
MenuSaveVO reqVO = randomPojo(MenuSaveVO.class, o -> {
|
|
||||||
o.setParentId(parentId);
|
|
||||||
o.setName("testSonName");
|
|
||||||
o.setType(MenuTypeEnum.MENU.getType());
|
|
||||||
}).setId(null); // 防止 id 被赋值
|
|
||||||
Long menuId = menuService.createMenu(reqVO);
|
|
||||||
|
|
||||||
// 校验记录的属性是否正确
|
|
||||||
MenuDO dbMenu = menuMapper.selectById(menuId);
|
|
||||||
assertPojoEquals(reqVO, dbMenu, "id");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testUpdateMenu_success() {
|
|
||||||
// mock 数据(构造父子菜单)
|
|
||||||
MenuDO sonMenuDO = createParentAndSonMenu();
|
|
||||||
Long sonId = sonMenuDO.getId();
|
|
||||||
// 准备参数
|
|
||||||
MenuSaveVO reqVO = randomPojo(MenuSaveVO.class, o -> {
|
|
||||||
o.setId(sonId);
|
|
||||||
o.setName("testSonName"); // 修改名字
|
|
||||||
o.setParentId(sonMenuDO.getParentId());
|
|
||||||
o.setType(MenuTypeEnum.MENU.getType());
|
|
||||||
});
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
menuService.updateMenu(reqVO);
|
|
||||||
// 校验记录的属性是否正确
|
|
||||||
MenuDO dbMenu = menuMapper.selectById(sonId);
|
|
||||||
assertPojoEquals(reqVO, dbMenu);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testUpdateMenu_sonIdNotExist() {
|
|
||||||
// 准备参数
|
|
||||||
MenuSaveVO reqVO = randomPojo(MenuSaveVO.class);
|
|
||||||
// 调用,并断言异常
|
|
||||||
assertServiceException(() -> menuService.updateMenu(reqVO), MENU_NOT_EXISTS);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testDeleteMenu_success() {
|
|
||||||
// mock 数据
|
|
||||||
MenuDO menuDO = randomPojo(MenuDO.class);
|
|
||||||
menuMapper.insert(menuDO);
|
|
||||||
// 准备参数
|
|
||||||
Long id = menuDO.getId();
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
menuService.deleteMenu(id);
|
|
||||||
// 断言
|
|
||||||
MenuDO dbMenuDO = menuMapper.selectById(id);
|
|
||||||
assertNull(dbMenuDO);
|
|
||||||
verify(permissionService).processMenuDeleted(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testDeleteMenu_menuNotExist() {
|
|
||||||
assertServiceException(() -> menuService.deleteMenu(randomLongId()),
|
|
||||||
MENU_NOT_EXISTS);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testDeleteMenu_existChildren() {
|
|
||||||
// mock 数据(构造父子菜单)
|
|
||||||
MenuDO sonMenu = createParentAndSonMenu();
|
|
||||||
// 准备参数
|
|
||||||
Long parentId = sonMenu.getParentId();
|
|
||||||
|
|
||||||
// 调用并断言异常
|
|
||||||
assertServiceException(() -> menuService.deleteMenu(parentId), MENU_EXISTS_CHILDREN);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetMenuList_all() {
|
|
||||||
// mock 数据
|
|
||||||
MenuDO menu100 = randomPojo(MenuDO.class);
|
|
||||||
menuMapper.insert(menu100);
|
|
||||||
MenuDO menu101 = randomPojo(MenuDO.class);
|
|
||||||
menuMapper.insert(menu101);
|
|
||||||
// 准备参数
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
List<MenuDO> list = menuService.getMenuList();
|
|
||||||
// 断言
|
|
||||||
assertEquals(2, list.size());
|
|
||||||
assertPojoEquals(menu100, list.get(0));
|
|
||||||
assertPojoEquals(menu101, list.get(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetMenuList() {
|
|
||||||
// mock 数据
|
|
||||||
MenuDO menuDO = randomPojo(MenuDO.class, o -> o.setName("芋艿").setStatus(CommonStatusEnum.ENABLE.getStatus()));
|
|
||||||
menuMapper.insert(menuDO);
|
|
||||||
// 测试 status 不匹配
|
|
||||||
menuMapper.insert(cloneIgnoreId(menuDO, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus())));
|
|
||||||
// 测试 name 不匹配
|
|
||||||
menuMapper.insert(cloneIgnoreId(menuDO, o -> o.setName("艿")));
|
|
||||||
// 准备参数
|
|
||||||
MenuListReqVO reqVO = new MenuListReqVO().setName("芋").setStatus(CommonStatusEnum.ENABLE.getStatus());
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
List<MenuDO> result = menuService.getMenuList(reqVO);
|
|
||||||
// 断言
|
|
||||||
assertEquals(1, result.size());
|
|
||||||
assertPojoEquals(menuDO, result.get(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetMenuListByTenant() {
|
|
||||||
// mock 数据
|
|
||||||
MenuDO menu100 = randomPojo(MenuDO.class, o -> o.setId(100L).setStatus(CommonStatusEnum.ENABLE.getStatus()));
|
|
||||||
menuMapper.insert(menu100);
|
|
||||||
MenuDO menu101 = randomPojo(MenuDO.class, o -> o.setId(101L).setStatus(CommonStatusEnum.DISABLE.getStatus()));
|
|
||||||
menuMapper.insert(menu101);
|
|
||||||
MenuDO menu102 = randomPojo(MenuDO.class, o -> o.setId(102L).setStatus(CommonStatusEnum.ENABLE.getStatus()));
|
|
||||||
menuMapper.insert(menu102);
|
|
||||||
// mock 过滤菜单
|
|
||||||
Set<Long> menuIds = asSet(100L, 101L);
|
|
||||||
doNothing().when(tenantService).handleTenantMenu(argThat(handler -> {
|
|
||||||
handler.handle(menuIds);
|
|
||||||
return true;
|
|
||||||
}));
|
|
||||||
// 准备参数
|
|
||||||
MenuListReqVO reqVO = new MenuListReqVO().setStatus(CommonStatusEnum.ENABLE.getStatus());
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
List<MenuDO> result = menuService.getMenuListByTenant(reqVO);
|
|
||||||
// 断言
|
|
||||||
assertEquals(1, result.size());
|
|
||||||
assertPojoEquals(menu100, result.get(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetMenuIdListByPermissionFromCache() {
|
|
||||||
// mock 数据
|
|
||||||
MenuDO menu100 = randomPojo(MenuDO.class);
|
|
||||||
menuMapper.insert(menu100);
|
|
||||||
MenuDO menu101 = randomPojo(MenuDO.class);
|
|
||||||
menuMapper.insert(menu101);
|
|
||||||
// 准备参数
|
|
||||||
String permission = menu100.getPermission();
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
List<Long> ids = menuService.getMenuIdListByPermissionFromCache(permission);
|
|
||||||
// 断言
|
|
||||||
assertEquals(1, ids.size());
|
|
||||||
assertEquals(menu100.getId(), ids.get(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetMenuList_ids() {
|
|
||||||
// mock 数据
|
|
||||||
MenuDO menu100 = randomPojo(MenuDO.class);
|
|
||||||
menuMapper.insert(menu100);
|
|
||||||
MenuDO menu101 = randomPojo(MenuDO.class);
|
|
||||||
menuMapper.insert(menu101);
|
|
||||||
// 准备参数
|
|
||||||
Collection<Long> ids = Collections.singleton(menu100.getId());
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
List<MenuDO> list = menuService.getMenuList(ids);
|
|
||||||
// 断言
|
|
||||||
assertEquals(1, list.size());
|
|
||||||
assertPojoEquals(menu100, list.get(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetMenu() {
|
|
||||||
// mock 数据
|
|
||||||
MenuDO menu = randomPojo(MenuDO.class);
|
|
||||||
menuMapper.insert(menu);
|
|
||||||
// 准备参数
|
|
||||||
Long id = menu.getId();
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
MenuDO dbMenu = menuService.getMenu(id);
|
|
||||||
// 断言
|
|
||||||
assertPojoEquals(menu, dbMenu);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testValidateParentMenu_success() {
|
|
||||||
// mock 数据
|
|
||||||
MenuDO menuDO = buildMenuDO(MenuTypeEnum.MENU, "parent", 0L);
|
|
||||||
menuMapper.insert(menuDO);
|
|
||||||
// 准备参数
|
|
||||||
Long parentId = menuDO.getId();
|
|
||||||
|
|
||||||
// 调用,无需断言
|
|
||||||
menuService.validateParentMenu(parentId, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testValidateParentMenu_canNotSetSelfToBeParent() {
|
|
||||||
// 调用,并断言异常
|
|
||||||
assertServiceException(() -> menuService.validateParentMenu(1L, 1L),
|
|
||||||
MENU_PARENT_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testValidateParentMenu_parentNotExist() {
|
|
||||||
// 调用,并断言异常
|
|
||||||
assertServiceException(() -> menuService.validateParentMenu(randomLongId(), null),
|
|
||||||
MENU_PARENT_NOT_EXISTS);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testValidateParentMenu_parentTypeError() {
|
|
||||||
// mock 数据
|
|
||||||
MenuDO menuDO = buildMenuDO(MenuTypeEnum.BUTTON, "parent", 0L);
|
|
||||||
menuMapper.insert(menuDO);
|
|
||||||
// 准备参数
|
|
||||||
Long parentId = menuDO.getId();
|
|
||||||
|
|
||||||
// 调用,并断言异常
|
|
||||||
assertServiceException(() -> menuService.validateParentMenu(parentId, null),
|
|
||||||
MENU_PARENT_NOT_DIR_OR_MENU);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testValidateMenu_Name_success() {
|
|
||||||
// mock 父子菜单
|
|
||||||
MenuDO sonMenu = createParentAndSonMenu();
|
|
||||||
// 准备参数
|
|
||||||
Long parentId = sonMenu.getParentId();
|
|
||||||
Long otherSonMenuId = randomLongId();
|
|
||||||
String otherSonMenuName = randomString();
|
|
||||||
|
|
||||||
// 调用,无需断言
|
|
||||||
menuService.validateMenuName(parentId, otherSonMenuName, otherSonMenuId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testValidateMenu_sonMenuNameNameDuplicate() {
|
|
||||||
// mock 父子菜单
|
|
||||||
MenuDO sonMenu = createParentAndSonMenu();
|
|
||||||
// 准备参数
|
|
||||||
Long parentId = sonMenu.getParentId();
|
|
||||||
Long otherSonMenuId = randomLongId();
|
|
||||||
String otherSonMenuName = sonMenu.getName(); //相同名称
|
|
||||||
|
|
||||||
// 调用,并断言异常
|
|
||||||
assertServiceException(() -> menuService.validateMenuName(parentId, otherSonMenuName, otherSonMenuId),
|
|
||||||
MENU_NAME_DUPLICATE);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ====================== 初始化方法 ======================
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 插入父子菜单,返回子菜单
|
|
||||||
*
|
|
||||||
* @return 子菜单
|
|
||||||
*/
|
|
||||||
private MenuDO createParentAndSonMenu() {
|
|
||||||
// 构造父子菜单
|
|
||||||
MenuDO parentMenuDO = buildMenuDO(MenuTypeEnum.MENU, "parent", ID_ROOT);
|
|
||||||
menuMapper.insert(parentMenuDO);
|
|
||||||
// 构建子菜单
|
|
||||||
MenuDO sonMenuDO = buildMenuDO(MenuTypeEnum.MENU, "testSonName",
|
|
||||||
parentMenuDO.getParentId());
|
|
||||||
menuMapper.insert(sonMenuDO);
|
|
||||||
return sonMenuDO;
|
|
||||||
}
|
|
||||||
|
|
||||||
private MenuDO buildMenuDO(MenuTypeEnum type, String name, Long parentId) {
|
|
||||||
return buildMenuDO(type, name, parentId, randomCommonStatus());
|
|
||||||
}
|
|
||||||
|
|
||||||
private MenuDO buildMenuDO(MenuTypeEnum type, String name, Long parentId, Integer status) {
|
|
||||||
return randomPojo(MenuDO.class, o -> o.setId(null).setName(name).setParentId(parentId)
|
|
||||||
.setType(type.getType()).setStatus(status));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,527 +0,0 @@
|
|||||||
package cn.iocoder.lyzsys.module.system.service.permission;
|
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
|
||||||
import cn.hutool.extra.spring.SpringUtil;
|
|
||||||
import cn.iocoder.lyzsys.framework.common.biz.system.permission.dto.DeptDataPermissionRespDTO;
|
|
||||||
import cn.iocoder.lyzsys.framework.common.enums.CommonStatusEnum;
|
|
||||||
import cn.iocoder.lyzsys.framework.test.core.ut.BaseDbUnitTest;
|
|
||||||
import cn.iocoder.lyzsys.module.system.dal.dataobject.dept.DeptDO;
|
|
||||||
import cn.iocoder.lyzsys.module.system.dal.dataobject.permission.MenuDO;
|
|
||||||
import cn.iocoder.lyzsys.module.system.dal.dataobject.permission.RoleDO;
|
|
||||||
import cn.iocoder.lyzsys.module.system.dal.dataobject.permission.RoleMenuDO;
|
|
||||||
import cn.iocoder.lyzsys.module.system.dal.dataobject.permission.UserRoleDO;
|
|
||||||
import cn.iocoder.lyzsys.module.system.dal.dataobject.user.AdminUserDO;
|
|
||||||
import cn.iocoder.lyzsys.module.system.dal.mysql.permission.RoleMenuMapper;
|
|
||||||
import cn.iocoder.lyzsys.module.system.dal.mysql.permission.UserRoleMapper;
|
|
||||||
import cn.iocoder.lyzsys.module.system.enums.permission.DataScopeEnum;
|
|
||||||
import cn.iocoder.lyzsys.module.system.service.dept.DeptService;
|
|
||||||
import cn.iocoder.lyzsys.module.system.service.user.AdminUserService;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.mockito.MockedStatic;
|
|
||||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
|
||||||
import org.springframework.context.annotation.Import;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import static cn.hutool.core.collection.ListUtil.toList;
|
|
||||||
import static cn.iocoder.lyzsys.framework.common.util.collection.SetUtils.asSet;
|
|
||||||
import static cn.iocoder.lyzsys.framework.test.core.util.AssertUtils.assertPojoEquals;
|
|
||||||
import static cn.iocoder.lyzsys.framework.test.core.util.RandomUtils.randomLongId;
|
|
||||||
import static cn.iocoder.lyzsys.framework.test.core.util.RandomUtils.randomPojo;
|
|
||||||
import static java.util.Collections.singleton;
|
|
||||||
import static java.util.Collections.singletonList;
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
|
||||||
import static org.mockito.Mockito.*;
|
|
||||||
|
|
||||||
@Import({PermissionServiceImpl.class})
|
|
||||||
public class PermissionServiceTest extends BaseDbUnitTest {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private PermissionServiceImpl permissionService;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private RoleMenuMapper roleMenuMapper;
|
|
||||||
@Resource
|
|
||||||
private UserRoleMapper userRoleMapper;
|
|
||||||
|
|
||||||
@MockBean
|
|
||||||
private RoleService roleService;
|
|
||||||
@MockBean
|
|
||||||
private MenuService menuService;
|
|
||||||
@MockBean
|
|
||||||
private DeptService deptService;
|
|
||||||
@MockBean
|
|
||||||
private AdminUserService userService;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testHasAnyPermissions_superAdmin() {
|
|
||||||
try (MockedStatic<SpringUtil> springUtilMockedStatic = mockStatic(SpringUtil.class)) {
|
|
||||||
springUtilMockedStatic.when(() -> SpringUtil.getBean(eq(PermissionServiceImpl.class)))
|
|
||||||
.thenReturn(permissionService);
|
|
||||||
|
|
||||||
// 准备参数
|
|
||||||
Long userId = 1L;
|
|
||||||
String[] roles = new String[]{"system:user:query", "system:user:create"};
|
|
||||||
// mock 用户登录的角色
|
|
||||||
userRoleMapper.insert(randomPojo(UserRoleDO.class).setUserId(userId).setRoleId(100L));
|
|
||||||
RoleDO role = randomPojo(RoleDO.class, o -> o.setId(100L)
|
|
||||||
.setStatus(CommonStatusEnum.ENABLE.getStatus()));
|
|
||||||
when(roleService.getRoleListFromCache(eq(singleton(100L)))).thenReturn(toList(role));
|
|
||||||
// mock 其它方法
|
|
||||||
when(roleService.hasAnySuperAdmin(eq(asSet(100L)))).thenReturn(true);
|
|
||||||
|
|
||||||
// 调用,并断言
|
|
||||||
assertTrue(permissionService.hasAnyPermissions(userId, roles));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testHasAnyPermissions_normal() {
|
|
||||||
try (MockedStatic<SpringUtil> springUtilMockedStatic = mockStatic(SpringUtil.class)) {
|
|
||||||
springUtilMockedStatic.when(() -> SpringUtil.getBean(eq(PermissionServiceImpl.class)))
|
|
||||||
.thenReturn(permissionService);
|
|
||||||
|
|
||||||
// 准备参数
|
|
||||||
Long userId = 1L;
|
|
||||||
String[] roles = new String[]{"system:user:query", "system:user:create"};
|
|
||||||
// mock 用户登录的角色
|
|
||||||
userRoleMapper.insert(randomPojo(UserRoleDO.class).setUserId(userId).setRoleId(100L));
|
|
||||||
RoleDO role = randomPojo(RoleDO.class, o -> o.setId(100L)
|
|
||||||
.setStatus(CommonStatusEnum.ENABLE.getStatus()));
|
|
||||||
when(roleService.getRoleListFromCache(eq(singleton(100L)))).thenReturn(toList(role));
|
|
||||||
// mock 菜单
|
|
||||||
Long menuId = 1000L;
|
|
||||||
when(menuService.getMenuIdListByPermissionFromCache(
|
|
||||||
eq("system:user:create"))).thenReturn(singletonList(menuId));
|
|
||||||
roleMenuMapper.insert(randomPojo(RoleMenuDO.class).setRoleId(100L).setMenuId(1000L));
|
|
||||||
|
|
||||||
// 调用,并断言
|
|
||||||
assertTrue(permissionService.hasAnyPermissions(userId, roles));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testHasAnyRoles() {
|
|
||||||
try (MockedStatic<SpringUtil> springUtilMockedStatic = mockStatic(SpringUtil.class)) {
|
|
||||||
springUtilMockedStatic.when(() -> SpringUtil.getBean(eq(PermissionServiceImpl.class)))
|
|
||||||
.thenReturn(permissionService);
|
|
||||||
|
|
||||||
// 准备参数
|
|
||||||
Long userId = 1L;
|
|
||||||
String[] roles = new String[]{"yunai", "tudou"};
|
|
||||||
// mock 用户与角色的缓存
|
|
||||||
userRoleMapper.insert(randomPojo(UserRoleDO.class).setUserId(userId).setRoleId(100L));
|
|
||||||
RoleDO role = randomPojo(RoleDO.class, o -> o.setId(100L).setCode("tudou")
|
|
||||||
.setStatus(CommonStatusEnum.ENABLE.getStatus()));
|
|
||||||
when(roleService.getRoleListFromCache(eq(singleton(100L)))).thenReturn(toList(role));
|
|
||||||
|
|
||||||
// 调用,并断言
|
|
||||||
assertTrue(permissionService.hasAnyRoles(userId, roles));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ========== 角色-菜单的相关方法 ==========
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testAssignRoleMenu() {
|
|
||||||
// 准备参数
|
|
||||||
Long roleId = 1L;
|
|
||||||
Set<Long> menuIds = asSet(200L, 300L);
|
|
||||||
// mock 数据
|
|
||||||
RoleMenuDO roleMenu01 = randomPojo(RoleMenuDO.class).setRoleId(1L).setMenuId(100L);
|
|
||||||
roleMenuMapper.insert(roleMenu01);
|
|
||||||
RoleMenuDO roleMenu02 = randomPojo(RoleMenuDO.class).setRoleId(1L).setMenuId(200L);
|
|
||||||
roleMenuMapper.insert(roleMenu02);
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
permissionService.assignRoleMenu(roleId, menuIds);
|
|
||||||
// 断言
|
|
||||||
List<RoleMenuDO> roleMenuList = roleMenuMapper.selectList();
|
|
||||||
assertEquals(2, roleMenuList.size());
|
|
||||||
assertEquals(1L, roleMenuList.get(0).getRoleId());
|
|
||||||
assertEquals(200L, roleMenuList.get(0).getMenuId());
|
|
||||||
assertEquals(1L, roleMenuList.get(1).getRoleId());
|
|
||||||
assertEquals(300L, roleMenuList.get(1).getMenuId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testProcessRoleDeleted() {
|
|
||||||
// 准备参数
|
|
||||||
Long roleId = randomLongId();
|
|
||||||
// mock 数据 UserRole
|
|
||||||
UserRoleDO userRoleDO01 = randomPojo(UserRoleDO.class, o -> o.setRoleId(roleId)); // 被删除
|
|
||||||
userRoleMapper.insert(userRoleDO01);
|
|
||||||
UserRoleDO userRoleDO02 = randomPojo(UserRoleDO.class); // 不被删除
|
|
||||||
userRoleMapper.insert(userRoleDO02);
|
|
||||||
// mock 数据 RoleMenu
|
|
||||||
RoleMenuDO roleMenuDO01 = randomPojo(RoleMenuDO.class, o -> o.setRoleId(roleId)); // 被删除
|
|
||||||
roleMenuMapper.insert(roleMenuDO01);
|
|
||||||
RoleMenuDO roleMenuDO02 = randomPojo(RoleMenuDO.class); // 不被删除
|
|
||||||
roleMenuMapper.insert(roleMenuDO02);
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
permissionService.processRoleDeleted(roleId);
|
|
||||||
// 断言数据 RoleMenuDO
|
|
||||||
List<RoleMenuDO> dbRoleMenus = roleMenuMapper.selectList();
|
|
||||||
assertEquals(1, dbRoleMenus.size());
|
|
||||||
assertPojoEquals(dbRoleMenus.get(0), roleMenuDO02);
|
|
||||||
// 断言数据 UserRoleDO
|
|
||||||
List<UserRoleDO> dbUserRoles = userRoleMapper.selectList();
|
|
||||||
assertEquals(1, dbUserRoles.size());
|
|
||||||
assertPojoEquals(dbUserRoles.get(0), userRoleDO02);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testProcessMenuDeleted() {
|
|
||||||
// 准备参数
|
|
||||||
Long menuId = randomLongId();
|
|
||||||
// mock 数据
|
|
||||||
RoleMenuDO roleMenuDO01 = randomPojo(RoleMenuDO.class, o -> o.setMenuId(menuId)); // 被删除
|
|
||||||
roleMenuMapper.insert(roleMenuDO01);
|
|
||||||
RoleMenuDO roleMenuDO02 = randomPojo(RoleMenuDO.class); // 不被删除
|
|
||||||
roleMenuMapper.insert(roleMenuDO02);
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
permissionService.processMenuDeleted(menuId);
|
|
||||||
// 断言数据
|
|
||||||
List<RoleMenuDO> dbRoleMenus = roleMenuMapper.selectList();
|
|
||||||
assertEquals(1, dbRoleMenus.size());
|
|
||||||
assertPojoEquals(dbRoleMenus.get(0), roleMenuDO02);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetRoleMenuIds_superAdmin() {
|
|
||||||
// 准备参数
|
|
||||||
Long roleId = 100L;
|
|
||||||
// mock 方法
|
|
||||||
when(roleService.hasAnySuperAdmin(eq(singleton(100L)))).thenReturn(true);
|
|
||||||
List<MenuDO> menuList = singletonList(randomPojo(MenuDO.class).setId(1L));
|
|
||||||
when(menuService.getMenuList()).thenReturn(menuList);
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
Set<Long> menuIds = permissionService.getRoleMenuListByRoleId(roleId);
|
|
||||||
// 断言
|
|
||||||
assertEquals(singleton(1L), menuIds);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetRoleMenuIds_normal() {
|
|
||||||
// 准备参数
|
|
||||||
Long roleId = 100L;
|
|
||||||
// mock 数据
|
|
||||||
RoleMenuDO roleMenu01 = randomPojo(RoleMenuDO.class).setRoleId(100L).setMenuId(1L);
|
|
||||||
roleMenuMapper.insert(roleMenu01);
|
|
||||||
RoleMenuDO roleMenu02 = randomPojo(RoleMenuDO.class).setRoleId(100L).setMenuId(2L);
|
|
||||||
roleMenuMapper.insert(roleMenu02);
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
Set<Long> menuIds = permissionService.getRoleMenuListByRoleId(roleId);
|
|
||||||
// 断言
|
|
||||||
assertEquals(asSet(1L, 2L), menuIds);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetMenuRoleIdListByMenuIdFromCache() {
|
|
||||||
// 准备参数
|
|
||||||
Long menuId = 1L;
|
|
||||||
// mock 数据
|
|
||||||
RoleMenuDO roleMenu01 = randomPojo(RoleMenuDO.class).setRoleId(100L).setMenuId(1L);
|
|
||||||
roleMenuMapper.insert(roleMenu01);
|
|
||||||
RoleMenuDO roleMenu02 = randomPojo(RoleMenuDO.class).setRoleId(200L).setMenuId(1L);
|
|
||||||
roleMenuMapper.insert(roleMenu02);
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
Set<Long> roleIds = permissionService.getMenuRoleIdListByMenuIdFromCache(menuId);
|
|
||||||
// 断言
|
|
||||||
assertEquals(asSet(100L, 200L), roleIds);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ========== 用户-角色的相关方法 ==========
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testAssignUserRole() {
|
|
||||||
// 准备参数
|
|
||||||
Long userId = 1L;
|
|
||||||
Set<Long> roleIds = asSet(200L, 300L);
|
|
||||||
// mock 数据
|
|
||||||
UserRoleDO userRole01 = randomPojo(UserRoleDO.class).setUserId(1L).setRoleId(100L);
|
|
||||||
userRoleMapper.insert(userRole01);
|
|
||||||
UserRoleDO userRole02 = randomPojo(UserRoleDO.class).setUserId(1L).setRoleId(200L);
|
|
||||||
userRoleMapper.insert(userRole02);
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
permissionService.assignUserRole(userId, roleIds);
|
|
||||||
// 断言
|
|
||||||
List<UserRoleDO> userRoleDOList = userRoleMapper.selectList();
|
|
||||||
assertEquals(2, userRoleDOList.size());
|
|
||||||
assertEquals(1L, userRoleDOList.get(0).getUserId());
|
|
||||||
assertEquals(200L, userRoleDOList.get(0).getRoleId());
|
|
||||||
assertEquals(1L, userRoleDOList.get(1).getUserId());
|
|
||||||
assertEquals(300L, userRoleDOList.get(1).getRoleId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testProcessUserDeleted() {
|
|
||||||
// 准备参数
|
|
||||||
Long userId = randomLongId();
|
|
||||||
// mock 数据
|
|
||||||
UserRoleDO userRoleDO01 = randomPojo(UserRoleDO.class, o -> o.setUserId(userId)); // 被删除
|
|
||||||
userRoleMapper.insert(userRoleDO01);
|
|
||||||
UserRoleDO userRoleDO02 = randomPojo(UserRoleDO.class); // 不被删除
|
|
||||||
userRoleMapper.insert(userRoleDO02);
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
permissionService.processUserDeleted(userId);
|
|
||||||
// 断言数据
|
|
||||||
List<UserRoleDO> dbUserRoles = userRoleMapper.selectList();
|
|
||||||
assertEquals(1, dbUserRoles.size());
|
|
||||||
assertPojoEquals(dbUserRoles.get(0), userRoleDO02);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetUserRoleIdListByUserId() {
|
|
||||||
// 准备参数
|
|
||||||
Long userId = 1L;
|
|
||||||
// mock 数据
|
|
||||||
UserRoleDO userRoleDO01 = randomPojo(UserRoleDO.class, o -> o.setUserId(1L).setRoleId(10L));
|
|
||||||
userRoleMapper.insert(userRoleDO01);
|
|
||||||
UserRoleDO roleMenuDO02 = randomPojo(UserRoleDO.class, o -> o.setUserId(1L).setRoleId(20L));
|
|
||||||
userRoleMapper.insert(roleMenuDO02);
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
Set<Long> result = permissionService.getUserRoleIdListByUserId(userId);
|
|
||||||
// 断言
|
|
||||||
assertEquals(asSet(10L, 20L), result);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetUserRoleIdListByUserIdFromCache() {
|
|
||||||
// 准备参数
|
|
||||||
Long userId = 1L;
|
|
||||||
// mock 数据
|
|
||||||
UserRoleDO userRoleDO01 = randomPojo(UserRoleDO.class, o -> o.setUserId(1L).setRoleId(10L));
|
|
||||||
userRoleMapper.insert(userRoleDO01);
|
|
||||||
UserRoleDO roleMenuDO02 = randomPojo(UserRoleDO.class, o -> o.setUserId(1L).setRoleId(20L));
|
|
||||||
userRoleMapper.insert(roleMenuDO02);
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
Set<Long> result = permissionService.getUserRoleIdListByUserIdFromCache(userId);
|
|
||||||
// 断言
|
|
||||||
assertEquals(asSet(10L, 20L), result);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetUserRoleIdsFromCache() {
|
|
||||||
// 准备参数
|
|
||||||
Long userId = 1L;
|
|
||||||
// mock 数据
|
|
||||||
UserRoleDO userRoleDO01 = randomPojo(UserRoleDO.class, o -> o.setUserId(1L).setRoleId(10L));
|
|
||||||
userRoleMapper.insert(userRoleDO01);
|
|
||||||
UserRoleDO roleMenuDO02 = randomPojo(UserRoleDO.class, o -> o.setUserId(1L).setRoleId(20L));
|
|
||||||
userRoleMapper.insert(roleMenuDO02);
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
Set<Long> result = permissionService.getUserRoleIdListByUserIdFromCache(userId);
|
|
||||||
// 断言
|
|
||||||
assertEquals(asSet(10L, 20L), result);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetUserRoleIdListByRoleId() {
|
|
||||||
// 准备参数
|
|
||||||
Collection<Long> roleIds = asSet(10L, 20L);
|
|
||||||
// mock 数据
|
|
||||||
UserRoleDO userRoleDO01 = randomPojo(UserRoleDO.class, o -> o.setUserId(1L).setRoleId(10L));
|
|
||||||
userRoleMapper.insert(userRoleDO01);
|
|
||||||
UserRoleDO roleMenuDO02 = randomPojo(UserRoleDO.class, o -> o.setUserId(2L).setRoleId(20L));
|
|
||||||
userRoleMapper.insert(roleMenuDO02);
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
Set<Long> result = permissionService.getUserRoleIdListByRoleId(roleIds);
|
|
||||||
// 断言
|
|
||||||
assertEquals(asSet(1L, 2L), result);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetEnableUserRoleListByUserIdFromCache() {
|
|
||||||
try (MockedStatic<SpringUtil> springUtilMockedStatic = mockStatic(SpringUtil.class)) {
|
|
||||||
springUtilMockedStatic.when(() -> SpringUtil.getBean(eq(PermissionServiceImpl.class)))
|
|
||||||
.thenReturn(permissionService);
|
|
||||||
|
|
||||||
// 准备参数
|
|
||||||
Long userId = 1L;
|
|
||||||
// mock 用户登录的角色
|
|
||||||
userRoleMapper.insert(randomPojo(UserRoleDO.class).setUserId(userId).setRoleId(100L));
|
|
||||||
userRoleMapper.insert(randomPojo(UserRoleDO.class).setUserId(userId).setRoleId(200L));
|
|
||||||
RoleDO role01 = randomPojo(RoleDO.class, o -> o.setId(100L)
|
|
||||||
.setStatus(CommonStatusEnum.ENABLE.getStatus()));
|
|
||||||
RoleDO role02 = randomPojo(RoleDO.class, o -> o.setId(200L)
|
|
||||||
.setStatus(CommonStatusEnum.DISABLE.getStatus()));
|
|
||||||
when(roleService.getRoleListFromCache(eq(asSet(100L, 200L))))
|
|
||||||
.thenReturn(toList(role01, role02));
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
List<RoleDO> result = permissionService.getEnableUserRoleListByUserIdFromCache(userId);
|
|
||||||
// 断言
|
|
||||||
assertEquals(1, result.size());
|
|
||||||
assertPojoEquals(role01, result.get(0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ========== 用户-部门的相关方法 ==========
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testAssignRoleDataScope() {
|
|
||||||
// 准备参数
|
|
||||||
Long roleId = 1L;
|
|
||||||
Integer dataScope = 2;
|
|
||||||
Set<Long> dataScopeDeptIds = asSet(10L, 20L);
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
permissionService.assignRoleDataScope(roleId, dataScope, dataScopeDeptIds);
|
|
||||||
// 断言
|
|
||||||
verify(roleService).updateRoleDataScope(eq(roleId), eq(dataScope), eq(dataScopeDeptIds));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetDeptDataPermission_All() {
|
|
||||||
try (MockedStatic<SpringUtil> springUtilMockedStatic = mockStatic(SpringUtil.class)) {
|
|
||||||
springUtilMockedStatic.when(() -> SpringUtil.getBean(eq(PermissionServiceImpl.class)))
|
|
||||||
.thenReturn(permissionService);
|
|
||||||
|
|
||||||
// 准备参数
|
|
||||||
Long userId = 1L;
|
|
||||||
// mock 用户的角色编号
|
|
||||||
userRoleMapper.insert(randomPojo(UserRoleDO.class).setUserId(userId).setRoleId(2L));
|
|
||||||
// mock 获得用户的角色
|
|
||||||
RoleDO roleDO = randomPojo(RoleDO.class, o -> o.setDataScope(DataScopeEnum.ALL.getScope())
|
|
||||||
.setStatus(CommonStatusEnum.ENABLE.getStatus()));
|
|
||||||
when(roleService.getRoleListFromCache(eq(singleton(2L)))).thenReturn(toList(roleDO));
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
DeptDataPermissionRespDTO result = permissionService.getDeptDataPermission(userId);
|
|
||||||
// 断言
|
|
||||||
assertTrue(result.getAll());
|
|
||||||
assertFalse(result.getSelf());
|
|
||||||
assertTrue(CollUtil.isEmpty(result.getDeptIds()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetDeptDataPermission_DeptCustom() {
|
|
||||||
try (MockedStatic<SpringUtil> springUtilMockedStatic = mockStatic(SpringUtil.class)) {
|
|
||||||
springUtilMockedStatic.when(() -> SpringUtil.getBean(eq(PermissionServiceImpl.class)))
|
|
||||||
.thenReturn(permissionService);
|
|
||||||
|
|
||||||
// 准备参数
|
|
||||||
Long userId = 1L;
|
|
||||||
// mock 用户的角色编号
|
|
||||||
userRoleMapper.insert(randomPojo(UserRoleDO.class).setUserId(userId).setRoleId(2L));
|
|
||||||
// mock 获得用户的角色
|
|
||||||
RoleDO roleDO = randomPojo(RoleDO.class, o -> o.setDataScope(DataScopeEnum.DEPT_CUSTOM.getScope())
|
|
||||||
.setStatus(CommonStatusEnum.ENABLE.getStatus()));
|
|
||||||
when(roleService.getRoleListFromCache(eq(singleton(2L)))).thenReturn(toList(roleDO));
|
|
||||||
// mock 部门的返回
|
|
||||||
when(userService.getUser(eq(1L))).thenReturn(new AdminUserDO().setDeptId(3L),
|
|
||||||
null, null); // 最后返回 null 的目的,看看会不会重复调用
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
DeptDataPermissionRespDTO result = permissionService.getDeptDataPermission(userId);
|
|
||||||
// 断言
|
|
||||||
assertFalse(result.getAll());
|
|
||||||
assertFalse(result.getSelf());
|
|
||||||
assertEquals(roleDO.getDataScopeDeptIds().size() + 1, result.getDeptIds().size());
|
|
||||||
assertTrue(CollUtil.containsAll(result.getDeptIds(), roleDO.getDataScopeDeptIds()));
|
|
||||||
assertTrue(CollUtil.contains(result.getDeptIds(), 3L));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetDeptDataPermission_DeptOnly() {
|
|
||||||
try (MockedStatic<SpringUtil> springUtilMockedStatic = mockStatic(SpringUtil.class)) {
|
|
||||||
springUtilMockedStatic.when(() -> SpringUtil.getBean(eq(PermissionServiceImpl.class)))
|
|
||||||
.thenReturn(permissionService);
|
|
||||||
|
|
||||||
// 准备参数
|
|
||||||
Long userId = 1L;
|
|
||||||
// mock 用户的角色编号
|
|
||||||
userRoleMapper.insert(randomPojo(UserRoleDO.class).setUserId(userId).setRoleId(2L));
|
|
||||||
// mock 获得用户的角色
|
|
||||||
RoleDO roleDO = randomPojo(RoleDO.class, o -> o.setDataScope(DataScopeEnum.DEPT_ONLY.getScope())
|
|
||||||
.setStatus(CommonStatusEnum.ENABLE.getStatus()));
|
|
||||||
when(roleService.getRoleListFromCache(eq(singleton(2L)))).thenReturn(toList(roleDO));
|
|
||||||
// mock 部门的返回
|
|
||||||
when(userService.getUser(eq(1L))).thenReturn(new AdminUserDO().setDeptId(3L),
|
|
||||||
null, null); // 最后返回 null 的目的,看看会不会重复调用
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
DeptDataPermissionRespDTO result = permissionService.getDeptDataPermission(userId);
|
|
||||||
// 断言
|
|
||||||
assertFalse(result.getAll());
|
|
||||||
assertFalse(result.getSelf());
|
|
||||||
assertEquals(1, result.getDeptIds().size());
|
|
||||||
assertTrue(CollUtil.contains(result.getDeptIds(), 3L));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetDeptDataPermission_DeptAndChild() {
|
|
||||||
try (MockedStatic<SpringUtil> springUtilMockedStatic = mockStatic(SpringUtil.class)) {
|
|
||||||
springUtilMockedStatic.when(() -> SpringUtil.getBean(eq(PermissionServiceImpl.class)))
|
|
||||||
.thenReturn(permissionService);
|
|
||||||
|
|
||||||
// 准备参数
|
|
||||||
Long userId = 1L;
|
|
||||||
// mock 用户的角色编号
|
|
||||||
userRoleMapper.insert(randomPojo(UserRoleDO.class).setUserId(userId).setRoleId(2L));
|
|
||||||
// mock 获得用户的角色
|
|
||||||
RoleDO roleDO = randomPojo(RoleDO.class, o -> o.setDataScope(DataScopeEnum.DEPT_AND_CHILD.getScope())
|
|
||||||
.setStatus(CommonStatusEnum.ENABLE.getStatus()));
|
|
||||||
when(roleService.getRoleListFromCache(eq(singleton(2L)))).thenReturn(toList(roleDO));
|
|
||||||
// mock 部门的返回
|
|
||||||
when(userService.getUser(eq(1L))).thenReturn(new AdminUserDO().setDeptId(3L),
|
|
||||||
null, null); // 最后返回 null 的目的,看看会不会重复调用
|
|
||||||
// mock 方法(部门)
|
|
||||||
DeptDO deptDO = randomPojo(DeptDO.class);
|
|
||||||
when(deptService.getChildDeptIdListFromCache(eq(3L))).thenReturn(singleton(deptDO.getId()));
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
DeptDataPermissionRespDTO result = permissionService.getDeptDataPermission(userId);
|
|
||||||
// 断言
|
|
||||||
assertFalse(result.getAll());
|
|
||||||
assertFalse(result.getSelf());
|
|
||||||
assertEquals(2, result.getDeptIds().size());
|
|
||||||
assertTrue(CollUtil.contains(result.getDeptIds(), deptDO.getId()));
|
|
||||||
assertTrue(CollUtil.contains(result.getDeptIds(), 3L));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetDeptDataPermission_Self() {
|
|
||||||
try (MockedStatic<SpringUtil> springUtilMockedStatic = mockStatic(SpringUtil.class)) {
|
|
||||||
springUtilMockedStatic.when(() -> SpringUtil.getBean(eq(PermissionServiceImpl.class)))
|
|
||||||
.thenReturn(permissionService);
|
|
||||||
|
|
||||||
// 准备参数
|
|
||||||
Long userId = 1L;
|
|
||||||
// mock 用户的角色编号
|
|
||||||
userRoleMapper.insert(randomPojo(UserRoleDO.class).setUserId(userId).setRoleId(2L));
|
|
||||||
// mock 获得用户的角色
|
|
||||||
RoleDO roleDO = randomPojo(RoleDO.class, o -> o.setDataScope(DataScopeEnum.SELF.getScope())
|
|
||||||
.setStatus(CommonStatusEnum.ENABLE.getStatus()));
|
|
||||||
when(roleService.getRoleListFromCache(eq(singleton(2L)))).thenReturn(toList(roleDO));
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
DeptDataPermissionRespDTO result = permissionService.getDeptDataPermission(userId);
|
|
||||||
// 断言
|
|
||||||
assertFalse(result.getAll());
|
|
||||||
assertTrue(result.getSelf());
|
|
||||||
assertTrue(CollUtil.isEmpty(result.getDeptIds()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,372 +0,0 @@
|
|||||||
package cn.iocoder.lyzsys.module.system.service.permission;
|
|
||||||
|
|
||||||
import cn.hutool.extra.spring.SpringUtil;
|
|
||||||
import cn.iocoder.lyzsys.framework.common.enums.CommonStatusEnum;
|
|
||||||
import cn.iocoder.lyzsys.framework.common.pojo.PageResult;
|
|
||||||
import cn.iocoder.lyzsys.framework.test.core.ut.BaseDbUnitTest;
|
|
||||||
import cn.iocoder.lyzsys.module.system.controller.admin.permission.vo.role.RolePageReqVO;
|
|
||||||
import cn.iocoder.lyzsys.module.system.controller.admin.permission.vo.role.RoleSaveReqVO;
|
|
||||||
import cn.iocoder.lyzsys.module.system.dal.dataobject.permission.RoleDO;
|
|
||||||
import cn.iocoder.lyzsys.module.system.dal.mysql.permission.RoleMapper;
|
|
||||||
import cn.iocoder.lyzsys.module.system.enums.permission.DataScopeEnum;
|
|
||||||
import cn.iocoder.lyzsys.module.system.enums.permission.RoleTypeEnum;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.mockito.MockedStatic;
|
|
||||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
|
||||||
import org.springframework.context.annotation.Import;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import static cn.hutool.core.util.RandomUtil.randomEle;
|
|
||||||
import static cn.iocoder.lyzsys.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime;
|
|
||||||
import static cn.iocoder.lyzsys.framework.common.util.date.LocalDateTimeUtils.buildTime;
|
|
||||||
import static cn.iocoder.lyzsys.framework.common.util.object.ObjectUtils.cloneIgnoreId;
|
|
||||||
import static cn.iocoder.lyzsys.framework.test.core.util.AssertUtils.assertPojoEquals;
|
|
||||||
import static cn.iocoder.lyzsys.framework.test.core.util.AssertUtils.assertServiceException;
|
|
||||||
import static cn.iocoder.lyzsys.framework.test.core.util.RandomUtils.*;
|
|
||||||
import static cn.iocoder.lyzsys.module.system.enums.ErrorCodeConstants.*;
|
|
||||||
import static java.util.Collections.singleton;
|
|
||||||
import static java.util.Collections.singletonList;
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
|
||||||
import static org.mockito.Mockito.mockStatic;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
|
|
||||||
@Import(RoleServiceImpl.class)
|
|
||||||
public class RoleServiceImplTest extends BaseDbUnitTest {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private RoleServiceImpl roleService;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private RoleMapper roleMapper;
|
|
||||||
|
|
||||||
@MockBean
|
|
||||||
private PermissionService permissionService;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testCreateRole() {
|
|
||||||
// 准备参数
|
|
||||||
RoleSaveReqVO reqVO = randomPojo(RoleSaveReqVO.class)
|
|
||||||
.setId(null) // 防止 id 被赋值
|
|
||||||
.setStatus(randomCommonStatus());
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
Long roleId = roleService.createRole(reqVO, null);
|
|
||||||
// 断言
|
|
||||||
RoleDO roleDO = roleMapper.selectById(roleId);
|
|
||||||
assertPojoEquals(reqVO, roleDO, "id");
|
|
||||||
assertEquals(RoleTypeEnum.CUSTOM.getType(), roleDO.getType());
|
|
||||||
assertEquals(DataScopeEnum.ALL.getScope(), roleDO.getDataScope());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testUpdateRole() {
|
|
||||||
// mock 数据
|
|
||||||
RoleDO roleDO = randomPojo(RoleDO.class, o -> o.setType(RoleTypeEnum.CUSTOM.getType()));
|
|
||||||
roleMapper.insert(roleDO);
|
|
||||||
// 准备参数
|
|
||||||
Long id = roleDO.getId();
|
|
||||||
RoleSaveReqVO reqVO = randomPojo(RoleSaveReqVO.class, o -> o.setId(id)
|
|
||||||
.setStatus(randomCommonStatus()));
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
roleService.updateRole(reqVO);
|
|
||||||
// 断言
|
|
||||||
RoleDO newRoleDO = roleMapper.selectById(id);
|
|
||||||
assertPojoEquals(reqVO, newRoleDO);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testUpdateRoleDataScope() {
|
|
||||||
// mock 数据
|
|
||||||
RoleDO roleDO = randomPojo(RoleDO.class, o -> o.setType(RoleTypeEnum.CUSTOM.getType()));
|
|
||||||
roleMapper.insert(roleDO);
|
|
||||||
// 准备参数
|
|
||||||
Long id = roleDO.getId();
|
|
||||||
Integer dataScope = randomEle(DataScopeEnum.values()).getScope();
|
|
||||||
Set<Long> dataScopeRoleIds = randomSet(Long.class);
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
roleService.updateRoleDataScope(id, dataScope, dataScopeRoleIds);
|
|
||||||
// 断言
|
|
||||||
RoleDO dbRoleDO = roleMapper.selectById(id);
|
|
||||||
assertEquals(dataScope, dbRoleDO.getDataScope());
|
|
||||||
assertEquals(dataScopeRoleIds, dbRoleDO.getDataScopeDeptIds());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testDeleteRole() {
|
|
||||||
// mock 数据
|
|
||||||
RoleDO roleDO = randomPojo(RoleDO.class, o -> o.setType(RoleTypeEnum.CUSTOM.getType()));
|
|
||||||
roleMapper.insert(roleDO);
|
|
||||||
// 参数准备
|
|
||||||
Long id = roleDO.getId();
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
roleService.deleteRole(id);
|
|
||||||
// 断言
|
|
||||||
assertNull(roleMapper.selectById(id));
|
|
||||||
// verify 删除相关数据
|
|
||||||
verify(permissionService).processRoleDeleted(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testValidateRoleDuplicate_success() {
|
|
||||||
// 调用,不会抛异常
|
|
||||||
roleService.validateRoleDuplicate(randomString(), randomString(), null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testValidateRoleDuplicate_nameDuplicate() {
|
|
||||||
// mock 数据
|
|
||||||
RoleDO roleDO = randomPojo(RoleDO.class, o -> o.setName("role_name"));
|
|
||||||
roleMapper.insert(roleDO);
|
|
||||||
// 准备参数
|
|
||||||
String name = "role_name";
|
|
||||||
|
|
||||||
// 调用,并断言异常
|
|
||||||
assertServiceException(() -> roleService.validateRoleDuplicate(name, randomString(), null),
|
|
||||||
ROLE_NAME_DUPLICATE, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testValidateRoleDuplicate_codeDuplicate() {
|
|
||||||
// mock 数据
|
|
||||||
RoleDO roleDO = randomPojo(RoleDO.class, o -> o.setCode("code"));
|
|
||||||
roleMapper.insert(roleDO);
|
|
||||||
// 准备参数
|
|
||||||
String code = "code";
|
|
||||||
|
|
||||||
// 调用,并断言异常
|
|
||||||
assertServiceException(() -> roleService.validateRoleDuplicate(randomString(), code, null),
|
|
||||||
ROLE_CODE_DUPLICATE, code);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testValidateUpdateRole_success() {
|
|
||||||
RoleDO roleDO = randomPojo(RoleDO.class, o -> o.setType(RoleTypeEnum.CUSTOM.getType()));
|
|
||||||
roleMapper.insert(roleDO);
|
|
||||||
// 准备参数
|
|
||||||
Long id = roleDO.getId();
|
|
||||||
|
|
||||||
// 调用,无异常
|
|
||||||
roleService.validateRoleForUpdate(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testValidateUpdateRole_roleIdNotExist() {
|
|
||||||
assertServiceException(() -> roleService.validateRoleForUpdate(randomLongId()), ROLE_NOT_EXISTS);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testValidateUpdateRole_systemRoleCanNotBeUpdate() {
|
|
||||||
RoleDO roleDO = randomPojo(RoleDO.class, o -> o.setType(RoleTypeEnum.SYSTEM.getType()));
|
|
||||||
roleMapper.insert(roleDO);
|
|
||||||
// 准备参数
|
|
||||||
Long id = roleDO.getId();
|
|
||||||
|
|
||||||
assertServiceException(() -> roleService.validateRoleForUpdate(id),
|
|
||||||
ROLE_CAN_NOT_UPDATE_SYSTEM_TYPE_ROLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetRole() {
|
|
||||||
// mock 数据
|
|
||||||
RoleDO roleDO = randomPojo(RoleDO.class);
|
|
||||||
roleMapper.insert(roleDO);
|
|
||||||
// 参数准备
|
|
||||||
Long id = roleDO.getId();
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
RoleDO dbRoleDO = roleService.getRole(id);
|
|
||||||
// 断言
|
|
||||||
assertPojoEquals(roleDO, dbRoleDO);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetRoleFromCache() {
|
|
||||||
// mock 数据(缓存)
|
|
||||||
RoleDO roleDO = randomPojo(RoleDO.class);
|
|
||||||
roleMapper.insert(roleDO);
|
|
||||||
// 参数准备
|
|
||||||
Long id = roleDO.getId();
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
RoleDO dbRoleDO = roleService.getRoleFromCache(id);
|
|
||||||
// 断言
|
|
||||||
assertPojoEquals(roleDO, dbRoleDO);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetRoleListByStatus() {
|
|
||||||
// mock 数据
|
|
||||||
RoleDO dbRole01 = randomPojo(RoleDO.class, o -> o.setStatus(CommonStatusEnum.ENABLE.getStatus()));
|
|
||||||
roleMapper.insert(dbRole01);
|
|
||||||
RoleDO dbRole02 = randomPojo(RoleDO.class, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus()));
|
|
||||||
roleMapper.insert(dbRole02);
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
List<RoleDO> list = roleService.getRoleListByStatus(
|
|
||||||
singleton(CommonStatusEnum.ENABLE.getStatus()));
|
|
||||||
// 断言
|
|
||||||
assertEquals(1, list.size());
|
|
||||||
assertPojoEquals(dbRole01, list.get(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetRoleList() {
|
|
||||||
// mock 数据
|
|
||||||
RoleDO dbRole01 = randomPojo(RoleDO.class, o -> o.setStatus(CommonStatusEnum.ENABLE.getStatus()));
|
|
||||||
roleMapper.insert(dbRole01);
|
|
||||||
RoleDO dbRole02 = randomPojo(RoleDO.class, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus()));
|
|
||||||
roleMapper.insert(dbRole02);
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
List<RoleDO> list = roleService.getRoleList();
|
|
||||||
// 断言
|
|
||||||
assertEquals(2, list.size());
|
|
||||||
assertPojoEquals(dbRole01, list.get(0));
|
|
||||||
assertPojoEquals(dbRole02, list.get(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetRoleList_ids() {
|
|
||||||
// mock 数据
|
|
||||||
RoleDO dbRole01 = randomPojo(RoleDO.class, o -> o.setStatus(CommonStatusEnum.ENABLE.getStatus()));
|
|
||||||
roleMapper.insert(dbRole01);
|
|
||||||
RoleDO dbRole02 = randomPojo(RoleDO.class, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus()));
|
|
||||||
roleMapper.insert(dbRole02);
|
|
||||||
// 准备参数
|
|
||||||
Collection<Long> ids = singleton(dbRole01.getId());
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
List<RoleDO> list = roleService.getRoleList(ids);
|
|
||||||
// 断言
|
|
||||||
assertEquals(1, list.size());
|
|
||||||
assertPojoEquals(dbRole01, list.get(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetRoleListFromCache() {
|
|
||||||
try (MockedStatic<SpringUtil> springUtilMockedStatic = mockStatic(SpringUtil.class)) {
|
|
||||||
springUtilMockedStatic.when(() -> SpringUtil.getBean(eq(RoleServiceImpl.class)))
|
|
||||||
.thenReturn(roleService);
|
|
||||||
|
|
||||||
// mock 数据
|
|
||||||
RoleDO dbRole = randomPojo(RoleDO.class, o -> o.setStatus(CommonStatusEnum.ENABLE.getStatus()));
|
|
||||||
roleMapper.insert(dbRole);
|
|
||||||
// 测试 id 不匹配
|
|
||||||
roleMapper.insert(cloneIgnoreId(dbRole, o -> {}));
|
|
||||||
// 准备参数
|
|
||||||
Collection<Long> ids = singleton(dbRole.getId());
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
List<RoleDO> list = roleService.getRoleListFromCache(ids);
|
|
||||||
// 断言
|
|
||||||
assertEquals(1, list.size());
|
|
||||||
assertPojoEquals(dbRole, list.get(0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetRolePage() {
|
|
||||||
// mock 数据
|
|
||||||
RoleDO dbRole = randomPojo(RoleDO.class, o -> { // 等会查询到
|
|
||||||
o.setName("土豆");
|
|
||||||
o.setCode("tudou");
|
|
||||||
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
|
||||||
o.setCreateTime(buildTime(2022, 2, 8));
|
|
||||||
});
|
|
||||||
roleMapper.insert(dbRole);
|
|
||||||
// 测试 name 不匹配
|
|
||||||
roleMapper.insert(cloneIgnoreId(dbRole, o -> o.setName("红薯")));
|
|
||||||
// 测试 code 不匹配
|
|
||||||
roleMapper.insert(cloneIgnoreId(dbRole, o -> o.setCode("hong")));
|
|
||||||
// 测试 createTime 不匹配
|
|
||||||
roleMapper.insert(cloneIgnoreId(dbRole, o -> o.setCreateTime(buildTime(2022, 2, 16))));
|
|
||||||
// 准备参数
|
|
||||||
RolePageReqVO reqVO = new RolePageReqVO();
|
|
||||||
reqVO.setName("土豆");
|
|
||||||
reqVO.setCode("tu");
|
|
||||||
reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
|
||||||
reqVO.setCreateTime(buildBetweenTime(2022, 2, 1, 2022, 2, 12));
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
PageResult<RoleDO> pageResult = roleService.getRolePage(reqVO);
|
|
||||||
// 断言
|
|
||||||
assertEquals(1, pageResult.getTotal());
|
|
||||||
assertEquals(1, pageResult.getList().size());
|
|
||||||
assertPojoEquals(dbRole, pageResult.getList().get(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testHasAnySuperAdmin_true() {
|
|
||||||
try (MockedStatic<SpringUtil> springUtilMockedStatic = mockStatic(SpringUtil.class)) {
|
|
||||||
springUtilMockedStatic.when(() -> SpringUtil.getBean(eq(RoleServiceImpl.class)))
|
|
||||||
.thenReturn(roleService);
|
|
||||||
|
|
||||||
// mock 数据
|
|
||||||
RoleDO dbRole = randomPojo(RoleDO.class).setCode("super_admin");
|
|
||||||
roleMapper.insert(dbRole);
|
|
||||||
// 准备参数
|
|
||||||
Long id = dbRole.getId();
|
|
||||||
|
|
||||||
// 调用,并调用
|
|
||||||
assertTrue(roleService.hasAnySuperAdmin(singletonList(id)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testHasAnySuperAdmin_false() {
|
|
||||||
try (MockedStatic<SpringUtil> springUtilMockedStatic = mockStatic(SpringUtil.class)) {
|
|
||||||
springUtilMockedStatic.when(() -> SpringUtil.getBean(eq(RoleServiceImpl.class)))
|
|
||||||
.thenReturn(roleService);
|
|
||||||
|
|
||||||
// mock 数据
|
|
||||||
RoleDO dbRole = randomPojo(RoleDO.class).setCode("tenant_admin");
|
|
||||||
roleMapper.insert(dbRole);
|
|
||||||
// 准备参数
|
|
||||||
Long id = dbRole.getId();
|
|
||||||
|
|
||||||
// 调用,并调用
|
|
||||||
assertFalse(roleService.hasAnySuperAdmin(singletonList(id)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testValidateRoleList_success() {
|
|
||||||
// mock 数据
|
|
||||||
RoleDO roleDO = randomPojo(RoleDO.class, o -> o.setStatus(CommonStatusEnum.ENABLE.getStatus()));
|
|
||||||
roleMapper.insert(roleDO);
|
|
||||||
// 准备参数
|
|
||||||
List<Long> ids = singletonList(roleDO.getId());
|
|
||||||
|
|
||||||
// 调用,无需断言
|
|
||||||
roleService.validateRoleList(ids);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testValidateRoleList_notFound() {
|
|
||||||
// 准备参数
|
|
||||||
List<Long> ids = singletonList(randomLongId());
|
|
||||||
|
|
||||||
// 调用, 并断言异常
|
|
||||||
assertServiceException(() -> roleService.validateRoleList(ids), ROLE_NOT_EXISTS);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testValidateRoleList_notEnable() {
|
|
||||||
// mock 数据
|
|
||||||
RoleDO RoleDO = randomPojo(RoleDO.class, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus()));
|
|
||||||
roleMapper.insert(RoleDO);
|
|
||||||
// 准备参数
|
|
||||||
List<Long> ids = singletonList(RoleDO.getId());
|
|
||||||
|
|
||||||
// 调用, 并断言异常
|
|
||||||
assertServiceException(() -> roleService.validateRoleList(ids), ROLE_IS_DISABLE, RoleDO.getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -436,7 +436,7 @@ public class SocialClientServiceImplTest extends BaseDbUnitTest {
|
|||||||
public void testGetSocialClientPage() {
|
public void testGetSocialClientPage() {
|
||||||
// mock 数据
|
// mock 数据
|
||||||
SocialClientDO dbSocialClient = randomPojo(SocialClientDO.class, o -> { // 等会查询到
|
SocialClientDO dbSocialClient = randomPojo(SocialClientDO.class, o -> { // 等会查询到
|
||||||
o.setName("芋头");
|
o.setName("鹭筑");
|
||||||
o.setSocialType(SocialTypeEnum.GITEE.getType());
|
o.setSocialType(SocialTypeEnum.GITEE.getType());
|
||||||
o.setUserType(UserTypeEnum.ADMIN.getValue());
|
o.setUserType(UserTypeEnum.ADMIN.getValue());
|
||||||
o.setClientId("lyzsys");
|
o.setClientId("lyzsys");
|
||||||
@@ -455,7 +455,7 @@ public class SocialClientServiceImplTest extends BaseDbUnitTest {
|
|||||||
socialClientMapper.insert(cloneIgnoreId(dbSocialClient, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus())));
|
socialClientMapper.insert(cloneIgnoreId(dbSocialClient, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus())));
|
||||||
// 准备参数
|
// 准备参数
|
||||||
SocialClientPageReqVO reqVO = new SocialClientPageReqVO();
|
SocialClientPageReqVO reqVO = new SocialClientPageReqVO();
|
||||||
reqVO.setName("芋");
|
reqVO.setName("鹭");
|
||||||
reqVO.setSocialType(SocialTypeEnum.GITEE.getType());
|
reqVO.setSocialType(SocialTypeEnum.GITEE.getType());
|
||||||
reqVO.setUserType(UserTypeEnum.ADMIN.getValue());
|
reqVO.setUserType(UserTypeEnum.ADMIN.getValue());
|
||||||
reqVO.setClientId("lyz");
|
reqVO.setClientId("lyz");
|
||||||
|
|||||||
@@ -257,7 +257,7 @@ public class SocialUserServiceImplTest extends BaseDbUnitTest {
|
|||||||
// mock 数据
|
// mock 数据
|
||||||
SocialUserDO dbSocialUser = randomPojo(SocialUserDO.class, o -> { // 等会查询到
|
SocialUserDO dbSocialUser = randomPojo(SocialUserDO.class, o -> { // 等会查询到
|
||||||
o.setType(SocialTypeEnum.GITEE.getType());
|
o.setType(SocialTypeEnum.GITEE.getType());
|
||||||
o.setNickname("芋艿");
|
o.setNickname("鹭鹭");
|
||||||
o.setOpenid("lyzsysyuanma");
|
o.setOpenid("lyzsysyuanma");
|
||||||
o.setCreateTime(buildTime(2020, 1, 15));
|
o.setCreateTime(buildTime(2020, 1, 15));
|
||||||
});
|
});
|
||||||
@@ -273,7 +273,7 @@ public class SocialUserServiceImplTest extends BaseDbUnitTest {
|
|||||||
// 准备参数
|
// 准备参数
|
||||||
SocialUserPageReqVO reqVO = new SocialUserPageReqVO();
|
SocialUserPageReqVO reqVO = new SocialUserPageReqVO();
|
||||||
reqVO.setType(SocialTypeEnum.GITEE.getType());
|
reqVO.setType(SocialTypeEnum.GITEE.getType());
|
||||||
reqVO.setNickname("芋");
|
reqVO.setNickname("鹭");
|
||||||
reqVO.setOpenid("lyzsys");
|
reqVO.setOpenid("lyzsys");
|
||||||
reqVO.setCreateTime(buildBetweenTime(2020, 1, 10, 2020, 1, 20));
|
reqVO.setCreateTime(buildBetweenTime(2020, 1, 10, 2020, 1, 20));
|
||||||
|
|
||||||
|
|||||||
@@ -289,7 +289,7 @@ public class TenantServiceImplTest extends BaseDbUnitTest {
|
|||||||
// mock 数据
|
// mock 数据
|
||||||
TenantDO dbTenant = randomPojo(TenantDO.class, o -> { // 等会查询到
|
TenantDO dbTenant = randomPojo(TenantDO.class, o -> { // 等会查询到
|
||||||
o.setName("lyz源码");
|
o.setName("lyz源码");
|
||||||
o.setContactName("芋艿");
|
o.setContactName("鹭鹭");
|
||||||
o.setContactMobile("15601691300");
|
o.setContactMobile("15601691300");
|
||||||
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||||
o.setCreateTime(buildTime(2020, 12, 12));
|
o.setCreateTime(buildTime(2020, 12, 12));
|
||||||
@@ -308,7 +308,7 @@ public class TenantServiceImplTest extends BaseDbUnitTest {
|
|||||||
// 准备参数
|
// 准备参数
|
||||||
TenantPageReqVO reqVO = new TenantPageReqVO();
|
TenantPageReqVO reqVO = new TenantPageReqVO();
|
||||||
reqVO.setName("lyz");
|
reqVO.setName("lyz");
|
||||||
reqVO.setContactName("艿");
|
reqVO.setContactName("鹭");
|
||||||
reqVO.setContactMobile("1560");
|
reqVO.setContactMobile("1560");
|
||||||
reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||||
reqVO.setCreateTime(buildBetweenTime(2020, 12, 1, 2020, 12, 24));
|
reqVO.setCreateTime(buildBetweenTime(2020, 12, 1, 2020, 12, 24));
|
||||||
|
|||||||
@@ -687,12 +687,12 @@ public class AdminUserServiceImplTest extends BaseDbUnitTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testGetUserListByNickname() {
|
public void testGetUserListByNickname() {
|
||||||
// mock 数据
|
// mock 数据
|
||||||
AdminUserDO user = randomAdminUserDO(o -> o.setNickname("芋头"));
|
AdminUserDO user = randomAdminUserDO(o -> o.setNickname("鹭筑"));
|
||||||
userMapper.insert(user);
|
userMapper.insert(user);
|
||||||
// 测试 nickname 不匹配
|
// 测试 nickname 不匹配
|
||||||
userMapper.insert(randomAdminUserDO(o -> o.setNickname("源码")));
|
userMapper.insert(randomAdminUserDO(o -> o.setNickname("源码")));
|
||||||
// 准备参数
|
// 准备参数
|
||||||
String nickname = "芋";
|
String nickname = "鹭";
|
||||||
|
|
||||||
// 调用
|
// 调用
|
||||||
List<AdminUserDO> result = userService.getUserListByNickname(nickname);
|
List<AdminUserDO> result = userService.getUserListByNickname(nickname);
|
||||||
|
|||||||
Reference in New Issue
Block a user