Search in sources :

Example 41 with MimePackage

use of com.axway.ats.action.objects.MimePackage in project ats-framework by Axway.

the class Test_MimePackage method testGetContentOfNewlyCreatedMixedMail.

@Test
public void testGetContentOfNewlyCreatedMixedMail() throws PackageException {
    MimePackage mimePack = new MimePackage();
    mimePack.setHeader("Content-type", "multipart/alternative");
    String contentPlain = "my test mail content";
    String contentHtml = "<html>" + contentPlain + "</html>";
    mimePack.addPart("dummy", MimePackage.PART_TYPE_TEXT_PLAIN);
    mimePack.addPart("dummyHtml", MimePackage.PART_TYPE_TEXT_HTML);
    mimePack.setBody(contentPlain, contentHtml);
    assertEquals(contentPlain, mimePack.getPlainTextBody());
    assertEquals(contentHtml, mimePack.getHtmlTextBody());
}
Also used : MimePackage(com.axway.ats.action.objects.MimePackage) BaseTest(com.axway.ats.action.BaseTest) Test(org.junit.Test)

Example 42 with MimePackage

use of com.axway.ats.action.objects.MimePackage in project ats-framework by Axway.

the class Test_MimePackage method setBody_textPart_only.

@Test
public void setBody_textPart_only() throws Exception {
    // create a new message. It comes by default with TEXT part only(no multiparts)
    MimePackage newMailMessage = new MimePackage();
    // verify there are no any parts yet
    try {
        newMailMessage.getPart(0, false);
        assertTrue("There are some parts, while we expect to have none", false);
    } catch (NoSuchMimePartException e) {
    }
    // set the body, effectively the only TEXT part
    newMailMessage.setBody("text plain body");
    MimePart textPart = newMailMessage.getPart(0, false);
    assertEquals(textPart.getContent(), "text plain body");
    assertEquals(textPart.getContentType(), "text/plain; charset=us-ascii");
    // verify there are no more parts
    try {
        newMailMessage.getPart(1, false);
        assertTrue("There is more than 1 part, while we expect to have just 1", false);
    } catch (NoSuchMimePartException e) {
    }
}
Also used : MimePackage(com.axway.ats.action.objects.MimePackage) NoSuchMimePartException(com.axway.ats.action.objects.model.NoSuchMimePartException) MimePart(javax.mail.internet.MimePart) BaseTest(com.axway.ats.action.BaseTest) Test(org.junit.Test)

Example 43 with MimePackage

use of com.axway.ats.action.objects.MimePackage in project ats-framework by Axway.

the class Test_MimePackage method setBody_multiParts_with_textPart_only.

@Test
public void setBody_multiParts_with_textPart_only() throws Exception {
    // create a new message and add TEXT part to it
    MimePackage newMailMessage = new MimePackage();
    newMailMessage.addPart("text plain body", MimePackage.PART_TYPE_TEXT_PLAIN);
    MimePart textPart = newMailMessage.getPart(0, false);
    assertEquals(textPart.getContent(), "text plain body");
    assertEquals(textPart.getContentType(), "text/plain; charset=us-ascii");
    // modify the only part
    newMailMessage.setBody("new body");
    // verify the modifications
    MimePart newTextPart = newMailMessage.getPart(0, false);
    assertEquals(newTextPart.getContent(), "new body");
    assertEquals(newTextPart.getContentType(), "text/plain; charset=us-ascii");
    // verify there are no more parts
    try {
        newMailMessage.getPart(1, false);
        assertTrue("There is more than 1 part, while we expect to have just 1", false);
    } catch (NoSuchMimePartException e) {
    }
}
Also used : MimePackage(com.axway.ats.action.objects.MimePackage) MimePart(javax.mail.internet.MimePart) NoSuchMimePartException(com.axway.ats.action.objects.model.NoSuchMimePartException) BaseTest(com.axway.ats.action.BaseTest) Test(org.junit.Test)

Example 44 with MimePackage

use of com.axway.ats.action.objects.MimePackage in project ats-framework by Axway.

the class Test_MimePackage method testGetContentOfNewlyCreatedTextOnlyMail.

@Test
public void testGetContentOfNewlyCreatedTextOnlyMail() throws PackageException {
    MimePackage mimePack = new MimePackage();
    String contentPlain = "my test mail content";
    // optional as by default the content type is text/plain
    mimePack.addPart("dummy", MimePackage.PART_TYPE_TEXT_PLAIN);
    mimePack.setBody(contentPlain);
    assertEquals(contentPlain, mimePack.getPlainTextBody());
    assertEquals(null, mimePack.getHtmlTextBody());
}
Also used : MimePackage(com.axway.ats.action.objects.MimePackage) BaseTest(com.axway.ats.action.BaseTest) Test(org.junit.Test)

Example 45 with MimePackage

use of com.axway.ats.action.objects.MimePackage in project ats-framework by Axway.

the class Test_MimePackage method testGetContentOfNewlyCreatedHtmlOnlyMail.

@Test
public void testGetContentOfNewlyCreatedHtmlOnlyMail() throws PackageException {
    MimePackage mimePack = new MimePackage();
    String contentHtml = "<html>my test mail content</html>";
    mimePack.addPart(contentHtml, MimePackage.PART_TYPE_TEXT_HTML, "UTF-8");
    assertEquals(contentHtml, mimePack.getHtmlTextBody());
    assertEquals(null, mimePack.getPlainTextBody());
}
Also used : MimePackage(com.axway.ats.action.objects.MimePackage) BaseTest(com.axway.ats.action.BaseTest) Test(org.junit.Test)

Aggregations

MimePackage (com.axway.ats.action.objects.MimePackage)53 Test (org.junit.Test)35 BaseTest (com.axway.ats.action.BaseTest)29 ImapMetaData (com.axway.ats.rbv.imap.ImapMetaData)15 Before (org.junit.Before)7 PackageException (com.axway.ats.action.objects.model.PackageException)6 BaseTest (com.axway.ats.rbv.BaseTest)6 FileInputStream (java.io.FileInputStream)6 MimePart (javax.mail.internet.MimePart)6 NoSuchMimePartException (com.axway.ats.action.objects.model.NoSuchMimePartException)5 RbvException (com.axway.ats.rbv.model.RbvException)5 Test_ImapStorage (com.axway.ats.rbv.imap.Test_ImapStorage)4 StringInMimePartRule (com.axway.ats.rbv.imap.rules.StringInMimePartRule)4 MimePartRule (com.axway.ats.rbv.imap.rules.MimePartRule)2 InputStream (java.io.InputStream)2 MessagingException (javax.mail.MessagingException)2 BeforeClass (org.junit.BeforeClass)2 MailSender (com.axway.ats.action.mail.MailSender)1 MailTransportListener (com.axway.ats.action.mail.model.MailTransportListener)1 DELIVERY_STATE (com.axway.ats.action.mail.model.MailTransportListener.DELIVERY_STATE)1