Search in sources :

Example 36 with Mailbox

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

the class MailToMultipleEndpointsTest 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());
    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());
    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());
}
Also used : Mailbox(org.jvnet.mock_javamail.Mailbox) Test(org.junit.Test)

Example 37 with Mailbox

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

the class MailUsingHeadersTest method testMailUsingHeaders.

@Test
public void testMailUsingHeaders() throws Exception {
    Mailbox.clearAll();
    // START SNIPPET: e1
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("To", "davsclaus@apache.org");
    map.put("From", "jstrachan@apache.org");
    map.put("Subject", "Camel rocks");
    map.put("CamelFileName", "fileOne");
    map.put("org.apache.camel.test", "value");
    String body = "Hello Claus.\nYes it does.\n\nRegards James.";
    template.sendBodyAndHeaders("smtp://davsclaus@apache.org", body, map);
    // END SNIPPET: e1
    Mailbox box = Mailbox.get("davsclaus@apache.org");
    Message msg = box.get(0);
    assertEquals("davsclaus@apache.org", msg.getRecipients(Message.RecipientType.TO)[0].toString());
    assertEquals("jstrachan@apache.org", msg.getFrom()[0].toString());
    assertEquals("Camel rocks", msg.getSubject());
    assertNull("We should not get the message header here", msg.getHeader("CamelFileName"));
    assertNull("We should not get the message header here", msg.getHeader("org.apache.camel.test"));
}
Also used : Mailbox(org.jvnet.mock_javamail.Mailbox) Message(javax.mail.Message) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 38 with Mailbox

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

the class MailUsingHeadersTest method testMailWithFromInEndpoint.

@Test
public void testMailWithFromInEndpoint() throws Exception {
    Mailbox.clearAll();
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("Subject", "Camel rocks");
    String body = "Hello Claus.\nYes it does.\n\nRegards James.";
    template.sendBodyAndHeaders("smtp://davsclaus@apache.org?from=James Strachan <jstrachan@apache.org>&to=davsclaus@apache.org", body, map);
    Mailbox box = Mailbox.get("davsclaus@apache.org");
    Message msg = box.get(0);
    assertEquals("davsclaus@apache.org", msg.getRecipients(Message.RecipientType.TO)[0].toString());
    assertEquals("James Strachan <jstrachan@apache.org>", msg.getFrom()[0].toString());
    assertEquals("Camel rocks", msg.getSubject());
}
Also used : Mailbox(org.jvnet.mock_javamail.Mailbox) Message(javax.mail.Message) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 39 with Mailbox

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

the class MailFetchSizeTest method testFetchSize.

@Test
public void testFetchSize() throws Exception {
    Mailbox mailbox = Mailbox.get("jones@localhost");
    assertEquals(5, mailbox.size());
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(2);
    mock.expectedBodiesReceived("Message 0", "Message 1");
    // should be done within 2 seconds as no delay when started
    mock.setResultWaitTime(2000L);
    mock.assertIsSatisfied();
    Thread.sleep(500);
    assertEquals(3, mailbox.size());
    // reset mock to assert the next batch of 2 messages polled
    mock.reset();
    mock.expectedMessageCount(2);
    mock.expectedBodiesReceived("Message 2", "Message 3");
    // should be done within 5 (delay) + 1 seconds (polling)
    mock.setResultWaitTime(7000L);
    mock.assertIsSatisfied();
    Thread.sleep(500);
    assertEquals(1, mailbox.size());
    // reset mock to assert the last message polled
    mock.reset();
    mock.expectedMessageCount(1);
    mock.expectedBodiesReceived("Message 4");
    mock.assertIsSatisfied();
}
Also used : Mailbox(org.jvnet.mock_javamail.Mailbox) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 40 with Mailbox

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

the class MailProducerTest method testProduer.

@Test
public void testProduer() throws Exception {
    Mailbox.clearAll();
    getMockEndpoint("mock:result").expectedMessageCount(1);
    template.sendBodyAndHeader("direct:start", "Message ", "To", "someone@localhost");
    assertMockEndpointsSatisfied();
    // need to check the message header
    Exchange exchange = getMockEndpoint("mock:result").getExchanges().get(0);
    assertNotNull("The message id should not be null", exchange.getIn().getHeader(MailConstants.MAIL_MESSAGE_ID));
    Mailbox box = Mailbox.get("someone@localhost");
    assertEquals(1, box.size());
}
Also used : Exchange(org.apache.camel.Exchange) Mailbox(org.jvnet.mock_javamail.Mailbox) 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