style: 修改测试类代码
This commit is contained in:
parent
a62daf4ee0
commit
9624d64d41
@ -1,11 +1,12 @@
|
|||||||
package com.cicdi.notify.dingtalk;
|
package com.cicdi.notify.dingtalk;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.cicdi.notify.*;
|
import com.cicdi.notify.*;
|
||||||
import com.cicdi.notify.template.AbstractTemplateManager;
|
import com.cicdi.notify.template.AbstractTemplateManager;
|
||||||
import com.cicdi.notify.template.Template;
|
import com.cicdi.notify.template.Template;
|
||||||
import com.cicdi.notify.template.TemplateManager;
|
import com.cicdi.notify.template.TemplateManager;
|
||||||
import com.cicdi.notify.template.TemplateProperties;
|
import com.cicdi.notify.template.TemplateProperties;
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -15,14 +16,32 @@ import java.util.Map;
|
|||||||
* @author xueye
|
* @author xueye
|
||||||
*/
|
*/
|
||||||
public class DingTalkTest {
|
public class DingTalkTest {
|
||||||
|
/**
|
||||||
|
* 模板管理器
|
||||||
|
*/
|
||||||
|
private TemplateManager templateManager;
|
||||||
|
/**
|
||||||
|
* 通知器管理器
|
||||||
|
*/
|
||||||
|
private NotifierManager notifierManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 测试钉钉消息发送
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void test() {
|
public void test() {
|
||||||
|
Notifier<Template> notifier = notifierManager.getNotifier(DefaultNotifyType.dingTalk, "123");
|
||||||
|
notifier.send(templateManager.getTemplate(DefaultNotifyType.dingTalk, "124"), new HashMap<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void init() {
|
||||||
// 通知器配置管理器
|
// 通知器配置管理器
|
||||||
NotifyConfigManager notifyConfigManager = (notifyType, configId) -> {
|
NotifyConfigManager notifyConfigManager = (notifyType, configId) -> {
|
||||||
NotifierProperties notifierProperties = new NotifierProperties();
|
NotifierProperties notifierProperties = new NotifierProperties();
|
||||||
notifierProperties.setType(DefaultNotifyType.dingTalk.getId());
|
notifierProperties.setType(DefaultNotifyType.dingTalk.getId());
|
||||||
notifierProperties.setProvider(DingTalkProvider.dingTalkMessage.getId());
|
notifierProperties.setProvider(DingTalkProvider.dingTalkMessage.getId());
|
||||||
notifierProperties.setId("12");
|
notifierProperties.setId("123");
|
||||||
|
|
||||||
Map<String, Object> config = new HashMap<>();
|
Map<String, Object> config = new HashMap<>();
|
||||||
config.put("appKey", "dinga5vkkpbrwqc0fmni");
|
config.put("appKey", "dinga5vkkpbrwqc0fmni");
|
||||||
@ -33,35 +52,33 @@ public class DingTalkTest {
|
|||||||
return notifierProperties;
|
return notifierProperties;
|
||||||
};
|
};
|
||||||
|
|
||||||
// 模板管理器
|
templateManager = new AbstractTemplateManager() {
|
||||||
TemplateManager templateManager = new AbstractTemplateManager() {
|
|
||||||
@Override
|
@Override
|
||||||
protected TemplateProperties getProperties(NotifyType type, String id) {
|
protected TemplateProperties getProperties(NotifyType type, String id) {
|
||||||
TemplateProperties templateProperties = new TemplateProperties();
|
TemplateProperties templateProperties = new TemplateProperties();
|
||||||
templateProperties.setType(DefaultNotifyType.dingTalk.getId());
|
templateProperties.setType(DefaultNotifyType.dingTalk.getId());
|
||||||
templateProperties.setProvider(DingTalkProvider.dingTalkMessage.getId());
|
templateProperties.setProvider(DingTalkProvider.dingTalkMessage.getId());
|
||||||
|
|
||||||
JSONObject jsonObject = new JSONObject();
|
DingTalkMessageTemplate template = new DingTalkMessageTemplate();
|
||||||
jsonObject.put("agentId", "1211676948");
|
template.setAgentId("1211676948");
|
||||||
jsonObject.put("userIdList", "manager276");
|
template.setUserIdList("manager276");
|
||||||
jsonObject.put("departmentIdList", "");
|
template.setDepartmentIdList("");
|
||||||
jsonObject.put("toAllUser", "false");
|
template.setToAllUser(false);
|
||||||
jsonObject.put("message", "Hello World!");
|
template.setMessage("Hello World! - " + System.currentTimeMillis());
|
||||||
|
|
||||||
templateProperties.setTemplate(jsonObject.toJSONString());
|
templateProperties.setTemplate(JSON.toJSONString(template));
|
||||||
|
|
||||||
return templateProperties;
|
return templateProperties;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
NotifierManager notifierManager = new AbstractNotifierManager(notifyConfigManager){};
|
notifierManager = new AbstractNotifierManager(notifyConfigManager) {
|
||||||
|
};
|
||||||
|
|
||||||
// register
|
// register
|
||||||
DingTalkNotifierProvider provider = new DingTalkNotifierProvider(templateManager);
|
DingTalkNotifierProvider provider = new DingTalkNotifierProvider(templateManager);
|
||||||
notifierManager.register(provider);
|
notifierManager.register(provider);
|
||||||
templateManager.register(provider);
|
templateManager.register(provider);
|
||||||
|
|
||||||
Notifier<Template> notifier = notifierManager.getNotifier(DefaultNotifyType.dingTalk, "123");
|
|
||||||
notifier.send(templateManager.getTemplate(DefaultNotifyType.dingTalk, "124"), new HashMap<>());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.cicdi.notify.email;
|
package com.cicdi.notify.email;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.cicdi.notify.*;
|
import com.cicdi.notify.*;
|
||||||
import com.cicdi.notify.template.AbstractTemplateManager;
|
import com.cicdi.notify.template.AbstractTemplateManager;
|
||||||
import com.cicdi.notify.template.Template;
|
import com.cicdi.notify.template.Template;
|
||||||
@ -9,6 +10,7 @@ import com.cicdi.notify.email.embedded.DefaultEmailNotifierProvider;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -55,7 +57,14 @@ public class DefaultEmailTest {
|
|||||||
TemplateProperties templateProperties = new TemplateProperties();
|
TemplateProperties templateProperties = new TemplateProperties();
|
||||||
templateProperties.setType(DefaultNotifyType.email.getId());
|
templateProperties.setType(DefaultNotifyType.email.getId());
|
||||||
templateProperties.setProvider(EmailProvider.embedded.getId());
|
templateProperties.setProvider(EmailProvider.embedded.getId());
|
||||||
templateProperties.setTemplate("{\"subject\":\"Hello\",\"sendTo\":[\"xueye404@qq.com\"],\"text\":\"<p>This is a test</p>\",\"attachments\":[]}");
|
|
||||||
|
EmailTemplate template = new EmailTemplate();
|
||||||
|
template.setSubject("Hello");
|
||||||
|
template.setSendTo(Collections.singletonList("xueye404@qq.com"));
|
||||||
|
template.setText("This is a test and do not reply this message!");
|
||||||
|
|
||||||
|
templateProperties.setTemplate(JSON.toJSONString(template));
|
||||||
|
|
||||||
return templateProperties;
|
return templateProperties;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
package com.cicdi.notify.sms;
|
package com.cicdi.notify.sms;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.cicdi.notify.*;
|
import com.cicdi.notify.*;
|
||||||
import com.cicdi.notify.sms.aliyun.AliyunSmsNotifierProvider;
|
|
||||||
import com.cicdi.notify.sms.telecom.TelecomSmsNotifierProvider;
|
import com.cicdi.notify.sms.telecom.TelecomSmsNotifierProvider;
|
||||||
|
import com.cicdi.notify.sms.telecom.TelecomSmsTemplate;
|
||||||
import com.cicdi.notify.template.AbstractTemplateManager;
|
import com.cicdi.notify.template.AbstractTemplateManager;
|
||||||
import com.cicdi.notify.template.Template;
|
import com.cicdi.notify.template.Template;
|
||||||
import com.cicdi.notify.template.TemplateManager;
|
import com.cicdi.notify.template.TemplateManager;
|
||||||
@ -19,23 +20,20 @@ public class TelecomSmsTest {
|
|||||||
@Test
|
@Test
|
||||||
public void test() {
|
public void test() {
|
||||||
// 通知器配置管理器
|
// 通知器配置管理器
|
||||||
NotifyConfigManager notifyConfigManager = new NotifyConfigManager() {
|
NotifyConfigManager notifyConfigManager = (notifyType, configId) -> {
|
||||||
@Override
|
NotifierProperties notifierProperties = new NotifierProperties();
|
||||||
public NotifierProperties getNotifyConfig(NotifyType notifyType, String configId) {
|
notifierProperties.setType(DefaultNotifyType.sms.getId());
|
||||||
NotifierProperties notifierProperties = new NotifierProperties();
|
notifierProperties.setProvider(SmsProvider.telecom.getId());
|
||||||
notifierProperties.setType(DefaultNotifyType.sms.getId());
|
notifierProperties.setId("12");
|
||||||
notifierProperties.setProvider(SmsProvider.telecom.getId());
|
|
||||||
notifierProperties.setId("12");
|
|
||||||
|
|
||||||
Map<String, Object> config = new HashMap<>();
|
Map<String, Object> config = new HashMap<>();
|
||||||
config.put("serviceUrl", "http://www.js139.com.cn:8022/hysms/SendMsg");
|
config.put("serviceUrl", "http://www.js139.com.cn:8022/hysms/SendMsg");
|
||||||
config.put("userId", "HYjlzx");
|
config.put("userId", "HYjlzx");
|
||||||
config.put("password", "5CA45EA4944D2C32567E8DBBDDBD65DD");
|
config.put("password", "5CA45EA4944D2C32567E8DBBDDBD65DD");
|
||||||
|
|
||||||
notifierProperties.setConfiguration(config);
|
notifierProperties.setConfiguration(config);
|
||||||
|
|
||||||
return notifierProperties;
|
return notifierProperties;
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// 模板管理器
|
// 模板管理器
|
||||||
@ -46,22 +44,22 @@ public class TelecomSmsTest {
|
|||||||
templateProperties.setType(DefaultNotifyType.sms.getId());
|
templateProperties.setType(DefaultNotifyType.sms.getId());
|
||||||
templateProperties.setProvider(SmsProvider.telecom.getId());
|
templateProperties.setProvider(SmsProvider.telecom.getId());
|
||||||
|
|
||||||
templateProperties.setTemplate("{\"text\":\"Hello\",\"mobile\":\"18605120786\"}");
|
TelecomSmsTemplate template = new TelecomSmsTemplate();
|
||||||
|
template.setText("Hello World!");
|
||||||
|
template.setMobile("18605120786");
|
||||||
|
|
||||||
|
templateProperties.setTemplate(JSON.toJSONString(template));
|
||||||
|
|
||||||
return templateProperties;
|
return templateProperties;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
NotifierManager notifierManager = new AbstractNotifierManager(notifyConfigManager){};
|
NotifierManager notifierManager = new AbstractNotifierManager(notifyConfigManager) {
|
||||||
|
};
|
||||||
|
|
||||||
// register
|
// register
|
||||||
AliyunSmsNotifierProvider aliyunSmsNotifierProvider = new AliyunSmsNotifierProvider(templateManager);
|
|
||||||
TelecomSmsNotifierProvider telecomSmsNotifierProvider = new TelecomSmsNotifierProvider(templateManager);
|
TelecomSmsNotifierProvider telecomSmsNotifierProvider = new TelecomSmsNotifierProvider(templateManager);
|
||||||
|
|
||||||
notifierManager.register(aliyunSmsNotifierProvider);
|
|
||||||
notifierManager.register(telecomSmsNotifierProvider);
|
notifierManager.register(telecomSmsNotifierProvider);
|
||||||
|
|
||||||
templateManager.register(aliyunSmsNotifierProvider);
|
|
||||||
templateManager.register(telecomSmsNotifierProvider);
|
templateManager.register(telecomSmsNotifierProvider);
|
||||||
|
|
||||||
Notifier<Template> notifier = notifierManager.getNotifier(DefaultNotifyType.sms, "123");
|
Notifier<Template> notifier = notifierManager.getNotifier(DefaultNotifyType.sms, "123");
|
||||||
|
Loading…
Reference in New Issue
Block a user