Search in sources :

Example 1 with ScriptMockSetup

use of org.xwiki.rendering.macro.script.ScriptMockSetup in project xwiki-platform by xwiki.

the class ClassLoadingTest method registerComponents.

@Override
protected void registerComponents() throws Exception {
    super.registerComponents();
    this.mockSetup = new ScriptMockSetup(getComponentManager());
    this.macro = getComponentManager().getInstance(Macro.class, "groovy");
    this.context = new MacroTransformationContext();
    // The script macro checks the current block (which is a macro block) to see what engine to use
    this.context.setCurrentMacroBlock(new MacroBlock("groovy", Collections.<String, String>emptyMap(), false));
    // Set the syntax since the script macro needs it to parse the script result using that syntax
    this.context.setSyntax(Syntax.XWIKI_2_0);
}
Also used : ScriptMockSetup(org.xwiki.rendering.macro.script.ScriptMockSetup) Macro(org.xwiki.rendering.macro.Macro) MacroTransformationContext(org.xwiki.rendering.transformation.MacroTransformationContext) MacroBlock(org.xwiki.rendering.block.MacroBlock)

Example 2 with ScriptMockSetup

use of org.xwiki.rendering.macro.script.ScriptMockSetup in project xwiki-platform by xwiki.

the class DefaultWikiMacroTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    // Script setup.
    ScriptMockSetup scriptMockSetup = new ScriptMockSetup(getMockery(), getComponentManager());
    final DocumentAccessBridge mockDocBridge = scriptMockSetup.bridge;
    this.mockWikiModel = scriptMockSetup.wikiModel;
    this.wikiMacroDocumentReference = new DocumentReference("wiki", "space", "macroPage");
    this.wikiMacroManager = getComponentManager().getInstance(WikiMacroManager.class);
    // Make sure the old XWiki Context is set up in the Execution Context since it's used in
    // DefaultWikiMacro.execute().
    this.xcontext = new HashMap<String, Object>();
    Execution execution = getComponentManager().getInstance(Execution.class);
    execution.getContext().setProperty("xwikicontext", this.xcontext);
    ScriptContextManager scm = getComponentManager().getInstance(ScriptContextManager.class);
    scm.getCurrentScriptContext().setAttribute("xcontext", this.xcontext, ScriptContext.ENGINE_SCOPE);
    getMockery().checking(new Expectations() {

        {
            allowing(mockWikiDescriptorManager).getCurrentWikiId();
            will(returnValue("wiki"));
            allowing(mockCurrentDocumentReferenceProvider).get();
            will(returnValue(new DocumentReference("wiki", "space", "document")));
            allowing(mockCurrentSpaceReferenceProvider).get();
            will(returnValue(new SpaceReference("space", new WikiReference("wiki"))));
            allowing(mockDocBridge).getCurrentUser();
            will(returnValue("dummy"));
            allowing(mockDocBridge).setCurrentUser(with(any(String.class)));
            allowing(mockDocBridge).getCurrentUserReference();
            will(returnValue(new DocumentReference("wiki", "XWiki", "dummy")));
            allowing(mockWikiMacroFactory).isAllowed(with(any(DocumentReference.class)), with(any(WikiMacroVisibility.class)));
            will(returnValue(true));
            // This is the document containing the wiki macro that will be put in the context available in the macro
            // Since we're not testing it here, it can be null.
            allowing(mockDocBridge).getDocumentInstance(wikiMacroDocumentReference);
            will(returnValue(null));
        }
    });
}
Also used : Expectations(org.jmock.Expectations) ScriptMockSetup(org.xwiki.rendering.macro.script.ScriptMockSetup) SpaceReference(org.xwiki.model.reference.SpaceReference) DocumentAccessBridge(org.xwiki.bridge.DocumentAccessBridge) ScriptContextManager(org.xwiki.script.ScriptContextManager) WikiMacroManager(org.xwiki.rendering.macro.wikibridge.WikiMacroManager) Execution(org.xwiki.context.Execution) WikiReference(org.xwiki.model.reference.WikiReference) WikiMacroVisibility(org.xwiki.rendering.macro.wikibridge.WikiMacroVisibility) DocumentReference(org.xwiki.model.reference.DocumentReference) Before(org.junit.Before)

Example 3 with ScriptMockSetup

use of org.xwiki.rendering.macro.script.ScriptMockSetup in project xwiki-platform by xwiki.

the class DisplayMacroTest method registerComponents.

@Override
protected void registerComponents() throws Exception {
    super.registerComponents();
    this.mockSetup = new ScriptMockSetup(getMockery(), getComponentManager());
    this.mockDocumentReferenceResolver = registerMockComponent(DocumentReferenceResolver.TYPE_STRING, "macro", "macroDocumentReferenceResolver");
    this.mockAuthorization = registerMockComponent(AuthorizationManager.class);
    this.displayMacro = (DisplayMacro) getComponentManager().getInstance(Macro.class, "display");
    this.rendererFactory = getComponentManager().getInstance(PrintRendererFactory.class, "event/1.0");
}
Also used : ScriptMockSetup(org.xwiki.rendering.macro.script.ScriptMockSetup) PrintRendererFactory(org.xwiki.rendering.renderer.PrintRendererFactory) AuthorizationManager(org.xwiki.security.authorization.AuthorizationManager)

Example 4 with ScriptMockSetup

use of org.xwiki.rendering.macro.script.ScriptMockSetup in project xwiki-platform by xwiki.

the class IncludeMacroTest method registerComponents.

@Override
protected void registerComponents() throws Exception {
    super.registerComponents();
    this.mockSetup = new ScriptMockSetup(getMockery(), getComponentManager());
    this.mockDocumentReferenceResolver = registerMockComponent(DocumentReferenceResolver.TYPE_STRING, "macro", "macroDocumentReferenceResolver");
    this.mockAuthorization = registerMockComponent(AuthorizationManager.class);
    this.includeMacro = getComponentManager().getInstance(Macro.class, "include");
    this.rendererFactory = getComponentManager().getInstance(PrintRendererFactory.class, "event/1.0");
}
Also used : ScriptMockSetup(org.xwiki.rendering.macro.script.ScriptMockSetup) IncludeMacro(org.xwiki.rendering.internal.macro.include.IncludeMacro) Macro(org.xwiki.rendering.macro.Macro) PrintRendererFactory(org.xwiki.rendering.renderer.PrintRendererFactory) AuthorizationManager(org.xwiki.security.authorization.AuthorizationManager)

Example 5 with ScriptMockSetup

use of org.xwiki.rendering.macro.script.ScriptMockSetup in project xwiki-platform by xwiki.

the class IntegrationTests method initialize.

@RenderingTestSuite.Initialized
public void initialize(MockingComponentManager cm) throws Exception {
    Mockery mockery = new JUnit4Mockery();
    new ScriptMockSetup(mockery, cm);
    // Script Context Mock
    final ScriptContextManager scm = cm.registerMockComponent(mockery, ScriptContextManager.class);
    final SimpleScriptContext scriptContext = new SimpleScriptContext();
    scriptContext.setAttribute("var", "value", ScriptContext.ENGINE_SCOPE);
    mockery.checking(new Expectations() {

        {
            allowing(scm).getScriptContext();
            will(returnValue(scriptContext));
        }
    });
}
Also used : Expectations(org.jmock.Expectations) JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery) ScriptMockSetup(org.xwiki.rendering.macro.script.ScriptMockSetup) SimpleScriptContext(javax.script.SimpleScriptContext) ScriptContextManager(org.xwiki.script.ScriptContextManager) JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery) Mockery(org.jmock.Mockery)

Aggregations

ScriptMockSetup (org.xwiki.rendering.macro.script.ScriptMockSetup)7 Expectations (org.jmock.Expectations)3 Macro (org.xwiki.rendering.macro.Macro)3 PrintRendererFactory (org.xwiki.rendering.renderer.PrintRendererFactory)3 ScriptContextManager (org.xwiki.script.ScriptContextManager)3 SimpleScriptContext (javax.script.SimpleScriptContext)2 Mockery (org.jmock.Mockery)2 JUnit4Mockery (org.jmock.integration.junit4.JUnit4Mockery)2 AuthorizationManager (org.xwiki.security.authorization.AuthorizationManager)2 Before (org.junit.Before)1 DocumentAccessBridge (org.xwiki.bridge.DocumentAccessBridge)1 Execution (org.xwiki.context.Execution)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1 SpaceReference (org.xwiki.model.reference.SpaceReference)1 WikiReference (org.xwiki.model.reference.WikiReference)1 MacroBlock (org.xwiki.rendering.block.MacroBlock)1 IncludeMacro (org.xwiki.rendering.internal.macro.include.IncludeMacro)1 WikiMacroManager (org.xwiki.rendering.macro.wikibridge.WikiMacroManager)1 WikiMacroVisibility (org.xwiki.rendering.macro.wikibridge.WikiMacroVisibility)1 MacroTransformationContext (org.xwiki.rendering.transformation.MacroTransformationContext)1