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