Search in sources :

Example 11 with Execution

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

the class WikiManagerScriptServiceTest method setUp.

@Before
public void setUp() throws Exception {
    wikiManager = mocker.getInstance(WikiManager.class);
    wikiDescriptorManager = mocker.getInstance(WikiDescriptorManager.class);
    authorizationManager = mocker.getInstance(AuthorizationManager.class);
    scriptServiceManager = mocker.getInstance(ScriptServiceManager.class);
    entityReferenceSerializer = mocker.getInstance(new DefaultParameterizedType(null, EntityReferenceSerializer.class, String.class));
    standardURLConfiguration = mocker.getInstance(StandardURLConfiguration.class);
    wikiConfiguration = mocker.getInstance(WikiConfiguration.class);
    xcontextProvider = mocker.registerMockComponent(XWikiContext.TYPE_PROVIDER);
    xcontext = mock(XWikiContext.class);
    when(xcontextProvider.get()).thenReturn(xcontext);
    execution = mocker.getInstance(Execution.class);
    executionContext = new ExecutionContext();
    when(execution.getContext()).thenReturn(executionContext);
    currentUserRef = new DocumentReference("mainWiki", "XWiki", "User");
    when(xcontext.getUserReference()).thenReturn(currentUserRef);
    currentDoc = mock(XWikiDocument.class);
    when(xcontext.getDoc()).thenReturn(currentDoc);
    when(wikiDescriptorManager.getMainWikiId()).thenReturn("mainWiki");
    when(entityReferenceSerializer.serialize(currentUserRef)).thenReturn("mainWiki:XWiki.User");
    wikiDescriptorDocumentHelper = mocker.getInstance(WikiDescriptorDocumentHelper.class);
}
Also used : WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) WikiConfiguration(org.xwiki.wiki.configuration.WikiConfiguration) ScriptServiceManager(org.xwiki.script.service.ScriptServiceManager) XWikiContext(com.xpn.xwiki.XWikiContext) WikiDescriptorDocumentHelper(org.xwiki.wiki.internal.descriptor.document.WikiDescriptorDocumentHelper) WikiManager(org.xwiki.wiki.manager.WikiManager) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) Execution(org.xwiki.context.Execution) ExecutionContext(org.xwiki.context.ExecutionContext) AuthorizationManager(org.xwiki.security.authorization.AuthorizationManager) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) StandardURLConfiguration(org.xwiki.url.internal.standard.StandardURLConfiguration) DocumentReference(org.xwiki.model.reference.DocumentReference) Before(org.junit.Before)

Example 12 with Execution

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

the class DefaultDocumentMergeImporterTest method setUp.

@Before
public void setUp() throws Exception {
    this.xwiki = mock(XWiki.class);
    when(this.xcontext.getWiki()).thenReturn(this.xwiki);
    // documents
    this.previousDocument = mock(XWikiDocument.class, "previous");
    when(this.previousDocument.isNew()).thenReturn(false);
    when(this.previousDocument.getDocumentReferenceWithLocale()).thenReturn(this.documentReference);
    this.currentDocument = mock(XWikiDocument.class, "current");
    when(this.currentDocument.isNew()).thenReturn(false);
    when(this.currentDocument.getDocumentReferenceWithLocale()).thenReturn(this.documentReference);
    when(this.xwiki.getDocument(same(this.documentReference), same(xcontext))).thenReturn(this.currentDocument);
    this.nextDocument = mock(XWikiDocument.class, "next");
    when(this.nextDocument.isNew()).thenReturn(false);
    when(this.nextDocument.getDocumentReferenceWithLocale()).thenReturn(this.documentReference);
    this.mergedDocument = mock(XWikiDocument.class, "merged");
    when(this.mergedDocument.isNew()).thenReturn(false);
    when(this.mergedDocument.getDocumentReferenceWithLocale()).thenReturn(this.documentReference);
    when(this.currentDocument.clone()).thenReturn(this.mergedDocument);
    // merge
    this.configuration = new PackageConfiguration();
    this.mergeResult = new MergeResult();
    when(this.mergedDocument.merge(same(this.previousDocument), same(this.nextDocument), any(MergeConfiguration.class), any(XWikiContext.class))).thenReturn(this.mergeResult);
    // job status
    this.jobStatus = mock(JobStatus.class);
    this.configuration.setJobStatus(this.jobStatus);
    // execution
    this.econtext = new ExecutionContext();
    this.execution = this.mocker.getInstance(Execution.class);
    when(this.execution.getContext()).thenReturn(this.econtext);
}
Also used : JobStatus(org.xwiki.job.event.status.JobStatus) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) ExecutionContext(org.xwiki.context.ExecutionContext) Execution(org.xwiki.context.Execution) MergeResult(com.xpn.xwiki.doc.merge.MergeResult) XWiki(com.xpn.xwiki.XWiki) XWikiContext(com.xpn.xwiki.XWikiContext) MergeConfiguration(com.xpn.xwiki.doc.merge.MergeConfiguration) PackageConfiguration(org.xwiki.extension.xar.internal.handler.packager.PackageConfiguration) Before(org.junit.Before)

Example 13 with Execution

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

the class LESSContextTest method setUp.

@Before
public void setUp() throws Exception {
    execution = mocker.getInstance(Execution.class);
    executionContext = new ExecutionContext();
    when(execution.getContext()).thenReturn(executionContext);
}
Also used : Execution(org.xwiki.context.Execution) ExecutionContext(org.xwiki.context.ExecutionContext) Before(org.junit.Before)

Example 14 with Execution

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

the class VelocityContextInitializerTest method testVelocityBridges.

/**
 * Test the presence of velocity bridges.
 *
 * @throws Exception
 */
@Test
public void testVelocityBridges() throws Exception {
    // Make sure the execution context is not null when velocity bridges are initialized.
    getComponentManager().<Execution>getInstance(Execution.class).setContext(new ExecutionContext());
    VelocityContextFactory factory = getComponentManager().getInstance(VelocityContextFactory.class);
    VelocityContext context = factory.createContext();
    Assert.assertNotNull(context.get("officeimporter"));
    Assert.assertNotNull(context.get("ooconfig"));
    Assert.assertNotNull(context.get("oomanager"));
}
Also used : Execution(org.xwiki.context.Execution) ExecutionContext(org.xwiki.context.ExecutionContext) VelocityContextFactory(org.xwiki.velocity.VelocityContextFactory) VelocityContext(org.apache.velocity.VelocityContext) Test(org.junit.Test)

Example 15 with Execution

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

the class XWikiSetupCleanupFilter method getReleasableComponents.

/**
 * @param componentManager the component manager
 * @return the list of JAX-RS resources that are implemented as components with per-lookup policy and that have been
 *         instantiated during this request
 */
private List<XWikiRestComponent> getReleasableComponents(ComponentManager componentManager) {
    try {
        ExecutionContext executionContext = componentManager.<Execution>getInstance(Execution.class).getContext();
        @SuppressWarnings("unchecked") List<XWikiRestComponent> releasableComponents = (List<XWikiRestComponent>) executionContext.getProperty(Constants.RELEASABLE_COMPONENT_REFERENCES);
        return releasableComponents != null ? releasableComponents : Collections.<XWikiRestComponent>emptyList();
    } catch (Exception e) {
        getLogger().log(Level.WARNING, "Failed to retrieve the list of releasable components.", e);
        return Collections.emptyList();
    }
}
Also used : ExecutionContext(org.xwiki.context.ExecutionContext) Execution(org.xwiki.context.Execution) XWikiRestComponent(org.xwiki.rest.XWikiRestComponent) List(java.util.List) ComponentLifecycleException(org.xwiki.component.manager.ComponentLifecycleException)

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