Search in sources :

Example 41 with Mailbox

use of org.jvnet.mock_javamail.Mailbox in project camel by apache.

the class MailRecipientsPipeIssueTest method testMultiRecipients.

@Test
public void testMultiRecipients() throws Exception {
    Mailbox.clearAll();
    sendBody("direct:a", "Camel does really rock");
    Mailbox inbox = Mailbox.get("camel|pipes@riders.org");
    Message msg = inbox.get(0);
    assertEquals("you@apache.org", msg.getFrom()[0].toString());
    assertEquals("camel|pipes@riders.org", msg.getRecipients(Message.RecipientType.TO)[0].toString());
    assertEquals("easy@riders.org", msg.getRecipients(Message.RecipientType.TO)[1].toString());
    inbox = Mailbox.get("easy@riders.org");
    msg = inbox.get(0);
    assertEquals("you@apache.org", msg.getFrom()[0].toString());
    assertEquals("camel|pipes@riders.org", msg.getRecipients(Message.RecipientType.TO)[0].toString());
    assertEquals("easy@riders.org", msg.getRecipients(Message.RecipientType.TO)[1].toString());
}
Also used : Mailbox(org.jvnet.mock_javamail.Mailbox) Message(javax.mail.Message) Test(org.junit.Test)

Example 42 with Mailbox

use of org.jvnet.mock_javamail.Mailbox in project camel by apache.

the class MailRecipientsTest method testMultiRecipients.

@Test
public void testMultiRecipients() throws Exception {
    Mailbox.clearAll();
    sendBody("direct:a", "Camel does really rock");
    Mailbox inbox = Mailbox.get("camel@riders.org");
    Message msg = inbox.get(0);
    assertEquals("you@apache.org", msg.getFrom()[0].toString());
    assertEquals("camel@riders.org", msg.getRecipients(Message.RecipientType.TO)[0].toString());
    assertEquals("easy@riders.org", msg.getRecipients(Message.RecipientType.TO)[1].toString());
    assertEquals("me@you.org", msg.getRecipients(Message.RecipientType.CC)[0].toString());
    assertEquals("someone@somewhere.org", msg.getRecipients(Message.RecipientType.BCC)[0].toString());
    inbox = Mailbox.get("easy@riders.org");
    msg = inbox.get(0);
    assertEquals("you@apache.org", msg.getFrom()[0].toString());
    assertEquals("camel@riders.org", msg.getRecipients(Message.RecipientType.TO)[0].toString());
    assertEquals("easy@riders.org", msg.getRecipients(Message.RecipientType.TO)[1].toString());
    assertEquals("me@you.org", msg.getRecipients(Message.RecipientType.CC)[0].toString());
    assertEquals("someone@somewhere.org", msg.getRecipients(Message.RecipientType.BCC)[0].toString());
    inbox = Mailbox.get("me@you.org");
    msg = inbox.get(0);
    assertEquals("you@apache.org", msg.getFrom()[0].toString());
    assertEquals("camel@riders.org", msg.getRecipients(Message.RecipientType.TO)[0].toString());
    assertEquals("easy@riders.org", msg.getRecipients(Message.RecipientType.TO)[1].toString());
    assertEquals("me@you.org", msg.getRecipients(Message.RecipientType.CC)[0].toString());
    assertEquals("someone@somewhere.org", msg.getRecipients(Message.RecipientType.BCC)[0].toString());
    inbox = Mailbox.get("someone@somewhere.org");
    msg = inbox.get(0);
    assertEquals("you@apache.org", msg.getFrom()[0].toString());
    assertEquals("camel@riders.org", msg.getRecipients(Message.RecipientType.TO)[0].toString());
    assertEquals("easy@riders.org", msg.getRecipients(Message.RecipientType.TO)[1].toString());
    assertEquals("me@you.org", msg.getRecipients(Message.RecipientType.CC)[0].toString());
    assertEquals("someone@somewhere.org", msg.getRecipients(Message.RecipientType.BCC)[0].toString());
}
Also used : Mailbox(org.jvnet.mock_javamail.Mailbox) Message(javax.mail.Message) Test(org.junit.Test)

Example 43 with Mailbox

use of org.jvnet.mock_javamail.Mailbox in project camel by apache.

the class MailSortTermTest method testSortTerm.

@Test
public void testSortTerm() throws Exception {
    Mailbox mailbox = Mailbox.get("bill@localhost");
    assertEquals(3, mailbox.size());
    // This one has search term *not* set
    MockEndpoint mockAsc = getMockEndpoint("mock:resultAscending");
    mockAsc.expectedBodiesReceived("Earlier date", "Later date");
    context.startAllRoutes();
    assertMockEndpointsSatisfied();
}
Also used : Mailbox(org.jvnet.mock_javamail.Mailbox) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 44 with Mailbox

use of org.jvnet.mock_javamail.Mailbox in project camel by apache.

the class FromFileSendMailTest method testSendFileAsMail.

@Test
public void testSendFileAsMail() throws Exception {
    Mailbox.clearAll();
    MockEndpoint result = getMockEndpoint("mock:result");
    result.expectedMessageCount(1);
    result.message(0).body().isInstanceOf(GenericFile.class);
    template.sendBodyAndHeader("file://target/mailtext", "Hi how are you", Exchange.FILE_NAME, "mail.txt");
    assertMockEndpointsSatisfied();
    Mailbox mailbox = Mailbox.get("james@localhost");
    assertEquals(1, mailbox.size());
    Object body = mailbox.get(0).getContent();
    assertEquals("Hi how are you", body);
    Object subject = mailbox.get(0).getSubject();
    assertEquals("Hello World", subject);
}
Also used : Mailbox(org.jvnet.mock_javamail.Mailbox) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Aggregations

Mailbox (org.jvnet.mock_javamail.Mailbox)44 Test (org.junit.Test)39 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)20 Message (javax.mail.Message)18 HashMap (java.util.HashMap)5 MimeMessage (javax.mail.internet.MimeMessage)3 Address (javax.mail.Address)2 Exchange (org.apache.camel.Exchange)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 HashSet (java.util.HashSet)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1 Folder (javax.mail.Folder)1 Session (javax.mail.Session)1 InternetAddress (javax.mail.internet.InternetAddress)1 MimeMultipart (javax.mail.internet.MimeMultipart)1 NotifyBuilder (org.apache.camel.builder.NotifyBuilder)1