Search in sources :

Example 6 with Execution

use of org.xwiki.context.Execution in project xwiki-platform by xwiki.

the class Utils method getXWikiContext.

/**
 * Retrieve the XWiki context from the current execution context.
 *
 * @param componentManager The component manager to be used to retrieve the execution context.
 * @return The XWiki context.
 * @throws RuntimeException If there was an error retrieving the context.
 */
public static XWikiContext getXWikiContext(ComponentManager componentManager) {
    Execution execution;
    XWikiContext xwikiContext;
    try {
        execution = componentManager.getInstance(Execution.class);
        xwikiContext = (XWikiContext) execution.getContext().getProperty("xwikicontext");
        return xwikiContext;
    } catch (Exception e) {
        throw new RuntimeException("Unable to get XWiki context", e);
    }
}
Also used : Execution(org.xwiki.context.Execution) XWikiContext(com.xpn.xwiki.XWikiContext) XWikiException(com.xpn.xwiki.XWikiException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) URIException(org.apache.commons.httpclient.URIException)

Example 7 with Execution

use of org.xwiki.context.Execution in project xwiki-platform by xwiki.

the class ResourceReferenceHandlerServlet method cleanupComponents.

private void cleanupComponents() throws ServletException {
    Container container;
    try {
        container = this.rootComponentManager.getInstance(Container.class);
    } catch (ComponentLookupException e) {
        throw new ServletException("Failed to locate a Container component", e);
    }
    Execution execution;
    try {
        execution = this.rootComponentManager.getInstance(Execution.class);
    } catch (ComponentLookupException e) {
        throw new ServletException("Failed to locate a Execution component", e);
    }
    // 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 : ServletException(javax.servlet.ServletException) Container(org.xwiki.container.Container) Execution(org.xwiki.context.Execution) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException)

Example 8 with Execution

use of org.xwiki.context.Execution in project xwiki-platform by xwiki.

the class WikiUserFromXEMMigrationTest method setUp.

@Before
public void setUp() throws Exception {
    wikiDescriptorManager = mocker.getInstance(WikiDescriptorManager.class);
    wikiUserConfigurationHelper = mocker.getInstance(WikiUserConfigurationHelper.class);
    execution = mock(Execution.class);
    mocker.registerComponent(Execution.class, execution);
    xcontext = mock(XWikiContext.class);
    xwiki = mock(XWiki.class);
    ExecutionContext executionContext = mock(ExecutionContext.class);
    when(execution.getContext()).thenReturn(executionContext);
    when(executionContext.getProperty("xwikicontext")).thenReturn(xcontext);
    when(xcontext.getWiki()).thenReturn(xwiki);
    when(wikiDescriptorManager.getMainWikiId()).thenReturn("mainWiki");
}
Also used : Execution(org.xwiki.context.Execution) ExecutionContext(org.xwiki.context.ExecutionContext) WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) Before(org.junit.Before)

Example 9 with Execution

use of org.xwiki.context.Execution in project xwiki-platform by xwiki.

the class WikiUserManagerScriptServiceTest method setUp.

@Before
public void setUp() throws Exception {
    // Components mocks
    wikiUserManager = mocker.getInstance(WikiUserManager.class);
    wikiDescriptorManager = mocker.getInstance(WikiDescriptorManager.class);
    authorizationManager = mocker.getInstance(AuthorizationManager.class);
    xcontextProvider = mocker.registerMockComponent(XWikiContext.TYPE_PROVIDER);
    documentReferenceResolver = mocker.getInstance(new DefaultParameterizedType(null, DocumentReferenceResolver.class, String.class));
    execution = mocker.getInstance(Execution.class);
    // Frequent uses
    xcontext = mock(XWikiContext.class);
    when(xcontextProvider.get()).thenReturn(xcontext);
    when(wikiDescriptorManager.getMainWikiId()).thenReturn("mainWiki");
    when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("subwiki");
    executionContext = new ExecutionContext();
    when(execution.getContext()).thenReturn(executionContext);
    currentDoc = mock(XWikiDocument.class);
    when(xcontext.getDoc()).thenReturn(currentDoc);
    userDocRef = new DocumentReference("mainWiki", "XWiki", "User");
    when(xcontext.getUserReference()).thenReturn(userDocRef);
    DocumentReference userReference = new DocumentReference("mainWiki", "XWiki", "User");
    when(documentReferenceResolver.resolve("mainWiki:XWiki.User")).thenReturn(userReference);
    DocumentReference otherUser = new DocumentReference("mainWiki", "XWiki", "OtherUser");
    when(documentReferenceResolver.resolve("mainWiki:XWiki.OtherUser")).thenReturn(otherUser);
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) Execution(org.xwiki.context.Execution) ExecutionContext(org.xwiki.context.ExecutionContext) WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) XWikiContext(com.xpn.xwiki.XWikiContext) AuthorizationManager(org.xwiki.security.authorization.AuthorizationManager) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) DocumentReference(org.xwiki.model.reference.DocumentReference) WikiUserManager(org.xwiki.wiki.user.WikiUserManager) Before(org.junit.Before)

Example 10 with Execution

use of org.xwiki.context.Execution in project xwiki-platform by xwiki.

the class DefaultWikiProvisioningJobExecutorTest method createAndExecuteJob.

@Test
public void createAndExecuteJob() throws Exception {
    // Mocks
    WikiProvisioningJob provisioningJob = mock(WikiProvisioningJob.class);
    mocker.registerComponent(Job.class, "wikiprovisioning.test", provisioningJob);
    ExecutionContextManager executionContextManager = mock(ExecutionContextManager.class);
    mocker.registerComponent(ExecutionContextManager.class, executionContextManager);
    Execution execution = mock(Execution.class);
    mocker.registerComponent(Execution.class, execution);
    DocumentReference user = new DocumentReference("xwiki", "XWiki", "User");
    when(xcontext.getUserReference()).thenReturn(user);
    // Execute
    WikiProvisioningJob job = mocker.getComponentUnderTest().createAndExecuteJob("wikiid", "wikiprovisioning.test", "templateid");
    // Verify
    // Id of the job.
    List<String> jobId = new ArrayList<String>();
    jobId.add("wiki");
    jobId.add("provisioning");
    jobId.add("wikiprovisioning.test");
    jobId.add("wikiid");
    verify(provisioningJob).initialize(eq(new WikiProvisioningJobRequest(jobId, "wikiid", "templateid", user)));
    Thread.sleep(100);
    verify(provisioningJob).run();
    // getJobs also works
    assertEquals(mocker.getComponentUnderTest().getJob(jobId), job);
}
Also used : Execution(org.xwiki.context.Execution) ExecutionContextManager(org.xwiki.context.ExecutionContextManager) ArrayList(java.util.ArrayList) WikiProvisioningJobRequest(org.xwiki.wiki.provisioning.WikiProvisioningJobRequest) DocumentReference(org.xwiki.model.reference.DocumentReference) WikiProvisioningJob(org.xwiki.wiki.provisioning.WikiProvisioningJob) Test(org.junit.Test)

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