|
|
|
@ -29,20 +29,21 @@ import java.util.LinkedHashMap;
|
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
import org.junit.BeforeClass; |
|
|
|
|
import org.junit.Ignore; |
|
|
|
|
import org.junit.Test; |
|
|
|
|
import org.junit.jupiter.api.Assertions; |
|
|
|
|
import org.junit.jupiter.api.BeforeAll; |
|
|
|
|
import org.junit.jupiter.api.Disabled; |
|
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
|
import org.slf4j.Logger; |
|
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
|
|
|
|
@Ignore("The test case makes no sense") |
|
|
|
|
@Disabled("The test case makes no sense") |
|
|
|
|
public class MailUtilsTest { |
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(MailUtilsTest.class); |
|
|
|
|
static MailSender mailSender; |
|
|
|
|
private static Map<String, String> emailConfig = new HashMap<>(); |
|
|
|
|
private static AlertTemplate alertTemplate; |
|
|
|
|
|
|
|
|
|
@BeforeClass |
|
|
|
|
@BeforeAll |
|
|
|
|
public static void initEmailConfig() { |
|
|
|
|
emailConfig.put(MailParamsConstants.NAME_MAIL_PROTOCOL, "smtp"); |
|
|
|
|
emailConfig.put(MailParamsConstants.NAME_MAIL_SMTP_HOST, "xxx.xxx.com"); |
|
|
|
@ -80,6 +81,35 @@ public class MailUtilsTest {
|
|
|
|
|
content); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void testAuthCheck() { |
|
|
|
|
String title = "Auth Exception"; |
|
|
|
|
String content = list2String(); |
|
|
|
|
|
|
|
|
|
// test auth false and user && pwd null will pass
|
|
|
|
|
emailConfig.put(MailParamsConstants.NAME_MAIL_SMTP_AUTH, "false"); |
|
|
|
|
emailConfig.put(MailParamsConstants.NAME_MAIL_USER, null); |
|
|
|
|
emailConfig.put(MailParamsConstants.NAME_MAIL_PASSWD, null); |
|
|
|
|
mailSender = new MailSender(emailConfig); |
|
|
|
|
mailSender.sendMails(title, content); |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
// test auth true and user null will throw exception
|
|
|
|
|
emailConfig.put(MailParamsConstants.NAME_MAIL_SMTP_AUTH, "true"); |
|
|
|
|
emailConfig.put(MailParamsConstants.NAME_MAIL_USER, null); |
|
|
|
|
mailSender = new MailSender(emailConfig); |
|
|
|
|
mailSender.sendMails(title, content); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
Assertions.assertTrue(e.getMessage().contains(MailParamsConstants.NAME_MAIL_USER)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// test auth true and user && pwd not null will pass
|
|
|
|
|
emailConfig.put(MailParamsConstants.NAME_MAIL_USER, "user"); |
|
|
|
|
emailConfig.put(MailParamsConstants.NAME_MAIL_PASSWD, "passwd"); |
|
|
|
|
mailSender = new MailSender(emailConfig); |
|
|
|
|
mailSender.sendMails(title, content); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public String list2String() { |
|
|
|
|
|
|
|
|
|
LinkedHashMap<String, Object> map1 = new LinkedHashMap<>(); |
|
|
|
|