Commit da829f7cf568f62133ff7a5685f692afc20a6f7d
1 parent
c2e9ecf7
✅ 增加 sms/tenant/senstiveword 模块的单测覆盖率
Showing
4 changed files
with
129 additions
and
11 deletions
yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/sensitiveword/SensitiveWordServiceImplTest.java
| @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.system.service.sensitiveword; | @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.system.service.sensitiveword; | ||
| 3 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | 3 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | import cn.iocoder.yudao.framework.common.util.collection.SetUtils; | 5 | import cn.iocoder.yudao.framework.common.util.collection.SetUtils; |
| 6 | +import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils; | ||
| 6 | import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; | 7 | import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; |
| 7 | import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordPageReqVO; | 8 | import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordPageReqVO; |
| 8 | import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordSaveVO; | 9 | import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordSaveVO; |
| @@ -13,6 +14,8 @@ import org.junit.jupiter.api.Test; | @@ -13,6 +14,8 @@ import org.junit.jupiter.api.Test; | ||
| 13 | import org.springframework.context.annotation.Import; | 14 | import org.springframework.context.annotation.Import; |
| 14 | 15 | ||
| 15 | import javax.annotation.Resource; | 16 | import javax.annotation.Resource; |
| 17 | +import java.time.Duration; | ||
| 18 | +import java.time.LocalDateTime; | ||
| 16 | import java.util.Arrays; | 19 | import java.util.Arrays; |
| 17 | import java.util.List; | 20 | import java.util.List; |
| 18 | 21 | ||
| @@ -79,6 +82,35 @@ public class SensitiveWordServiceImplTest extends BaseDbUnitTest { | @@ -79,6 +82,35 @@ public class SensitiveWordServiceImplTest extends BaseDbUnitTest { | ||
| 79 | } | 82 | } |
| 80 | 83 | ||
| 81 | @Test | 84 | @Test |
| 85 | + public void testRefreshLocalCache() { | ||
| 86 | + // mock 数据 | ||
| 87 | + SensitiveWordDO wordDO1 = randomPojo(SensitiveWordDO.class, o -> o.setName("傻瓜") | ||
| 88 | + .setTags(singletonList("论坛")).setStatus(CommonStatusEnum.ENABLE.getStatus())); | ||
| 89 | + wordDO1.setUpdateTime(LocalDateTime.now()); | ||
| 90 | + sensitiveWordMapper.insert(wordDO1); | ||
| 91 | + sensitiveWordService.initLocalCache(); | ||
| 92 | + // mock 数据 ② | ||
| 93 | + SensitiveWordDO wordDO2 = randomPojo(SensitiveWordDO.class, o -> o.setName("笨蛋") | ||
| 94 | + .setTags(singletonList("蔬菜")).setStatus(CommonStatusEnum.ENABLE.getStatus())); | ||
| 95 | + wordDO2.setUpdateTime(LocalDateTimeUtils.addTime(Duration.ofMinutes(1))); // 避免时间相同 | ||
| 96 | + sensitiveWordMapper.insert(wordDO2); | ||
| 97 | + | ||
| 98 | + // 调用 | ||
| 99 | + sensitiveWordService.refreshLocalCache(); | ||
| 100 | + // 断言 sensitiveWordTagsCache 缓存 | ||
| 101 | + assertEquals(SetUtils.asSet("论坛", "蔬菜"), sensitiveWordService.getSensitiveWordTagSet()); | ||
| 102 | + // 断言 sensitiveWordCache | ||
| 103 | + assertEquals(2, sensitiveWordService.getSensitiveWordCache().size()); | ||
| 104 | + assertPojoEquals(wordDO1, sensitiveWordService.getSensitiveWordCache().get(0)); | ||
| 105 | + assertPojoEquals(wordDO2, sensitiveWordService.getSensitiveWordCache().get(1)); | ||
| 106 | + // 断言 tagSensitiveWordTries 缓存 | ||
| 107 | + assertNotNull(sensitiveWordService.getDefaultSensitiveWordTrie()); | ||
| 108 | + assertEquals(2, sensitiveWordService.getTagSensitiveWordTries().size()); | ||
| 109 | + assertNotNull(sensitiveWordService.getTagSensitiveWordTries().get("论坛")); | ||
| 110 | + assertNotNull(sensitiveWordService.getTagSensitiveWordTries().get("蔬菜")); | ||
| 111 | + } | ||
| 112 | + | ||
| 113 | + @Test | ||
| 82 | public void testCreateSensitiveWord_success() { | 114 | public void testCreateSensitiveWord_success() { |
| 83 | // 准备参数 | 115 | // 准备参数 |
| 84 | SensitiveWordSaveVO reqVO = randomPojo(SensitiveWordSaveVO.class) | 116 | SensitiveWordSaveVO reqVO = randomPojo(SensitiveWordSaveVO.class) |
yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/sms/SmsSendServiceImplTest.java
| @@ -16,6 +16,7 @@ import cn.iocoder.yudao.module.system.mq.producer.sms.SmsProducer; | @@ -16,6 +16,7 @@ import cn.iocoder.yudao.module.system.mq.producer.sms.SmsProducer; | ||
| 16 | import cn.iocoder.yudao.module.system.service.member.MemberService; | 16 | import cn.iocoder.yudao.module.system.service.member.MemberService; |
| 17 | import cn.iocoder.yudao.module.system.service.user.AdminUserService; | 17 | import cn.iocoder.yudao.module.system.service.user.AdminUserService; |
| 18 | import org.assertj.core.util.Lists; | 18 | import org.assertj.core.util.Lists; |
| 19 | +import org.junit.jupiter.api.Assertions; | ||
| 19 | import org.junit.jupiter.api.Test; | 20 | import org.junit.jupiter.api.Test; |
| 20 | import org.mockito.InjectMocks; | 21 | import org.mockito.InjectMocks; |
| 21 | import org.mockito.Mock; | 22 | import org.mockito.Mock; |
| @@ -35,7 +36,7 @@ import static org.mockito.Mockito.*; | @@ -35,7 +36,7 @@ import static org.mockito.Mockito.*; | ||
| 35 | public class SmsSendServiceImplTest extends BaseMockitoUnitTest { | 36 | public class SmsSendServiceImplTest extends BaseMockitoUnitTest { |
| 36 | 37 | ||
| 37 | @InjectMocks | 38 | @InjectMocks |
| 38 | - private SmsSendServiceImpl smsService; | 39 | + private SmsSendServiceImpl smsSendService; |
| 39 | 40 | ||
| 40 | @Mock | 41 | @Mock |
| 41 | private AdminUserService adminUserService; | 42 | private AdminUserService adminUserService; |
| @@ -80,7 +81,7 @@ public class SmsSendServiceImplTest extends BaseMockitoUnitTest { | @@ -80,7 +81,7 @@ public class SmsSendServiceImplTest extends BaseMockitoUnitTest { | ||
| 80 | eq(content), eq(templateParams))).thenReturn(smsLogId); | 81 | eq(content), eq(templateParams))).thenReturn(smsLogId); |
| 81 | 82 | ||
| 82 | // 调用 | 83 | // 调用 |
| 83 | - Long resultSmsLogId = smsService.sendSingleSmsToAdmin(null, userId, templateCode, templateParams); | 84 | + Long resultSmsLogId = smsSendService.sendSingleSmsToAdmin(null, userId, templateCode, templateParams); |
| 84 | // 断言 | 85 | // 断言 |
| 85 | assertEquals(smsLogId, resultSmsLogId); | 86 | assertEquals(smsLogId, resultSmsLogId); |
| 86 | // 断言调用 | 87 | // 断言调用 |
| @@ -119,7 +120,7 @@ public class SmsSendServiceImplTest extends BaseMockitoUnitTest { | @@ -119,7 +120,7 @@ public class SmsSendServiceImplTest extends BaseMockitoUnitTest { | ||
| 119 | eq(content), eq(templateParams))).thenReturn(smsLogId); | 120 | eq(content), eq(templateParams))).thenReturn(smsLogId); |
| 120 | 121 | ||
| 121 | // 调用 | 122 | // 调用 |
| 122 | - Long resultSmsLogId = smsService.sendSingleSmsToMember(null, userId, templateCode, templateParams); | 123 | + Long resultSmsLogId = smsSendService.sendSingleSmsToMember(null, userId, templateCode, templateParams); |
| 123 | // 断言 | 124 | // 断言 |
| 124 | assertEquals(smsLogId, resultSmsLogId); | 125 | assertEquals(smsLogId, resultSmsLogId); |
| 125 | // 断言调用 | 126 | // 断言调用 |
| @@ -159,7 +160,7 @@ public class SmsSendServiceImplTest extends BaseMockitoUnitTest { | @@ -159,7 +160,7 @@ public class SmsSendServiceImplTest extends BaseMockitoUnitTest { | ||
| 159 | eq(content), eq(templateParams))).thenReturn(smsLogId); | 160 | eq(content), eq(templateParams))).thenReturn(smsLogId); |
| 160 | 161 | ||
| 161 | // 调用 | 162 | // 调用 |
| 162 | - Long resultSmsLogId = smsService.sendSingleSms(mobile, userId, userType, templateCode, templateParams); | 163 | + Long resultSmsLogId = smsSendService.sendSingleSms(mobile, userId, userType, templateCode, templateParams); |
| 163 | // 断言 | 164 | // 断言 |
| 164 | assertEquals(smsLogId, resultSmsLogId); | 165 | assertEquals(smsLogId, resultSmsLogId); |
| 165 | // 断言调用 | 166 | // 断言调用 |
| @@ -199,7 +200,7 @@ public class SmsSendServiceImplTest extends BaseMockitoUnitTest { | @@ -199,7 +200,7 @@ public class SmsSendServiceImplTest extends BaseMockitoUnitTest { | ||
| 199 | eq(content), eq(templateParams))).thenReturn(smsLogId); | 200 | eq(content), eq(templateParams))).thenReturn(smsLogId); |
| 200 | 201 | ||
| 201 | // 调用 | 202 | // 调用 |
| 202 | - Long resultSmsLogId = smsService.sendSingleSms(mobile, userId, userType, templateCode, templateParams); | 203 | + Long resultSmsLogId = smsSendService.sendSingleSms(mobile, userId, userType, templateCode, templateParams); |
| 203 | // 断言 | 204 | // 断言 |
| 204 | assertEquals(smsLogId, resultSmsLogId); | 205 | assertEquals(smsLogId, resultSmsLogId); |
| 205 | // 断言调用 | 206 | // 断言调用 |
| @@ -214,7 +215,7 @@ public class SmsSendServiceImplTest extends BaseMockitoUnitTest { | @@ -214,7 +215,7 @@ public class SmsSendServiceImplTest extends BaseMockitoUnitTest { | ||
| 214 | // mock 方法 | 215 | // mock 方法 |
| 215 | 216 | ||
| 216 | // 调用,并断言异常 | 217 | // 调用,并断言异常 |
| 217 | - assertServiceException(() -> smsService.validateSmsTemplate(templateCode), | 218 | + assertServiceException(() -> smsSendService.validateSmsTemplate(templateCode), |
| 218 | SMS_SEND_TEMPLATE_NOT_EXISTS); | 219 | SMS_SEND_TEMPLATE_NOT_EXISTS); |
| 219 | } | 220 | } |
| 220 | 221 | ||
| @@ -227,7 +228,7 @@ public class SmsSendServiceImplTest extends BaseMockitoUnitTest { | @@ -227,7 +228,7 @@ public class SmsSendServiceImplTest extends BaseMockitoUnitTest { | ||
| 227 | // mock 方法 | 228 | // mock 方法 |
| 228 | 229 | ||
| 229 | // 调用,并断言异常 | 230 | // 调用,并断言异常 |
| 230 | - assertServiceException(() -> smsService.buildTemplateParams(template, templateParams), | 231 | + assertServiceException(() -> smsSendService.buildTemplateParams(template, templateParams), |
| 231 | SMS_SEND_MOBILE_TEMPLATE_PARAM_MISS, "code"); | 232 | SMS_SEND_MOBILE_TEMPLATE_PARAM_MISS, "code"); |
| 232 | } | 233 | } |
| 233 | 234 | ||
| @@ -237,11 +238,25 @@ public class SmsSendServiceImplTest extends BaseMockitoUnitTest { | @@ -237,11 +238,25 @@ public class SmsSendServiceImplTest extends BaseMockitoUnitTest { | ||
| 237 | // mock 方法 | 238 | // mock 方法 |
| 238 | 239 | ||
| 239 | // 调用,并断言异常 | 240 | // 调用,并断言异常 |
| 240 | - assertServiceException(() -> smsService.validateMobile(null), | 241 | + assertServiceException(() -> smsSendService.validateMobile(null), |
| 241 | SMS_SEND_MOBILE_NOT_EXISTS); | 242 | SMS_SEND_MOBILE_NOT_EXISTS); |
| 242 | } | 243 | } |
| 243 | 244 | ||
| 244 | @Test | 245 | @Test |
| 246 | + public void testSendBatchNotify() { | ||
| 247 | + // 准备参数 | ||
| 248 | + // mock 方法 | ||
| 249 | + | ||
| 250 | + // 调用 | ||
| 251 | + UnsupportedOperationException exception = Assertions.assertThrows( | ||
| 252 | + UnsupportedOperationException.class, | ||
| 253 | + () -> smsSendService.sendBatchSms(null, null, null, null, null) | ||
| 254 | + ); | ||
| 255 | + // 断言 | ||
| 256 | + assertEquals("暂时不支持该操作,感兴趣可以实现该功能哟!", exception.getMessage()); | ||
| 257 | + } | ||
| 258 | + | ||
| 259 | + @Test | ||
| 245 | @SuppressWarnings("unchecked") | 260 | @SuppressWarnings("unchecked") |
| 246 | public void testDoSendSms() throws Throwable { | 261 | public void testDoSendSms() throws Throwable { |
| 247 | // 准备参数 | 262 | // 准备参数 |
| @@ -255,7 +270,7 @@ public class SmsSendServiceImplTest extends BaseMockitoUnitTest { | @@ -255,7 +270,7 @@ public class SmsSendServiceImplTest extends BaseMockitoUnitTest { | ||
| 255 | eq(message.getTemplateParams()))).thenReturn(sendResult); | 270 | eq(message.getTemplateParams()))).thenReturn(sendResult); |
| 256 | 271 | ||
| 257 | // 调用 | 272 | // 调用 |
| 258 | - smsService.doSendSms(message); | 273 | + smsSendService.doSendSms(message); |
| 259 | // 断言 | 274 | // 断言 |
| 260 | verify(smsLogService).updateSmsSendResult(eq(message.getLogId()), | 275 | verify(smsLogService).updateSmsSendResult(eq(message.getLogId()), |
| 261 | eq(sendResult.getSuccess()), eq(sendResult.getApiCode()), | 276 | eq(sendResult.getSuccess()), eq(sendResult.getApiCode()), |
| @@ -274,7 +289,7 @@ public class SmsSendServiceImplTest extends BaseMockitoUnitTest { | @@ -274,7 +289,7 @@ public class SmsSendServiceImplTest extends BaseMockitoUnitTest { | ||
| 274 | List<SmsReceiveRespDTO> receiveResults = randomPojoList(SmsReceiveRespDTO.class); | 289 | List<SmsReceiveRespDTO> receiveResults = randomPojoList(SmsReceiveRespDTO.class); |
| 275 | 290 | ||
| 276 | // 调用 | 291 | // 调用 |
| 277 | - smsService.receiveSmsStatus(channelCode, text); | 292 | + smsSendService.receiveSmsStatus(channelCode, text); |
| 278 | // 断言 | 293 | // 断言 |
| 279 | receiveResults.forEach(result -> smsLogService.updateSmsReceiveResult(eq(result.getLogId()), eq(result.getSuccess()), | 294 | receiveResults.forEach(result -> smsLogService.updateSmsReceiveResult(eq(result.getLogId()), eq(result.getSuccess()), |
| 280 | eq(result.getReceiveTime()), eq(result.getErrorCode()), eq(result.getErrorCode()))); | 295 | eq(result.getReceiveTime()), eq(result.getErrorCode()), eq(result.getErrorCode()))); |
yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/sms/SmsTemplateServiceImplTest.java
| 1 | package cn.iocoder.yudao.module.system.service.sms; | 1 | package cn.iocoder.yudao.module.system.service.sms; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.map.MapUtil; | ||
| 3 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | 4 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; | 6 | import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; |
| @@ -8,8 +9,8 @@ import cn.iocoder.yudao.framework.sms.core.client.SmsClient; | @@ -8,8 +9,8 @@ import cn.iocoder.yudao.framework.sms.core.client.SmsClient; | ||
| 8 | import cn.iocoder.yudao.framework.sms.core.client.dto.SmsTemplateRespDTO; | 9 | import cn.iocoder.yudao.framework.sms.core.client.dto.SmsTemplateRespDTO; |
| 9 | import cn.iocoder.yudao.framework.sms.core.enums.SmsTemplateAuditStatusEnum; | 10 | import cn.iocoder.yudao.framework.sms.core.enums.SmsTemplateAuditStatusEnum; |
| 10 | import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; | 11 | import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; |
| 11 | -import cn.iocoder.yudao.module.system.controller.admin.sms.vo.template.SmsTemplateSaveReqVO; | ||
| 12 | import cn.iocoder.yudao.module.system.controller.admin.sms.vo.template.SmsTemplatePageReqVO; | 12 | import cn.iocoder.yudao.module.system.controller.admin.sms.vo.template.SmsTemplatePageReqVO; |
| 13 | +import cn.iocoder.yudao.module.system.controller.admin.sms.vo.template.SmsTemplateSaveReqVO; | ||
| 13 | import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsChannelDO; | 14 | import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsChannelDO; |
| 14 | import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsTemplateDO; | 15 | import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsTemplateDO; |
| 15 | import cn.iocoder.yudao.module.system.dal.mysql.sms.SmsTemplateMapper; | 16 | import cn.iocoder.yudao.module.system.dal.mysql.sms.SmsTemplateMapper; |
| @@ -21,6 +22,7 @@ import org.springframework.context.annotation.Import; | @@ -21,6 +22,7 @@ import org.springframework.context.annotation.Import; | ||
| 21 | 22 | ||
| 22 | import javax.annotation.Resource; | 23 | import javax.annotation.Resource; |
| 23 | import java.util.List; | 24 | import java.util.List; |
| 25 | +import java.util.Map; | ||
| 24 | import java.util.function.Consumer; | 26 | import java.util.function.Consumer; |
| 25 | 27 | ||
| 26 | import static cn.hutool.core.util.RandomUtil.randomEle; | 28 | import static cn.hutool.core.util.RandomUtil.randomEle; |
| @@ -49,6 +51,19 @@ public class SmsTemplateServiceImplTest extends BaseDbUnitTest { | @@ -49,6 +51,19 @@ public class SmsTemplateServiceImplTest extends BaseDbUnitTest { | ||
| 49 | private SmsClient smsClient; | 51 | private SmsClient smsClient; |
| 50 | 52 | ||
| 51 | @Test | 53 | @Test |
| 54 | + public void testFormatSmsTemplateContent() { | ||
| 55 | + // 准备参数 | ||
| 56 | + String content = "正在进行登录操作{operation},您的验证码是{code}"; | ||
| 57 | + Map<String, Object> params = MapUtil.<String, Object>builder("operation", "登录") | ||
| 58 | + .put("code", "1234").build(); | ||
| 59 | + | ||
| 60 | + // 调用 | ||
| 61 | + String result = smsTemplateService.formatSmsTemplateContent(content, params); | ||
| 62 | + // 断言 | ||
| 63 | + assertEquals("正在进行登录操作登录,您的验证码是1234", result); | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + @Test | ||
| 52 | public void testParseTemplateContentParams() { | 67 | public void testParseTemplateContentParams() { |
| 53 | // 准备参数 | 68 | // 准备参数 |
| 54 | String content = "正在进行登录操作{operation},您的验证码是{code}"; | 69 | String content = "正在进行登录操作{operation},您的验证码是{code}"; |
| @@ -157,6 +172,34 @@ public class SmsTemplateServiceImplTest extends BaseDbUnitTest { | @@ -157,6 +172,34 @@ public class SmsTemplateServiceImplTest extends BaseDbUnitTest { | ||
| 157 | } | 172 | } |
| 158 | 173 | ||
| 159 | @Test | 174 | @Test |
| 175 | + public void testGetSmsTemplate() { | ||
| 176 | + // mock 数据 | ||
| 177 | + SmsTemplateDO dbSmsTemplate = randomSmsTemplateDO(); | ||
| 178 | + smsTemplateMapper.insert(dbSmsTemplate);// @Sql: 先插入出一条存在的数据 | ||
| 179 | + // 准备参数 | ||
| 180 | + Long id = dbSmsTemplate.getId(); | ||
| 181 | + | ||
| 182 | + // 调用 | ||
| 183 | + SmsTemplateDO smsTemplate = smsTemplateService.getSmsTemplate(id); | ||
| 184 | + // 校验 | ||
| 185 | + assertPojoEquals(dbSmsTemplate, smsTemplate); | ||
| 186 | + } | ||
| 187 | + | ||
| 188 | + @Test | ||
| 189 | + public void testGetSmsTemplateByCodeFromCache() { | ||
| 190 | + // mock 数据 | ||
| 191 | + SmsTemplateDO dbSmsTemplate = randomSmsTemplateDO(); | ||
| 192 | + smsTemplateMapper.insert(dbSmsTemplate);// @Sql: 先插入出一条存在的数据 | ||
| 193 | + // 准备参数 | ||
| 194 | + String code = dbSmsTemplate.getCode(); | ||
| 195 | + | ||
| 196 | + // 调用 | ||
| 197 | + SmsTemplateDO smsTemplate = smsTemplateService.getSmsTemplateByCodeFromCache(code); | ||
| 198 | + // 校验 | ||
| 199 | + assertPojoEquals(dbSmsTemplate, smsTemplate); | ||
| 200 | + } | ||
| 201 | + | ||
| 202 | + @Test | ||
| 160 | public void testGetSmsTemplatePage() { | 203 | public void testGetSmsTemplatePage() { |
| 161 | // mock 数据 | 204 | // mock 数据 |
| 162 | SmsTemplateDO dbSmsTemplate = randomPojo(SmsTemplateDO.class, o -> { // 等会查询到 | 205 | SmsTemplateDO dbSmsTemplate = randomPojo(SmsTemplateDO.class, o -> { // 等会查询到 |
| @@ -202,6 +245,22 @@ public class SmsTemplateServiceImplTest extends BaseDbUnitTest { | @@ -202,6 +245,22 @@ public class SmsTemplateServiceImplTest extends BaseDbUnitTest { | ||
| 202 | } | 245 | } |
| 203 | 246 | ||
| 204 | @Test | 247 | @Test |
| 248 | + public void testGetSmsTemplateCountByChannelId() { | ||
| 249 | + // mock 数据 | ||
| 250 | + SmsTemplateDO dbSmsTemplate = randomPojo(SmsTemplateDO.class, o -> o.setChannelId(1L)); | ||
| 251 | + smsTemplateMapper.insert(dbSmsTemplate); | ||
| 252 | + // 测试 channelId 不匹配 | ||
| 253 | + smsTemplateMapper.insert(ObjectUtils.cloneIgnoreId(dbSmsTemplate, o -> o.setChannelId(2L))); | ||
| 254 | + // 准备参数 | ||
| 255 | + Long channelId = 1L; | ||
| 256 | + | ||
| 257 | + // 调用 | ||
| 258 | + Long count = smsTemplateService.getSmsTemplateCountByChannelId(channelId); | ||
| 259 | + // 断言 | ||
| 260 | + assertEquals(1, count); | ||
| 261 | + } | ||
| 262 | + | ||
| 263 | + @Test | ||
| 205 | public void testValidateSmsChannel_success() { | 264 | public void testValidateSmsChannel_success() { |
| 206 | // 准备参数 | 265 | // 准备参数 |
| 207 | Long channelId = randomLongId(); | 266 | Long channelId = randomLongId(); |
yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/tenant/TenantServiceImplTest.java
| @@ -332,6 +332,18 @@ public class TenantServiceImplTest extends BaseDbUnitTest { | @@ -332,6 +332,18 @@ public class TenantServiceImplTest extends BaseDbUnitTest { | ||
| 332 | } | 332 | } |
| 333 | 333 | ||
| 334 | @Test | 334 | @Test |
| 335 | + public void testGetTenantByWebsite() { | ||
| 336 | + // mock 数据 | ||
| 337 | + TenantDO dbTenant = randomPojo(TenantDO.class, o -> o.setWebsite("https://www.iocoder.cn")); | ||
| 338 | + tenantMapper.insert(dbTenant);// @Sql: 先插入出一条存在的数据 | ||
| 339 | + | ||
| 340 | + // 调用 | ||
| 341 | + TenantDO result = tenantService.getTenantByWebsite("https://www.iocoder.cn"); | ||
| 342 | + // 校验存在 | ||
| 343 | + assertPojoEquals(result, dbTenant); | ||
| 344 | + } | ||
| 345 | + | ||
| 346 | + @Test | ||
| 335 | public void testGetTenantListByPackageId() { | 347 | public void testGetTenantListByPackageId() { |
| 336 | // mock 数据 | 348 | // mock 数据 |
| 337 | TenantDO dbTenant1 = randomPojo(TenantDO.class, o -> o.setPackageId(1L)); | 349 | TenantDO dbTenant1 = randomPojo(TenantDO.class, o -> o.setPackageId(1L)); |