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);
}
}
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();
}
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");
}
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);
}
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);
}
Aggregations