use of org.jvnet.mock_javamail.Mailbox in project camel by apache.
the class MailProducerConcurrentTest method doSendMessages.
private void doSendMessages(int files, int poolSize) throws Exception {
Mailbox.clearAll();
NotifyBuilder builder = new NotifyBuilder(context).whenDone(files).create();
getMockEndpoint("mock:result").expectedMessageCount(files);
getMockEndpoint("mock:result").expectsNoDuplicates(body());
final CountDownLatch latch = new CountDownLatch(files);
ExecutorService executor = Executors.newFixedThreadPool(poolSize);
for (int i = 0; i < files; i++) {
final int index = i;
executor.submit(new Callable<Object>() {
public Object call() throws Exception {
template.sendBodyAndHeader("direct:start", "Message " + index, "To", "someone@localhost");
latch.countDown();
return null;
}
});
}
// wait first for all the exchanges above to be thoroughly sent asynchronously
assertTrue(latch.await(5, TimeUnit.SECONDS));
assertMockEndpointsSatisfied();
assertTrue(builder.matchesMockWaitTime());
Mailbox box = Mailbox.get("someone@localhost");
assertEquals(files, box.size());
// as we use concurrent producers the mails can arrive out of order
Set<Object> bodies = new HashSet<Object>();
for (int i = 0; i < files; i++) {
bodies.add(box.get(i).getContent());
}
assertEquals("There should be " + files + " unique mails", files, bodies.size());
executor.shutdownNow();
}
use of org.jvnet.mock_javamail.Mailbox in project camel by apache.
the class MailProducerTest method testProducerBodyIsMimeMessage.
@Test
public void testProducerBodyIsMimeMessage() throws Exception {
Mailbox.clearAll();
getMockEndpoint("mock:result").expectedMessageCount(1);
Address from = new InternetAddress("fromCamelTest@localhost");
Address to = new InternetAddress("recipient2@localhost");
Session session = Session.getDefaultInstance(System.getProperties());
MimeMessage mimeMessage = new MimeMessage(session);
mimeMessage.setFrom(from);
mimeMessage.addRecipient(RecipientType.TO, to);
mimeMessage.setSubject("This is the subject.");
mimeMessage.setText("This is the message");
template.sendBodyAndHeader("direct:start", mimeMessage, "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(0, box.size());
// Check if the mimeMessagea has override body and headers
Mailbox box2 = Mailbox.get("recipient2@localhost");
assertEquals(1, box2.size());
}
use of org.jvnet.mock_javamail.Mailbox in project camel by apache.
the class MailReplyToTest method testMailReplyTo.
@Test
public void testMailReplyTo() throws Exception {
Mailbox.clearAll();
String body = "The Camel riders";
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(1);
mock.expectedHeaderReceived("Reply-To", "noReply1@localhost,noReply2@localhost");
mock.expectedBodiesReceived(body);
template.sendBodyAndHeader("direct:a", body, "Reply-To", "noReply1@localhost,noReply2@localhost");
mock.assertIsSatisfied();
Mailbox mailbox = Mailbox.get("christian@localhost");
assertEquals(1, mailbox.size());
assertEquals("noReply1@localhost", ((InternetAddress) mailbox.get(0).getReplyTo()[0]).getAddress());
assertEquals("noReply2@localhost", ((InternetAddress) mailbox.get(0).getReplyTo()[1]).getAddress());
assertEquals(body, mailbox.get(0).getContent());
}
use of org.jvnet.mock_javamail.Mailbox in project camel by apache.
the class MailReplyToTest method testMailReplyTo2.
@Test
public void testMailReplyTo2() throws Exception {
Mailbox.clearAll();
String body = "The Camel riders";
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(1);
mock.expectedHeaderReceived("Reply-To", "noReply1@localhost, noReply2@localhost");
mock.expectedBodiesReceived(body);
template.sendBody("direct:b", body);
mock.assertIsSatisfied();
Mailbox mailbox = Mailbox.get("christian@localhost");
assertEquals(1, mailbox.size());
assertEquals("noReply1@localhost", ((InternetAddress) mailbox.get(0).getReplyTo()[0]).getAddress());
assertEquals("noReply2@localhost", ((InternetAddress) mailbox.get(0).getReplyTo()[1]).getAddress());
assertEquals(body, mailbox.get(0).getContent());
}
use of org.jvnet.mock_javamail.Mailbox in project camel by apache.
the class MailRouteTest method assertMailboxReceivedMessages.
protected void assertMailboxReceivedMessages(String name) throws IOException, MessagingException {
Mailbox mailbox = Mailbox.get(name);
assertEquals(name + " should have received 1 mail", 1, mailbox.size());
Message message = mailbox.get(0);
assertNotNull(name + " should have received at least one mail!", message);
assertEquals("hello world!", message.getContent());
assertEquals("camel@localhost", message.getFrom()[0].toString());
boolean found = false;
for (Address adr : message.getRecipients(RecipientType.TO)) {
if (name.equals(adr.toString())) {
found = true;
}
}
assertTrue("Should have found the recpient to in the mail: " + name, found);
}
Aggregations