Search in sources :

Example 6 with MailStatusStore

use of org.xwiki.mail.MailStatusStore in project xwiki-platform by xwiki.

the class DatabaseMailStatusResultTest method getAll.

@Test
public void getAll() throws Exception {
    MailStatusStore store = mock(MailStatusStore.class);
    MailStatus status = new MailStatus();
    when(store.load(Collections.<String, Object>singletonMap("batchId", "batchid"), 0, 0, "date", true)).thenReturn(Arrays.asList(status));
    DatabaseMailStatusResult result = new DatabaseMailStatusResult(store);
    result.setBatchId("batchid");
    Iterator<MailStatus> resultStatuses = result.getAll();
    MailStatus resultStatus = resultStatuses.next();
    assertSame(status, resultStatus);
    assertFalse(resultStatuses.hasNext());
}
Also used : MailStatusStore(org.xwiki.mail.MailStatusStore) MailStatus(org.xwiki.mail.MailStatus) Test(org.junit.Test)

Example 7 with MailStatusStore

use of org.xwiki.mail.MailStatusStore in project xwiki-platform by xwiki.

the class DatabaseMailListenerTest method onPrepareWhenSaveFails.

@Test
public void onPrepareWhenSaveFails() throws Exception {
    MailStatusStore mailStatusStore = this.mocker.getInstance(MailStatusStore.class, "database");
    doThrow(new MailStoreException("error")).when(mailStatusStore).save(any(MailStatus.class), anyMap());
    MailListener listener = this.mocker.getComponentUnderTest();
    listener.onPrepareBegin(batchId, Collections.<String, Object>emptyMap());
    listener.onPrepareMessageSuccess(this.message, Collections.<String, Object>emptyMap());
    ArgumentCaptor<MailStatus> statusCapture = ArgumentCaptor.forClass(MailStatus.class);
    verify(mailStatusStore).save(statusCapture.capture(), anyMap());
    assertEquals("Failed to save mail status [messageId = [" + this.messageId + "], batchId = [" + this.batchId + "], state = [prepare_success], date = [" + statusCapture.getValue().getDate() + "], " + "recipients = [<null>], type = [type], wiki = [mywiki]] to the database", this.logRule.getMessage(0));
}
Also used : MailListener(org.xwiki.mail.MailListener) MailStatusStore(org.xwiki.mail.MailStatusStore) MailStoreException(org.xwiki.mail.MailStoreException) MailStatus(org.xwiki.mail.MailStatus) Test(org.junit.Test)

Example 8 with MailStatusStore

use of org.xwiki.mail.MailStatusStore in project xwiki-platform by xwiki.

the class DatabaseMailListenerTest method onSuccessWhenStatusLoadFails.

@Test
public void onSuccessWhenStatusLoadFails() throws Exception {
    MailStatusStore mailStatusStore = this.mocker.getInstance(MailStatusStore.class, "database");
    when(mailStatusStore.load(this.messageId)).thenThrow(new MailStoreException("error"));
    MailListener listener = this.mocker.getComponentUnderTest();
    listener.onPrepareBegin(batchId, Collections.<String, Object>emptyMap());
    listener.onSendMessageSuccess(this.message, Collections.<String, Object>emptyMap());
    assertEquals("Error when looking for a previous mail status for message [" + this.messageId + "] of batch [" + batchId + "] and state [send_success].", this.logRule.getMessage(0));
    assertEquals("Forcing a new mail status for message [" + this.messageId + "] of batch [" + batchId + "] to send_success state.", this.logRule.getMessage(1));
    // Verify that save and delete happened
    verify(mailStatusStore).save(any(MailStatus.class), anyMap());
    MailContentStore mailContentStore = this.mocker.getInstance(MailContentStore.class, "filesystem");
    verify(mailContentStore).delete(any(), any());
}
Also used : MailListener(org.xwiki.mail.MailListener) MailStatusStore(org.xwiki.mail.MailStatusStore) MailStoreException(org.xwiki.mail.MailStoreException) MailContentStore(org.xwiki.mail.MailContentStore) MailStatus(org.xwiki.mail.MailStatus) Test(org.junit.Test)

Example 9 with MailStatusStore

use of org.xwiki.mail.MailStatusStore in project xwiki-platform by xwiki.

the class DatabaseMailListenerTest method onPrepareError.

@Test
public void onPrepareError() throws Exception {
    MailStatusStore mailStatusStore = this.mocker.getInstance(MailStatusStore.class, "database");
    MailListener listener = this.mocker.getComponentUnderTest();
    listener.onPrepareBegin(batchId, Collections.<String, Object>emptyMap());
    listener.onPrepareMessageError(this.message, new Exception("Error"), Collections.<String, Object>emptyMap());
    verify(mailStatusStore).save(argThat(new isSameMailStatus(MailState.PREPARE_ERROR, "mywiki")), anyMap());
}
Also used : MailListener(org.xwiki.mail.MailListener) MailStatusStore(org.xwiki.mail.MailStatusStore) MailStoreException(org.xwiki.mail.MailStoreException) Test(org.junit.Test)

Example 10 with MailStatusStore

use of org.xwiki.mail.MailStatusStore in project xwiki-platform by xwiki.

the class DatabaseMailListenerTest method onSuccessWhenMailContentDeletionFails.

@Test
public void onSuccessWhenMailContentDeletionFails() throws Exception {
    MailStatusStore mailStatusStore = this.mocker.getInstance(MailStatusStore.class, "database");
    MailStatus status = new MailStatus(this.batchId, this.message, MailState.PREPARE_SUCCESS);
    status.setWiki("otherwiki");
    when(mailStatusStore.load(this.messageId)).thenReturn(status);
    MailContentStore mailContentStore = this.mocker.getInstance(MailContentStore.class, "filesystem");
    doThrow(new MailStoreException("error")).when(mailContentStore).delete(this.batchId, this.messageId);
    MailListener listener = this.mocker.getComponentUnderTest();
    listener.onPrepareBegin(batchId, Collections.<String, Object>emptyMap());
    listener.onSendMessageSuccess(this.message, Collections.<String, Object>emptyMap());
    assertEquals("Failed to remove previously failing message [" + this.messageId + "] (batch id [" + this.batchId + "]) from the file system. Reason [MailStoreException: error].", this.logRule.getMessage(0));
}
Also used : MailListener(org.xwiki.mail.MailListener) MailStatusStore(org.xwiki.mail.MailStatusStore) MailStoreException(org.xwiki.mail.MailStoreException) MailContentStore(org.xwiki.mail.MailContentStore) MailStatus(org.xwiki.mail.MailStatus) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)11 MailStatusStore (org.xwiki.mail.MailStatusStore)11 MailListener (org.xwiki.mail.MailListener)10 MailStatus (org.xwiki.mail.MailStatus)9 MailStoreException (org.xwiki.mail.MailStoreException)7 MailContentStore (org.xwiki.mail.MailContentStore)5 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 ExtendedMimeMessage (org.xwiki.mail.ExtendedMimeMessage)2 MailSender (org.xwiki.mail.MailSender)2