Search in sources :

Example 26 with MailStatus

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

Example 27 with MailStatus

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);
}
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