Search in sources :

Example 1 with EmailService

use of password.pwm.svc.email.EmailService in project pwm by pwm-project.

the class EmailQueueManagerTest method testConvertEmailItemToMessage.

@Test
public void testConvertEmailItemToMessage() throws MessagingException, IOException {
    EmailService emailService = new EmailService();
    Configuration config = Mockito.mock(Configuration.class);
    Mockito.when(config.readAppProperty(AppProperty.SMTP_SUBJECT_ENCODING_CHARSET)).thenReturn("UTF8");
    EmailItemBean emailItemBean = new EmailItemBean("fred@flintstones.tv, barney@flintstones.tv", "bedrock-admin@flintstones.tv", "Test Subject", "bodyPlain", "bodyHtml");
    EmailServer emailServer = EmailServer.builder().javaMailProps(new Properties()).build();
    List<Message> messages = EmailServerUtil.convertEmailItemToMessages(emailItemBean, config, emailServer);
    Assert.assertEquals(2, messages.size());
    Message message = messages.get(0);
    Assert.assertEquals(new InternetAddress("fred@flintstones.tv"), message.getRecipients(Message.RecipientType.TO)[0]);
    Assert.assertEquals(new InternetAddress("bedrock-admin@flintstones.tv"), message.getFrom()[0]);
    Assert.assertEquals("Test Subject", message.getSubject());
    String content = IOUtils.toString(message.getInputStream());
    Assert.assertTrue(content.contains("bodyPlain"));
    Assert.assertTrue(content.contains("bodyHtml"));
    message = messages.get(1);
    Assert.assertEquals(new InternetAddress("barney@flintstones.tv"), message.getRecipients(Message.RecipientType.TO)[0]);
    Assert.assertEquals(new InternetAddress("bedrock-admin@flintstones.tv"), message.getFrom()[0]);
    Assert.assertEquals("Test Subject", message.getSubject());
    content = IOUtils.toString(message.getInputStream());
    Assert.assertTrue(content.contains("bodyPlain"));
    Assert.assertTrue(content.contains("bodyHtml"));
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) Configuration(password.pwm.config.Configuration) EmailItemBean(password.pwm.bean.EmailItemBean) Message(javax.mail.Message) EmailServer(password.pwm.svc.email.EmailServer) EmailService(password.pwm.svc.email.EmailService) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

Properties (java.util.Properties)1 Message (javax.mail.Message)1 InternetAddress (javax.mail.internet.InternetAddress)1 Test (org.junit.Test)1 EmailItemBean (password.pwm.bean.EmailItemBean)1 Configuration (password.pwm.config.Configuration)1 EmailServer (password.pwm.svc.email.EmailServer)1 EmailService (password.pwm.svc.email.EmailService)1