Search in sources :

Example 66 with WiserMessage

use of org.subethamail.wiser.WiserMessage in project jbpm by kiegroup.

the class SendHtmlTest method useEmailWorkItemHandlerWithAuthentication.

@Test
public void useEmailWorkItemHandlerWithAuthentication() throws Exception {
    // Add authentication to Wiser SMTP server
    wiser.getServer().setAuthenticationHandlerFactory(new TestAuthHandlerFactory());
    // Input
    String testMethodName = Thread.currentThread().getStackTrace()[1].getMethodName();
    String toAddress = "rgivens@yahoo.com";
    String fromAddress = "rgivens@kty.us.gov";
    EmailWorkItemHandler handler = new EmailWorkItemHandler();
    handler.setConnection(emailHost, emailPort, authUsername, authPassword);
    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setParameter("To", toAddress);
    workItem.setParameter("From", fromAddress);
    workItem.setParameter("Reply-To", fromAddress);
    workItem.setParameter("Subject", "Test mail for " + testMethodName);
    workItem.setParameter("Body", "Don't forget to check on Boyd later today.");
    WorkItemManager manager = new DefaultWorkItemManager(null);
    handler.executeWorkItem(workItem, manager);
    List<WiserMessage> messages = wiser.getMessages();
    assertEquals(1, messages.size());
    for (WiserMessage wiserMessage : messages) {
        MimeMessage message = wiserMessage.getMimeMessage();
        assertEquals(workItem.getParameter("Subject"), message.getSubject());
        assertTrue(Arrays.equals(InternetAddress.parse(toAddress), message.getRecipients(RecipientType.TO)));
    }
}
Also used : DefaultWorkItemManager(org.drools.core.process.instance.impl.DefaultWorkItemManager) MimeMessage(javax.mail.internet.MimeMessage) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) WiserMessage(org.subethamail.wiser.WiserMessage) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) DefaultWorkItemManager(org.drools.core.process.instance.impl.DefaultWorkItemManager) AbstractBaseTest(org.jbpm.test.AbstractBaseTest) Test(org.junit.Test)

Example 67 with WiserMessage

use of org.subethamail.wiser.WiserMessage in project jbpm by kiegroup.

the class EmailNotificationPublisherTest method testEmailNotificationWithTemplate.

@Test
public void testEmailNotificationWithTemplate() throws Exception {
    EmailNotificationPublisher publisher = new EmailNotificationPublisher(connection, userInfo);
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("Name", "John Doe");
    Set<OrganizationalEntity> recipients = new HashSet<>(Arrays.asList(factory.newUser("john")));
    publisher.publish("admin@jbpm.org", "Test notification", recipients, "basic-email", parameters);
    assertEquals(1, wiser.getMessages().size());
    String expectedBody = "<html><body>Hello John Doe</body></html>";
    MimeMessage msg = ((WiserMessage) wiser.getMessages().get(0)).getMimeMessage();
    // Side effect of MIME encoding (I think.. ): \r\n..
    String content = ((String) msg.getContent()).replace("\r\n", "");
    assertEquals(expectedBody, content);
    assertEquals("Test notification", msg.getSubject());
    assertEquals("admin@jbpm.org", ((InternetAddress) msg.getFrom()[0]).getAddress());
    assertEquals("john@domain.com", ((InternetAddress) msg.getRecipients(RecipientType.TO)[0]).getAddress());
    assertNull(msg.getRecipients(RecipientType.CC));
    assertNull(msg.getRecipients(RecipientType.BCC));
}
Also used : OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) HashMap(java.util.HashMap) MimeMessage(javax.mail.internet.MimeMessage) WiserMessage(org.subethamail.wiser.WiserMessage) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Test(org.junit.Test)

Aggregations

WiserMessage (org.subethamail.wiser.WiserMessage)67 MimeMessage (javax.mail.internet.MimeMessage)34 Test (org.junit.Test)27 HashMap (java.util.HashMap)26 Deployment (org.activiti.engine.test.Deployment)22 ArrayList (java.util.ArrayList)12 MimeMultipart (javax.mail.internet.MimeMultipart)12 Deployment (org.camunda.bpm.engine.test.Deployment)10 Date (java.util.Date)9 WorkItemImpl (org.drools.core.process.instance.impl.WorkItemImpl)6 AbstractBaseTest (org.jbpm.test.AbstractBaseTest)6 InputStreamReader (java.io.InputStreamReader)5 Reader (java.io.Reader)5 DefaultWorkItemManager (org.drools.core.process.instance.impl.DefaultWorkItemManager)5 CountDownTaskEventListener (org.jbpm.services.task.util.CountDownTaskEventListener)5 WorkItemManager (org.kie.api.runtime.process.WorkItemManager)5 InternalTask (org.kie.internal.task.api.model.InternalTask)5 File (java.io.File)4 LinkedHashSet (java.util.LinkedHashSet)4 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)4