开始搭建 unit test 的示例。

1. 禁用 spring security 的自动配置
2. 禁用 quartz 的自动配置
pull/2/head
YunaiV 2021-02-28 02:02:24 +08:00
parent 172574c3c8
commit 99855e7cdc
12 changed files with 1222 additions and 273 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,5 @@
package cn.iocoder.dashboard;
import de.codecentric.boot.admin.server.config.EnableAdminServer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

View File

@ -4,6 +4,7 @@ import cn.iocoder.dashboard.framework.security.core.filter.JwtAuthenticationToke
import cn.iocoder.dashboard.framework.security.core.handler.LogoutSuccessHandlerImpl;
import cn.iocoder.dashboard.framework.web.config.WebProperties;
import de.codecentric.boot.admin.server.config.AdminServerProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpMethod;
@ -68,8 +69,9 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
* Spring Security AuthenticationManager @Bean
* @Bean
*/
@Bean
@Override
@Bean
@ConditionalOnMissingBean(AuthenticationManager.class)
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}

View File

@ -1,7 +0,0 @@
package cn.iocoder.dashboard;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class TestApplication {
}

View File

@ -0,0 +1,14 @@
package cn.iocoder.dashboard.config;
import org.springframework.context.annotation.Configuration;
@Configuration
public class QuartzTestConfiguration {
// TODO 芋艿:暂时不用 Scheduler
// @Bean
// public Scheduler scheduler() {
// return Mockito.mock(Scheduler.class);
// }
}

View File

@ -0,0 +1,16 @@
package cn.iocoder.dashboard.config;
import org.mockito.Mockito;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
@Configuration
public class SecurityTestConfiguration {
@Bean
public AuthenticationManager authenticationManager() {
return Mockito.mock(AuthenticationManager.class);
}
}

View File

@ -1,7 +1,6 @@
package cn.iocoder.dashboard.framework.quartz.core.scheduler;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.dashboard.TestApplication;
import cn.iocoder.dashboard.modules.system.job.auth.SysUserSessionTimeoutJob;
import org.junit.jupiter.api.Test;
import org.quartz.SchedulerException;
@ -9,9 +8,7 @@ import org.springframework.boot.test.context.SpringBootTest;
import javax.annotation.Resource;
import static org.junit.jupiter.api.Assertions.*;
@SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@SpringBootTest
class SchedulerManagerTest {
@Resource

View File

@ -1,6 +1,5 @@
package cn.iocoder.dashboard.modules.tool.dal.mysql.coegen;
import cn.iocoder.dashboard.TestApplication;
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolSchemaColumnDO;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@ -8,10 +7,9 @@ import org.springframework.boot.test.context.SpringBootTest;
import javax.annotation.Resource;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.*;
@SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@SpringBootTest
public class ToolInformationSchemaColumnMapperTest {
@Resource

View File

@ -1,6 +1,5 @@
package cn.iocoder.dashboard.modules.tool.dal.mysql.coegen;
import cn.iocoder.dashboard.TestApplication;
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolSchemaTableDO;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@ -10,7 +9,7 @@ import java.util.List;
import static org.junit.jupiter.api.Assertions.assertTrue;
@SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@SpringBootTest
class ToolInformationSchemaTableMapperTest {
@Resource

View File

@ -1,6 +1,5 @@
package cn.iocoder.dashboard.modules.tool.service.codegen.impl;
import cn.iocoder.dashboard.TestApplication;
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;
@ -12,7 +11,7 @@ import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
@SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@SpringBootTest
public class ToolCodegenEngineTest {
@Resource

View File

@ -1,12 +1,11 @@
package cn.iocoder.dashboard.modules.tool.service.codegen.impl;
import cn.iocoder.dashboard.TestApplication;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import javax.annotation.Resource;
@SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@SpringBootTest
class ToolCodegenServiceImplTest {
@Resource

View File

@ -0,0 +1,44 @@
spring:
application:
name: dashboard
profiles:
active: local
# Servlet 配置
servlet:
# 文件上传相关配置项
multipart:
max-file-size: 16MB # 单个文件大小
max-request-size: 32MB # 设置总上传的文件大小
# Jackson 配置项
jackson:
serialization:
write-dates-as-timestamps: true # 设置 Date 的格式,使用时间戳
write-date-timestamps-as-nanoseconds: false # 设置不使用 nanoseconds 的格式。例如说 1611460870.401,而是直接 1611460870401
write-durations-as-timestamps: true # 设置 Duration 的格式,使用时间戳
fail-on-empty-beans: false # 允许序列化无属性的 Bean
main:
lazy-initialization: true
# 去除的自动配置项
autoconfigure:
exclude:
- org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration
- org.springframework.boot.autoconfigure.security.reactive.ReactiveSecurityAutoConfiguration
- org.springframework.boot.autoconfigure.quartz.QuartzAutoConfiguration
# MyBatis Plus 的配置项
mybatis-plus:
configuration:
map-underscore-to-camel-case: true # 虽然默认为 true ,但是还是显示去指定下。
# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 打印日志
global-config:
db-config:
id-type: AUTO # 自增 ID
logic-delete-value: 1 # 逻辑已删除值(默认为 1)
logic-not-delete-value: 0 # 逻辑未删除值(默认为 0)
mapper-locations: classpath*:mapper/*.xml
type-aliases-package: ${yudao.info.base-package}.modules.*.dal.dataobject