单元测试修改

This commit is contained in:
handy 2023-08-01 16:16:03 +08:00
parent df0ef8e3b3
commit dde8ca3cc1
1 changed files with 34 additions and 17 deletions

View File

@ -5,10 +5,20 @@ import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import org.dromara.sms4j.aliyun.service.AlibabaSmsImpl;
import org.dromara.sms4j.api.entity.SmsResponse;
import org.dromara.sms4j.cloopen.service.CloopenSmsImpl;
import org.dromara.sms4j.comm.utils.SmsUtil;
import org.dromara.sms4j.core.factory.SmsFactory;
import org.dromara.sms4j.provider.enumerate.SupplierType;
import org.dromara.sms4j.ctyun.service.CtyunSmsImpl;
import org.dromara.sms4j.emay.service.EmaySmsImpl;
import org.dromara.sms4j.huawei.service.HuaweiSmsImpl;
import org.dromara.sms4j.jdcloud.service.JdCloudSmsImpl;
import org.dromara.sms4j.netease.service.NeteaseSmsImpl;
import org.dromara.sms4j.tencent.service.TencentSmsImpl;
import org.dromara.sms4j.unisms.service.UniSmsImpl;
import org.dromara.sms4j.yunpian.service.YunPianSmsImpl;
import org.dromara.sms4j.zhutong.service.ZhutongSmsImpl;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@ -24,13 +34,19 @@ class Sms4jTest {
private static final String PHONE = "";
@Test
public void alibabaSmsTest() {
public void byLoadTest() {
if (StrUtil.isBlank(PHONE)) {
return;
}
// 通过负载均衡服务获取短信服务对象
SmsResponse smsResponse = SmsFactory.getByLoad().sendMessage(PHONE, SmsUtil.getRandomInt(6));
Assert.isTrue(smsResponse.isSuccess());
}
@Test
public void alibabaSmsTest() {
// 阿里
SmsResponse smsResponse = SmsFactory.createSmsBlend(SupplierType.ALIBABA).sendMessage(PHONE, SmsUtil.getRandomInt(6));
log.info(JSONUtil.toJsonStr(smsResponse));
SmsResponse smsResponse = SmsFactory.getFirstBySupplier(AlibabaSmsImpl.SUPPLIER).sendMessage(PHONE, SmsUtil.getRandomInt(6));
Assert.isTrue(smsResponse.isSuccess());
}
@ -40,7 +56,7 @@ class Sms4jTest {
return;
}
// 华为
SmsResponse smsResponse = SmsFactory.createSmsBlend(SupplierType.HUAWEI).sendMessage(PHONE, SmsUtil.getRandomInt(6));
SmsResponse smsResponse = SmsFactory.getFirstBySupplier(HuaweiSmsImpl.SUPPLIER).sendMessage(PHONE, SmsUtil.getRandomInt(6));
log.info(JSONUtil.toJsonStr(smsResponse));
Assert.isTrue(smsResponse.isSuccess());
}
@ -51,7 +67,7 @@ class Sms4jTest {
return;
}
// 容联云
SmsResponse smsResponse = SmsFactory.createSmsBlend(SupplierType.CLOOPEN).sendMessage(PHONE, SmsUtil.getRandomInt(6));
SmsResponse smsResponse = SmsFactory.getFirstBySupplier(CloopenSmsImpl.SUPPLIER).sendMessage(PHONE, SmsUtil.getRandomInt(6));
log.info(JSONUtil.toJsonStr(smsResponse));
Assert.isTrue(smsResponse.isSuccess());
}
@ -62,7 +78,7 @@ class Sms4jTest {
return;
}
// 亿美软通
SmsResponse smsResponse = SmsFactory.createSmsBlend(SupplierType.EMAY).sendMessage(PHONE, SmsUtil.getRandomInt(6));
SmsResponse smsResponse = SmsFactory.getFirstBySupplier(EmaySmsImpl.SUPPLIER).sendMessage(PHONE, SmsUtil.getRandomInt(6));
log.info(JSONUtil.toJsonStr(smsResponse));
Assert.isTrue(smsResponse.isSuccess());
}
@ -73,7 +89,7 @@ class Sms4jTest {
return;
}
// 京东云
SmsResponse smsResponse = SmsFactory.createSmsBlend(SupplierType.JD_CLOUD).sendMessage(PHONE, SmsUtil.getRandomInt(6));
SmsResponse smsResponse = SmsFactory.getFirstBySupplier(JdCloudSmsImpl.SUPPLIER).sendMessage(PHONE, SmsUtil.getRandomInt(6));
log.info(JSONUtil.toJsonStr(smsResponse));
Assert.isTrue(smsResponse.isSuccess());
}
@ -84,7 +100,7 @@ class Sms4jTest {
return;
}
// 云片
SmsResponse smsResponse = SmsFactory.createSmsBlend(SupplierType.YUNPIAN).sendMessage(PHONE, SmsUtil.getRandomInt(6));
SmsResponse smsResponse = SmsFactory.getFirstBySupplier(YunPianSmsImpl.SUPPLIER).sendMessage(PHONE, SmsUtil.getRandomInt(6));
log.info(JSONUtil.toJsonStr(smsResponse));
Assert.isTrue(smsResponse.isSuccess());
}
@ -95,7 +111,7 @@ class Sms4jTest {
return;
}
// 腾讯
SmsResponse smsResponse = SmsFactory.createSmsBlend(SupplierType.TENCENT).sendMessage(PHONE, SmsUtil.getRandomInt(6));
SmsResponse smsResponse = SmsFactory.getFirstBySupplier(TencentSmsImpl.SUPPLIER).sendMessage(PHONE, SmsUtil.getRandomInt(6));
log.info(JSONUtil.toJsonStr(smsResponse));
Assert.isTrue(smsResponse.isSuccess());
}
@ -106,7 +122,7 @@ class Sms4jTest {
return;
}
// 合一
SmsResponse smsResponse = SmsFactory.createSmsBlend(SupplierType.UNI_SMS).sendMessage(PHONE, SmsUtil.getRandomInt(6));
SmsResponse smsResponse = SmsFactory.getFirstBySupplier(UniSmsImpl.SUPPLIER).sendMessage(PHONE, SmsUtil.getRandomInt(6));
log.info(JSONUtil.toJsonStr(smsResponse));
Assert.isTrue(smsResponse.isSuccess());
}
@ -117,7 +133,7 @@ class Sms4jTest {
return;
}
// 天翼云
SmsResponse smsResponse = SmsFactory.createSmsBlend(SupplierType.CTYUN).sendMessage(PHONE, SmsUtil.getRandomInt(6));
SmsResponse smsResponse = SmsFactory.getFirstBySupplier(CtyunSmsImpl.SUPPLIER).sendMessage(PHONE, SmsUtil.getRandomInt(6));
log.info(JSONUtil.toJsonStr(smsResponse));
Assert.isTrue(smsResponse.isSuccess());
}
@ -128,7 +144,7 @@ class Sms4jTest {
return;
}
// 网易云短信
SmsResponse smsResponse = SmsFactory.createSmsBlend(SupplierType.NETEASE).sendMessage(PHONE, SmsUtil.getRandomInt(6));
SmsResponse smsResponse = SmsFactory.getFirstBySupplier(NeteaseSmsImpl.SUPPLIER).sendMessage(PHONE, SmsUtil.getRandomInt(6));
log.info(JSONUtil.toJsonStr(smsResponse));
Assert.isTrue(smsResponse.isSuccess());
}
@ -143,7 +159,7 @@ class Sms4jTest {
}
// 助通短信短信
String msg = StrUtil.format("【图书商城】您好,你的验证码是{}5分钟失效", SmsUtil.getRandomInt(6));
SmsResponse smsResponse = SmsFactory.createSmsBlend(SupplierType.ZHUTONG).sendMessage(PHONE, msg);
SmsResponse smsResponse = SmsFactory.getFirstBySupplier(ZhutongSmsImpl.SUPPLIER).sendMessage(PHONE, msg);
log.info(JSONUtil.toJsonStr(smsResponse));
Assert.isTrue(smsResponse.isSuccess());
}
@ -159,7 +175,7 @@ class Sms4jTest {
// 助通短信短信
LinkedHashMap<String, String> messages = new LinkedHashMap<>(1);
messages.put("code", SmsUtil.getRandomInt(6));
SmsResponse smsResponse = SmsFactory.createSmsBlend(SupplierType.ZHUTONG).sendMessage(PHONE, "59264", messages);
SmsResponse smsResponse = SmsFactory.getFirstBySupplier(ZhutongSmsImpl.SUPPLIER).sendMessage(PHONE, "59264", messages);
log.info(JSONUtil.toJsonStr(smsResponse));
Assert.isTrue(smsResponse.isSuccess());
}
@ -174,7 +190,7 @@ class Sms4jTest {
}
// 助通短信短信
String msg = StrUtil.format("【图书商城】您好,你的验证码是{}5分钟失效", SmsUtil.getRandomInt(6));
SmsResponse smsResponse = SmsFactory.createSmsBlend(SupplierType.ZHUTONG).massTexting(ListUtil.of(PHONE, "180****1111"), msg);
SmsResponse smsResponse = SmsFactory.getFirstBySupplier(ZhutongSmsImpl.SUPPLIER).massTexting(ListUtil.of(PHONE, "180****1111"), msg);
log.info(JSONUtil.toJsonStr(smsResponse));
Assert.isTrue(smsResponse.isSuccess());
}
@ -190,8 +206,9 @@ class Sms4jTest {
// 助通短信短信
LinkedHashMap<String, String> messages = new LinkedHashMap<>(1);
messages.put("code", SmsUtil.getRandomInt(6));
SmsResponse smsResponse = SmsFactory.createSmsBlend(SupplierType.ZHUTONG).massTexting(ListUtil.of(PHONE, "180****1111"), "59264", messages);
SmsResponse smsResponse = SmsFactory.getFirstBySupplier(ZhutongSmsImpl.SUPPLIER).massTexting(ListUtil.of(PHONE, "180****1111"), "59264", messages);
log.info(JSONUtil.toJsonStr(smsResponse));
Assert.isTrue(smsResponse.isSuccess());
}
}