use of org.xwiki.mail.MailStatusStore in project xwiki-platform by xwiki.
the class DatabaseMailListenerTest method onSendMessageSuccess.
@Test
public void onSendMessageSuccess() 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);
MailListener listener = this.mocker.getComponentUnderTest();
listener.onPrepareBegin(batchId, Collections.<String, Object>emptyMap());
listener.onSendMessageSuccess(this.message, Collections.<String, Object>emptyMap());
verify(mailStatusStore).load(this.messageId);
verify(mailStatusStore).save(argThat(new isSameMailStatus(MailState.SEND_SUCCESS, "otherwiki")), anyMap());
MailContentStore mailContentStore = this.mocker.getInstance(MailContentStore.class, "filesystem");
verify(mailContentStore).delete(this.batchId, this.messageId);
}
use of org.xwiki.mail.MailStatusStore in project xwiki-platform by xwiki.
the class DatabaseMailListenerTest method onSendMessageError.
@Test
public void onSendMessageError() 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);
MailListener listener = this.mocker.getComponentUnderTest();
listener.onPrepareBegin(batchId, Collections.<String, Object>emptyMap());
listener.onSendMessageError(this.message, new Exception("Error"), Collections.<String, Object>emptyMap());
verify(mailStatusStore).load(this.messageId);
verify(mailStatusStore).save(argThat(new isSameMailStatus(MailState.SEND_ERROR, "otherwiki")), anyMap());
}
use of org.xwiki.mail.MailStatusStore in project xwiki-platform by xwiki.
the class DatabaseMailListenerTest method onSendMessageFatalError.
@Test
public void onSendMessageFatalError() 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);
MailListener listener = this.mocker.getComponentUnderTest();
listener.onPrepareBegin(batchId, Collections.<String, Object>emptyMap());
listener.onSendMessageFatalError(this.messageId, new Exception("Error"), Collections.<String, Object>emptyMap());
verify(mailStatusStore).load(this.messageId);
verify(mailStatusStore).save(argThat(new isSameMailStatus(MailState.SEND_FATAL_ERROR, "otherwiki")), anyMap());
}
use of org.xwiki.mail.MailStatusStore in project xwiki-platform by xwiki.
the class DatabaseMailListenerTest method onPrepareSuccess.
@Test
public void onPrepareSuccess() throws Exception {
MailStatusStore mailStatusStore = this.mocker.getInstance(MailStatusStore.class, "database");
MailListener listener = this.mocker.getComponentUnderTest();
listener.onPrepareBegin(batchId, Collections.<String, Object>emptyMap());
listener.onPrepareMessageSuccess(this.message, Collections.<String, Object>emptyMap());
verify(mailStatusStore).save(argThat(new isSameMailStatus(MailState.PREPARE_SUCCESS, "mywiki")), anyMap());
}
use of org.xwiki.mail.MailStatusStore in project xwiki-platform by xwiki.
the class DatabaseMailResenderTest method resendAsynchronouslySeveralMessagesWhenMailContentStoreLoadingFailsForFirstMessage.
@Test
public void resendAsynchronouslySeveralMessagesWhenMailContentStoreLoadingFailsForFirstMessage() throws Exception {
Map filterMap = Collections.singletonMap("state", "prepare_%");
MailStatus status1 = new MailStatus();
status1.setBatchId("batch1");
status1.setMessageId("message1");
MailStatus status2 = new MailStatus();
status2.setBatchId("batch2");
status2.setMessageId("message2");
List<MailStatus> statuses = new ArrayList<>();
statuses.add(status1);
statuses.add(status2);
MailStatusStore statusStore = this.mocker.getInstance(MailStatusStore.class, "database");
when(statusStore.load(filterMap, 0, 0, null, true)).thenReturn(statuses);
MailContentStore contentStore = this.mocker.getInstance(MailContentStore.class, "filesystem");
when(contentStore.load(any(), eq("batch1"), eq("message1"))).thenThrow(new MailStoreException("error1"));
ExtendedMimeMessage message2 = new ExtendedMimeMessage();
when(contentStore.load(any(), eq("batch2"), eq("message2"))).thenReturn(message2);
MailSender sender = this.mocker.getInstance(MailSender.class);
this.mocker.getComponentUnderTest().resendAsynchronously(filterMap, 0, 0);
// The test is here
verify(this.mocker.getMockedLogger()).warn("Failed to load mail content for batchId [{}], messageId [{}]", "batch1", "message1");
verify(sender).sendAsynchronously(eq(Arrays.asList(message2)), any(), any(MailListener.class));
}
Aggregations