use of org.xwiki.context.Execution in project xwiki-platform by xwiki.
the class AbstractJob method execute.
@Override
public final void execute(JobExecutionContext jobContext) throws JobExecutionException {
JobDataMap data = jobContext.getJobDetail().getJobDataMap();
// The XWiki context was saved in the Job execution data map. Get it as we'll retrieve
// the script to execute from it.
this.xcontext = (XWikiContext) data.get("context");
// Clone the XWikiContex to have a new one for each run
this.xcontext = this.xcontext.clone();
// Init execution context
Execution execution;
try {
ExecutionContextManager ecim = Utils.getComponent(ExecutionContextManager.class);
execution = Utils.getComponent(Execution.class);
ExecutionContext context = new ExecutionContext();
// Bridge with old XWiki Context, required for old code
this.xcontext.declareInExecutionContext(context);
ecim.initialize(context);
} catch (ExecutionContextException e) {
throw new JobExecutionException("Fail to initialize execution context", e);
}
try {
// Execute the job
executeJob(jobContext);
} finally {
// We must ensure we clean the ThreadLocal variables located in the Execution
// component as otherwise we will have a potential memory leak.
execution.removeContext();
}
}
use of org.xwiki.context.Execution in project xwiki-platform by xwiki.
the class PageTest method configureComponentsBeforeOldcoreRuleForPageTest.
/**
* Set up of Components after the Components declared in {@link org.xwiki.test.annotation.ComponentList} have been
* handled but before {@link MockitoOldcoreRule#before(Class)} has been called (i.e. before it has created Mocks
* and configured Components).
*
* @throws Exception in case of errors
*/
@AfterComponent
public void configureComponentsBeforeOldcoreRuleForPageTest() throws Exception {
// Configure the Execution Context
ExecutionContext ec = new ExecutionContext();
mocker.<Execution>getInstance(Execution.class).setContext(ec);
}
use of org.xwiki.context.Execution in project xwiki-platform by xwiki.
the class WikiCreationJobTest method setUp.
@Before
public void setUp() throws Exception {
observationManager = mocker.getInstance(ObservationManager.class);
loggerManager = mocker.getInstance(LoggerManager.class);
store = mocker.getInstance(JobStatusStore.class);
executionProvider = mock(Provider.class);
mocker.registerComponent(new DefaultParameterizedType(null, Provider.class, Execution.class), executionProvider);
when(executionProvider.get()).thenReturn(execution);
executionContextManagerProvider = mock(Provider.class);
mocker.registerComponent(new DefaultParameterizedType(null, Provider.class, ExecutionContextManager.class), executionContextManagerProvider);
executionContextManager = mock(ExecutionContextManager.class);
when(executionContextManagerProvider.get()).thenReturn(executionContextManager);
jobContext = mocker.getInstance(JobContext.class);
progressManager = mocker.getInstance(JobProgressManager.class);
execution.pushContext(new ExecutionContext());
}
use of org.xwiki.context.Execution in project xwiki-platform by xwiki.
the class WikiCreationJobScriptServicesTest method setUp.
@Before
public void setUp() throws Exception {
wikiCreator = mocker.getInstance(WikiCreator.class);
execution = mocker.getInstance(Execution.class);
authorizationManager = mocker.getInstance(AuthorizationManager.class);
wikiDescriptorManager = mocker.getInstance(WikiDescriptorManager.class);
distributionManager = mocker.getInstance(DistributionManager.class);
xcontextProvider = mocker.registerMockComponent(XWikiContext.TYPE_PROVIDER);
xcontext = mock(XWikiContext.class);
when(xcontextProvider.get()).thenReturn(xcontext);
xwiki = mock(XWiki.class);
when(xcontext.getWiki()).thenReturn(xwiki);
when(wikiDescriptorManager.getMainWikiId()).thenReturn("mainWikiId");
ExecutionContext executionContext = new ExecutionContext();
when(execution.getContext()).thenReturn(executionContext);
ExtensionId extensionId = new ExtensionId("authorized-extension", "1.0");
when(distributionManager.getWikiUIExtensionId()).thenReturn(extensionId);
}
use of org.xwiki.context.Execution in project xwiki-platform by xwiki.
the class DefaultWikiComponentBridgeTest method configure.
@Before
public void configure() throws Exception {
getMockery().setImposteriser(ClassImposteriser.INSTANCE);
Utils.setComponentManager(getComponentManager());
final Execution execution = registerMockComponent(Execution.class);
final ExecutionContext context = new ExecutionContext();
final Provider<XWikiContext> xcontextProvider = registerMockComponent(XWikiContext.TYPE_PROVIDER);
this.xwiki = getMockery().mock(XWiki.class);
this.xwikiContext = new XWikiContext();
this.xwikiContext.setWikiId("xwiki");
this.xwikiContext.setWiki(this.xwiki);
context.setProperty("xwikicontext", this.xwikiContext);
this.componentDoc = getMockery().mock(XWikiDocument.class);
this.componentObject = getMockery().mock(BaseObject.class, "component");
getMockery().checking(new Expectations() {
{
allowing(xcontextProvider).get();
will(returnValue(xwikiContext));
allowing(execution).getContext();
will(returnValue(context));
allowing(xwiki).getDocument(DOC_REFERENCE, xwikiContext);
will(returnValue(componentDoc));
}
});
this.bridge = getComponentManager().getInstance(WikiComponentBridge.class);
}
Aggregations