Search in sources :

Example 51 with Execution

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);
}
Also used : ScriptService(org.xwiki.script.service.ScriptService) MailSenderScriptService(org.xwiki.mail.script.MailSenderScriptService) DefaultExecution(org.xwiki.context.internal.DefaultExecution) Execution(org.xwiki.context.Execution) ExecutionContext(org.xwiki.context.ExecutionContext) Copier(org.xwiki.mail.internal.thread.context.Copier) ApplicationReadyEvent(org.xwiki.bridge.event.ApplicationReadyEvent) XWikiContext(com.xpn.xwiki.XWikiContext) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) MailSenderInitializerListener(org.xwiki.mail.internal.thread.MailSenderInitializerListener) Before(org.junit.Before)

Example 52 with Execution

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);
}
Also used : ExtendedMimeMessage(org.xwiki.mail.ExtendedMimeMessage) Execution(org.xwiki.context.Execution) ExecutionContext(org.xwiki.context.ExecutionContext) XWikiContext(com.xpn.xwiki.XWikiContext) Before(org.junit.Before)

Example 53 with Execution

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);
}
Also used : HashMap(java.util.HashMap) XWikiContext(com.xpn.xwiki.XWikiContext) Provider(javax.inject.Provider) Execution(org.xwiki.context.Execution) ExecutionContext(org.xwiki.context.ExecutionContext) MimeMessage(javax.mail.internet.MimeMessage) MimeMessageFactory(org.xwiki.mail.MimeMessageFactory) ComponentManager(org.xwiki.component.manager.ComponentManager) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 54 with Execution

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);
}
Also used : Execution(org.xwiki.context.Execution) ComponentManager(org.xwiki.component.manager.ComponentManager) Before(org.junit.Before)

Example 55 with Execution

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();
}
Also used : Container(org.xwiki.container.Container) Execution(org.xwiki.context.Execution)

Aggregations

Execution (org.xwiki.context.Execution)82 ExecutionContext (org.xwiki.context.ExecutionContext)58 Before (org.junit.Before)36 XWikiContext (com.xpn.xwiki.XWikiContext)30 Test (org.junit.Test)19 DocumentReference (org.xwiki.model.reference.DocumentReference)17 XWiki (com.xpn.xwiki.XWiki)13 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)13 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)11 WikiDescriptorManager (org.xwiki.wiki.descriptor.WikiDescriptorManager)10 DocumentAccessBridge (org.xwiki.bridge.DocumentAccessBridge)8 ComponentManager (org.xwiki.component.manager.ComponentManager)8 HashMap (java.util.HashMap)7 Expectations (org.jmock.Expectations)7 VelocityContext (org.apache.velocity.VelocityContext)5 ExecutionContextManager (org.xwiki.context.ExecutionContextManager)5 BaseObject (com.xpn.xwiki.objects.BaseObject)4 DefaultComponentDescriptor (org.xwiki.component.descriptor.DefaultComponentDescriptor)4 XDOM (org.xwiki.rendering.block.XDOM)4 AuthorizationManager (org.xwiki.security.authorization.AuthorizationManager)4