|
|
@ -18,10 +18,9 @@ |
|
|
|
package org.apache.dolphinscheduler.plugin.alert.email; |
|
|
|
package org.apache.dolphinscheduler.plugin.alert.email; |
|
|
|
|
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.alert.api.AlertConstants; |
|
|
|
import org.apache.dolphinscheduler.alert.api.AlertConstants; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.alert.api.AlertResult; |
|
|
|
import org.apache.dolphinscheduler.alert.api.ShowType; |
|
|
|
import org.apache.dolphinscheduler.alert.api.ShowType; |
|
|
|
import org.apache.dolphinscheduler.common.utils.JSONUtils; |
|
|
|
import org.apache.dolphinscheduler.common.utils.JSONUtils; |
|
|
|
import org.apache.dolphinscheduler.plugin.alert.email.template.AlertTemplate; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.plugin.alert.email.template.DefaultHTMLTemplate; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.HashMap; |
|
|
@ -42,7 +41,6 @@ public class MailUtilsTest { |
|
|
|
private static final Logger logger = LoggerFactory.getLogger(MailUtilsTest.class); |
|
|
|
private static final Logger logger = LoggerFactory.getLogger(MailUtilsTest.class); |
|
|
|
static MailSender mailSender; |
|
|
|
static MailSender mailSender; |
|
|
|
private static Map<String, String> emailConfig = new HashMap<>(); |
|
|
|
private static Map<String, String> emailConfig = new HashMap<>(); |
|
|
|
private static AlertTemplate alertTemplate; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@BeforeAll |
|
|
|
@BeforeAll |
|
|
|
public static void initEmailConfig() { |
|
|
|
public static void initEmailConfig() { |
|
|
@ -59,7 +57,6 @@ public class MailUtilsTest { |
|
|
|
emailConfig.put(MailParamsConstants.NAME_PLUGIN_DEFAULT_EMAIL_RECEIVERS, "347801120@qq.com"); |
|
|
|
emailConfig.put(MailParamsConstants.NAME_PLUGIN_DEFAULT_EMAIL_RECEIVERS, "347801120@qq.com"); |
|
|
|
emailConfig.put(MailParamsConstants.NAME_PLUGIN_DEFAULT_EMAIL_RECEIVERCCS, "347801120@qq.com"); |
|
|
|
emailConfig.put(MailParamsConstants.NAME_PLUGIN_DEFAULT_EMAIL_RECEIVERCCS, "347801120@qq.com"); |
|
|
|
emailConfig.put(AlertConstants.NAME_SHOW_TYPE, ShowType.TEXT.getDescp()); |
|
|
|
emailConfig.put(AlertConstants.NAME_SHOW_TYPE, ShowType.TEXT.getDescp()); |
|
|
|
alertTemplate = new DefaultHTMLTemplate(); |
|
|
|
|
|
|
|
mailSender = new MailSender(emailConfig); |
|
|
|
mailSender = new MailSender(emailConfig); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -77,9 +74,10 @@ public class MailUtilsTest { |
|
|
|
+ "\"Host: 192.168.xx.xx\"," |
|
|
|
+ "\"Host: 192.168.xx.xx\"," |
|
|
|
+ "\"Notify group :4\"]"; |
|
|
|
+ "\"Notify group :4\"]"; |
|
|
|
|
|
|
|
|
|
|
|
mailSender.sendMails( |
|
|
|
AlertResult alertResult = mailSender.sendMails( |
|
|
|
"Mysql Exception", |
|
|
|
"Mysql Exception", |
|
|
|
content); |
|
|
|
content); |
|
|
|
|
|
|
|
Assertions.assertEquals("false", alertResult.getStatus()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
@ -108,7 +106,8 @@ public class MailUtilsTest { |
|
|
|
emailConfig.put(MailParamsConstants.NAME_MAIL_USER, "user"); |
|
|
|
emailConfig.put(MailParamsConstants.NAME_MAIL_USER, "user"); |
|
|
|
emailConfig.put(MailParamsConstants.NAME_MAIL_PASSWD, "passwd"); |
|
|
|
emailConfig.put(MailParamsConstants.NAME_MAIL_PASSWD, "passwd"); |
|
|
|
mailSender = new MailSender(emailConfig); |
|
|
|
mailSender = new MailSender(emailConfig); |
|
|
|
mailSender.sendMails(title, content); |
|
|
|
AlertResult alertResult = mailSender.sendMails(title, content); |
|
|
|
|
|
|
|
Assertions.assertEquals("false", alertResult.getStatus()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public String list2String() { |
|
|
|
public String list2String() { |
|
|
@ -134,7 +133,6 @@ public class MailUtilsTest { |
|
|
|
logger.info(mapjson); |
|
|
|
logger.info(mapjson); |
|
|
|
|
|
|
|
|
|
|
|
return mapjson; |
|
|
|
return mapjson; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
@ -143,7 +141,8 @@ public class MailUtilsTest { |
|
|
|
String content = list2String(); |
|
|
|
String content = list2String(); |
|
|
|
emailConfig.put(AlertConstants.NAME_SHOW_TYPE, ShowType.TABLE.getDescp()); |
|
|
|
emailConfig.put(AlertConstants.NAME_SHOW_TYPE, ShowType.TABLE.getDescp()); |
|
|
|
mailSender = new MailSender(emailConfig); |
|
|
|
mailSender = new MailSender(emailConfig); |
|
|
|
mailSender.sendMails(title, content); |
|
|
|
AlertResult alertResult = mailSender.sendMails(title, content); |
|
|
|
|
|
|
|
Assertions.assertEquals("false", alertResult.getStatus()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
@ -151,7 +150,8 @@ public class MailUtilsTest { |
|
|
|
String content = list2String(); |
|
|
|
String content = list2String(); |
|
|
|
emailConfig.put(AlertConstants.NAME_SHOW_TYPE, ShowType.ATTACHMENT.getDescp()); |
|
|
|
emailConfig.put(AlertConstants.NAME_SHOW_TYPE, ShowType.ATTACHMENT.getDescp()); |
|
|
|
mailSender = new MailSender(emailConfig); |
|
|
|
mailSender = new MailSender(emailConfig); |
|
|
|
mailSender.sendMails("gaojing", content); |
|
|
|
AlertResult alertResult = mailSender.sendMails("gaojing", content); |
|
|
|
|
|
|
|
Assertions.assertEquals("false", alertResult.getStatus()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
@ -159,7 +159,7 @@ public class MailUtilsTest { |
|
|
|
String content = list2String(); |
|
|
|
String content = list2String(); |
|
|
|
emailConfig.put(AlertConstants.NAME_SHOW_TYPE, ShowType.TABLE_ATTACHMENT.getDescp()); |
|
|
|
emailConfig.put(AlertConstants.NAME_SHOW_TYPE, ShowType.TABLE_ATTACHMENT.getDescp()); |
|
|
|
mailSender = new MailSender(emailConfig); |
|
|
|
mailSender = new MailSender(emailConfig); |
|
|
|
mailSender.sendMails("gaojing", content); |
|
|
|
AlertResult alertResult = mailSender.sendMails("gaojing", content); |
|
|
|
|
|
|
|
Assertions.assertEquals("false", alertResult.getStatus()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|