完善 TenantPackageServiceImpl 单元测试
This commit is contained in:
parent
ac25dbe286
commit
9c216e5b7d
@ -140,7 +140,7 @@ public class DeptServiceImpl implements DeptService {
|
|||||||
}
|
}
|
||||||
List<DeptDO> result = new ArrayList<>();
|
List<DeptDO> result = new ArrayList<>();
|
||||||
// 递归,简单粗暴
|
// 递归,简单粗暴
|
||||||
this.getDeptsByParentIdFromCache(result, parentId,
|
getDeptsByParentIdFromCache(result, parentId,
|
||||||
recursive ? Integer.MAX_VALUE : 1, // 如果递归获取,则无限;否则,只递归 1 次
|
recursive ? Integer.MAX_VALUE : 1, // 如果递归获取,则无限;否则,只递归 1 次
|
||||||
parentDeptCache);
|
parentDeptCache);
|
||||||
return result;
|
return result;
|
||||||
@ -205,7 +205,7 @@ public class DeptServiceImpl implements DeptService {
|
|||||||
throw exception(DEPT_NOT_ENABLE);
|
throw exception(DEPT_NOT_ENABLE);
|
||||||
}
|
}
|
||||||
// 父部门不能是原来的子部门
|
// 父部门不能是原来的子部门
|
||||||
List<DeptDO> children = this.getDeptListByParentIdFromCache(id, true);
|
List<DeptDO> children = getDeptListByParentIdFromCache(id, true);
|
||||||
if (children.stream().anyMatch(dept1 -> dept1.getId().equals(parentId))) {
|
if (children.stream().anyMatch(dept1 -> dept1.getId().equals(parentId))) {
|
||||||
throw exception(DEPT_PARENT_IS_CHILD);
|
throw exception(DEPT_PARENT_IS_CHILD);
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ public class ErrorCodeServiceImpl implements ErrorCodeService {
|
|||||||
@Override
|
@Override
|
||||||
public void updateErrorCode(ErrorCodeUpdateReqVO updateReqVO) {
|
public void updateErrorCode(ErrorCodeUpdateReqVO updateReqVO) {
|
||||||
// 校验存在
|
// 校验存在
|
||||||
this.validateErrorCodeExists(updateReqVO.getId());
|
validateErrorCodeExists(updateReqVO.getId());
|
||||||
// 校验 code 重复
|
// 校验 code 重复
|
||||||
validateCodeDuplicate(updateReqVO.getCode(), updateReqVO.getId());
|
validateCodeDuplicate(updateReqVO.getCode(), updateReqVO.getId());
|
||||||
|
|
||||||
@ -71,7 +71,7 @@ public class ErrorCodeServiceImpl implements ErrorCodeService {
|
|||||||
@Override
|
@Override
|
||||||
public void deleteErrorCode(Long id) {
|
public void deleteErrorCode(Long id) {
|
||||||
// 校验存在
|
// 校验存在
|
||||||
this.validateErrorCodeExists(id);
|
validateErrorCodeExists(id);
|
||||||
// 删除
|
// 删除
|
||||||
errorCodeMapper.deleteById(id);
|
errorCodeMapper.deleteById(id);
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ public class SmsChannelServiceImpl implements SmsChannelService {
|
|||||||
@Override
|
@Override
|
||||||
public void updateSmsChannel(SmsChannelUpdateReqVO updateReqVO) {
|
public void updateSmsChannel(SmsChannelUpdateReqVO updateReqVO) {
|
||||||
// 校验存在
|
// 校验存在
|
||||||
this.validateSmsChannelExists(updateReqVO.getId());
|
validateSmsChannelExists(updateReqVO.getId());
|
||||||
// 更新
|
// 更新
|
||||||
SmsChannelDO updateObj = SmsChannelConvert.INSTANCE.convert(updateReqVO);
|
SmsChannelDO updateObj = SmsChannelConvert.INSTANCE.convert(updateReqVO);
|
||||||
smsChannelMapper.updateById(updateObj);
|
smsChannelMapper.updateById(updateObj);
|
||||||
@ -79,7 +79,7 @@ public class SmsChannelServiceImpl implements SmsChannelService {
|
|||||||
@Override
|
@Override
|
||||||
public void deleteSmsChannel(Long id) {
|
public void deleteSmsChannel(Long id) {
|
||||||
// 校验存在
|
// 校验存在
|
||||||
this.validateSmsChannelExists(id);
|
validateSmsChannelExists(id);
|
||||||
// 校验是否有在使用该账号的模版
|
// 校验是否有在使用该账号的模版
|
||||||
if (smsTemplateService.countByChannelId(id) > 0) {
|
if (smsTemplateService.countByChannelId(id) > 0) {
|
||||||
throw exception(SMS_CHANNEL_HAS_CHILDREN);
|
throw exception(SMS_CHANNEL_HAS_CHILDREN);
|
||||||
|
@ -90,7 +90,7 @@ public class SmsSendServiceImpl implements SmsSendService {
|
|||||||
// 校验手机号码是否存在
|
// 校验手机号码是否存在
|
||||||
mobile = validateMobile(mobile);
|
mobile = validateMobile(mobile);
|
||||||
// 构建有序的模板参数。为什么放在这个位置,是提前保证模板参数的正确性,而不是到了插入发送日志
|
// 构建有序的模板参数。为什么放在这个位置,是提前保证模板参数的正确性,而不是到了插入发送日志
|
||||||
List<KeyValue<String, Object>> newTemplateParams = this.buildTemplateParams(template, templateParams);
|
List<KeyValue<String, Object>> newTemplateParams = buildTemplateParams(template, templateParams);
|
||||||
|
|
||||||
// 创建发送日志。如果模板被禁用,则不发送短信,只记录日志
|
// 创建发送日志。如果模板被禁用,则不发送短信,只记录日志
|
||||||
Boolean isSend = CommonStatusEnum.ENABLE.getStatus().equals(template.getStatus())
|
Boolean isSend = CommonStatusEnum.ENABLE.getStatus().equals(template.getStatus())
|
||||||
|
@ -125,7 +125,7 @@ public class SmsTemplateServiceImpl implements SmsTemplateService {
|
|||||||
@Override
|
@Override
|
||||||
public void updateSmsTemplate(SmsTemplateUpdateReqVO updateReqVO) {
|
public void updateSmsTemplate(SmsTemplateUpdateReqVO updateReqVO) {
|
||||||
// 校验存在
|
// 校验存在
|
||||||
this.validateSmsTemplateExists(updateReqVO.getId());
|
validateSmsTemplateExists(updateReqVO.getId());
|
||||||
// 校验短信渠道
|
// 校验短信渠道
|
||||||
SmsChannelDO channelDO = checkSmsChannel(updateReqVO.getChannelId());
|
SmsChannelDO channelDO = checkSmsChannel(updateReqVO.getChannelId());
|
||||||
// 校验短信编码是否重复
|
// 校验短信编码是否重复
|
||||||
@ -145,7 +145,7 @@ public class SmsTemplateServiceImpl implements SmsTemplateService {
|
|||||||
@Override
|
@Override
|
||||||
public void deleteSmsTemplate(Long id) {
|
public void deleteSmsTemplate(Long id) {
|
||||||
// 校验存在
|
// 校验存在
|
||||||
this.validateSmsTemplateExists(id);
|
validateSmsTemplateExists(id);
|
||||||
// 更新
|
// 更新
|
||||||
smsTemplateMapper.deleteById(id);
|
smsTemplateMapper.deleteById(id);
|
||||||
// 发送刷新消息
|
// 发送刷新消息
|
||||||
|
@ -64,9 +64,9 @@ public class TenantPackageServiceImpl implements TenantPackageService {
|
|||||||
@Override
|
@Override
|
||||||
public void deleteTenantPackage(Long id) {
|
public void deleteTenantPackage(Long id) {
|
||||||
// 校验存在
|
// 校验存在
|
||||||
this.validateTenantPackageExists(id);
|
validateTenantPackageExists(id);
|
||||||
// 校验正在使用
|
// 校验正在使用
|
||||||
this.validateTenantUsed(id);
|
validateTenantUsed(id);
|
||||||
// 删除
|
// 删除
|
||||||
tenantPackageMapper.deleteById(id);
|
tenantPackageMapper.deleteById(id);
|
||||||
}
|
}
|
||||||
|
@ -25,12 +25,12 @@ import org.springframework.boot.test.mock.mockito.MockBean;
|
|||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import static cn.hutool.core.util.RandomUtil.randomEle;
|
import static cn.hutool.core.util.RandomUtil.randomEle;
|
||||||
|
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime;
|
||||||
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime;
|
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime;
|
||||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
|
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
|
||||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
|
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
|
||||||
@ -224,7 +224,7 @@ public class SmsTemplateServiceImplTest extends BaseDbUnitTest {
|
|||||||
reqVO.setContent("芋道");
|
reqVO.setContent("芋道");
|
||||||
reqVO.setApiTemplateId("yu");
|
reqVO.setApiTemplateId("yu");
|
||||||
reqVO.setChannelId(1L);
|
reqVO.setChannelId(1L);
|
||||||
reqVO.setCreateTime((new LocalDateTime[]{buildTime(2021, 11, 1),buildTime(2021, 12, 1)}));
|
reqVO.setCreateTime(buildBetweenTime(2021, 11, 1, 2021, 12, 1));
|
||||||
|
|
||||||
// 调用
|
// 调用
|
||||||
PageResult<SmsTemplateDO> pageResult = smsTemplateService.getSmsTemplatePage(reqVO);
|
PageResult<SmsTemplateDO> pageResult = smsTemplateService.getSmsTemplatePage(reqVO);
|
||||||
@ -269,7 +269,7 @@ public class SmsTemplateServiceImplTest extends BaseDbUnitTest {
|
|||||||
reqVO.setContent("芋道");
|
reqVO.setContent("芋道");
|
||||||
reqVO.setApiTemplateId("yu");
|
reqVO.setApiTemplateId("yu");
|
||||||
reqVO.setChannelId(1L);
|
reqVO.setChannelId(1L);
|
||||||
reqVO.setCreateTime((new LocalDateTime[]{buildTime(2021, 11, 1),buildTime(2021, 12, 1)}));
|
reqVO.setCreateTime(buildBetweenTime(2021, 11, 1, 2021, 12, 1));
|
||||||
|
|
||||||
// 调用
|
// 调用
|
||||||
List<SmsTemplateDO> list = smsTemplateService.getSmsTemplateList(reqVO);
|
List<SmsTemplateDO> list = smsTemplateService.getSmsTemplateList(reqVO);
|
||||||
|
@ -35,7 +35,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
|||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
@Import(SocialUserServiceImpl.class)
|
@Import(SocialUserServiceImpl.class)
|
||||||
public class SocialUserServiceTest extends BaseDbAndRedisUnitTest {
|
public class SocialUserServiceImplTest extends BaseDbAndRedisUnitTest {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private SocialUserServiceImpl socialUserService;
|
private SocialUserServiceImpl socialUserService;
|
@ -2,22 +2,22 @@ package cn.iocoder.yudao.module.system.service.tenant;
|
|||||||
|
|
||||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
|
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
||||||
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackageCreateReqVO;
|
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackageCreateReqVO;
|
||||||
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackagePageReqVO;
|
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackagePageReqVO;
|
||||||
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackageUpdateReqVO;
|
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackageUpdateReqVO;
|
||||||
import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantDO;
|
import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantDO;
|
||||||
import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantPackageDO;
|
import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantPackageDO;
|
||||||
import cn.iocoder.yudao.module.system.dal.mysql.tenant.TenantPackageMapper;
|
import cn.iocoder.yudao.module.system.dal.mysql.tenant.TenantPackageMapper;
|
||||||
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
|
||||||
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.context.annotation.Import;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime;
|
||||||
|
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime;
|
||||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.buildLocalDateTime;
|
|
||||||
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
|
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
|
||||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
|
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
|
||||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
|
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
|
||||||
@ -142,7 +142,7 @@ public class TenantPackageServiceImplTest extends BaseDbUnitTest {
|
|||||||
o.setName("芋道源码");
|
o.setName("芋道源码");
|
||||||
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||||
o.setRemark("源码解析");
|
o.setRemark("源码解析");
|
||||||
o.setCreateTime(buildLocalDateTime(2022, 10, 10));
|
o.setCreateTime(buildTime(2022, 10, 10));
|
||||||
});
|
});
|
||||||
tenantPackageMapper.insert(dbTenantPackage);
|
tenantPackageMapper.insert(dbTenantPackage);
|
||||||
// 测试 name 不匹配
|
// 测试 name 不匹配
|
||||||
@ -152,13 +152,13 @@ public class TenantPackageServiceImplTest extends BaseDbUnitTest {
|
|||||||
// 测试 remark 不匹配
|
// 测试 remark 不匹配
|
||||||
tenantPackageMapper.insert(cloneIgnoreId(dbTenantPackage, o -> o.setRemark("解析")));
|
tenantPackageMapper.insert(cloneIgnoreId(dbTenantPackage, o -> o.setRemark("解析")));
|
||||||
// 测试 createTime 不匹配
|
// 测试 createTime 不匹配
|
||||||
tenantPackageMapper.insert(cloneIgnoreId(dbTenantPackage, o -> o.setCreateTime(buildLocalDateTime(2022, 11, 11))));
|
tenantPackageMapper.insert(cloneIgnoreId(dbTenantPackage, o -> o.setCreateTime(buildTime(2022, 11, 11))));
|
||||||
// 准备参数
|
// 准备参数
|
||||||
TenantPackagePageReqVO reqVO = new TenantPackagePageReqVO();
|
TenantPackagePageReqVO reqVO = new TenantPackagePageReqVO();
|
||||||
reqVO.setName("芋道");
|
reqVO.setName("芋道");
|
||||||
reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||||
reqVO.setRemark("源码");
|
reqVO.setRemark("源码");
|
||||||
reqVO.setCreateTime((new LocalDateTime[]{buildLocalDateTime(2022, 10, 9),buildLocalDateTime(2022, 10, 11)}));
|
reqVO.setCreateTime(buildBetweenTime(2022, 10, 9, 2022, 10, 11));
|
||||||
|
|
||||||
// 调用
|
// 调用
|
||||||
PageResult<TenantPackageDO> pageResult = tenantPackageService.getTenantPackagePage(reqVO);
|
PageResult<TenantPackageDO> pageResult = tenantPackageService.getTenantPackagePage(reqVO);
|
||||||
@ -201,4 +201,34 @@ public class TenantPackageServiceImplTest extends BaseDbUnitTest {
|
|||||||
assertServiceException(() -> tenantPackageService.validTenantPackage(dbTenantPackage.getId()),
|
assertServiceException(() -> tenantPackageService.validTenantPackage(dbTenantPackage.getId()),
|
||||||
TENANT_PACKAGE_DISABLE, dbTenantPackage.getName());
|
TENANT_PACKAGE_DISABLE, dbTenantPackage.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetTenantPackage() {
|
||||||
|
// mock 数据
|
||||||
|
TenantPackageDO dbTenantPackage = randomPojo(TenantPackageDO.class);
|
||||||
|
tenantPackageMapper.insert(dbTenantPackage);// @Sql: 先插入出一条存在的数据
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
TenantPackageDO result = tenantPackageService.getTenantPackage(dbTenantPackage.getId());
|
||||||
|
// 断言
|
||||||
|
assertPojoEquals(result, dbTenantPackage);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetTenantPackageListByStatus() {
|
||||||
|
// mock 数据
|
||||||
|
TenantPackageDO dbTenantPackage = randomPojo(TenantPackageDO.class,
|
||||||
|
o -> o.setStatus(CommonStatusEnum.ENABLE.getStatus()));
|
||||||
|
tenantPackageMapper.insert(dbTenantPackage);
|
||||||
|
// 测试 status 不匹配
|
||||||
|
tenantPackageMapper.insert(cloneIgnoreId(dbTenantPackage,
|
||||||
|
o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus())));
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
List<TenantPackageDO> list = tenantPackageService.getTenantPackageListByStatus(
|
||||||
|
CommonStatusEnum.ENABLE.getStatus());
|
||||||
|
assertEquals(1, list.size());
|
||||||
|
assertPojoEquals(dbTenantPackage, list.get(0));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user