Search in sources :

Example 46 with WiserMessage

use of org.subethamail.wiser.WiserMessage in project Activiti by Activiti.

the class EmailSendTaskTest method testTextMailWithFileAttachment.

@Deployment
public void testTextMailWithFileAttachment() throws Exception {
    HashMap<String, Object> vars = new HashMap<String, Object>();
    vars.put("attachmentsBean", new AttachmentsBean());
    runtimeService.startProcessInstanceByKey("textMailWithFileAttachment", vars);
    List<WiserMessage> messages = wiser.getMessages();
    assertEquals(1, messages.size());
    WiserMessage message = messages.get(0);
    MimeMultipart mm = (MimeMultipart) message.getMimeMessage().getContent();
    assertEquals(2, mm.getCount());
    String attachmentFileName = mm.getBodyPart(1).getDataHandler().getName();
    assertEquals(new AttachmentsBean().getFile().getName(), attachmentFileName);
}
Also used : HashMap(java.util.HashMap) MimeMultipart(javax.mail.internet.MimeMultipart) WiserMessage(org.subethamail.wiser.WiserMessage) Deployment(org.activiti.engine.test.Deployment)

Example 47 with WiserMessage

use of org.subethamail.wiser.WiserMessage in project Activiti by Activiti.

the class EmailSendTaskTest method testTextMailWithDataSourceAttachment.

@Deployment
public void testTextMailWithDataSourceAttachment() throws Exception {
    String fileName = "file-name-to-be-displayed";
    String fileContent = "This is the file content";
    HashMap<String, Object> vars = new HashMap<String, Object>();
    vars.put("attachmentsBean", new AttachmentsBean());
    vars.put("fileContent", fileContent);
    vars.put("fileName", fileName);
    runtimeService.startProcessInstanceByKey("textMailWithDataSourceAttachment", vars);
    List<WiserMessage> messages = wiser.getMessages();
    assertEquals(1, messages.size());
    WiserMessage message = messages.get(0);
    MimeMultipart mm = (MimeMultipart) message.getMimeMessage().getContent();
    assertEquals(2, mm.getCount());
    String attachmentFileName = mm.getBodyPart(1).getDataHandler().getName();
    assertEquals(fileName, attachmentFileName);
}
Also used : HashMap(java.util.HashMap) MimeMultipart(javax.mail.internet.MimeMultipart) WiserMessage(org.subethamail.wiser.WiserMessage) Deployment(org.activiti.engine.test.Deployment)

Example 48 with WiserMessage

use of org.subethamail.wiser.WiserMessage in project Activiti by Activiti.

the class EmailSendTaskTest method testHtmlMailWithFileAttachment.

@Deployment
public void testHtmlMailWithFileAttachment() throws Exception {
    HashMap<String, Object> vars = new HashMap<String, Object>();
    vars.put("attachmentsBean", new AttachmentsBean());
    vars.put("gender", "male");
    runtimeService.startProcessInstanceByKey("htmlMailWithFileAttachment", vars);
    List<WiserMessage> messages = wiser.getMessages();
    assertEquals(1, messages.size());
    WiserMessage message = messages.get(0);
    MimeMultipart mm = (MimeMultipart) message.getMimeMessage().getContent();
    assertEquals(2, mm.getCount());
    String attachmentFileName = mm.getBodyPart(1).getDataHandler().getName();
    assertEquals(new AttachmentsBean().getFile().getName(), attachmentFileName);
}
Also used : HashMap(java.util.HashMap) MimeMultipart(javax.mail.internet.MimeMultipart) WiserMessage(org.subethamail.wiser.WiserMessage) Deployment(org.activiti.engine.test.Deployment)

Example 49 with WiserMessage

use of org.subethamail.wiser.WiserMessage in project spring-integration-samples by spring-projects.

the class MimeMessageParsingTest method testProcessingOfEmailAttachments.

/**
 * This test will create a Mime Message that contains an Attachment, send it
 * to an SMTP Server (Using Wiser) and retrieve and process the Mime Message.
 *
 * This test verifies that the parsing of the retrieved Mime Message is
 * successful and that the correct number of {@link EmailFragment}s is created.
 */
@Test
public void testProcessingOfEmailAttachments() {
    final JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
    mailSender.setPort(this.wiserPort);
    final MimeMessage message = mailSender.createMimeMessage();
    final String pictureName = "picture.png";
    final ByteArrayResource byteArrayResource = getFileData(pictureName);
    try {
        final MimeMessageHelper helper = new MimeMessageHelper(message, true);
        helper.setFrom("testfrom@springintegration.org");
        helper.setTo("testto@springintegration.org");
        helper.setSubject("Parsing of Attachments");
        helper.setText("Spring Integration Rocks!");
        helper.addAttachment(pictureName, byteArrayResource, "image/png");
    } catch (MessagingException e) {
        throw new MailParseException(e);
    }
    mailSender.send(message);
    final List<WiserMessage> wiserMessages = wiser.getMessages();
    Assert.assertTrue(wiserMessages.size() == 1);
    boolean foundTextMessage = false;
    boolean foundPicture = false;
    for (WiserMessage wiserMessage : wiserMessages) {
        final List<EmailFragment> emailFragments = new ArrayList<EmailFragment>();
        try {
            final MimeMessage mailMessage = wiserMessage.getMimeMessage();
            EmailParserUtils.handleMessage(null, mailMessage, emailFragments);
        } catch (MessagingException e) {
            throw new IllegalStateException("Error while retrieving Mime Message.");
        }
        Assert.assertTrue(emailFragments.size() == 2);
        for (EmailFragment emailFragment : emailFragments) {
            if ("picture.png".equals(emailFragment.getFilename())) {
                foundPicture = true;
            }
            if ("message.txt".equals(emailFragment.getFilename())) {
                foundTextMessage = true;
            }
        }
        Assert.assertTrue(foundPicture);
        Assert.assertTrue(foundTextMessage);
    }
}
Also used : MessagingException(javax.mail.MessagingException) ArrayList(java.util.ArrayList) WiserMessage(org.subethamail.wiser.WiserMessage) ByteArrayResource(org.springframework.core.io.ByteArrayResource) MimeMessageHelper(org.springframework.mail.javamail.MimeMessageHelper) JavaMailSenderImpl(org.springframework.mail.javamail.JavaMailSenderImpl) MimeMessage(javax.mail.internet.MimeMessage) MailParseException(org.springframework.mail.MailParseException) EmailFragment(org.springframework.integration.samples.mailattachments.support.EmailFragment) Test(org.junit.Test)

Example 50 with WiserMessage

use of org.subethamail.wiser.WiserMessage in project motech by motech.

the class EmailBundleIT method testEmailService.

@Test
public void testEmailService() throws MessagingException, IOException, EmailSendException {
    ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
        mailService.send("from@from.com", "to@to.com", "test", "test");
    } finally {
        Thread.currentThread().setContextClassLoader(oldCl);
    }
    WiserMessage message = smtpServer.getMessages().get(0);
    String msgTxt = (String) message.getMimeMessage().getContent();
    assertNotNull(msgTxt);
    assertEquals("test", msgTxt.trim());
}
Also used : WiserMessage(org.subethamail.wiser.WiserMessage) 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