Search in sources :

Example 1 with MailStatus

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));
}
Also used : ExtendedMimeMessage(org.xwiki.mail.ExtendedMimeMessage) ArrayList(java.util.ArrayList) MailStatus(org.xwiki.mail.MailStatus) Test(org.junit.Test)

Example 2 with MailStatus

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();
}
Also used : MailStatus(org.xwiki.mail.MailStatus)

Example 3 with MailStatus

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();
}
Also used : MailStatus(org.xwiki.mail.MailStatus)

Example 4 with MailStatus

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();
}
Also used : MailStatus(org.xwiki.mail.MailStatus)

Example 5 with MailStatus

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();
}
Also used : MailStatus(org.xwiki.mail.MailStatus)

Aggregations

MailStatus (org.xwiki.mail.MailStatus)27 Test (org.junit.Test)14 MailStoreException (org.xwiki.mail.MailStoreException)9 MailStatusStore (org.xwiki.mail.MailStatusStore)8 ExtendedMimeMessage (org.xwiki.mail.ExtendedMimeMessage)7 MailContentStore (org.xwiki.mail.MailContentStore)7 MailListener (org.xwiki.mail.MailListener)7 ArrayList (java.util.ArrayList)4 XWikiContext (com.xpn.xwiki.XWikiContext)3 Properties (java.util.Properties)3 Session (javax.mail.Session)3 MimeMessage (javax.mail.internet.MimeMessage)3 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)3 MemoryMailListener (org.xwiki.mail.internal.MemoryMailListener)3 UpdateableMailStatusResult (org.xwiki.mail.internal.UpdateableMailStatusResult)3 Map (java.util.Map)2 MailSender (org.xwiki.mail.MailSender)2 XWikiException (com.xpn.xwiki.XWikiException)1 XWikiHibernateBaseStore (com.xpn.xwiki.store.XWikiHibernateBaseStore)1 XWikiHibernateStore (com.xpn.xwiki.store.XWikiHibernateStore)1