Search in sources :

Example 1 with Mailbox

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

the class MailBatchConsumerTest method testBatchConsumer.

@Test
public void testBatchConsumer() throws Exception {
    Mailbox mailbox = Mailbox.get("jones@localhost");
    assertEquals(5, mailbox.size());
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(5);
    mock.expectsAscending(body());
    mock.message(0).exchangeProperty(Exchange.BATCH_INDEX).isEqualTo(0);
    mock.message(1).exchangeProperty(Exchange.BATCH_INDEX).isEqualTo(1);
    mock.message(2).exchangeProperty(Exchange.BATCH_INDEX).isEqualTo(2);
    mock.message(3).exchangeProperty(Exchange.BATCH_INDEX).isEqualTo(3);
    mock.message(4).exchangeProperty(Exchange.BATCH_INDEX).isEqualTo(4);
    mock.message(0).exchangeProperty(Exchange.BATCH_COMPLETE).isEqualTo(false);
    mock.message(1).exchangeProperty(Exchange.BATCH_COMPLETE).isEqualTo(false);
    mock.message(2).exchangeProperty(Exchange.BATCH_COMPLETE).isEqualTo(false);
    mock.message(3).exchangeProperty(Exchange.BATCH_COMPLETE).isEqualTo(false);
    mock.message(3).exchangeProperty(Exchange.BATCH_COMPLETE).isEqualTo(false);
    mock.message(4).exchangeProperty(Exchange.BATCH_COMPLETE).isEqualTo(true);
    mock.expectedPropertyReceived(Exchange.BATCH_SIZE, 5);
    assertMockEndpointsSatisfied();
}
Also used : Mailbox(org.jvnet.mock_javamail.Mailbox) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 2 with Mailbox

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

the class MailCommitOnCompletionTest method testCommitOnCompletion.

@Test
public void testCommitOnCompletion() throws Exception {
    Mailbox mailbox = Mailbox.get("jones@localhost");
    assertEquals(5, mailbox.size());
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("Hi Message 0", "Hi Message 1", "Hi Message 2", "Hi Message 3", "Hi Message 4");
    mock.assertIsSatisfied();
    // wait a bit because delete is on completion
    Thread.sleep(1000);
    assertEquals(0, mailbox.size());
}
Also used : Mailbox(org.jvnet.mock_javamail.Mailbox) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 3 with Mailbox

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

the class MailComponentRecipientSetTest method testMultipleEndpoints.

@Test
public void testMultipleEndpoints() throws Exception {
    Mailbox.clearAll();
    template.sendBodyAndHeader("direct:a", "Hello World", "Subject", "Hello a");
    template.sendBodyAndHeader("direct:b", "Bye World", "Subject", "Hello b");
    template.sendBodyAndHeader("direct:c", "Hi World", "Subject", "Hello c");
    Mailbox boxA = Mailbox.get("a@a.com");
    assertEquals(1, boxA.size());
    assertEquals("Hello a", boxA.get(0).getSubject());
    assertEquals("Hello World", boxA.get(0).getContent());
    assertEquals("me@me.com", boxA.get(0).getFrom()[0].toString());
    assertEquals("spy@spy.com", boxA.get(0).getRecipients(Message.RecipientType.CC)[0].toString());
    Mailbox boxB = Mailbox.get("b@b.com");
    assertEquals(1, boxB.size());
    assertEquals("Hello b", boxB.get(0).getSubject());
    assertEquals("Bye World", boxB.get(0).getContent());
    assertEquals("you@you.com", boxB.get(0).getFrom()[0].toString());
    assertEquals("spy@spy.com", boxB.get(0).getRecipients(Message.RecipientType.CC)[0].toString());
    Mailbox boxC = Mailbox.get("c@c.com");
    assertEquals(1, boxC.size());
    assertEquals("Hello c", boxC.get(0).getSubject());
    assertEquals("Hi World", boxC.get(0).getContent());
    assertEquals("me@me.com", boxC.get(0).getFrom()[0].toString());
    assertEquals("you@you.com", boxC.get(0).getRecipients(Message.RecipientType.CC)[0].toString());
    assertEquals("them@them.com", boxC.get(0).getRecipients(Message.RecipientType.CC)[1].toString());
// no spy as its overridden by endpoint
}
Also used : Mailbox(org.jvnet.mock_javamail.Mailbox) Test(org.junit.Test)

Example 4 with Mailbox

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

the class MailContentTypeTest method testSendHtmlMail.

@Test
public void testSendHtmlMail() throws Exception {
    Mailbox.clearAll();
    sendBody("direct:a", "<html><body><h1>Hello</h1>World</body></html>");
    Mailbox box = Mailbox.get("claus@localhost");
    Message msg = box.get(0);
    assertTrue(msg.getContentType().startsWith("text/html"));
    assertEquals("<html><body><h1>Hello</h1>World</body></html>", msg.getContent());
}
Also used : Mailbox(org.jvnet.mock_javamail.Mailbox) Message(javax.mail.Message) Test(org.junit.Test)

Example 5 with Mailbox

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

the class MailContentTypeTest method testSendPlainMail.

@Test
public void testSendPlainMail() throws Exception {
    Mailbox.clearAll();
    sendBody("direct:b", "Hello World");
    Mailbox box = Mailbox.get("claus@localhost");
    Message msg = box.get(0);
    assertTrue(msg.getContentType().startsWith("text/plain"));
    assertEquals("Hello World", msg.getContent());
}
Also used : Mailbox(org.jvnet.mock_javamail.Mailbox) Message(javax.mail.Message) 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