use of org.xwiki.context.Execution in project xwiki-platform by xwiki.
the class ScriptingIntegrationTest method initialize.
@Before
public void initialize() throws Exception {
this.scriptService = this.componentManager.getInstance(ScriptService.class, "mailsender");
// Set the EC
Execution execution = this.componentManager.getInstance(Execution.class);
ExecutionContext executionContext = new ExecutionContext();
XWikiContext xContext = new XWikiContext();
xContext.setWikiId("wiki");
executionContext.setProperty(XWikiContext.EXECUTIONCONTEXT_KEY, xContext);
execution.setContext(executionContext);
Copier<ExecutionContext> executionContextCloner = this.componentManager.getInstance(new DefaultParameterizedType(null, Copier.class, ExecutionContext.class));
// Just return the same execution context
when(executionContextCloner.copy(executionContext)).thenReturn(executionContext);
// Simulate receiving the Application Ready Event to start the mail threads
MailSenderInitializerListener listener = this.componentManager.getInstance(EventListener.class, MailSenderInitializerListener.LISTENER_NAME);
listener.onEvent(new ApplicationReadyEvent(), null, null);
}
use of org.xwiki.context.Execution in project xwiki-platform by xwiki.
the class DatabaseMailListenerTest method setUp.
@Before
public void setUp() throws Exception {
this.message = new ExtendedMimeMessage();
this.message.setType("type");
this.message.saveChanges();
this.message.setHeader("Message-ID", mimeMessageId);
this.messageId = message.getUniqueMessageId();
Execution execution = this.mocker.getInstance(Execution.class);
ExecutionContext executionContext = Mockito.mock(ExecutionContext.class);
XWikiContext xcontext = Mockito.mock(XWikiContext.class);
when(xcontext.getWikiId()).thenReturn("mywiki");
when(executionContext.getProperty(XWikiContext.EXECUTIONCONTEXT_KEY)).thenReturn(xcontext);
when(execution.getContext()).thenReturn(executionContext);
}
use of org.xwiki.context.Execution in project xwiki-platform by xwiki.
the class UsersAndGroupsMimeMessageFactoryTest method createMessage.
@Test
public void createMessage() throws Exception {
DocumentReference userReference = new DocumentReference("userwiki", "userspace", "userpage");
Map<String, Object> source = Collections.<String, Object>singletonMap("users", Collections.singletonList(userReference));
Map<String, Object> parameters = new HashMap<>();
parameters.put("hint", "template");
parameters.put("source", new DocumentReference("templatewiki", "templatespace", "templatepage"));
Provider<ComponentManager> componentManagerProvider = this.mocker.registerMockComponent(new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context");
when(componentManagerProvider.get()).thenReturn(this.mocker);
this.mocker.registerMockComponent(new DefaultParameterizedType(null, MimeMessageFactory.class, MimeMessage.class), "template");
// Setup XWikiContext since this is required internally by the iterator constructor
Execution execution = this.mocker.registerMockComponent(Execution.class);
XWikiContext xwikiContext = mock(XWikiContext.class);
ExecutionContext executionContext = new ExecutionContext();
executionContext.setProperty(XWikiContext.EXECUTIONCONTEXT_KEY, xwikiContext);
when(execution.getContext()).thenReturn(executionContext);
Iterator<MimeMessage> iterator = this.mocker.getComponentUnderTest().createMessage(source, parameters);
assertNotNull(iterator);
}
use of org.xwiki.context.Execution in project xwiki-platform by xwiki.
the class ScriptMimeMessageTest method setUp.
@Before
public void setUp() throws Exception {
Execution execution = mock(Execution.class);
ComponentManager componentManager = mock(ComponentManager.class);
this.scriptMessage = new ScriptMimeMessage(execution, componentManager);
}
use of org.xwiki.context.Execution in project xwiki-platform by xwiki.
the class XWikiAction method cleanupComponents.
protected void cleanupComponents() {
Container container = Utils.getComponent(Container.class);
Execution execution = Utils.getComponent(Execution.class);
// We must ensure we clean the ThreadLocal variables located in the Container and Execution
// components as otherwise we will have a potential memory leak.
container.removeRequest();
container.removeResponse();
container.removeSession();
execution.removeContext();
}
Aggregations