use of org.xwiki.mail.MailListener 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.MailListener 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.MailListener 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.MailListener in project xwiki-platform by xwiki.
the class DatabaseMailResenderTest method resendAsynchronouslySingleMesssage.
@Test
public void resendAsynchronouslySingleMesssage() throws Exception {
MailListener listener = this.mocker.registerMockComponent(MailListener.class, "database");
ExtendedMimeMessage message = new ExtendedMimeMessage();
String batchId = UUID.randomUUID().toString();
MailContentStore contentStore = this.mocker.getInstance(MailContentStore.class, "filesystem");
when(contentStore.load(any(), eq(batchId), eq("messageId"))).thenReturn(message);
MailSender sender = this.mocker.getInstance(MailSender.class);
when(sender.sendAsynchronously(eq(Arrays.asList(message)), any(), any(MailListener.class))).thenReturn(new DefaultMailResult(batchId));
this.mocker.getComponentUnderTest().resendAsynchronously(batchId, "messageId");
// The test is here
verify(sender).sendAsynchronously(eq(Arrays.asList(message)), any(), same(listener));
verify(listener).getMailStatusResult();
}
use of org.xwiki.mail.MailListener in project xwiki-platform by xwiki.
the class DatabaseMailResender method resendAsynchronously.
@Override
public MailStatusResult resendAsynchronously(String batchId, String uniqueMessageId) throws MailStoreException {
// Note: We don't need to check permissions since the caller already needs to know the batch id and mail id
// to be able to call this method and for it to have any effect.
// Set the batch id so that no new batch id is generated when re-sending the mail
Session session = this.sessionFactory.create(Collections.singletonMap(SESSION_BATCHID_KEY, batchId));
MimeMessage message = loadMessage(session, batchId, uniqueMessageId);
MailListener databaseMailListener = this.databaseMailListenerProvider.get();
this.mailSender.sendAsynchronously(Arrays.asList(message), session, databaseMailListener);
return databaseMailListener.getMailStatusResult();
}
Aggregations