Search in sources :

Example 26 with Mailbox

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

the class ReportIncidentRoutesTest method testReportIncident.

@Test
public void testReportIncident() throws Exception {
    // assert mailbox is empty before starting
    Mailbox inbox = Mailbox.get("incident@mycompany.com");
    inbox.clear();
    assertEquals("Should not have mails", 0, inbox.size());
    // create input parameter
    InputReportIncident input = new InputReportIncident();
    input.setIncidentId("123");
    input.setIncidentDate("2008-08-18");
    input.setGivenName("Claus");
    input.setFamilyName("Ibsen");
    input.setSummary("Bla");
    input.setDetails("Bla bla");
    input.setEmail("davsclaus@apache.org");
    input.setPhone("0045 2962 7576");
    // create the webservice client and send the request
    String url = context.resolvePropertyPlaceholders(URL);
    ReportIncidentEndpoint client = createCXFClient(url);
    OutputReportIncident out = client.reportIncident(input);
    // assert we got a OK back
    assertEquals("0", out.getCode());
    // let some time pass to allow Camel to pickup the file and send it as an email
    Thread.sleep(3000);
    // assert mail box
    assertEquals("Should have got 1 mail", 1, inbox.size());
}
Also used : Mailbox(org.jvnet.mock_javamail.Mailbox) Test(org.junit.Test)

Example 27 with Mailbox

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

the class RawMailMessageTest method testNormalMessageConsumer.

private void testNormalMessageConsumer(String type) throws Exception {
    Mailbox mailbox = Mailbox.get("jones" + type + "@localhost");
    assertEquals(1, mailbox.size());
    MockEndpoint mock = getMockEndpoint("mock://normalMessage" + type);
    mock.expectedMessageCount(1);
    mock.expectedBodyReceived().body().isNotNull();
    assertMockEndpointsSatisfied();
    String body = mock.getExchanges().get(0).getIn().getBody(String.class);
    MimeMessage mm = new MimeMessage(null, new ByteArrayInputStream(body.getBytes()));
    String subject = mm.getSubject();
    assertNull("mail subject should not be available", subject);
    Map<String, Object> headers = mock.getExchanges().get(0).getIn().getHeaders();
    assertNotNull(headers);
    assertTrue(!headers.isEmpty());
}
Also used : Mailbox(org.jvnet.mock_javamail.Mailbox) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MimeMessage(javax.mail.internet.MimeMessage) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 28 with Mailbox

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

the class RawMailMessageTest method testRawMessageConsumer.

private void testRawMessageConsumer(String type) throws Exception {
    Mailbox mailboxRaw = Mailbox.get("jonesRaw" + type + "@localhost");
    assertEquals(1, mailboxRaw.size());
    MockEndpoint mock = getMockEndpoint("mock://rawMessage" + type);
    mock.expectedMessageCount(1);
    mock.expectedBodyReceived().body().isNotNull();
    assertMockEndpointsSatisfied();
    Message mailMessage = mock.getExchanges().get(0).getIn().getBody(Message.class);
    assertNotNull("mail subject should not be null", mailMessage.getSubject());
    assertEquals("mail subject should be hurz", "hurz", mailMessage.getSubject());
    Map<String, Object> headers = mock.getExchanges().get(0).getIn().getHeaders();
    assertNotNull(headers);
    assertTrue(!headers.isEmpty());
}
Also used : Mailbox(org.jvnet.mock_javamail.Mailbox) Message(javax.mail.Message) MimeMessage(javax.mail.internet.MimeMessage) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 29 with Mailbox

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

the class MyMockStore method getFolder.

@Override
public Folder getFolder(String name) throws MessagingException {
    if ("INBOX".equals(name)) {
        return super.getFolder(name);
    }
    Folder folder = folders.get(name);
    if (folder == null) {
        // need a new mailbox as its a sub folder
        String adr = name + "-" + address;
        Mailbox mailbox = Mailbox.get(Aliases.getInstance().resolve(adr));
        folder = new MyMockFolder(this, mailbox, name);
        folders.put(name, folder);
    }
    return folder;
}
Also used : Mailbox(org.jvnet.mock_javamail.Mailbox) Folder(javax.mail.Folder)

Example 30 with Mailbox

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

the class MailContentTypeTest method testSendMultipartMail.

@Test
public void testSendMultipartMail() throws Exception {
    Mailbox.clearAll();
    Map<String, Object> headers = new HashMap<String, Object>();
    headers.put(MailConstants.MAIL_ALTERNATIVE_BODY, "Hello World");
    sendBody("direct:c", "<html><body><h1>Hello</h1>World</body></html>", headers);
    Mailbox box = Mailbox.get("claus@localhost");
    Message msg = box.get(0);
    assertTrue(msg.getContentType().startsWith("multipart/alternative"));
    assertEquals("Hello World", ((MimeMultipart) msg.getContent()).getBodyPart(0).getContent());
    assertEquals("<html><body><h1>Hello</h1>World</body></html>", ((MimeMultipart) msg.getContent()).getBodyPart(1).getContent());
}
Also used : Mailbox(org.jvnet.mock_javamail.Mailbox) Message(javax.mail.Message) HashMap(java.util.HashMap) MimeMultipart(javax.mail.internet.MimeMultipart) 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