use of org.xwiki.mail.MailStatus in project xwiki-platform by xwiki.
the class MemoryMailListenerTest method onErrorAndGetMailStatusResult.
@Test
public void onErrorAndGetMailStatusResult() throws Exception {
MemoryMailListener listener = this.mocker.getComponentUnderTest();
String batchId = UUID.randomUUID().toString();
listener.onPrepareBegin(batchId, Collections.<String, Object>emptyMap());
ExtendedMimeMessage message1 = mock(ExtendedMimeMessage.class);
when(message1.getUniqueMessageId()).thenReturn(UNIQUE_MESSAGE_ID1);
when(message1.getType()).thenReturn("mailtype1");
listener.onPrepareMessageError(message1, new Exception("error1"), Collections.<String, Object>emptyMap());
ExtendedMimeMessage message2 = mock(ExtendedMimeMessage.class);
when(message2.getUniqueMessageId()).thenReturn(UNIQUE_MESSAGE_ID2);
when(message2.getType()).thenReturn("mailtype2");
listener.onPrepareMessageError(message2, new Exception("error2"), Collections.<String, Object>emptyMap());
Iterator<MailStatus> results = listener.getMailStatusResult().getByState(MailState.PREPARE_ERROR);
assertTrue("These should be mails in error!", results.hasNext());
MailStatus status = results.next();
assertEquals("Exception: error1", status.getErrorSummary());
assertTrue(status.getErrorDescription().contains("error1"));
assertEquals(batchId, status.getBatchId());
assertEquals(UNIQUE_MESSAGE_ID1, status.getMessageId());
assertEquals("mailtype1", status.getType());
status = results.next();
assertEquals("Exception: error2", status.getErrorSummary());
assertTrue(status.getErrorDescription().contains("error2"));
assertEquals(batchId, status.getBatchId());
assertEquals(UNIQUE_MESSAGE_ID2, status.getMessageId());
assertEquals("mailtype2", status.getType());
assertFalse(results.hasNext());
}
use of org.xwiki.mail.MailStatus in project xwiki-platform by xwiki.
the class MemoryMailListener method onPrepareMessageSuccess.
@Override
public void onPrepareMessageSuccess(ExtendedMimeMessage message, Map<String, Object> parameters) {
super.onPrepareMessageSuccess(message, parameters);
MailStatus status = new MailStatus(getBatchId(), message, MailState.PREPARE_SUCCESS);
this.mailStatusResult.setStatus(status);
}
Aggregations