mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 15:21:53 +08:00
【功能修复】单测执行报错的问题
This commit is contained in:
parent
76385af634
commit
9a885639ae
@ -18,10 +18,17 @@ import java.util.stream.Collectors;
|
||||
@AllArgsConstructor
|
||||
public enum DbTypeEnum {
|
||||
|
||||
/**
|
||||
* H2
|
||||
*
|
||||
* 注意:H2 不支持 find_in_set 函数
|
||||
*/
|
||||
H2(DbType.H2, "H2", ""),
|
||||
|
||||
/**
|
||||
* MySQL
|
||||
*/
|
||||
MY_SQL( DbType.MYSQL, "MySQL", "FIND_IN_SET('#{value}', #{column}) <> 0"),
|
||||
MY_SQL(DbType.MYSQL, "MySQL", "FIND_IN_SET('#{value}', #{column}) <> 0"),
|
||||
|
||||
/**
|
||||
* Oracle
|
||||
|
@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.common.util.spring.SpringUtils;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.enums.DbTypeEnum;
|
||||
import com.baomidou.dynamic.datasource.DynamicRoutingDataSource;
|
||||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
@ -50,8 +51,13 @@ public class JdbcUtils {
|
||||
* @return DB 类型
|
||||
*/
|
||||
public static DbType getDbType() {
|
||||
DynamicRoutingDataSource dynamicRoutingDataSource = SpringUtils.getBean(DynamicRoutingDataSource.class);
|
||||
DataSource dataSource = dynamicRoutingDataSource.determineDataSource();
|
||||
DataSource dataSource;
|
||||
try {
|
||||
DynamicRoutingDataSource dynamicRoutingDataSource = SpringUtils.getBean(DynamicRoutingDataSource.class);
|
||||
dataSource = dynamicRoutingDataSource.determineDataSource();
|
||||
} catch (NoSuchBeanDefinitionException e) {
|
||||
dataSource = SpringUtils.getBean(DataSource.class);
|
||||
}
|
||||
try (Connection conn = dataSource.getConnection()) {
|
||||
return DbTypeEnum.find(conn.getMetaData().getDatabaseProductName());
|
||||
} catch (SQLException e) {
|
||||
|
@ -96,7 +96,6 @@ public class MyBatisUtils {
|
||||
* @return sql
|
||||
*/
|
||||
public static String findInSet(String column, Object value) {
|
||||
// 这里不用SqlConstants.DB_TYPE,因为它是使用 primary 数据源的 url 推断出来的类型
|
||||
DbType dbType = JdbcUtils.getDbType();
|
||||
return DbTypeEnum.getFindInSetTemplate(dbType)
|
||||
.replace("#{column}", column)
|
||||
|
@ -1,5 +1,6 @@
|
||||
package cn.iocoder.yudao.framework.test.core.ut;
|
||||
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import cn.iocoder.yudao.framework.datasource.config.YudaoDataSourceAutoConfiguration;
|
||||
import cn.iocoder.yudao.framework.mybatis.config.YudaoMybatisAutoConfiguration;
|
||||
import cn.iocoder.yudao.framework.redis.config.YudaoRedisAutoConfiguration;
|
||||
@ -44,6 +45,9 @@ public class BaseDbAndRedisUnitTest {
|
||||
YudaoRedisAutoConfiguration.class, // 自己的 Redis 配置类
|
||||
RedisAutoConfiguration.class, // Spring Redis 自动配置类
|
||||
RedissonAutoConfiguration.class, // Redisson 自动配置类
|
||||
|
||||
// 其它配置类
|
||||
SpringUtil.class
|
||||
})
|
||||
public static class Application {
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package cn.iocoder.yudao.framework.test.core.ut;
|
||||
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import cn.iocoder.yudao.framework.datasource.config.YudaoDataSourceAutoConfiguration;
|
||||
import cn.iocoder.yudao.framework.mybatis.config.YudaoMybatisAutoConfiguration;
|
||||
import cn.iocoder.yudao.framework.test.config.SqlInitializationTestConfiguration;
|
||||
@ -36,6 +37,9 @@ public class BaseDbUnitTest {
|
||||
YudaoMybatisAutoConfiguration.class, // 自己的 MyBatis 配置类
|
||||
MybatisPlusAutoConfiguration.class, // MyBatis 的自动配置类
|
||||
MybatisPlusJoinAutoConfiguration.class, // MyBatis 的Join配置类
|
||||
|
||||
// 其它配置类
|
||||
SpringUtil.class
|
||||
})
|
||||
public static class Application {
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package cn.iocoder.yudao.framework.test.core.ut;
|
||||
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import cn.iocoder.yudao.framework.redis.config.YudaoRedisAutoConfiguration;
|
||||
import cn.iocoder.yudao.framework.test.config.RedisTestConfiguration;
|
||||
import org.redisson.spring.starter.RedissonAutoConfiguration;
|
||||
@ -25,6 +26,9 @@ public class BaseRedisUnitTest {
|
||||
RedisAutoConfiguration.class, // Spring Redis 自动配置类
|
||||
YudaoRedisAutoConfiguration.class, // 自己的 Redis 配置类
|
||||
RedissonAutoConfiguration.class, // Redisson 自动配置类
|
||||
|
||||
// 其它配置类
|
||||
SpringUtil.class
|
||||
})
|
||||
public static class Application {
|
||||
}
|
||||
|
@ -3,18 +3,16 @@ package cn.iocoder.yudao.module.system.service.notify;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.enums.SqlConstants;
|
||||
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageMyPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessagePageReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO;
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.notify.NotifyMessageMapper;
|
||||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@ -158,7 +156,6 @@ public class NotifyMessageServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Test
|
||||
public void testGetUnreadNotifyMessageList() {
|
||||
SqlConstants.init(DbType.MYSQL);
|
||||
// mock 数据
|
||||
NotifyMessageDO dbNotifyMessage = randomPojo(NotifyMessageDO.class, o -> { // 等会查询到
|
||||
o.setUserId(1L);
|
||||
@ -187,7 +184,6 @@ public class NotifyMessageServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Test
|
||||
public void testGetUnreadNotifyMessageCount() {
|
||||
SqlConstants.init(DbType.MYSQL);
|
||||
// mock 数据
|
||||
NotifyMessageDO dbNotifyMessage = randomPojo(NotifyMessageDO.class, o -> { // 等会查询到
|
||||
o.setUserId(1L);
|
||||
|
@ -1,7 +1,6 @@
|
||||
package cn.iocoder.yudao.module.system.service.sms;
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.enums.SqlConstants;
|
||||
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
||||
import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeSendReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeUseReqDTO;
|
||||
@ -10,13 +9,12 @@ import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsCodeDO;
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.sms.SmsCodeMapper;
|
||||
import cn.iocoder.yudao.module.system.enums.sms.SmsSceneEnum;
|
||||
import cn.iocoder.yudao.module.system.framework.sms.config.SmsCodeProperties;
|
||||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@ -61,8 +59,6 @@ public class SmsCodeServiceImplTest extends BaseDbUnitTest {
|
||||
o.setMobile("15601691300");
|
||||
o.setScene(SmsSceneEnum.MEMBER_LOGIN.getScene());
|
||||
});
|
||||
// mock 方法
|
||||
SqlConstants.init(DbType.MYSQL);
|
||||
|
||||
// 调用
|
||||
smsCodeService.sendSmsCode(reqDTO);
|
||||
@ -88,8 +84,6 @@ public class SmsCodeServiceImplTest extends BaseDbUnitTest {
|
||||
o.setMobile("15601691300");
|
||||
o.setScene(SmsSceneEnum.MEMBER_LOGIN.getScene());
|
||||
});
|
||||
// mock 方法
|
||||
SqlConstants.init(DbType.MYSQL);
|
||||
|
||||
// 调用,并断言异常
|
||||
assertServiceException(() -> smsCodeService.sendSmsCode(reqDTO),
|
||||
@ -107,8 +101,6 @@ public class SmsCodeServiceImplTest extends BaseDbUnitTest {
|
||||
o.setMobile("15601691300");
|
||||
o.setScene(SmsSceneEnum.MEMBER_LOGIN.getScene());
|
||||
});
|
||||
// mock 方法
|
||||
SqlConstants.init(DbType.MYSQL);
|
||||
when(smsCodeProperties.getSendFrequency()).thenReturn(Duration.ofMillis(0));
|
||||
|
||||
// 调用,并断言异常
|
||||
@ -123,8 +115,6 @@ public class SmsCodeServiceImplTest extends BaseDbUnitTest {
|
||||
o.setMobile("15601691300");
|
||||
o.setScene(randomEle(SmsSceneEnum.values()).getScene());
|
||||
});
|
||||
// mock 数据
|
||||
SqlConstants.init(DbType.MYSQL);
|
||||
smsCodeMapper.insert(randomPojo(SmsCodeDO.class, o -> {
|
||||
o.setMobile(reqDTO.getMobile()).setScene(reqDTO.getScene())
|
||||
.setCode(reqDTO.getCode()).setUsed(false);
|
||||
@ -146,8 +136,6 @@ public class SmsCodeServiceImplTest extends BaseDbUnitTest {
|
||||
o.setMobile("15601691300");
|
||||
o.setScene(randomEle(SmsSceneEnum.values()).getScene());
|
||||
});
|
||||
// mock 数据
|
||||
SqlConstants.init(DbType.MYSQL);
|
||||
smsCodeMapper.insert(randomPojo(SmsCodeDO.class, o -> o.setMobile(reqDTO.getMobile())
|
||||
.setScene(reqDTO.getScene()).setCode(reqDTO.getCode()).setUsed(false)));
|
||||
|
||||
@ -162,8 +150,6 @@ public class SmsCodeServiceImplTest extends BaseDbUnitTest {
|
||||
o.setMobile("15601691300");
|
||||
o.setScene(randomEle(SmsSceneEnum.values()).getScene());
|
||||
});
|
||||
// mock 数据
|
||||
SqlConstants.init(DbType.MYSQL);
|
||||
|
||||
// 调用,并断言异常
|
||||
assertServiceException(() -> smsCodeService.validateSmsCode(reqDTO),
|
||||
@ -177,8 +163,6 @@ public class SmsCodeServiceImplTest extends BaseDbUnitTest {
|
||||
o.setMobile("15601691300");
|
||||
o.setScene(randomEle(SmsSceneEnum.values()).getScene());
|
||||
});
|
||||
// mock 数据
|
||||
SqlConstants.init(DbType.MYSQL);
|
||||
smsCodeMapper.insert(randomPojo(SmsCodeDO.class, o -> o.setMobile(reqDTO.getMobile())
|
||||
.setScene(reqDTO.getScene()).setCode(reqDTO.getCode()).setUsed(false)
|
||||
.setCreateTime(LocalDateTime.now().minusMinutes(6))));
|
||||
@ -195,8 +179,6 @@ public class SmsCodeServiceImplTest extends BaseDbUnitTest {
|
||||
o.setMobile("15601691300");
|
||||
o.setScene(randomEle(SmsSceneEnum.values()).getScene());
|
||||
});
|
||||
// mock 数据
|
||||
SqlConstants.init(DbType.MYSQL);
|
||||
smsCodeMapper.insert(randomPojo(SmsCodeDO.class, o -> o.setMobile(reqDTO.getMobile())
|
||||
.setScene(reqDTO.getScene()).setCode(reqDTO.getCode()).setUsed(true)
|
||||
.setCreateTime(LocalDateTime.now())));
|
||||
|
Loading…
Reference in New Issue
Block a user