mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2025-01-19 11:40:05 +08:00
Merge branch 'rouyi/master' into feature/notice_test
This commit is contained in:
commit
adac2e63cb
@ -13,7 +13,8 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
* @author 芋道源码
|
* @author 芋道源码
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@MapperScan(value = "${yudao.info.base-package}", annotationClass = Mapper.class)
|
@MapperScan(value = "${yudao.info.base-package}", annotationClass = Mapper.class,
|
||||||
|
lazyInitialization = "${mybatis.lazy-initialization:false}") // Mapper 懒加载,目前仅用于单元测试
|
||||||
public class MybatisConfiguration {
|
public class MybatisConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
@ -152,7 +152,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
|
|||||||
.anyRequest().authenticated()
|
.anyRequest().authenticated()
|
||||||
.and()
|
.and()
|
||||||
.headers().frameOptions().disable();
|
.headers().frameOptions().disable();
|
||||||
httpSecurity.logout().logoutUrl("/logout").logoutSuccessHandler(logoutSuccessHandler);
|
httpSecurity.logout().logoutUrl(webProperties.getApiPrefix() + "/logout").logoutSuccessHandler(logoutSuccessHandler);
|
||||||
// 添加 JWT Filter
|
// 添加 JWT Filter
|
||||||
httpSecurity.addFilterBefore(authenticationTokenFilter, UsernamePasswordAuthenticationFilter.class);
|
httpSecurity.addFilterBefore(authenticationTokenFilter, UsernamePasswordAuthenticationFilter.class);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package cn.iocoder.dashboard.framework.security.core.handler;
|
package cn.iocoder.dashboard.framework.security.core.handler;
|
||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.iocoder.dashboard.common.pojo.CommonResult;
|
||||||
import cn.iocoder.dashboard.framework.security.config.SecurityProperties;
|
import cn.iocoder.dashboard.framework.security.config.SecurityProperties;
|
||||||
import cn.iocoder.dashboard.framework.security.core.service.SecurityAuthFrameworkService;
|
import cn.iocoder.dashboard.framework.security.core.service.SecurityAuthFrameworkService;
|
||||||
import cn.iocoder.dashboard.framework.security.core.util.SecurityFrameworkUtils;
|
import cn.iocoder.dashboard.framework.security.core.util.SecurityFrameworkUtils;
|
||||||
@ -36,6 +37,6 @@ public class LogoutSuccessHandlerImpl implements LogoutSuccessHandler {
|
|||||||
securityFrameworkService.logout(token);
|
securityFrameworkService.logout(token);
|
||||||
}
|
}
|
||||||
// 返回成功
|
// 返回成功
|
||||||
ServletUtils.writeJSON(response, null);
|
ServletUtils.writeJSON(response, CommonResult.success(null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,10 @@ package cn.iocoder.dashboard.framework.security.core.util;
|
|||||||
|
|
||||||
import cn.iocoder.dashboard.framework.security.core.LoginUser;
|
import cn.iocoder.dashboard.framework.security.core.LoginUser;
|
||||||
import cn.iocoder.dashboard.framework.web.core.util.WebFrameworkUtils;
|
import cn.iocoder.dashboard.framework.web.core.util.WebFrameworkUtils;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||||
|
import org.springframework.security.core.Authentication;
|
||||||
|
import org.springframework.security.core.context.SecurityContext;
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
import org.springframework.security.web.authentication.WebAuthenticationDetailsSource;
|
import org.springframework.security.web.authentication.WebAuthenticationDetailsSource;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
@ -40,9 +43,20 @@ public class SecurityFrameworkUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前用户
|
* 获取当前用户
|
||||||
|
*
|
||||||
|
* @return 当前用户
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public static LoginUser getLoginUser() {
|
public static LoginUser getLoginUser() {
|
||||||
return (LoginUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
SecurityContext context = SecurityContextHolder.getContext();
|
||||||
|
if (context == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Authentication authentication = context.getAuthentication();
|
||||||
|
if (authentication == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return (LoginUser) authentication.getPrincipal();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -50,8 +64,10 @@ public class SecurityFrameworkUtils {
|
|||||||
*
|
*
|
||||||
* @return 用户编号
|
* @return 用户编号
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public static Long getLoginUserId() {
|
public static Long getLoginUserId() {
|
||||||
return getLoginUser().getId();
|
LoginUser loginUser = getLoginUser();
|
||||||
|
return loginUser != null ? loginUser.getId() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -59,8 +75,10 @@ public class SecurityFrameworkUtils {
|
|||||||
*
|
*
|
||||||
* @return 角色编号数组
|
* @return 角色编号数组
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public static Set<Long> getLoginUserRoleIds() {
|
public static Set<Long> getLoginUserRoleIds() {
|
||||||
return getLoginUser().getRoleIds();
|
LoginUser loginUser = getLoginUser();
|
||||||
|
return loginUser != null ? loginUser.getRoleIds() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -160,7 +160,26 @@ public class SysAuthServiceImpl implements SysAuthService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void logout(String token) {
|
public void logout(String token) {
|
||||||
// AsyncManager.me().execute(AsyncFactory.recordLogininfor(userName, Constants.LOGOUT, "退出成功")); TODO 需要搞一搞
|
// 查询用户信息
|
||||||
|
LoginUser loginUser = userSessionService.getLoginUser(token);
|
||||||
|
if (loginUser == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 删除 session
|
||||||
|
userSessionService.deleteUserSession(token);
|
||||||
|
// 记录登出日子和
|
||||||
|
this.createLogoutLog(loginUser.getUsername());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createLogoutLog(String username) {
|
||||||
|
SysLoginLogCreateReqVO reqVO = new SysLoginLogCreateReqVO();
|
||||||
|
reqVO.setLogType(SysLoginLogTypeEnum.LOGOUT_SELF.getType());
|
||||||
|
reqVO.setTraceId(TracerUtils.getTraceId());
|
||||||
|
reqVO.setUsername(username);
|
||||||
|
reqVO.setUserAgent(ServletUtils.getUserAgent());
|
||||||
|
reqVO.setUserIp(ServletUtils.getClientIP());
|
||||||
|
reqVO.setResult(SysLoginResultEnum.SUCCESS.getResult());
|
||||||
|
loginLogService.createLoginLog(reqVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -0,0 +1,46 @@
|
|||||||
|
package cn.iocoder.dashboard;
|
||||||
|
|
||||||
|
import cn.iocoder.dashboard.config.RedisTestConfiguration;
|
||||||
|
import cn.iocoder.dashboard.framework.datasource.config.DataSourceConfiguration;
|
||||||
|
import cn.iocoder.dashboard.framework.mybatis.config.MybatisConfiguration;
|
||||||
|
import cn.iocoder.dashboard.framework.redis.config.RedisConfig;
|
||||||
|
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure;
|
||||||
|
import com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration;
|
||||||
|
import org.redisson.spring.starter.RedissonAutoConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
|
import org.springframework.test.context.jdbc.Sql;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 依赖内存 DB 的单元测试
|
||||||
|
*
|
||||||
|
* 注意,Service 层同样适用。对于 Service 层的单元测试,我们针对自己模块的 Mapper 走的是 H2 内存数据库,针对别的模块的 Service 走的是 Mock 方法
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = BaseDbAndRedisUnitTest.Application.class)
|
||||||
|
@ActiveProfiles("unit-test") // 设置使用 application-unit-test 配置文件
|
||||||
|
@Sql(scripts = "/sql/clean.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD) // 每个单元测试结束后,清理 DB
|
||||||
|
public class BaseDbAndRedisUnitTest {
|
||||||
|
|
||||||
|
@Import({
|
||||||
|
// DB 配置类
|
||||||
|
DataSourceConfiguration.class, // 自己的 DB 配置类
|
||||||
|
DataSourceAutoConfiguration.class, // Spring DB 自动配置类
|
||||||
|
DruidDataSourceAutoConfigure.class, // Druid 自动配置类
|
||||||
|
// MyBatis 配置类
|
||||||
|
MybatisConfiguration.class, // 自己的 MyBatis 配置类
|
||||||
|
MybatisPlusAutoConfiguration.class, // MyBatis 的自动配置类
|
||||||
|
// Redis 配置类
|
||||||
|
RedisTestConfiguration.class, // Redis 测试配置类,用于启动 RedisServer
|
||||||
|
RedisAutoConfiguration.class, // Spring Redis 自动配置类
|
||||||
|
RedisConfig.class, // 自己的 Redis 配置类
|
||||||
|
RedissonAutoConfiguration.class, // Redisson 自动高配置类
|
||||||
|
})
|
||||||
|
public static class Application {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
37
src/test/java/cn/iocoder/dashboard/BaseDbUnitTest.java
Normal file
37
src/test/java/cn/iocoder/dashboard/BaseDbUnitTest.java
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
package cn.iocoder.dashboard;
|
||||||
|
|
||||||
|
import cn.iocoder.dashboard.framework.datasource.config.DataSourceConfiguration;
|
||||||
|
import cn.iocoder.dashboard.framework.mybatis.config.MybatisConfiguration;
|
||||||
|
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure;
|
||||||
|
import com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
|
import org.springframework.test.context.jdbc.Sql;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 依赖内存 DB 的单元测试
|
||||||
|
*
|
||||||
|
* 注意,Service 层同样适用。对于 Service 层的单元测试,我们针对自己模块的 Mapper 走的是 H2 内存数据库,针对别的模块的 Service 走的是 Mock 方法
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = BaseDbUnitTest.Application.class)
|
||||||
|
@ActiveProfiles("unit-test") // 设置使用 application-unit-test 配置文件
|
||||||
|
@Sql(scripts = "/sql/clean.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD) // 每个单元测试结束后,清理 DB
|
||||||
|
public class BaseDbUnitTest {
|
||||||
|
|
||||||
|
@Import({
|
||||||
|
// DB 配置类
|
||||||
|
DataSourceConfiguration.class, // 自己的 DB 配置类
|
||||||
|
DataSourceAutoConfiguration.class, // Spring DB 自动配置类
|
||||||
|
DruidDataSourceAutoConfigure.class, // Druid 自动配置类
|
||||||
|
// MyBatis 配置类
|
||||||
|
MybatisConfiguration.class, // 自己的 MyBatis 配置类
|
||||||
|
MybatisPlusAutoConfiguration.class, // MyBatis 的自动配置类
|
||||||
|
})
|
||||||
|
public static class Application {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -12,6 +12,7 @@ import javax.annotation.Resource;
|
|||||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
|
||||||
@ActiveProfiles("unit-test") // 设置使用 application-unit-test 配置文件
|
@ActiveProfiles("unit-test") // 设置使用 application-unit-test 配置文件
|
||||||
@Sql(scripts = "/sql/clean.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD) // 每个单元测试结束后,清理 DB
|
@Sql(scripts = "/sql/clean.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD) // 每个单元测试结束后,清理 DB
|
||||||
|
@Deprecated
|
||||||
public class BaseSpringBootUnitTest {
|
public class BaseSpringBootUnitTest {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
|
@ -8,12 +8,10 @@ import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
|
|||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Lazy;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
@Lazy(false) // 禁用懒加载,因为需要保证 Redis Server 必须先启动
|
|
||||||
@EnableConfigurationProperties(RedisProperties.class)
|
@EnableConfigurationProperties(RedisProperties.class)
|
||||||
@AutoConfigureBefore({RedisAutoConfiguration.class, RedissonAutoConfiguration.class}) // 在 Redis 自动配置前,进行初始化
|
@AutoConfigureBefore({RedisAutoConfiguration.class, RedissonAutoConfiguration.class}) // 在 Redis 自动配置前,进行初始化
|
||||||
public class RedisTestConfiguration {
|
public class RedisTestConfiguration {
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,6 +1,6 @@
|
|||||||
package cn.iocoder.dashboard.modules.infra.service.config;
|
package cn.iocoder.dashboard.modules.infra.service.config;
|
||||||
|
|
||||||
import cn.iocoder.dashboard.BaseSpringBootUnitTest;
|
import cn.iocoder.dashboard.BaseDbUnitTest;
|
||||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||||
import cn.iocoder.dashboard.modules.infra.controller.config.vo.InfConfigCreateReqVO;
|
import cn.iocoder.dashboard.modules.infra.controller.config.vo.InfConfigCreateReqVO;
|
||||||
import cn.iocoder.dashboard.modules.infra.controller.config.vo.InfConfigExportReqVO;
|
import cn.iocoder.dashboard.modules.infra.controller.config.vo.InfConfigExportReqVO;
|
||||||
@ -15,6 +15,7 @@ import cn.iocoder.dashboard.util.collection.ArrayUtils;
|
|||||||
import cn.iocoder.dashboard.util.object.ObjectUtils;
|
import cn.iocoder.dashboard.util.object.ObjectUtils;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -35,7 +36,8 @@ import static org.mockito.Mockito.verify;
|
|||||||
*
|
*
|
||||||
* @author 芋道源码
|
* @author 芋道源码
|
||||||
*/
|
*/
|
||||||
public class InfConfigServiceTest extends BaseSpringBootUnitTest {
|
@Import(InfConfigServiceImpl.class)
|
||||||
|
public class InfConfigServiceTest extends BaseDbUnitTest {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private InfConfigServiceImpl configService;
|
private InfConfigServiceImpl configService;
|
||||||
|
@ -1,15 +1,19 @@
|
|||||||
package cn.iocoder.dashboard.modules.system.service.auth;
|
package cn.iocoder.dashboard.modules.system.service.auth;
|
||||||
|
|
||||||
import cn.iocoder.dashboard.BaseSpringBootUnitTest;
|
import cn.iocoder.dashboard.BaseDbUnitTest;
|
||||||
import cn.iocoder.dashboard.common.enums.CommonStatusEnum;
|
import cn.iocoder.dashboard.common.enums.CommonStatusEnum;
|
||||||
import cn.iocoder.dashboard.framework.security.core.LoginUser;
|
import cn.iocoder.dashboard.framework.security.core.LoginUser;
|
||||||
import cn.iocoder.dashboard.modules.system.dal.dataobject.user.SysUserDO;
|
import cn.iocoder.dashboard.modules.system.dal.dataobject.user.SysUserDO;
|
||||||
import cn.iocoder.dashboard.modules.system.service.auth.impl.SysAuthServiceImpl;
|
import cn.iocoder.dashboard.modules.system.service.auth.impl.SysAuthServiceImpl;
|
||||||
|
import cn.iocoder.dashboard.modules.system.service.common.SysCaptchaService;
|
||||||
|
import cn.iocoder.dashboard.modules.system.service.logger.SysLoginLogService;
|
||||||
import cn.iocoder.dashboard.modules.system.service.permission.SysPermissionService;
|
import cn.iocoder.dashboard.modules.system.service.permission.SysPermissionService;
|
||||||
import cn.iocoder.dashboard.modules.system.service.user.SysUserService;
|
import cn.iocoder.dashboard.modules.system.service.user.SysUserService;
|
||||||
import cn.iocoder.dashboard.util.AssertUtils;
|
import cn.iocoder.dashboard.util.AssertUtils;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
import org.springframework.security.authentication.AuthenticationManager;
|
||||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
@ -21,7 +25,13 @@ import static org.junit.jupiter.api.Assertions.*;
|
|||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
public class SysAuthServiceImplTest extends BaseSpringBootUnitTest {
|
/**
|
||||||
|
* {@link SysAuthServiceImpl} 的单元测试
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
@Import(SysAuthServiceImpl.class)
|
||||||
|
public class SysAuthServiceImplTest extends BaseDbUnitTest {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private SysAuthServiceImpl authService;
|
private SysAuthServiceImpl authService;
|
||||||
@ -30,6 +40,14 @@ public class SysAuthServiceImplTest extends BaseSpringBootUnitTest {
|
|||||||
private SysUserService userService;
|
private SysUserService userService;
|
||||||
@MockBean
|
@MockBean
|
||||||
private SysPermissionService permissionService;
|
private SysPermissionService permissionService;
|
||||||
|
@MockBean
|
||||||
|
private AuthenticationManager authenticationManager;
|
||||||
|
@MockBean
|
||||||
|
private SysCaptchaService captchaService;
|
||||||
|
@MockBean
|
||||||
|
private SysLoginLogService loginLogService;
|
||||||
|
@MockBean
|
||||||
|
private SysUserSessionService userSessionService;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLoadUserByUsername_success() {
|
public void testLoadUserByUsername_success() {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package cn.iocoder.dashboard.modules.system.service.dict;
|
package cn.iocoder.dashboard.modules.system.service.dict;
|
||||||
|
|
||||||
import cn.iocoder.dashboard.BaseSpringBootUnitTest;
|
import cn.iocoder.dashboard.BaseDbUnitTest;
|
||||||
import cn.iocoder.dashboard.common.enums.CommonStatusEnum;
|
import cn.iocoder.dashboard.common.enums.CommonStatusEnum;
|
||||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||||
import cn.iocoder.dashboard.modules.system.controller.dict.vo.data.SysDictDataCreateReqVO;
|
import cn.iocoder.dashboard.modules.system.controller.dict.vo.data.SysDictDataCreateReqVO;
|
||||||
@ -17,6 +17,7 @@ import cn.iocoder.dashboard.util.object.ObjectUtils;
|
|||||||
import com.google.common.collect.ImmutableTable;
|
import com.google.common.collect.ImmutableTable;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@ -37,7 +38,8 @@ import static org.mockito.Mockito.*;
|
|||||||
*
|
*
|
||||||
* @author 芋道源码
|
* @author 芋道源码
|
||||||
*/
|
*/
|
||||||
public class SysDictDataServiceTest extends BaseSpringBootUnitTest {
|
@Import(SysDictDataServiceImpl.class)
|
||||||
|
public class SysDictDataServiceTest extends BaseDbUnitTest {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private SysDictDataServiceImpl dictDataService;
|
private SysDictDataServiceImpl dictDataService;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package cn.iocoder.dashboard.modules.system.service.dict;
|
package cn.iocoder.dashboard.modules.system.service.dict;
|
||||||
|
|
||||||
import cn.iocoder.dashboard.BaseSpringBootUnitTest;
|
import cn.iocoder.dashboard.BaseDbUnitTest;
|
||||||
import cn.iocoder.dashboard.common.enums.CommonStatusEnum;
|
import cn.iocoder.dashboard.common.enums.CommonStatusEnum;
|
||||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||||
import cn.iocoder.dashboard.modules.system.controller.dict.vo.type.SysDictTypeCreateReqVO;
|
import cn.iocoder.dashboard.modules.system.controller.dict.vo.type.SysDictTypeCreateReqVO;
|
||||||
@ -14,6 +14,7 @@ import cn.iocoder.dashboard.util.collection.ArrayUtils;
|
|||||||
import cn.iocoder.dashboard.util.object.ObjectUtils;
|
import cn.iocoder.dashboard.util.object.ObjectUtils;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -24,7 +25,6 @@ import static cn.iocoder.dashboard.modules.system.enums.SysErrorCodeConstants.*;
|
|||||||
import static cn.iocoder.dashboard.util.AssertUtils.assertPojoEquals;
|
import static cn.iocoder.dashboard.util.AssertUtils.assertPojoEquals;
|
||||||
import static cn.iocoder.dashboard.util.AssertUtils.assertServiceException;
|
import static cn.iocoder.dashboard.util.AssertUtils.assertServiceException;
|
||||||
import static cn.iocoder.dashboard.util.RandomUtils.*;
|
import static cn.iocoder.dashboard.util.RandomUtils.*;
|
||||||
import static cn.iocoder.dashboard.util.RandomUtils.randomString;
|
|
||||||
import static cn.iocoder.dashboard.util.date.DateUtils.buildTime;
|
import static cn.iocoder.dashboard.util.date.DateUtils.buildTime;
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
@ -35,7 +35,8 @@ import static org.mockito.Mockito.when;
|
|||||||
*
|
*
|
||||||
* @author 芋道源码
|
* @author 芋道源码
|
||||||
*/
|
*/
|
||||||
public class SysDictTypeServiceTest extends BaseSpringBootUnitTest {
|
@Import(SysDictTypeServiceImpl.class)
|
||||||
|
public class SysDictTypeServiceTest extends BaseDbUnitTest {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private SysDictTypeServiceImpl dictTypeService;
|
private SysDictTypeServiceImpl dictTypeService;
|
||||||
|
@ -3,21 +3,6 @@ spring:
|
|||||||
lazy-initialization: true # 开启懒加载,加快速度
|
lazy-initialization: true # 开启懒加载,加快速度
|
||||||
banner-mode: off # 单元测试,禁用 Banner
|
banner-mode: off # 单元测试,禁用 Banner
|
||||||
|
|
||||||
# 去除的自动配置项
|
|
||||||
autoconfigure:
|
|
||||||
exclude:
|
|
||||||
- org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration # 单元测试,禁用 SpringSecurity
|
|
||||||
- org.springframework.boot.autoconfigure.security.reactive.ReactiveSecurityAutoConfiguration # 单元测试,禁用 SpringSecurity
|
|
||||||
- org.springframework.boot.autoconfigure.quartz.QuartzAutoConfiguration # 单元测试,禁用 Quartz
|
|
||||||
- com.baomidou.lock.spring.boot.autoconfigure.LockAutoConfiguration # 单元测试,禁用 Lock4j 分布式锁
|
|
||||||
- org.springframework.boot.autoconfigure.task.TaskSchedulingAutoConfiguration # 单元测试,禁用 Scheduler 定时任务
|
|
||||||
- org.springframework.boot.autoconfigure.data.redis.RedisRepositoriesAutoConfiguration # 项目没有使用 Spring Data,所以禁用配置类,加速启动
|
|
||||||
|
|
||||||
# Swagger 接口文档的自动配置(单元测试,禁用 Swagger)
|
|
||||||
springfox:
|
|
||||||
documentation:
|
|
||||||
auto-startup: false
|
|
||||||
|
|
||||||
--- #################### 数据库相关配置 ####################
|
--- #################### 数据库相关配置 ####################
|
||||||
|
|
||||||
spring:
|
spring:
|
||||||
@ -29,6 +14,9 @@ spring:
|
|||||||
username: sa
|
username: sa
|
||||||
password:
|
password:
|
||||||
schema: classpath:sql/create_tables.sql # MySQL 转 H2 的语句,使用 https://www.jooq.org/translate/ 工具
|
schema: classpath:sql/create_tables.sql # MySQL 转 H2 的语句,使用 https://www.jooq.org/translate/ 工具
|
||||||
|
druid:
|
||||||
|
async-init: true # 单元测试,异步初始化 Druid 连接池,提升启动速度
|
||||||
|
initial-size: 1 # 单元测试,配置为 1,提升启动速度
|
||||||
|
|
||||||
# Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
|
# Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
|
||||||
redis:
|
redis:
|
||||||
@ -36,17 +24,13 @@ spring:
|
|||||||
port: 16379 # 端口(单元测试,使用 16379 端口)
|
port: 16379 # 端口(单元测试,使用 16379 端口)
|
||||||
database: 0 # 数据库索引
|
database: 0 # 数据库索引
|
||||||
|
|
||||||
|
mybatis:
|
||||||
|
lazy-initialization: true # 单元测试,设置 MyBatis Mapper 延迟加载,加速每个单元测试
|
||||||
|
|
||||||
--- #################### 定时任务相关配置 ####################
|
--- #################### 定时任务相关配置 ####################
|
||||||
|
|
||||||
# Quartz 配置项,对应 QuartzProperties 配置类(单元测试,禁用 Quartz)
|
|
||||||
|
|
||||||
--- #################### 配置中心相关配置 ####################
|
--- #################### 配置中心相关配置 ####################
|
||||||
|
|
||||||
# Apollo 配置中心
|
|
||||||
apollo:
|
|
||||||
bootstrap:
|
|
||||||
enabled: false # 单元测试,禁用配置中心
|
|
||||||
|
|
||||||
--- #################### 服务保障相关配置 ####################
|
--- #################### 服务保障相关配置 ####################
|
||||||
|
|
||||||
# Lock4j 配置项(单元测试,禁用 Lock4j)
|
# Lock4j 配置项(单元测试,禁用 Lock4j)
|
||||||
@ -63,23 +47,6 @@ resilience4j:
|
|||||||
|
|
||||||
--- #################### 监控相关配置 ####################
|
--- #################### 监控相关配置 ####################
|
||||||
|
|
||||||
# Actuator 监控端点的配置项
|
|
||||||
management:
|
|
||||||
endpoints:
|
|
||||||
enabled-by-default: false
|
|
||||||
|
|
||||||
# Spring Boot Admin 配置项
|
|
||||||
spring:
|
|
||||||
boot:
|
|
||||||
admin:
|
|
||||||
# Spring Boot Admin Client 客户端的相关配置
|
|
||||||
client:
|
|
||||||
enabled: false
|
|
||||||
# Spring Boot Admin Server 服务端的相关配置
|
|
||||||
context-path: /admin # 配置 Spring
|
|
||||||
|
|
||||||
# 日志文件配置(不需要配置)
|
|
||||||
|
|
||||||
--- #################### 芋道相关配置 ####################
|
--- #################### 芋道相关配置 ####################
|
||||||
|
|
||||||
# 芋道配置项,设置当前项目所有自定义的配置
|
# 芋道配置项,设置当前项目所有自定义的配置
|
||||||
|
@ -9,9 +9,9 @@ CREATE TABLE IF NOT EXISTS "inf_config" (
|
|||||||
"value" varchar(500) NOT NULL DEFAULT '',
|
"value" varchar(500) NOT NULL DEFAULT '',
|
||||||
"sensitive" bit NOT NULL,
|
"sensitive" bit NOT NULL,
|
||||||
"remark" varchar(500) DEFAULT NULL,
|
"remark" varchar(500) DEFAULT NULL,
|
||||||
"create_by" varchar(64) DEFAULT '',
|
"creator" varchar(64) DEFAULT '',
|
||||||
"create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
"create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
"update_by" varchar(64) DEFAULT '',
|
"updater" varchar(64) DEFAULT '',
|
||||||
"update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
"update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
"deleted" bit NOT NULL DEFAULT FALSE,
|
"deleted" bit NOT NULL DEFAULT FALSE,
|
||||||
PRIMARY KEY ("id")
|
PRIMARY KEY ("id")
|
||||||
@ -28,9 +28,9 @@ CREATE TABLE IF NOT EXISTS "sys_dept" (
|
|||||||
"phone" varchar(11) DEFAULT NULL,
|
"phone" varchar(11) DEFAULT NULL,
|
||||||
"email" varchar(50) DEFAULT NULL,
|
"email" varchar(50) DEFAULT NULL,
|
||||||
"status" tinyint NOT NULL,
|
"status" tinyint NOT NULL,
|
||||||
"create_by" varchar(64) DEFAULT '',
|
"creator" varchar(64) DEFAULT '',
|
||||||
"create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
"create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
"update_by" varchar(64) DEFAULT '',
|
"updater" varchar(64) DEFAULT '',
|
||||||
"update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
"update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
"deleted" bit NOT NULL DEFAULT FALSE,
|
"deleted" bit NOT NULL DEFAULT FALSE,
|
||||||
PRIMARY KEY ("id")
|
PRIMARY KEY ("id")
|
||||||
@ -44,9 +44,9 @@ CREATE TABLE IF NOT EXISTS "sys_dict_data" (
|
|||||||
"dict_type" varchar(100) NOT NULL DEFAULT '',
|
"dict_type" varchar(100) NOT NULL DEFAULT '',
|
||||||
"status" tinyint NOT NULL DEFAULT '0',
|
"status" tinyint NOT NULL DEFAULT '0',
|
||||||
"remark" varchar(500) DEFAULT NULL,
|
"remark" varchar(500) DEFAULT NULL,
|
||||||
"create_by" varchar(64) DEFAULT '',
|
"creator" varchar(64) DEFAULT '',
|
||||||
"create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
"create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
"update_by" varchar(64) DEFAULT '',
|
"updater" varchar(64) DEFAULT '',
|
||||||
"update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
"update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
"deleted" bit NOT NULL DEFAULT FALSE,
|
"deleted" bit NOT NULL DEFAULT FALSE,
|
||||||
PRIMARY KEY ("id")
|
PRIMARY KEY ("id")
|
||||||
@ -62,9 +62,9 @@ CREATE TABLE IF NOT EXISTS "sys_role" (
|
|||||||
"status" tinyint NOT NULL,
|
"status" tinyint NOT NULL,
|
||||||
"type" tinyint NOT NULL,
|
"type" tinyint NOT NULL,
|
||||||
"remark" varchar(500) DEFAULT NULL,
|
"remark" varchar(500) DEFAULT NULL,
|
||||||
"create_by" varchar(64) DEFAULT '',
|
"creator" varchar(64) DEFAULT '',
|
||||||
"create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
"create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
"update_by" varchar(64) DEFAULT '',
|
"updater" varchar(64) DEFAULT '',
|
||||||
"update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
"update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
"deleted" bit NOT NULL DEFAULT FALSE,
|
"deleted" bit NOT NULL DEFAULT FALSE,
|
||||||
PRIMARY KEY ("id")
|
PRIMARY KEY ("id")
|
||||||
@ -74,9 +74,9 @@ CREATE TABLE IF NOT EXISTS "sys_role_menu" (
|
|||||||
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
|
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
|
||||||
"role_id" bigint NOT NULL,
|
"role_id" bigint NOT NULL,
|
||||||
"menu_id" bigint NOT NULL,
|
"menu_id" bigint NOT NULL,
|
||||||
"create_by" varchar(64) DEFAULT '',
|
"creator" varchar(64) DEFAULT '',
|
||||||
"create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
"create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
"update_by" varchar(64) DEFAULT '',
|
"updater" varchar(64) DEFAULT '',
|
||||||
"update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
"update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
"deleted" bit NOT NULL DEFAULT FALSE,
|
"deleted" bit NOT NULL DEFAULT FALSE,
|
||||||
PRIMARY KEY ("id")
|
PRIMARY KEY ("id")
|
||||||
@ -93,9 +93,9 @@ CREATE TABLE IF NOT EXISTS "sys_menu" (
|
|||||||
"icon" varchar(100) DEFAULT '#',
|
"icon" varchar(100) DEFAULT '#',
|
||||||
"component" varchar(255) DEFAULT NULL,
|
"component" varchar(255) DEFAULT NULL,
|
||||||
"status" tinyint NOT NULL DEFAULT '0',
|
"status" tinyint NOT NULL DEFAULT '0',
|
||||||
"create_by" varchar(64) DEFAULT '',
|
"creator" varchar(64) DEFAULT '',
|
||||||
"create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
"create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
"update_by" varchar(64) DEFAULT '',
|
"updater" varchar(64) DEFAULT '',
|
||||||
"update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
"update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
"deleted" bit NOT NULL DEFAULT FALSE,
|
"deleted" bit NOT NULL DEFAULT FALSE,
|
||||||
PRIMARY KEY ("id")
|
PRIMARY KEY ("id")
|
||||||
@ -107,9 +107,9 @@ CREATE TABLE "sys_dict_type" (
|
|||||||
"type" varchar(100) NOT NULL DEFAULT '',
|
"type" varchar(100) NOT NULL DEFAULT '',
|
||||||
"status" tinyint NOT NULL DEFAULT '0',
|
"status" tinyint NOT NULL DEFAULT '0',
|
||||||
"remark" varchar(500) DEFAULT NULL,
|
"remark" varchar(500) DEFAULT NULL,
|
||||||
"create_by" varchar(64) DEFAULT '',
|
"creator" varchar(64) DEFAULT '',
|
||||||
"create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
"create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
"update_by" varchar(64) DEFAULT '',
|
"updater" varchar(64) DEFAULT '',
|
||||||
"update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
"update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
"deleted" bit NOT NULL DEFAULT FALSE,
|
"deleted" bit NOT NULL DEFAULT FALSE,
|
||||||
PRIMARY KEY ("id")
|
PRIMARY KEY ("id")
|
||||||
|
Loading…
Reference in New Issue
Block a user