Search in sources :

Example 6 with Mailbox

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

the class MailFetchSizeZeroTest method testFetchSize.

@Test
public void testFetchSize() throws Exception {
    Mailbox mailbox = Mailbox.get("bill@localhost");
    assertEquals(5, mailbox.size());
    MockEndpoint mock = getMockEndpoint("mock:result");
    // no messages expected as we have a fetch size of zero
    mock.expectedMessageCount(0);
    // should be done within 2 seconds as no delay when started
    mock.setResultWaitTime(2000L);
    mock.assertIsSatisfied();
    assertEquals(5, mailbox.size());
}
Also used : Mailbox(org.jvnet.mock_javamail.Mailbox) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 7 with Mailbox

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

the class MailCustomContentTypeTest method testSendPlainMailContentTypeInHeader.

@Test
public void testSendPlainMailContentTypeInHeader() throws Exception {
    Mailbox.clearAll();
    template.sendBodyAndHeader("direct:b", "Hello World", "contentType", "text/plain; charset=iso-8859-1");
    Mailbox box = Mailbox.get("claus@localhost");
    Message msg = box.get(0);
    assertEquals("text/plain; charset=iso-8859-1", msg.getContentType());
    assertEquals("Hello World", msg.getContent());
}
Also used : Mailbox(org.jvnet.mock_javamail.Mailbox) Message(javax.mail.Message) Test(org.junit.Test)

Example 8 with Mailbox

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

the class MailCustomContentTypeTest method testSendPlainMailContentTypeInHeader2.

@Test
public void testSendPlainMailContentTypeInHeader2() throws Exception {
    Mailbox.clearAll();
    template.sendBodyAndHeader("direct:b", "Hello World", Exchange.CONTENT_TYPE, "text/plain; charset=iso-8859-1");
    Mailbox box = Mailbox.get("claus@localhost");
    Message msg = box.get(0);
    assertEquals("text/plain; charset=iso-8859-1", msg.getContentType());
    assertEquals("Hello World", msg.getContent());
}
Also used : Mailbox(org.jvnet.mock_javamail.Mailbox) Message(javax.mail.Message) Test(org.junit.Test)

Example 9 with Mailbox

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

the class MailCustomContentTypeTest 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("text/html; charset=UTF-8", msg.getContentType());
    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 10 with Mailbox

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

the class MailUsingCustomSessionTest method testSendAndReceiveMailsWithCustomSession.

@Test
public void testSendAndReceiveMailsWithCustomSession() throws Exception {
    MockEndpoint mockEndpoint = getMockEndpoint("mock:result");
    mockEndpoint.expectedBodiesReceived("hello camel!");
    Map<String, Object> headers = new HashMap<>();
    headers.put("subject", "Hello Camel");
    template.sendBodyAndHeaders("smtp://james@localhost?session=#myCustomMailSession", "hello camel!", headers);
    mockEndpoint.assertIsSatisfied();
    Mailbox mailbox = Mailbox.get("james@localhost");
    assertEquals("Expected one mail for james@localhost", 1, mailbox.size());
    Message message = mailbox.get(0);
    assertEquals("hello camel!", message.getContent());
    assertEquals("camel@localhost", message.getFrom()[0].toString());
}
Also used : Mailbox(org.jvnet.mock_javamail.Mailbox) Message(javax.mail.Message) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) HashMap(java.util.HashMap) 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