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