use of org.xwiki.context.ExecutionContext in project xwiki-platform by xwiki.
the class MessageStreamScriptServiceTest method configure.
@Before
public void configure() throws Exception {
this.streamService = this.mocker.getComponentUnderTest();
Execution execution = this.mocker.getInstance(Execution.class);
this.executionContext = new ExecutionContext();
when(execution.getContext()).thenReturn(this.executionContext);
}
use of org.xwiki.context.ExecutionContext in project xwiki-platform by xwiki.
the class DefaultModelContext method getCurrentEntityReference.
@Override
public EntityReference getCurrentEntityReference() {
WikiReference result = null;
// TODO: This is bridge to the old XWiki Context since we currently don't store the current entity in the
// new Execution Context yet. Remove when we do so.
ExecutionContext econtext = this.execution.getContext();
if (econtext != null) {
Map<String, Object> xcontext = (Map<String, Object>) econtext.getProperty(XCONTEXT_KEY);
if (xcontext != null) {
String wikiName = (String) xcontext.get(WIKINAME_KEY);
if (wikiName != null) {
result = new WikiReference(wikiName);
}
}
}
return result;
}
use of org.xwiki.context.ExecutionContext in project xwiki-platform by xwiki.
the class UsersAndGroupsMimeMessageIteratorTest method setUpBaseMocks.
@Before
public void setUpBaseMocks() {
this.execution = mock(Execution.class);
this.xwikiContext = mock(XWikiContext.class);
ExecutionContext executionContext = new ExecutionContext();
executionContext.setProperty(XWikiContext.EXECUTIONCONTEXT_KEY, this.xwikiContext);
when(this.execution.getContext()).thenReturn(executionContext);
this.xwiki = mock(XWiki.class);
when(this.xwikiContext.getWiki()).thenReturn(this.xwiki);
this.factory = mock(MimeMessageFactory.class);
this.resolver = mock(DocumentReferenceResolver.class);
}
use of org.xwiki.context.ExecutionContext in project xwiki-platform by xwiki.
the class PrepareMailQueueItemTest method verifyToString.
@Test
public void verifyToString() throws Exception {
Session session = Session.getDefaultInstance(new Properties());
MimeMessage message = new MimeMessage(session);
String batchId = UUID.randomUUID().toString();
ExecutionContext context = new ExecutionContext();
XWikiContext xContext = new XWikiContext();
xContext.setWikiId("wiki");
context.setProperty(XWikiContext.EXECUTIONCONTEXT_KEY, xContext);
PrepareMailQueueItem item = new PrepareMailQueueItem(Arrays.asList(message), session, null, batchId, context);
assertEquals("batchId = [" + batchId + "], context = [[xwikicontext] = [{originalWiki=wiki, wiki=wiki}]]", item.toString());
}
use of org.xwiki.context.ExecutionContext in project xwiki-platform by xwiki.
the class PrepareMailRunnableTest method prepareMailWhenContentStoreFails.
@Test
public void prepareMailWhenContentStoreFails() throws Exception {
Properties properties = new Properties();
Session session = Session.getDefaultInstance(properties);
MimeMessage message1 = new MimeMessage(session);
message1.setText("Content1");
MimeMessage message2 = new MimeMessage(session);
message2.setText("Content2");
String batchId1 = UUID.randomUUID().toString();
String batchId2 = UUID.randomUUID().toString();
ExecutionContext context1 = new ExecutionContext();
XWikiContext xContext1 = new XWikiContext();
xContext1.setWikiId("wiki1");
context1.setProperty(XWikiContext.EXECUTIONCONTEXT_KEY, xContext1);
ExecutionContext context2 = new ExecutionContext();
XWikiContext xContext2 = new XWikiContext();
xContext2.setWikiId("wiki2");
context2.setProperty(XWikiContext.EXECUTIONCONTEXT_KEY, xContext2);
MemoryMailListener listener1 = this.mocker.getInstance(MailListener.class, "memory");
PrepareMailQueueItem item1 = new PrepareMailQueueItem(Arrays.asList(message1), session, listener1, batchId1, context1);
MemoryMailListener listener2 = this.mocker.getInstance(MailListener.class, "memory");
PrepareMailQueueItem item2 = new PrepareMailQueueItem(Arrays.asList(message2), session, listener2, batchId2, context2);
MailQueueManager mailQueueManager = this.mocker.getInstance(new DefaultParameterizedType(null, MailQueueManager.class, PrepareMailQueueItem.class));
// Make the content store save fail
MailContentStore contentStore = this.mocker.getInstance(MailContentStore.class, "filesystem");
doThrow(new MailStoreException("error")).when(contentStore).save(any(String.class), any(ExtendedMimeMessage.class));
// Prepare 2 mails. Both will fail but we want to verify that the second one is processed even though the first
// one failed.
mailQueueManager.addToQueue(item1);
mailQueueManager.addToQueue(item2);
MailRunnable runnable = this.mocker.getComponentUnderTest();
Thread thread = new Thread(runnable);
thread.start();
// Wait for the mails to have been processed.
try {
listener1.getMailStatusResult().waitTillProcessed(10000L);
listener2.getMailStatusResult().waitTillProcessed(10000L);
} finally {
runnable.stopProcessing();
thread.interrupt();
thread.join();
}
MailStatusResult result1 = listener1.getMailStatusResult();
MailStatusResult result2 = listener2.getMailStatusResult();
// Despite the errors, both process should be ended with known total number of mails
assertTrue(result1.isProcessed());
assertTrue(result2.isProcessed());
// This is the real test: we verify that there's been an error while sending each email.
MailStatus status1 = result1.getByState(MailState.PREPARE_ERROR).next();
assertEquals("MailStoreException: error", status1.getErrorSummary());
MailStatus status2 = result2.getByState(MailState.PREPARE_ERROR).next();
assertEquals("MailStoreException: error", status2.getErrorSummary());
}
Aggregations