Search in sources :

Example 81 with Execution

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

the class DefaultTranslationBundleContextTest method before.

@Before
public void before() throws Exception {
    this.mockExecutionContext = new ExecutionContext();
    Execution mockExecution = this.mocker.getInstance(Execution.class);
    when(mockExecution.getContext()).thenReturn(mockExecutionContext);
    this.mockModelContext = this.mocker.getInstance(ModelContext.class);
    when(this.mockModelContext.getCurrentEntityReference()).thenReturn(new WikiReference("currentWiki"));
    this.mockContextComponentManagerProvider = this.mocker.registerMockComponent(new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context");
}
Also used : ModelContext(org.xwiki.model.ModelContext) ExecutionContext(org.xwiki.context.ExecutionContext) Execution(org.xwiki.context.Execution) WikiReference(org.xwiki.model.reference.WikiReference) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) Before(org.junit.Before)

Example 82 with Execution

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

the class XWikiDocument method backupContext.

public static void backupContext(Map<String, Object> backup, XWikiContext context) {
    // The XWiki Context isn't recreated when the Execution Context is cloned so we have to backup some of its data.
    // Backup the current document on the XWiki Context.
    backup.put("doc", context.getDoc());
    backup.put("cdoc", context.get("cdoc"));
    backup.put("tdoc", context.get("tdoc"));
    // Backup the secure document
    backup.put(CKEY_SDOC, context.get(CKEY_SDOC));
    // Clone the Execution Context to provide isolation. The clone will have a new Velocity and Script Context.
    Execution execution = Utils.getComponent(Execution.class);
    try {
        execution.pushContext(Utils.getComponent(ExecutionContextManager.class).clone(execution.getContext()));
    } catch (ExecutionContextException e) {
        throw new RuntimeException("Failed to clone the Execution Context", e);
    }
    // Bridge with old XWiki Context, required for legacy code.
    execution.getContext().setProperty(XWikiContext.EXECUTIONCONTEXT_KEY, context);
}
Also used : Execution(org.xwiki.context.Execution) ExecutionContextException(org.xwiki.context.ExecutionContextException)

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