引入 redis mock 服务器
This commit is contained in:
parent
2f0d7e8aba
commit
7bb2dd1167
7
pom.xml
7
pom.xml
@ -183,6 +183,13 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.fppt</groupId> <!-- 单元测试,我们采用内嵌的 Redis 数据库 -->
|
||||
<artifactId>jedis-mock</artifactId>
|
||||
<version>0.1.16</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- 工具类相关 -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
|
@ -13,7 +13,6 @@ import cn.iocoder.dashboard.modules.infra.service.config.InfConfigService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@ -30,19 +29,6 @@ import static cn.iocoder.dashboard.modules.infra.enums.InfErrorCodeConstants.CON
|
||||
@RequestMapping("/infra/config")
|
||||
public class InfConfigController {
|
||||
|
||||
@Value("${demo.test}")
|
||||
private String demo;
|
||||
|
||||
@GetMapping("/demo")
|
||||
public String demo() {
|
||||
return demo;
|
||||
}
|
||||
|
||||
@PostMapping("/demo")
|
||||
public void setDemo() {
|
||||
|
||||
}
|
||||
|
||||
@Resource
|
||||
private InfConfigService configService;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
package cn.iocoder.dashboard.modules.tool.dal.mysql.coegen;
|
||||
package cn.iocoder.dashboard.modules.tool.dal.mysql.codegen;
|
||||
|
||||
import cn.iocoder.dashboard.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolCodegenColumnDO;
|
@ -1,4 +1,4 @@
|
||||
package cn.iocoder.dashboard.modules.tool.dal.mysql.coegen;
|
||||
package cn.iocoder.dashboard.modules.tool.dal.mysql.codegen;
|
||||
|
||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||
import cn.iocoder.dashboard.framework.mybatis.core.mapper.BaseMapperX;
|
@ -1,4 +1,4 @@
|
||||
package cn.iocoder.dashboard.modules.tool.dal.mysql.coegen;
|
||||
package cn.iocoder.dashboard.modules.tool.dal.mysql.codegen;
|
||||
|
||||
import cn.iocoder.dashboard.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolSchemaColumnDO;
|
@ -1,4 +1,4 @@
|
||||
package cn.iocoder.dashboard.modules.tool.dal.mysql.coegen;
|
||||
package cn.iocoder.dashboard.modules.tool.dal.mysql.codegen;
|
||||
|
||||
import cn.iocoder.dashboard.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.dashboard.framework.mybatis.core.query.QueryWrapperX;
|
@ -10,10 +10,10 @@ import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolCodegenColum
|
||||
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolCodegenTableDO;
|
||||
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolSchemaColumnDO;
|
||||
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolSchemaTableDO;
|
||||
import cn.iocoder.dashboard.modules.tool.dal.mysql.coegen.ToolCodegenColumnMapper;
|
||||
import cn.iocoder.dashboard.modules.tool.dal.mysql.coegen.ToolCodegenTableMapper;
|
||||
import cn.iocoder.dashboard.modules.tool.dal.mysql.coegen.ToolSchemaColumnMapper;
|
||||
import cn.iocoder.dashboard.modules.tool.dal.mysql.coegen.ToolSchemaTableMapper;
|
||||
import cn.iocoder.dashboard.modules.tool.dal.mysql.codegen.ToolCodegenColumnMapper;
|
||||
import cn.iocoder.dashboard.modules.tool.dal.mysql.codegen.ToolCodegenTableMapper;
|
||||
import cn.iocoder.dashboard.modules.tool.dal.mysql.codegen.ToolSchemaColumnMapper;
|
||||
import cn.iocoder.dashboard.modules.tool.dal.mysql.codegen.ToolSchemaTableMapper;
|
||||
import cn.iocoder.dashboard.modules.tool.enums.codegen.ToolCodegenImportTypeEnum;
|
||||
import cn.iocoder.dashboard.modules.tool.service.codegen.ToolCodegenService;
|
||||
import cn.iocoder.dashboard.util.collection.CollectionUtils;
|
||||
|
@ -0,0 +1,31 @@
|
||||
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
|
||||
@ActiveProfiles("unit-test") // 设置使用 application-unit-test 配置文件
|
||||
@Sql(scripts = "/sql/clean.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD) // 每个单元测试结束后,清理 DB
|
||||
public class BaseSpringBootUnitTest {
|
||||
|
||||
@Resource
|
||||
private StringRedisTemplate stringRedisTemplate;
|
||||
|
||||
/**
|
||||
* 每个单元测试结束后,清理 Redis
|
||||
*/
|
||||
@AfterEach
|
||||
public void cleanRedis() {
|
||||
stringRedisTemplate.execute((RedisCallback<Object>) connection -> {
|
||||
connection.flushDb();
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -1,14 +1,18 @@
|
||||
package cn.iocoder.dashboard.config;
|
||||
|
||||
import io.reactivex.rxjava3.core.Scheduler;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
|
||||
@Configuration
|
||||
@Lazy(false)
|
||||
public class QuartzTestConfiguration {
|
||||
|
||||
// TODO 芋艿:暂时不用 Scheduler
|
||||
// @Bean
|
||||
// public Scheduler scheduler() {
|
||||
// return Mockito.mock(Scheduler.class);
|
||||
// }
|
||||
@Bean
|
||||
public Scheduler scheduler() {
|
||||
return Mockito.mock(Scheduler.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,29 @@
|
||||
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
|
||||
@Lazy(false) // 禁用懒加载,因为需要保证 Redis Server 必须先启动
|
||||
@EnableConfigurationProperties(RedisProperties.class)
|
||||
@AutoConfigureBefore({RedisAutoConfiguration.class, RedissonAutoConfiguration.class}) // 在 Redis 自动配置前,进行初始化
|
||||
public class RedisTestConfiguration {
|
||||
|
||||
/**
|
||||
* 创建模拟的 Redis Server 服务器
|
||||
*/
|
||||
@Bean(initMethod = "start", destroyMethod = "stop")
|
||||
public RedisServer redisServer(RedisProperties properties) throws IOException {
|
||||
return new RedisServer(properties.getPort());
|
||||
}
|
||||
|
||||
}
|
@ -1,15 +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.modules.system.job.auth.SysUserSessionTimeoutJob;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.quartz.SchedulerException;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@SpringBootTest
|
||||
class SchedulerManagerTest {
|
||||
class SchedulerManagerTest extends BaseSpringBootUnitTest {
|
||||
|
||||
@Resource
|
||||
private SchedulerManager schedulerManager;
|
||||
|
@ -1,5 +1,6 @@
|
||||
package cn.iocoder.dashboard.modules.infra.service.config;
|
||||
|
||||
import cn.iocoder.dashboard.BaseSpringBootUnitTest;
|
||||
import cn.iocoder.dashboard.common.exception.ServiceException;
|
||||
import cn.iocoder.dashboard.modules.infra.controller.config.vo.InfConfigCreateReqVO;
|
||||
import cn.iocoder.dashboard.modules.infra.dal.dataobject.config.InfConfigDO;
|
||||
@ -9,9 +10,7 @@ import cn.iocoder.dashboard.modules.infra.mq.producer.config.InfConfigProducer;
|
||||
import cn.iocoder.dashboard.modules.infra.service.config.impl.InfConfigServiceImpl;
|
||||
import cn.iocoder.dashboard.util.AssertUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.jdbc.Sql;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@ -21,10 +20,7 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@SpringBootTest
|
||||
@ActiveProfiles("unit-test")
|
||||
@Sql(scripts = "/sql/clean.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
|
||||
public class InfConfigServiceImplTest {
|
||||
public class InfConfigServiceImplTest extends BaseSpringBootUnitTest {
|
||||
|
||||
@Resource
|
||||
private InfConfigServiceImpl configService;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package cn.iocoder.dashboard.modules.tool.dal.mysql.coegen;
|
||||
package cn.iocoder.dashboard.modules.tool.dal.mysql.codegen;
|
||||
|
||||
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolSchemaColumnDO;
|
||||
import org.junit.jupiter.api.Test;
|
@ -1,4 +1,4 @@
|
||||
package cn.iocoder.dashboard.modules.tool.dal.mysql.coegen;
|
||||
package cn.iocoder.dashboard.modules.tool.dal.mysql.codegen;
|
||||
|
||||
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolSchemaTableDO;
|
||||
import org.junit.jupiter.api.Test;
|
@ -2,8 +2,8 @@ package cn.iocoder.dashboard.modules.tool.service.codegen.impl;
|
||||
|
||||
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.coegen.ToolCodegenColumnMapper;
|
||||
import cn.iocoder.dashboard.modules.tool.dal.mysql.coegen.ToolCodegenTableMapper;
|
||||
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;
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
spring:
|
||||
main:
|
||||
lazy-initialization: true
|
||||
lazy-initialization: true # 开启懒加载,加快速度
|
||||
banner-mode: off # 单元测试,禁用 Banner
|
||||
|
||||
# 去除的自动配置项
|
||||
autoconfigure:
|
||||
@ -10,6 +11,11 @@ spring:
|
||||
- org.springframework.boot.autoconfigure.quartz.QuartzAutoConfiguration # 单元测试,禁用 Quartz
|
||||
- com.baomidou.lock.spring.boot.autoconfigure.LockAutoConfiguration # 单元测试,禁用 Lock4j 分布式锁
|
||||
|
||||
# Swagger 接口文档的自动配置(单元测试,禁用 Swagger)
|
||||
springfox:
|
||||
documentation:
|
||||
auto-startup: false
|
||||
|
||||
--- #################### 数据库相关配置 ####################
|
||||
|
||||
spring:
|
||||
@ -25,7 +31,7 @@ spring:
|
||||
# Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
|
||||
redis:
|
||||
host: 127.0.0.1 # 地址
|
||||
port: 6379 # 端口
|
||||
port: 36379 # 端口(单元测试,使用 363979 端口)
|
||||
database: 0 # 数据库索引
|
||||
|
||||
--- #################### 定时任务相关配置 ####################
|
||||
@ -70,10 +76,7 @@ spring:
|
||||
# Spring Boot Admin Server 服务端的相关配置
|
||||
context-path: /admin # 配置 Spring
|
||||
|
||||
# 日志文件配置
|
||||
logging:
|
||||
file:
|
||||
path: ${user.home}/logs/ # 日志文件的路径
|
||||
# 日志文件配置(不需要配置)
|
||||
|
||||
--- #################### 芋道相关配置 ####################
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user