mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-07-17 20:45:06 +08:00
Merge branch 'master' of gitee.com:zhijiantianya/ruoyi-vue-pro into feature/ut-job
This commit is contained in:
@ -16,9 +16,9 @@ import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.jdbc.Sql;
|
||||
|
||||
/**
|
||||
* 依赖内存 DB 的单元测试
|
||||
* 依赖内存 DB + Redis 的单元测试
|
||||
*
|
||||
* 注意,Service 层同样适用。对于 Service 层的单元测试,我们针对自己模块的 Mapper 走的是 H2 内存数据库,针对别的模块的 Service 走的是 Mock 方法
|
||||
* 相比 {@link BaseDbUnitTest} 来说,额外增加了内存 Redis
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
|
32
src/test/java/cn/iocoder/dashboard/BaseRedisUnitTest.java
Normal file
32
src/test/java/cn/iocoder/dashboard/BaseRedisUnitTest.java
Normal file
@ -0,0 +1,32 @@
|
||||
package cn.iocoder.dashboard;
|
||||
|
||||
import cn.iocoder.dashboard.config.RedisTestConfiguration;
|
||||
import cn.iocoder.dashboard.framework.redis.config.RedisConfig;
|
||||
import org.redisson.spring.starter.RedissonAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
|
||||
/**
|
||||
* 依赖内存 Redis 的单元测试
|
||||
*
|
||||
* 相比 {@link BaseDbUnitTest} 来说,从内存 DB 改成了内存 Redis
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = BaseRedisUnitTest.Application.class)
|
||||
@ActiveProfiles("unit-test") // 设置使用 application-unit-test 配置文件
|
||||
public class BaseRedisUnitTest {
|
||||
|
||||
@Import({
|
||||
// Redis 配置类
|
||||
RedisTestConfiguration.class, // Redis 测试配置类,用于启动 RedisServer
|
||||
RedisAutoConfiguration.class, // Spring Redis 自动配置类
|
||||
RedisConfig.class, // 自己的 Redis 配置类
|
||||
RedissonAutoConfiguration.class, // Redisson 自动高配置类
|
||||
})
|
||||
public static class Application {
|
||||
}
|
||||
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
package cn.iocoder.dashboard;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.data.redis.core.RedisCallback;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.jdbc.Sql;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
|
||||
@ActiveProfiles("unit-test") // 设置使用 application-unit-test 配置文件
|
||||
@Sql(scripts = "/sql/clean.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD) // 每个单元测试结束后,清理 DB
|
||||
@Deprecated
|
||||
public class BaseSpringBootUnitTest {
|
||||
|
||||
@Resource
|
||||
private StringRedisTemplate stringRedisTemplate;
|
||||
|
||||
/**
|
||||
* 每个单元测试结束后,清理 Redis
|
||||
*/
|
||||
@AfterEach
|
||||
public void cleanRedis() {
|
||||
stringRedisTemplate.execute((RedisCallback<Object>) connection -> {
|
||||
connection.flushDb();
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -1,19 +1,17 @@
|
||||
package cn.iocoder.dashboard.config;
|
||||
|
||||
import com.github.fppt.jedismock.RedisServer;
|
||||
import org.redisson.spring.starter.RedissonAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@Lazy(false) // 禁止延迟加载
|
||||
@EnableConfigurationProperties(RedisProperties.class)
|
||||
@AutoConfigureBefore({RedisAutoConfiguration.class, RedissonAutoConfiguration.class}) // 在 Redis 自动配置前,进行初始化
|
||||
public class RedisTestConfiguration {
|
||||
|
||||
/**
|
||||
|
@ -1,14 +1,14 @@
|
||||
package cn.iocoder.dashboard.framework.quartz.core.scheduler;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.iocoder.dashboard.BaseSpringBootUnitTest;
|
||||
import cn.iocoder.dashboard.BaseDbUnitTest;
|
||||
import cn.iocoder.dashboard.modules.system.job.auth.SysUserSessionTimeoutJob;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.quartz.SchedulerException;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
class SchedulerManagerTest extends BaseSpringBootUnitTest {
|
||||
class SchedulerManagerTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private SchedulerManager schedulerManager;
|
||||
|
@ -0,0 +1,177 @@
|
||||
package cn.iocoder.dashboard.modules.infra.service.logger;
|
||||
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.iocoder.dashboard.BaseDbUnitTest;
|
||||
import cn.iocoder.dashboard.common.enums.UserTypeEnum;
|
||||
import cn.iocoder.dashboard.common.exception.enums.GlobalErrorCodeConstants;
|
||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||
import cn.iocoder.dashboard.framework.logger.apilog.core.service.dto.ApiAccessLogCreateDTO;
|
||||
import cn.iocoder.dashboard.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogExportReqVO;
|
||||
import cn.iocoder.dashboard.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogPageReqVO;
|
||||
import cn.iocoder.dashboard.modules.infra.dal.dataobject.logger.InfApiAccessLogDO;
|
||||
import cn.iocoder.dashboard.modules.infra.dal.mysql.logger.InfApiAccessLogMapper;
|
||||
import cn.iocoder.dashboard.modules.infra.service.logger.impl.InfApiAccessLogServiceImpl;
|
||||
import cn.iocoder.dashboard.util.RandomUtils;
|
||||
import cn.iocoder.dashboard.util.object.ObjectUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import static cn.iocoder.dashboard.util.AssertUtils.assertPojoEquals;
|
||||
import static cn.iocoder.dashboard.util.date.DateUtils.buildTime;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
/**
|
||||
* {@link InfApiAccessLogServiceImpl} 单元测试
|
||||
*/
|
||||
@Import(InfApiAccessLogServiceImpl.class)
|
||||
public class InfApiAccessLogServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private InfApiAccessLogService infApiAccessLogServiceImpl;
|
||||
|
||||
@Resource
|
||||
private InfApiAccessLogMapper infApiAccessLogMapper;
|
||||
|
||||
|
||||
@Test
|
||||
public void testCreateApiAccessLogAsync() throws Exception {
|
||||
ApiAccessLogCreateDTO createDTO = RandomUtils.randomPojo(
|
||||
ApiAccessLogCreateDTO.class,
|
||||
dto -> dto.setUserType(RandomUtil.randomEle(UserTypeEnum.values()).getValue())
|
||||
);
|
||||
|
||||
// 执行service方法
|
||||
Future<Boolean> future = infApiAccessLogServiceImpl.createApiAccessLogAsync(createDTO);
|
||||
|
||||
// 等异步执行完
|
||||
future.get();
|
||||
|
||||
InfApiAccessLogDO infApiAccessLogDO = infApiAccessLogMapper.selectOne(null);
|
||||
// 断言
|
||||
assertNotNull(infApiAccessLogDO);
|
||||
// 断言,忽略基本字段
|
||||
assertPojoEquals(createDTO, infApiAccessLogDO);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetApiAccessLogPage() {
|
||||
// 构造测试数据
|
||||
long userId = 2233L;
|
||||
int userType = UserTypeEnum.ADMIN.getValue();
|
||||
String applicationName = "ruoyi-test";
|
||||
String requestUrl = "foo";
|
||||
Date beginTime = buildTime(2021, 3, 13);
|
||||
int duration = 1000;
|
||||
int resultCode = GlobalErrorCodeConstants.SUCCESS.getCode();
|
||||
|
||||
InfApiAccessLogDO infApiAccessLogDO = RandomUtils.randomPojo(InfApiAccessLogDO.class, dto -> {
|
||||
dto.setUserId(userId);
|
||||
dto.setUserType(userType);
|
||||
dto.setApplicationName(applicationName);
|
||||
dto.setRequestUrl(requestUrl);
|
||||
dto.setBeginTime(beginTime);
|
||||
dto.setDuration(duration);
|
||||
dto.setResultCode(resultCode);
|
||||
});
|
||||
infApiAccessLogMapper.insert(infApiAccessLogDO);
|
||||
|
||||
// 下面几个都是不匹配的数据
|
||||
// userId 不同的
|
||||
infApiAccessLogMapper.insert(ObjectUtils.clone(infApiAccessLogDO, logDO -> logDO.setUserId(3344L)));
|
||||
// userType
|
||||
infApiAccessLogMapper.insert(ObjectUtils.clone(infApiAccessLogDO, logDO -> logDO.setUserType(UserTypeEnum.MEMBER.getValue())));
|
||||
// applicationName 不同的
|
||||
infApiAccessLogMapper.insert(ObjectUtils.clone(infApiAccessLogDO, logDO -> logDO.setApplicationName("test")));
|
||||
// requestUrl 不同的
|
||||
infApiAccessLogMapper.insert(ObjectUtils.clone(infApiAccessLogDO, logDO -> logDO.setRequestUrl("bar")));
|
||||
// 构造一个早期时间 2021-02-06 00:00:00
|
||||
infApiAccessLogMapper.insert(ObjectUtils.clone(infApiAccessLogDO, logDO -> logDO.setBeginTime(buildTime(2021, 2, 6))));
|
||||
// duration 不同的
|
||||
infApiAccessLogMapper.insert(ObjectUtils.clone(infApiAccessLogDO, logDO -> logDO.setDuration(100)));
|
||||
// resultCode 不同的
|
||||
infApiAccessLogMapper.insert(ObjectUtils.clone(infApiAccessLogDO, logDO -> logDO.setResultCode(2)));
|
||||
|
||||
// 构造调用参数
|
||||
InfApiAccessLogPageReqVO reqVO = new InfApiAccessLogPageReqVO();
|
||||
reqVO.setUserId(userId);
|
||||
reqVO.setUserType(userType);
|
||||
reqVO.setApplicationName(applicationName);
|
||||
reqVO.setRequestUrl(requestUrl);
|
||||
reqVO.setBeginBeginTime(buildTime(2021, 3, 12));
|
||||
reqVO.setEndBeginTime(buildTime(2021, 3, 14));
|
||||
reqVO.setDuration(duration);
|
||||
reqVO.setResultCode(resultCode);
|
||||
|
||||
// 调用service方法
|
||||
PageResult<InfApiAccessLogDO> pageResult = infApiAccessLogServiceImpl.getApiAccessLogPage(reqVO);
|
||||
|
||||
// 断言,只查到了一条符合条件的
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(infApiAccessLogDO, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetApiAccessLogList() {
|
||||
// 构造测试数据
|
||||
long userId = 2233L;
|
||||
int userType = UserTypeEnum.ADMIN.getValue();
|
||||
String applicationName = "ruoyi-test";
|
||||
String requestUrl = "foo";
|
||||
Date beginTime = buildTime(2021, 3, 13);
|
||||
int duration = 1000;
|
||||
int resultCode = GlobalErrorCodeConstants.SUCCESS.getCode();
|
||||
|
||||
InfApiAccessLogDO infApiAccessLogDO = RandomUtils.randomPojo(InfApiAccessLogDO.class, dto -> {
|
||||
dto.setUserId(userId);
|
||||
dto.setUserType(userType);
|
||||
dto.setApplicationName(applicationName);
|
||||
dto.setRequestUrl(requestUrl);
|
||||
dto.setBeginTime(beginTime);
|
||||
dto.setDuration(duration);
|
||||
dto.setResultCode(resultCode);
|
||||
});
|
||||
infApiAccessLogMapper.insert(infApiAccessLogDO);
|
||||
|
||||
// 下面几个都是不匹配的数据
|
||||
// userId 不同的
|
||||
infApiAccessLogMapper.insert(ObjectUtils.clone(infApiAccessLogDO, logDO -> logDO.setUserId(3344L)));
|
||||
// userType
|
||||
infApiAccessLogMapper.insert(ObjectUtils.clone(infApiAccessLogDO, logDO -> logDO.setUserType(UserTypeEnum.MEMBER.getValue())));
|
||||
// applicationName 不同的
|
||||
infApiAccessLogMapper.insert(ObjectUtils.clone(infApiAccessLogDO, logDO -> logDO.setApplicationName("test")));
|
||||
// requestUrl 不同的
|
||||
infApiAccessLogMapper.insert(ObjectUtils.clone(infApiAccessLogDO, logDO -> logDO.setRequestUrl("bar")));
|
||||
// 构造一个早期时间 2021-02-06 00:00:00
|
||||
infApiAccessLogMapper.insert(ObjectUtils.clone(infApiAccessLogDO, logDO -> logDO.setBeginTime(buildTime(2021, 2, 6))));
|
||||
// duration 不同的
|
||||
infApiAccessLogMapper.insert(ObjectUtils.clone(infApiAccessLogDO, logDO -> logDO.setDuration(100)));
|
||||
// resultCode 不同的
|
||||
infApiAccessLogMapper.insert(ObjectUtils.clone(infApiAccessLogDO, logDO -> logDO.setResultCode(2)));
|
||||
|
||||
// 构造调用参数
|
||||
InfApiAccessLogExportReqVO reqVO = new InfApiAccessLogExportReqVO();
|
||||
reqVO.setUserId(userId);
|
||||
reqVO.setUserType(userType);
|
||||
reqVO.setApplicationName(applicationName);
|
||||
reqVO.setRequestUrl(requestUrl);
|
||||
reqVO.setBeginBeginTime(buildTime(2021, 3, 12));
|
||||
reqVO.setEndBeginTime(buildTime(2021, 3, 14));
|
||||
reqVO.setDuration(duration);
|
||||
reqVO.setResultCode(resultCode);
|
||||
|
||||
// 调用service方法
|
||||
List<InfApiAccessLogDO> list = infApiAccessLogServiceImpl.getApiAccessLogList(reqVO);
|
||||
|
||||
// 断言,只查到了一条符合条件的
|
||||
assertEquals(1, list.size());
|
||||
assertPojoEquals(infApiAccessLogDO, list.get(0));
|
||||
}
|
||||
}
|
@ -0,0 +1,207 @@
|
||||
package cn.iocoder.dashboard.modules.infra.service.logger;
|
||||
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.iocoder.dashboard.BaseDbUnitTest;
|
||||
import cn.iocoder.dashboard.common.enums.UserTypeEnum;
|
||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||
import cn.iocoder.dashboard.framework.logger.apilog.core.service.dto.ApiErrorLogCreateDTO;
|
||||
import cn.iocoder.dashboard.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogExportReqVO;
|
||||
import cn.iocoder.dashboard.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogPageReqVO;
|
||||
import cn.iocoder.dashboard.modules.infra.dal.dataobject.logger.InfApiErrorLogDO;
|
||||
import cn.iocoder.dashboard.modules.infra.dal.mysql.logger.InfApiErrorLogMapper;
|
||||
import cn.iocoder.dashboard.modules.infra.enums.logger.InfApiErrorLogProcessStatusEnum;
|
||||
import cn.iocoder.dashboard.modules.infra.service.logger.impl.InfApiErrorLogServiceImpl;
|
||||
import cn.iocoder.dashboard.util.RandomUtils;
|
||||
import cn.iocoder.dashboard.util.object.ObjectUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import static cn.iocoder.dashboard.modules.infra.enums.InfErrorCodeConstants.API_ERROR_LOG_NOT_FOUND;
|
||||
import static cn.iocoder.dashboard.modules.infra.enums.InfErrorCodeConstants.API_ERROR_LOG_PROCESSED;
|
||||
import static cn.iocoder.dashboard.util.AssertUtils.assertPojoEquals;
|
||||
import static cn.iocoder.dashboard.util.AssertUtils.assertServiceException;
|
||||
import static cn.iocoder.dashboard.util.date.DateUtils.buildTime;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
/**
|
||||
* {@link InfApiErrorLogServiceImpl} 单元测试
|
||||
*/
|
||||
@Import(InfApiErrorLogServiceImpl.class)
|
||||
public class InfApiErrorLogServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private InfApiErrorLogService infApiErrorLogServiceImpl;
|
||||
|
||||
@Resource
|
||||
private InfApiErrorLogMapper infApiErrorLogMapper;
|
||||
|
||||
|
||||
@Test
|
||||
public void testCreateApiErrorLogAsync() throws Exception {
|
||||
ApiErrorLogCreateDTO createDTO = RandomUtils.randomPojo(
|
||||
ApiErrorLogCreateDTO.class,
|
||||
dto -> dto.setUserType(RandomUtil.randomEle(UserTypeEnum.values()).getValue())
|
||||
);
|
||||
|
||||
// 执行service方法
|
||||
Future<Boolean> future = infApiErrorLogServiceImpl.createApiErrorLogAsync(createDTO);
|
||||
|
||||
// 等异步执行完
|
||||
future.get();
|
||||
|
||||
InfApiErrorLogDO infApiErrorLogDO = infApiErrorLogMapper.selectOne(null);
|
||||
// 断言
|
||||
assertNotNull(infApiErrorLogDO);
|
||||
// 断言,忽略基本字段
|
||||
assertPojoEquals(createDTO, infApiErrorLogDO);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetApiErrorLogPage() {
|
||||
// 构造测试数据
|
||||
long userId = 2233L;
|
||||
int userType = UserTypeEnum.ADMIN.getValue();
|
||||
String applicationName = "ruoyi-test";
|
||||
String requestUrl = "foo";
|
||||
Date beginTime = buildTime(2021, 3, 13);
|
||||
int progressStatus = InfApiErrorLogProcessStatusEnum.INIT.getStatus();
|
||||
|
||||
InfApiErrorLogDO infApiErrorLogDO = RandomUtils.randomPojo(InfApiErrorLogDO.class, logDO -> {
|
||||
logDO.setUserId(userId);
|
||||
logDO.setUserType(userType);
|
||||
logDO.setApplicationName(applicationName);
|
||||
logDO.setRequestUrl(requestUrl);
|
||||
logDO.setExceptionTime(beginTime);
|
||||
logDO.setProcessStatus(progressStatus);
|
||||
});
|
||||
infApiErrorLogMapper.insert(infApiErrorLogDO);
|
||||
|
||||
// 下面几个都是不匹配的数据
|
||||
// userId 不同的
|
||||
infApiErrorLogMapper.insert(ObjectUtils.clone(infApiErrorLogDO, logDO -> logDO.setUserId(3344L)));
|
||||
// userType
|
||||
infApiErrorLogMapper.insert(ObjectUtils.clone(infApiErrorLogDO, logDO -> logDO.setUserType(UserTypeEnum.MEMBER.getValue())));
|
||||
// applicationName 不同的
|
||||
infApiErrorLogMapper.insert(ObjectUtils.clone(infApiErrorLogDO, logDO -> logDO.setApplicationName("test")));
|
||||
// requestUrl 不同的
|
||||
infApiErrorLogMapper.insert(ObjectUtils.clone(infApiErrorLogDO, logDO -> logDO.setRequestUrl("bar")));
|
||||
// 构造一个早期时间 2021-02-06 00:00:00
|
||||
infApiErrorLogMapper.insert(ObjectUtils.clone(infApiErrorLogDO, logDO -> logDO.setExceptionTime(buildTime(2021, 2, 6))));
|
||||
// progressStatus 不同的
|
||||
infApiErrorLogMapper.insert(ObjectUtils.clone(infApiErrorLogDO, logDO -> logDO.setProcessStatus(InfApiErrorLogProcessStatusEnum.DONE.getStatus())));
|
||||
|
||||
// 构造调用参数
|
||||
InfApiErrorLogPageReqVO reqVO = new InfApiErrorLogPageReqVO();
|
||||
reqVO.setUserId(userId);
|
||||
reqVO.setUserType(userType);
|
||||
reqVO.setApplicationName(applicationName);
|
||||
reqVO.setRequestUrl(requestUrl);
|
||||
reqVO.setBeginExceptionTime(buildTime(2021, 3, 12));
|
||||
reqVO.setEndExceptionTime(buildTime(2021, 3, 14));
|
||||
reqVO.setProcessStatus(progressStatus);
|
||||
|
||||
// 调用service方法
|
||||
PageResult<InfApiErrorLogDO> pageResult = infApiErrorLogServiceImpl.getApiErrorLogPage(reqVO);
|
||||
|
||||
// 断言,只查到了一条符合条件的
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(infApiErrorLogDO, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetApiErrorLogList() {
|
||||
// 构造测试数据
|
||||
long userId = 2233L;
|
||||
int userType = UserTypeEnum.ADMIN.getValue();
|
||||
String applicationName = "ruoyi-test";
|
||||
String requestUrl = "foo";
|
||||
Date beginTime = buildTime(2021, 3, 13);
|
||||
int progressStatus = InfApiErrorLogProcessStatusEnum.INIT.getStatus();
|
||||
|
||||
InfApiErrorLogDO infApiErrorLogDO = RandomUtils.randomPojo(InfApiErrorLogDO.class, logDO -> {
|
||||
logDO.setUserId(userId);
|
||||
logDO.setUserType(userType);
|
||||
logDO.setApplicationName(applicationName);
|
||||
logDO.setRequestUrl(requestUrl);
|
||||
logDO.setExceptionTime(beginTime);
|
||||
logDO.setProcessStatus(progressStatus);
|
||||
});
|
||||
infApiErrorLogMapper.insert(infApiErrorLogDO);
|
||||
|
||||
// 下面几个都是不匹配的数据
|
||||
// userId 不同的
|
||||
infApiErrorLogMapper.insert(ObjectUtils.clone(infApiErrorLogDO, logDO -> logDO.setUserId(3344L)));
|
||||
// userType
|
||||
infApiErrorLogMapper.insert(ObjectUtils.clone(infApiErrorLogDO, logDO -> logDO.setUserType(UserTypeEnum.MEMBER.getValue())));
|
||||
// applicationName 不同的
|
||||
infApiErrorLogMapper.insert(ObjectUtils.clone(infApiErrorLogDO, logDO -> logDO.setApplicationName("test")));
|
||||
// requestUrl 不同的
|
||||
infApiErrorLogMapper.insert(ObjectUtils.clone(infApiErrorLogDO, logDO -> logDO.setRequestUrl("bar")));
|
||||
// 构造一个早期时间 2021-02-06 00:00:00
|
||||
infApiErrorLogMapper.insert(ObjectUtils.clone(infApiErrorLogDO, logDO -> logDO.setExceptionTime(buildTime(2021, 2, 6))));
|
||||
// progressStatus 不同的
|
||||
infApiErrorLogMapper.insert(ObjectUtils.clone(infApiErrorLogDO, logDO -> logDO.setProcessStatus(InfApiErrorLogProcessStatusEnum.DONE.getStatus())));
|
||||
|
||||
// 构造调用参数
|
||||
InfApiErrorLogExportReqVO reqVO = new InfApiErrorLogExportReqVO();
|
||||
reqVO.setUserId(userId);
|
||||
reqVO.setUserType(userType);
|
||||
reqVO.setApplicationName(applicationName);
|
||||
reqVO.setRequestUrl(requestUrl);
|
||||
reqVO.setBeginExceptionTime(buildTime(2021, 3, 12));
|
||||
reqVO.setEndExceptionTime(buildTime(2021, 3, 14));
|
||||
reqVO.setProcessStatus(progressStatus);
|
||||
|
||||
// 调用service方法
|
||||
List<InfApiErrorLogDO> list = infApiErrorLogServiceImpl.getApiErrorLogList(reqVO);
|
||||
|
||||
// 断言,只查到了一条符合条件的
|
||||
assertEquals(1, list.size());
|
||||
assertPojoEquals(infApiErrorLogDO, list.get(0));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testUpdateApiErrorLogProcess() {
|
||||
// 先构造两条数据,第一条用于抛出异常,第二条用于正常的执行update操作
|
||||
Long processUserId = 2233L;
|
||||
|
||||
InfApiErrorLogDO first = RandomUtils.randomPojo(InfApiErrorLogDO.class, logDO -> {
|
||||
logDO.setProcessUserId(processUserId);
|
||||
logDO.setUserType(UserTypeEnum.ADMIN.getValue());
|
||||
logDO.setProcessStatus(InfApiErrorLogProcessStatusEnum.DONE.getStatus());
|
||||
});
|
||||
infApiErrorLogMapper.insert(first);
|
||||
|
||||
InfApiErrorLogDO second = RandomUtils.randomPojo(InfApiErrorLogDO.class, logDO -> {
|
||||
logDO.setProcessUserId(1122L);
|
||||
logDO.setUserType(UserTypeEnum.ADMIN.getValue());
|
||||
logDO.setProcessStatus(InfApiErrorLogProcessStatusEnum.INIT.getStatus());
|
||||
});
|
||||
infApiErrorLogMapper.insert(second);
|
||||
|
||||
Long firstId = first.getId();
|
||||
Long secondId = second.getId();
|
||||
|
||||
// 执行正常的 update 操作
|
||||
infApiErrorLogServiceImpl.updateApiErrorLogProcess(secondId, InfApiErrorLogProcessStatusEnum.DONE.getStatus(), processUserId);
|
||||
InfApiErrorLogDO secondSelect = infApiErrorLogMapper.selectOne("id", secondId);
|
||||
|
||||
// id 为 0 查询不到,应该抛出异常 API_ERROR_LOG_NOT_FOUND
|
||||
assertServiceException(() -> infApiErrorLogServiceImpl.updateApiErrorLogProcess(0L, InfApiErrorLogProcessStatusEnum.DONE.getStatus(), processUserId), API_ERROR_LOG_NOT_FOUND);
|
||||
// id 为 first 的 progressStatus 为 DONE ,应该抛出 API_ERROR_LOG_PROCESSED
|
||||
assertServiceException(() -> infApiErrorLogServiceImpl.updateApiErrorLogProcess(firstId, InfApiErrorLogProcessStatusEnum.DONE.getStatus(), processUserId), API_ERROR_LOG_PROCESSED);
|
||||
// 验证 progressStatus 是否修改成功
|
||||
assertEquals(InfApiErrorLogProcessStatusEnum.DONE.getStatus(), secondSelect.getProcessStatus());
|
||||
// 验证 progressUserId 是否修改成功
|
||||
assertEquals(processUserId, secondSelect.getProcessUserId());
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
package cn.iocoder.dashboard.modules.system.service.common;
|
||||
|
||||
import cn.iocoder.dashboard.BaseRedisUnitTest;
|
||||
import cn.iocoder.dashboard.framework.captcha.config.CaptchaProperties;
|
||||
import cn.iocoder.dashboard.modules.system.controller.common.vo.SysCaptchaImageRespVO;
|
||||
import cn.iocoder.dashboard.modules.system.dal.redis.common.SysCaptchaRedisDAO;
|
||||
import cn.iocoder.dashboard.modules.system.service.common.impl.SysCaptchaServiceImpl;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import static cn.iocoder.dashboard.util.RandomUtils.randomString;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@Import({SysCaptchaServiceImpl.class, CaptchaProperties.class, SysCaptchaRedisDAO.class})
|
||||
public class SysCaptchaServiceTest extends BaseRedisUnitTest {
|
||||
|
||||
@Resource
|
||||
private SysCaptchaServiceImpl captchaService;
|
||||
|
||||
@Resource
|
||||
private SysCaptchaRedisDAO captchaRedisDAO;
|
||||
@Resource
|
||||
private CaptchaProperties captchaProperties;
|
||||
|
||||
@Test
|
||||
public void testGetCaptchaImage() {
|
||||
// 调用
|
||||
SysCaptchaImageRespVO respVO = captchaService.getCaptchaImage();
|
||||
// 断言
|
||||
assertNotNull(respVO.getUuid());
|
||||
assertNotNull(respVO.getImg());
|
||||
String captchaCode = captchaRedisDAO.get(respVO.getUuid());
|
||||
assertNotNull(captchaCode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCaptchaCode() {
|
||||
// 准备参数
|
||||
String uuid = randomString();
|
||||
String code = randomString();
|
||||
// mock 数据
|
||||
captchaRedisDAO.set(uuid, code, captchaProperties.getTimeout());
|
||||
|
||||
// 调用
|
||||
String resultCode = captchaService.getCaptchaCode(uuid);
|
||||
// 断言
|
||||
assertEquals(code, resultCode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteCaptchaCode() {
|
||||
// 准备参数
|
||||
String uuid = randomString();
|
||||
String code = randomString();
|
||||
// mock 数据
|
||||
captchaRedisDAO.set(uuid, code, captchaProperties.getTimeout());
|
||||
|
||||
// 调用
|
||||
captchaService.deleteCaptchaCode(uuid);
|
||||
// 断言
|
||||
assertNull(captchaRedisDAO.get(uuid));
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package cn.iocoder.dashboard.modules.tool.dal.mysql.codegen;
|
||||
|
||||
import cn.iocoder.dashboard.BaseSpringBootUnitTest;
|
||||
import cn.iocoder.dashboard.BaseDbUnitTest;
|
||||
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolSchemaColumnDO;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@ -9,7 +9,7 @@ import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class ToolInformationSchemaColumnMapperTest extends BaseSpringBootUnitTest {
|
||||
public class ToolInformationSchemaColumnMapperTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private ToolSchemaColumnMapper toolInformationSchemaColumnMapper;
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cn.iocoder.dashboard.modules.tool.dal.mysql.codegen;
|
||||
|
||||
import cn.iocoder.dashboard.BaseSpringBootUnitTest;
|
||||
import cn.iocoder.dashboard.BaseDbUnitTest;
|
||||
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolSchemaTableDO;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@ -9,7 +9,7 @@ import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class ToolInformationSchemaTableMapperTest extends BaseSpringBootUnitTest {
|
||||
class ToolInformationSchemaTableMapperTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private ToolSchemaTableMapper toolInformationSchemaTableMapper;
|
||||
|
@ -1,18 +1,17 @@
|
||||
package cn.iocoder.dashboard.modules.tool.service.codegen.impl;
|
||||
|
||||
import cn.iocoder.dashboard.BaseSpringBootUnitTest;
|
||||
import cn.iocoder.dashboard.BaseDbUnitTest;
|
||||
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolCodegenColumnDO;
|
||||
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolCodegenTableDO;
|
||||
import cn.iocoder.dashboard.modules.tool.dal.mysql.codegen.ToolCodegenColumnMapper;
|
||||
import cn.iocoder.dashboard.modules.tool.dal.mysql.codegen.ToolCodegenTableMapper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ToolCodegenEngineTest extends BaseSpringBootUnitTest {
|
||||
public class ToolCodegenEngineTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private ToolCodegenTableMapper codegenTableMapper;
|
||||
|
@ -1,9 +1,9 @@
|
||||
package cn.iocoder.dashboard.modules.tool.service.codegen.impl;
|
||||
|
||||
import cn.iocoder.dashboard.BaseSpringBootUnitTest;
|
||||
import cn.iocoder.dashboard.BaseDbUnitTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class ToolCodegenSQLParserTest extends BaseSpringBootUnitTest {
|
||||
public class ToolCodegenSQLParserTest extends BaseDbUnitTest {
|
||||
|
||||
@Test
|
||||
public void testParse() {
|
||||
|
@ -1,12 +1,11 @@
|
||||
package cn.iocoder.dashboard.modules.tool.service.codegen.impl;
|
||||
|
||||
import cn.iocoder.dashboard.BaseSpringBootUnitTest;
|
||||
import cn.iocoder.dashboard.BaseDbUnitTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
class ToolCodegenServiceImplTest extends BaseSpringBootUnitTest {
|
||||
class ToolCodegenServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private ToolCodegenServiceImpl toolCodegenService;
|
||||
|
@ -131,7 +131,7 @@ CREATE TABLE IF NOT EXISTS "sys_menu" (
|
||||
PRIMARY KEY ("id")
|
||||
) COMMENT '菜单权限表';
|
||||
|
||||
CREATE TABLE "sys_dict_type" (
|
||||
CREATE TABLE IF NOT EXISTS "sys_dict_type" (
|
||||
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
|
||||
"name" varchar(100) NOT NULL DEFAULT '',
|
||||
"type" varchar(100) NOT NULL DEFAULT '',
|
||||
@ -145,7 +145,7 @@ CREATE TABLE "sys_dict_type" (
|
||||
PRIMARY KEY ("id")
|
||||
) COMMENT '字典类型表';
|
||||
|
||||
CREATE TABLE `sys_user_session` (
|
||||
CREATE TABLE IF NOT EXISTS `sys_user_session` (
|
||||
`id` varchar(32) NOT NULL,
|
||||
`user_id` bigint DEFAULT NULL,
|
||||
`username` varchar(50) NOT NULL DEFAULT '',
|
||||
@ -209,7 +209,7 @@ CREATE TABLE IF NOT EXISTS `sys_login_log` (
|
||||
) COMMENT ='系统访问记录';
|
||||
|
||||
|
||||
CREATE TABLE `sys_operate_log` (
|
||||
CREATE TABLE IF NOT EXISTS `sys_operate_log` (
|
||||
`id` bigint(20) NOT NULL GENERATED BY DEFAULT AS IDENTITY,
|
||||
`trace_id` varchar(64) NOT NULL DEFAULT '',
|
||||
`user_id` bigint(20) NOT NULL,
|
||||
@ -237,7 +237,7 @@ CREATE TABLE `sys_operate_log` (
|
||||
PRIMARY KEY (`id`)
|
||||
) COMMENT ='操作日志记录';
|
||||
|
||||
create table "sys_user" (
|
||||
create table IF NOT EXISTS "sys_user" (
|
||||
"id" bigint not null GENERATED BY DEFAULT AS IDENTITY,
|
||||
"username" varchar(30) not null,
|
||||
"password" varchar(100) not null default '',
|
||||
@ -259,3 +259,60 @@ create table "sys_user" (
|
||||
"deleted" bit not null default false,
|
||||
primary key ("id")
|
||||
) comment '用户信息表';
|
||||
|
||||
|
||||
create table "inf_api_access_log" (
|
||||
"id" bigint not null GENERATED BY DEFAULT AS IDENTITY,
|
||||
"trace_id" varchar(64) not null default '',
|
||||
"user_id" bigint not null default '0',
|
||||
"user_type" tinyint not null default '0',
|
||||
"application_name" varchar(50) not null,
|
||||
"request_method" varchar(16) not null default '',
|
||||
"request_url" varchar(255) not null default '',
|
||||
"request_params" varchar(8000) not null default '',
|
||||
"user_ip" varchar(50) not null,
|
||||
"user_agent" varchar(512) not null,
|
||||
"begin_time" timestamp not null,
|
||||
"end_time" timestamp not null,
|
||||
"duration" integer not null,
|
||||
"result_code" integer not null default '0',
|
||||
"result_msg" varchar(512) default '',
|
||||
"creator" varchar(64) default '',
|
||||
"create_time" timestamp not null default current_timestamp,
|
||||
"updater" varchar(64) default '',
|
||||
"update_time" timestamp not null default current_timestamp,
|
||||
"deleted" bit not null default false,
|
||||
primary key ("id")
|
||||
) comment 'API 访问日志表';
|
||||
|
||||
|
||||
create table "inf_api_error_log" (
|
||||
"id" integer not null GENERATED BY DEFAULT AS IDENTITY,
|
||||
"trace_id" varchar(64) not null,
|
||||
"user_id" bigint not null default '0',
|
||||
"user_type" tinyint not null default '0',
|
||||
"application_name" varchar(50) not null,
|
||||
"request_method" varchar(16) not null,
|
||||
"request_url" varchar(255) not null,
|
||||
"request_params" varchar(8000) not null,
|
||||
"user_ip" varchar(50) not null,
|
||||
"user_agent" varchar(512) not null,
|
||||
"exception_time" timestamp not null,
|
||||
"exception_name" varchar(128) not null default '',
|
||||
"exception_message" clob not null,
|
||||
"exception_root_cause_message" clob not null,
|
||||
"exception_stack_trace" clob not null,
|
||||
"exception_class_name" varchar(512) not null,
|
||||
"exception_file_name" varchar(512) not null,
|
||||
"exception_method_name" varchar(512) not null,
|
||||
"exception_line_number" integer not null,
|
||||
"process_status" tinyint not null,
|
||||
"process_time" timestamp default null,
|
||||
"process_user_id" bigint default '0',
|
||||
"creator" varchar(64) default '',
|
||||
"create_time" timestamp not null default current_timestamp,
|
||||
"updater" varchar(64) default '',
|
||||
"update_time" timestamp not null default current_timestamp,
|
||||
"deleted" bit not null default false,
|
||||
primary key ("id")
|
||||
) comment '系统异常日志';
|
Reference in New Issue
Block a user