复杂测试案例添加

This commit is contained in:
15946460103 2023-12-06 13:51:01 +08:00
parent 2fd2f4ba60
commit 920cb94ed5
3 changed files with 69 additions and 22 deletions

View File

@ -25,6 +25,9 @@ public class BlackListRecordingProcessor implements SmsProcessor, SmsDaoAware, S
@Setter
Object smsConfig;
public int getOrder(){
return 1;
}
@Override
public Object[] preProcessor(Method method, Object source, Object[] param) {

View File

@ -51,13 +51,13 @@ public class SingleBlendRestrictedProcessor implements SmsProcessor, SmsDaoAware
SmsBlend smsBlend = (SmsBlend) source;
String configId = smsBlend.getConfigId();
Map targetConfig = (Map) smsBlendsConfig.get(configId);
Object maximumString = targetConfig.get("maximum");
if (SmsUtils.isEmpty(maximumString)) {
Object maximumObj = targetConfig.get("maximum");
if (SmsUtils.isEmpty(maximumObj)) {
return param;
}
Integer maximum = 0;
int maximum = 0;
try{
maximum = Integer.getInteger((String) maximumString) ;
maximum = (int) maximumObj ;
}catch (Exception e){
log.error("获取厂商级发送上限参数错误!请检查!");
throw new IllegalArgumentException("获取厂商级发送上限参数错误");

View File

@ -24,65 +24,101 @@ public class SmsProcessorTest {
/**
* 填测试手机号
*/
private static final String PHONE = "13899998888";
private static final String PHONE = "11111111111";
private static final String PHONE1 = "22222222222";
//基础发送测试即黑名单账户限制渠道限制都不预设直接发送新增参数全为空
@Test
public void test1() {
System.out.println("------------");
SmsBlend smsBlend = SmsFactory.getBySupplier(SupplierConstant.UNISMS);
SmsResponse smsResponse = smsBlend.sendMessage(PHONE, SmsUtils.getRandomInt(6));
Assert.isTrue(smsResponse.isSuccess());
System.out.println(smsResponse.getData());
}
//第二个账号的测试
@Test
public void test2() {
System.out.println("------------");
SmsBlend smsBlend = SmsFactory.getBySupplier(SupplierConstant.HUAWEI);
SmsResponse smsResponse = smsBlend.sendMessage(PHONE1, SmsUtils.getRandomInt(6));
Assert.isTrue(smsResponse.isSuccess());
System.out.println(smsResponse.getData());
}
//参数校验测试
@Test
public void testParamValidate() {
public void test3() {
System.out.println("------------");
SmsBlendException knowEx = null;
try {
SmsFactory.getBySupplier(SupplierConstant.ALIBABA).sendMessage(PHONE, new LinkedHashMap<>());
SmsFactory.getBySupplier(SupplierConstant.UNISMS).sendMessage(PHONE, new LinkedHashMap<>());
} catch (SmsBlendException e) {
knowEx = e;
System.out.println(knowEx.getMessage());
}
Assert.notNull(knowEx);
knowEx = null;
try {
SmsFactory.getBySupplier(SupplierConstant.ALIBABA).sendMessage("", SmsUtils.getRandomInt(6));
SmsFactory.getBySupplier(SupplierConstant.UNISMS).sendMessage("", SmsUtils.getRandomInt(6));
} catch (SmsBlendException e) {
knowEx = e;
System.out.println(knowEx.getMessage());
}
Assert.notNull(knowEx);
knowEx = null;
try {
SmsFactory.getBySupplier(SupplierConstant.ALIBABA).sendMessage(PHONE, "");
SmsFactory.getBySupplier(SupplierConstant.UNISMS).sendMessage(PHONE, "");
} catch (SmsBlendException e) {
knowEx = e;
System.out.println(knowEx.getMessage());
}
Assert.notNull(knowEx);
knowEx = null;
try {
SmsFactory.getBySupplier(SupplierConstant.ALIBABA).sendMessage(PHONE, "111", new LinkedHashMap<>());
SmsFactory.getBySupplier(SupplierConstant.UNISMS).sendMessage(PHONE, "111", new LinkedHashMap<>());
} catch (SmsBlendException e) {
knowEx = e;
System.out.println(knowEx.getMessage());
}
Assert.notNull(knowEx);
knowEx = null;
try {
SmsFactory.getBySupplier(SupplierConstant.ALIBABA).massTexting(Collections.singletonList(PHONE), "");
SmsFactory.getBySupplier(SupplierConstant.UNISMS).massTexting(Collections.singletonList(PHONE), "");
} catch (SmsBlendException e) {
knowEx = e;
System.out.println(knowEx.getMessage());
}
Assert.notNull(knowEx);
knowEx = null;
try {
SmsFactory.getBySupplier(SupplierConstant.ALIBABA).massTexting(Collections.singletonList(PHONE), "2222", new LinkedHashMap<>());
SmsFactory.getBySupplier(SupplierConstant.UNISMS).massTexting(Collections.singletonList(PHONE), "2222", new LinkedHashMap<>());
} catch (SmsBlendException e) {
knowEx = e;
System.out.println(knowEx.getMessage());
}
Assert.notNull(knowEx);
knowEx = null;
try {
SmsFactory.getBySupplier(SupplierConstant.ALIBABA).massTexting(new ArrayList<String>(), "321321");
SmsFactory.getBySupplier(SupplierConstant.UNISMS).massTexting(new ArrayList<String>(), "321321");
} catch (SmsBlendException e) {
knowEx = e;
System.out.println(knowEx.getMessage());
}
Assert.notNull(knowEx);
}
//黑名单测试 黑名单手机号13899998888
//黑名单测试
@Test
public void testBlackList() {
public void test4() {
System.out.println("------------");
SmsBlend smsBlend = SmsFactory.getBySupplier(SupplierConstant.UNISMS);
//单黑名单添加
smsBlend.joinInBlacklist(PHONE);
@ -91,6 +127,7 @@ public class SmsProcessorTest {
smsBlend.sendMessage(PHONE, SmsUtils.getRandomInt(6));
} catch (SmsBlendException e) {
knowEx = e;
System.out.println(knowEx.getMessage());
}
Assert.notNull(knowEx);
//单黑名单移除
@ -104,18 +141,21 @@ public class SmsProcessorTest {
smsBlend.sendMessage(PHONE, SmsUtils.getRandomInt(6));
} catch (SmsBlendException e) {
knowEx = e;
System.out.println(knowEx.getMessage());
}
Assert.notNull(knowEx);
//批量黑名单添加
smsBlend.removeFromBlacklist(PHONE);
smsBlend.batchRemovalFromBlacklist(Collections.singletonList(PHONE));
smsResponse = smsBlend.sendMessage(PHONE, SmsUtils.getRandomInt(6));
Assert.isTrue(smsResponse.isSuccess());
}
//账号级上限测试需成功发送一笔特殊配置
//账号级上限测试需成功发送4笔再发就会报错 参数配置 4
@Test
public void testAcctLimt() {
public void test5() {
System.out.println("------------");
SmsResponse smsResponse = SmsFactory.getBySupplier(SupplierConstant.UNISMS).sendMessage(PHONE, SmsUtils.getRandomInt(6));
Assert.isTrue(smsResponse.isSuccess());
SmsBlendException knowEx = null;
@ -123,21 +163,25 @@ public class SmsProcessorTest {
SmsFactory.getBySupplier(SupplierConstant.UNISMS).sendMessage(PHONE, SmsUtils.getRandomInt(6));
} catch (SmsBlendException e) {
knowEx = e;
System.out.println(knowEx.getMessage());
}
Assert.notNull(knowEx);
}
//账号级上限测试需成功发送一笔特殊配置
//渠道级上限测试需成功发送6笔再发就会报错 参数配置 6
@Test
public void testChannelLimt() {
SmsResponse smsResponse = SmsFactory.getBySupplier(SupplierConstant.UNISMS).sendMessage(PHONE, SmsUtils.getRandomInt(6));
public void test6() {
System.out.println("------------");
SmsResponse smsResponse = SmsFactory.getBySupplier(SupplierConstant.UNISMS).sendMessage(PHONE1, SmsUtils.getRandomInt(6));
Assert.isTrue(smsResponse.isSuccess());
SmsBlendException knowEx = null;
try {
SmsFactory.getBySupplier(SupplierConstant.UNISMS).sendMessage(PHONE, SmsUtils.getRandomInt(6));
SmsFactory.getBySupplier(SupplierConstant.UNISMS).sendMessage(PHONE1, SmsUtils.getRandomInt(6));
} catch (SmsBlendException e) {
knowEx = e;
System.out.println(knowEx.getMessage());
}
Assert.notNull(knowEx);
}