Search in sources :

Example 26 with Execution

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();
    }
}
Also used : JobDataMap(org.quartz.JobDataMap) Execution(org.xwiki.context.Execution) JobExecutionContext(org.quartz.JobExecutionContext) ExecutionContext(org.xwiki.context.ExecutionContext) JobExecutionException(org.quartz.JobExecutionException) ExecutionContextManager(org.xwiki.context.ExecutionContextManager) ExecutionContextException(org.xwiki.context.ExecutionContextException)

Example 27 with Execution

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);
}
Also used : ExecutionContext(org.xwiki.context.ExecutionContext) Execution(org.xwiki.context.Execution) AfterComponent(org.xwiki.test.annotation.AfterComponent)

Example 28 with Execution

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());
}
Also used : Execution(org.xwiki.context.Execution) DefaultExecution(org.xwiki.context.internal.DefaultExecution) ExecutionContext(org.xwiki.context.ExecutionContext) ExecutionContextManager(org.xwiki.context.ExecutionContextManager) LoggerManager(org.xwiki.logging.LoggerManager) ObservationManager(org.xwiki.observation.ObservationManager) JobContext(org.xwiki.job.JobContext) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) JobProgressManager(org.xwiki.job.event.status.JobProgressManager) JobStatusStore(org.xwiki.job.JobStatusStore) Provider(javax.inject.Provider) Before(org.junit.Before)

Example 29 with Execution

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);
}
Also used : Execution(org.xwiki.context.Execution) ExecutionContext(org.xwiki.context.ExecutionContext) WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) WikiCreator(org.xwiki.platform.wiki.creationjob.WikiCreator) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) ExtensionId(org.xwiki.extension.ExtensionId) AuthorizationManager(org.xwiki.security.authorization.AuthorizationManager) DistributionManager(org.xwiki.extension.distribution.internal.DistributionManager) Before(org.junit.Before)

Example 30 with Execution

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);
}
Also used : Expectations(org.jmock.Expectations) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) Execution(org.xwiki.context.Execution) ExecutionContext(org.xwiki.context.ExecutionContext) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) DefaultWikiComponentBridge(org.xwiki.component.wiki.internal.bridge.DefaultWikiComponentBridge) WikiComponentBridge(org.xwiki.component.wiki.internal.bridge.WikiComponentBridge) BaseObject(com.xpn.xwiki.objects.BaseObject) Before(org.junit.Before)

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