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());
}
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());
}
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());
}
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;
}
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());
}
Aggregations