use of org.xwiki.mail.MailStatus 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.MailStatus 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));
}
use of org.xwiki.mail.MailStatus in project xwiki-platform by xwiki.
the class DatabaseMailResenderTest method resendAsynchronouslySeveralMessages.
@Test
public void resendAsynchronouslySeveralMessages() 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");
ExtendedMimeMessage message1 = new ExtendedMimeMessage();
when(contentStore.load(any(), eq("batch1"), eq("message1"))).thenReturn(message1);
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(sender).sendAsynchronously(eq(Arrays.asList(message1)), any(), any(MailListener.class));
verify(sender).sendAsynchronously(eq(Arrays.asList(message2)), any(), any(MailListener.class));
}
use of org.xwiki.mail.MailStatus in project xwiki-platform by xwiki.
the class DatabaseMailStatusStoreTest method logsForloadMailStatus.
@Test
public void logsForloadMailStatus() throws Exception {
Provider<XWikiContext> xcontextProvider = mocker.registerMockComponent(XWikiContext.TYPE_PROVIDER);
XWikiContext xcontext = mock(XWikiContext.class);
when(xcontextProvider.get()).thenReturn(xcontext);
when(xcontext.getWikiId()).thenReturn("wiki");
when(xcontext.getMainXWiki()).thenReturn("mainwiki");
XWikiHibernateStore hibernateStore = mock(XWikiHibernateStore.class);
ReflectionUtils.setFieldValue(this.mocker.getComponentUnderTest(), "hibernateStore", hibernateStore);
MailStatus status = new MailStatus();
status.setBatchId("batchid");
status.setMessageId("messageid");
status.setState(MailState.PREPARE_SUCCESS);
status.setRecipients("recipients");
when(hibernateStore.executeRead(eq(xcontext), any())).thenReturn(Arrays.asList(status));
Map<String, Object> filterMap = new LinkedHashMap<>();
filterMap.put("status", "failed");
filterMap.put("wiki", "mywiki");
this.mocker.getComponentUnderTest().load(filterMap, 0, 0, null, false);
// The test is here, we verify that debug logs are correct
assertEquals(2, this.logRule.size());
assertEquals("Find mail statuses for query [from org.xwiki.mail.MailStatus where mail_status like :status " + "and mail_wiki like :wiki] and parameters [[status] = [failed], [wiki] = [mywiki]]", this.logRule.getMessage(0));
assertEquals("Loaded mail status [messageId = [messageid], batchId = [batchid], state = [prepare_success], " + "date = [<null>], recipients = [recipients]]", this.logRule.getMessage(1));
}
use of org.xwiki.mail.MailStatus in project xwiki-platform by xwiki.
the class DatabaseMailListener 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);
status.setWiki(((XWikiContext) execution.getContext().getProperty(XWikiContext.EXECUTIONCONTEXT_KEY)).getWikiId());
saveStatus(status, parameters);
}
Aggregations