use of org.xwiki.mail.MailStatus in project xwiki-platform by xwiki.
the class MemoryMailStatusResultTest method getAllErrorTest.
@Test
public void getAllErrorTest() throws Exception {
MemoryMailStatusResult statusResult = new MemoryMailStatusResult();
ExtendedMimeMessage message1 = mock(ExtendedMimeMessage.class);
when(message1.getUniqueMessageId()).thenReturn(UNIQUE_MESSAGE_ID1);
ExtendedMimeMessage message2 = mock(ExtendedMimeMessage.class);
when(message2.getUniqueMessageId()).thenReturn(UNIQUE_MESSAGE_ID2);
ExtendedMimeMessage message3 = mock(ExtendedMimeMessage.class);
when(message3.getUniqueMessageId()).thenReturn(UNIQUE_MESSAGE_ID3);
ExtendedMimeMessage message4 = mock(ExtendedMimeMessage.class);
when(message4.getUniqueMessageId()).thenReturn(UNIQUE_MESSAGE_ID4);
ExtendedMimeMessage message5 = mock(ExtendedMimeMessage.class);
when(message5.getUniqueMessageId()).thenReturn(UNIQUE_MESSAGE_ID5);
statusResult.setStatus(new MailStatus(BATCH_ID, message1, MailState.PREPARE_SUCCESS));
statusResult.setStatus(new MailStatus(BATCH_ID, message2, MailState.PREPARE_ERROR));
statusResult.setStatus(new MailStatus(BATCH_ID, message3, MailState.SEND_SUCCESS));
statusResult.setStatus(new MailStatus(BATCH_ID, message4, MailState.SEND_ERROR));
statusResult.setStatus(new MailStatus(BATCH_ID, message5, MailState.SEND_FATAL_ERROR));
List<String> allErrorIds = new ArrayList<>();
Iterator<MailStatus> it = statusResult.getAllErrors();
while (it.hasNext()) {
allErrorIds.add(it.next().getMessageId());
}
assertThat(allErrorIds, containsInAnyOrder(UNIQUE_MESSAGE_ID2, UNIQUE_MESSAGE_ID4, UNIQUE_MESSAGE_ID5));
assertThat(allErrorIds.size(), equalTo(3));
}
use of org.xwiki.mail.MailStatus in project xwiki-platform by xwiki.
the class MemoryMailListener method onSendMessageError.
@Override
public void onSendMessageError(ExtendedMimeMessage message, Exception exception, Map<String, Object> parameters) {
super.onSendMessageError(message, exception, parameters);
MailStatus status = new MailStatus(getBatchId(), message, MailState.SEND_ERROR);
status.setError(exception);
this.mailStatusResult.setStatus(status);
// This mail will not reach the send queue, so its processing is done now.
this.mailStatusResult.incrementCurrentSize();
}
use of org.xwiki.mail.MailStatus in project xwiki-platform by xwiki.
the class MemoryMailListener method onSendMessageSuccess.
@Override
public void onSendMessageSuccess(ExtendedMimeMessage message, Map<String, Object> parameters) {
super.onPrepareMessageSuccess(message, parameters);
MailStatus status = new MailStatus(getBatchId(), message, MailState.SEND_SUCCESS);
this.mailStatusResult.setStatus(status);
this.mailStatusResult.incrementCurrentSize();
}
use of org.xwiki.mail.MailStatus in project xwiki-platform by xwiki.
the class MemoryMailListener method onSendMessageFatalError.
@Override
public void onSendMessageFatalError(String uniqueMessageId, Exception exception, Map<String, Object> parameters) {
super.onSendMessageFatalError(uniqueMessageId, exception, parameters);
MailStatus status = this.mailStatusResult.getStatus(uniqueMessageId);
if (status != null) {
status.setState(MailState.SEND_FATAL_ERROR);
status.setError(exception);
this.mailStatusResult.setStatus(status);
} else {
this.logger.error("Failed to find a previous mail status for message id [{}] of batch [{}]. " + "Unable to report the fatal error encountered during mail sending.", uniqueMessageId, getBatchId(), exception);
}
this.mailStatusResult.incrementCurrentSize();
}
use of org.xwiki.mail.MailStatus in project xwiki-platform by xwiki.
the class MemoryMailListener method onPrepareMessageError.
@Override
public void onPrepareMessageError(ExtendedMimeMessage message, Exception exception, Map<String, Object> parameters) {
super.onPrepareMessageError(message, exception, parameters);
MailStatus status = new MailStatus(getBatchId(), message, MailState.PREPARE_ERROR);
status.setError(exception);
this.mailStatusResult.setStatus(status);
// This mail will not reach the send queue, so its processing is done now.
this.mailStatusResult.incrementCurrentSize();
}
Aggregations