use of javax.mail.Message in project camel by apache.
the class MailSorterTest method createMessage.
/**
* Create a new message with the specified data
*/
private static Message createMessage(String to, String cc, String from, Date received, Date sent, int size, String subject) throws MessagingException {
final Message msg = Mockito.mock(Message.class);
when(msg.getFrom()).thenReturn(new Address[] { new InternetAddress(from) });
when(msg.getRecipients(Message.RecipientType.TO)).thenReturn(new Address[] { new InternetAddress(to) });
when(msg.getRecipients(Message.RecipientType.CC)).thenReturn(new Address[] { new InternetAddress(cc) });
when(msg.getSentDate()).thenReturn(sent);
when(msg.getReceivedDate()).thenReturn(received);
when(msg.getSize()).thenReturn(size);
when(msg.getSubject()).thenReturn(subject);
return msg;
}
use of javax.mail.Message in project camel by apache.
the class MailSorterTest method testSortMessages.
@Test
public void testSortMessages() throws Exception {
Message[] expected = new Message[] { MESSAGES[0], MESSAGES[1], MESSAGES[2] };
// Sort using all the terms. Message order should be the same no matter what term is used
for (SortTerm term : POSSIBLE_TERMS) {
Message[] actual = MESSAGES.clone();
MailSorter.sortMessages(actual, new SortTerm[] { term });
try {
assertArrayEquals(actual, expected);
} catch (Exception ex) {
throw new Exception("Term: " + term.toString(), ex);
}
}
}
use of javax.mail.Message 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());
}
use of javax.mail.Message in project camel by apache.
the class MailProcessOnlyUnseenMessagesTest method prepareMailbox.
private void prepareMailbox() throws Exception {
// connect to mailbox
Mailbox.clearAll();
JavaMailSender sender = new DefaultJavaMailSender();
Store store = sender.getSession().getStore("imap");
store.connect("localhost", 25, "claus", "secret");
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_WRITE);
folder.expunge();
// inserts two messages with the SEEN flag
Message[] msg = new Message[2];
msg[0] = new MimeMessage(sender.getSession());
msg[0].setText("Message 1");
msg[0].setHeader("Message-ID", "0");
msg[0].setFlag(Flags.Flag.SEEN, true);
msg[1] = new MimeMessage(sender.getSession());
msg[1].setText("Message 2");
msg[0].setHeader("Message-ID", "1");
msg[1].setFlag(Flags.Flag.SEEN, true);
folder.appendMessages(msg);
folder.close(true);
}
use of javax.mail.Message 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