提交 4be5e159 编写于 作者: C chengshiwen

Fix unit tests

上级 045980b7
...@@ -96,9 +96,6 @@ public class EmailAlertPlugin implements AlertPlugin { ...@@ -96,9 +96,6 @@ public class EmailAlertPlugin implements AlertPlugin {
retMaps = emailManager.send(receviersList, receviersCcList, alert.getTitle(), alert.getContent(), retMaps = emailManager.send(receviersList, receviersCcList, alert.getTitle(), alert.getContent(),
alert.getShowType()); alert.getShowType());
//send flag
boolean flag = false;
if (retMaps == null) { if (retMaps == null) {
retMaps = new HashMap<>(); retMaps = new HashMap<>();
retMaps.put(Constants.MESSAGE, "alert send error."); retMaps.put(Constants.MESSAGE, "alert send error.");
...@@ -107,9 +104,12 @@ public class EmailAlertPlugin implements AlertPlugin { ...@@ -107,9 +104,12 @@ public class EmailAlertPlugin implements AlertPlugin {
return retMaps; return retMaps;
} }
flag = Boolean.parseBoolean(String.valueOf(retMaps.get(Constants.STATUS))); boolean enabled = Boolean.parseBoolean(String.valueOf(retMaps.get(Constants.MAIL_ENABLED)));
boolean status = Boolean.parseBoolean(String.valueOf(retMaps.get(Constants.STATUS)));
if (flag) { if (!enabled) {
logger.warn("mail wasn't sent since the mail config isn't set");
retMaps.put(Constants.MESSAGE, "mail wasn't sent since the mail config isn't set");
} else if (status) {
logger.info("alert send success"); logger.info("alert send success");
retMaps.put(Constants.MESSAGE, "email send success."); retMaps.put(Constants.MESSAGE, "email send success.");
if (EnterpriseWeChatUtils.isEnable()) { if (EnterpriseWeChatUtils.isEnable()) {
...@@ -121,7 +121,6 @@ public class EmailAlertPlugin implements AlertPlugin { ...@@ -121,7 +121,6 @@ public class EmailAlertPlugin implements AlertPlugin {
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);
} }
} }
} else { } else {
retMaps.put(Constants.MESSAGE, "alert send error."); retMaps.put(Constants.MESSAGE, "alert send error.");
logger.info("alert send error : {}", retMaps.get(Constants.MESSAGE)); logger.info("alert send error : {}", retMaps.get(Constants.MESSAGE));
......
...@@ -75,6 +75,7 @@ public class EmailAlertPluginTest { ...@@ -75,6 +75,7 @@ public class EmailAlertPluginTest {
List<String> list = new ArrayList<String>(){{ add("xx@xx.com"); }}; List<String> list = new ArrayList<String>(){{ add("xx@xx.com"); }};
alertInfo.addProp("receivers", list); alertInfo.addProp("receivers", list);
Map<String, Object> ret = plugin.process(alertInfo); Map<String, Object> ret = plugin.process(alertInfo);
assertFalse(Boolean.parseBoolean(String.valueOf(ret.get(Constants.STATUS)))); assertFalse(Boolean.parseBoolean(String.valueOf(ret.get(Constants.MAIL_ENABLED))));
assertTrue(Boolean.parseBoolean(String.valueOf(ret.get(Constants.STATUS))));
} }
} }
\ No newline at end of file
...@@ -453,11 +453,11 @@ public class SqlTask extends AbstractTask { ...@@ -453,11 +453,11 @@ public class SqlTask extends AbstractTask {
if(EnumUtils.isValidEnum(ShowType.class,showTypeName)){ if(EnumUtils.isValidEnum(ShowType.class,showTypeName)){
Map<String, Object> mailResult = MailUtils.sendMails(receiversList, Map<String, Object> mailResult = MailUtils.sendMails(receiversList,
receiversCcList, title, content, ShowType.valueOf(showTypeName).getDescp()); receiversCcList, title, content, ShowType.valueOf(showTypeName).getDescp());
if(!(boolean) mailResult.get(STATUS)){ if(!(boolean) mailResult.get(MAIL_ENABLED)){
throw new RuntimeException("send mail failed!");
}else if(!(boolean) mailResult.get(MAIL_ENABLED)){
logger.info("mail info : {} {}", title, content); logger.info("mail info : {} {}", title, content);
logger.warn("mail wasn't sent since the mail config isn't set"); logger.warn("mail wasn't sent since the mail config isn't set");
}else if(!(boolean) mailResult.get(STATUS)){
throw new RuntimeException("send mail failed!");
} }
}else{ }else{
logger.error("showType: {} is not valid " ,showTypeName); logger.error("showType: {} is not valid " ,showTypeName);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册