Search in sources :

Example 16 with ExecutionContext

use of org.xwiki.context.ExecutionContext 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 17 with ExecutionContext

use of org.xwiki.context.ExecutionContext 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 18 with ExecutionContext

use of org.xwiki.context.ExecutionContext 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 19 with ExecutionContext

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

the class CachedModelBridge method getToggeableFilterActivations.

@Override
public Map<String, Boolean> getToggeableFilterActivations(DocumentReference user) throws NotificationException {
    // We need to store the user reference in the cache's key, otherwise all users of the same context will share
    // the same cache, which can happen when a notification email is triggered.
    final String contextEntry = String.format(CONTEXT_KEY_FORMAT, USER_TOGGLEABLE_FILTER_PREFERENCES, serializer.serialize(user));
    ExecutionContext context = execution.getContext();
    if (context.hasProperty(contextEntry)) {
        return (Map<String, Boolean>) context.getProperty(contextEntry);
    }
    Map<String, Boolean> values = modelBridge.getToggeableFilterActivations(user);
    context.setProperty(contextEntry, values);
    return values;
}
Also used : ExecutionContext(org.xwiki.context.ExecutionContext) Map(java.util.Map)

Example 20 with ExecutionContext

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

the class DefaultVelocityManager method getVelocityEngineMacrosTemplate.

/**
 * @return the key used to cache the Velocity Engines. We have one Velocity Engine per skin which has a macros.vm
 *         file on the filesystem. Right now we don't support macros.vm defined in custom skins in wiki pages.
 */
private Template getVelocityEngineMacrosTemplate() {
    Template template = null;
    Map<String, Template> templateCache = null;
    Skin currentSkin = this.skinManager.getCurrentSkin(true);
    // Generating this key is very expensive so we cache it in the context
    ExecutionContext econtext = this.execution.getContext();
    if (econtext != null) {
        templateCache = (Map<String, Template>) econtext.getProperty(VELOCITYENGINE_CACHEKEY_NAME);
        if (templateCache == null) {
            templateCache = new HashMap<>();
            econtext.setProperty(VELOCITYENGINE_CACHEKEY_NAME, templateCache);
        } else {
            template = templateCache.get(currentSkin.getId());
        }
    }
    if (template == null) {
        template = this.templates.get().getTemplate("macros.vm");
        if (templateCache != null) {
            templateCache.put(currentSkin.getId(), template);
        }
    }
    return template;
}
Also used : ExecutionContext(org.xwiki.context.ExecutionContext) Skin(org.xwiki.skin.Skin) Template(org.xwiki.template.Template)

Aggregations

ExecutionContext (org.xwiki.context.ExecutionContext)114 Execution (org.xwiki.context.Execution)62 XWikiContext (com.xpn.xwiki.XWikiContext)47 Before (org.junit.Before)31 Test (org.junit.Test)25 XWiki (com.xpn.xwiki.XWiki)19 DocumentReference (org.xwiki.model.reference.DocumentReference)19 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)15 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)14 ComponentManager (org.xwiki.component.manager.ComponentManager)9 ExecutionContextException (org.xwiki.context.ExecutionContextException)9 WikiDescriptorManager (org.xwiki.wiki.descriptor.WikiDescriptorManager)9 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)8 ExecutionContextManager (org.xwiki.context.ExecutionContextManager)8 List (java.util.List)6 Map (java.util.Map)6 Properties (java.util.Properties)6 Session (javax.mail.Session)6 MimeMessage (javax.mail.internet.MimeMessage)6 XWikiException (com.xpn.xwiki.XWikiException)5