Search in sources :

Example 1 with SkinExtension

use of org.xwiki.skinx.SkinExtension in project xwiki-platform by xwiki.

the class IntegrationTest method initialize.

@RenderingTestSuite.Initialized
@SuppressWarnings("unchecked")
public void initialize(final MockingComponentManager componentManager) throws Exception {
    Mockery mockery = new JUnit4Mockery();
    // Since we have a dependency on XWiki Platform Oldcore the Context Component Manager will be found and the
    // test will try to look up the Dashboard macro in the User and Wiki Component Manager and thus need a Current
    // User and a Current Wiki. It's easier for this test to simply unregister the Context Component Manager rather
    // than have to provide mocks for them.
    componentManager.unregisterComponent(ComponentManager.class, "context");
    final SkinExtension mockSsfx = componentManager.registerMockComponent(mockery, SkinExtension.class, "ssfx", "ssfxMock");
    final SkinExtension mockJsfx = componentManager.registerMockComponent(mockery, SkinExtension.class, "jsfx", "jsfxMock");
    mockery.checking(new Expectations() {

        {
            allowing(mockSsfx).use(with("uicomponents/container/columns.css"), with(any(Map.class)));
            allowing(mockSsfx).use(with("uicomponents/dashboard/dashboard.css"), with(any(Map.class)));
            allowing(mockJsfx).use(with("js/scriptaculous/dragdrop.js"));
            allowing(mockJsfx).use(with("js/scriptaculous/effects.js"));
            allowing(mockJsfx).use(with("uicomponents/dashboard/dashboard.js"), with(any(Map.class)));
        }
    });
    final GadgetSource mockGadgetSource = componentManager.registerMockComponent(mockery, GadgetSource.class);
    mockery.checking(new Expectations() {

        {
            // Mock gadget for macrodashboard_nested_velocity.test
            allowing(mockGadgetSource).getGadgets(with("nested_velocity"), with(any(MacroTransformationContext.class)));
            will(returnValue(Arrays.asList(new Gadget("0", Arrays.asList(new WordBlock("title")), Arrays.asList(new MacroMarkerBlock("velocity", Collections.emptyMap(), "someVelocityCodeHere", Collections.singletonList(new WordBlock("someVelocityOutputHere")), true)), "1,1"))));
            // Mock gadget for macrodashboard1.test
            allowing(mockGadgetSource).getGadgets(with(aNull(String.class)), with(any(MacroTransformationContext.class)));
            will(returnValue(Arrays.asList(new Gadget("0", Arrays.<Block>asList(new WordBlock("title")), Arrays.<Block>asList(new WordBlock("content")), "1,1"))));
            allowing(mockGadgetSource).getDashboardSourceMetadata(with(AnyOf.anyOf(aNull(String.class), any(String.class))), with(any(MacroTransformationContext.class)));
            will(returnValue(Collections.<Block>emptyList()));
            allowing(mockGadgetSource).isEditing();
            // return true on is editing, to take as many paths possible
            will(returnValue(true));
        }
    });
    // Mock VelocityManager used in macrodashboard_nested_velocity.test because we do not have an XWikiContext
    // instance in the ExecutionContext.
    final VelocityManager mockVelocityManager = componentManager.registerMockComponentWithId(mockery, VelocityManager.class, "velocityManagerMock");
    mockery.checking(new Expectations() {

        {
            allowing(mockVelocityManager).getVelocityContext();
            will(returnValue(new VelocityContext()));
            allowing(mockVelocityManager).getCurrentVelocityContext();
            will(returnValue(new VelocityContext()));
            allowing(mockVelocityManager).getVelocityEngine();
            will(doAll(new CustomAction("mockGetVelocityEngine") {

                @Override
                public Object invoke(Invocation invocation) throws Throwable {
                    VelocityEngine velocityEngine = componentManager.getInstance(VelocityEngine.class);
                    Properties properties = new Properties();
                    properties.setProperty("resource.loader", "file");
                    velocityEngine.initialize(properties);
                    return velocityEngine;
                }
            }));
            allowing(mockVelocityManager).evaluate(with(any(Writer.class)), with(any(String.class)), with(any(Reader.class)));
            will(doAll(new CustomAction("mockEvaluate") {

                @Override
                public Object invoke(Invocation invocation) throws Throwable {
                    VelocityEngine velocityEngine = mockVelocityManager.getVelocityEngine();
                    return velocityEngine.evaluate(mockVelocityManager.getVelocityContext(), (Writer) invocation.getParameter(0), (String) invocation.getParameter(1), (Reader) invocation.getParameter(2));
                }
            }));
        }
    });
    componentManager.registerMockComponent(mockery, ContextualAuthorizationManager.class);
}
Also used : Expectations(org.jmock.Expectations) VelocityEngine(org.xwiki.velocity.VelocityEngine) SkinExtension(org.xwiki.skinx.SkinExtension) Invocation(org.jmock.api.Invocation) CustomAction(org.jmock.lib.action.CustomAction) VelocityContext(org.apache.velocity.VelocityContext) WordBlock(org.xwiki.rendering.block.WordBlock) MacroMarkerBlock(org.xwiki.rendering.block.MacroMarkerBlock) Reader(java.io.Reader) Properties(java.util.Properties) Mockery(org.jmock.Mockery) JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery) JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery) VelocityManager(org.xwiki.velocity.VelocityManager) MacroTransformationContext(org.xwiki.rendering.transformation.MacroTransformationContext) Map(java.util.Map) Writer(java.io.Writer)

Example 2 with SkinExtension

use of org.xwiki.skinx.SkinExtension in project xwiki-platform by xwiki.

the class IntegrationTests method initialize.

@RenderingTestSuite.Initialized
public void initialize(MockingComponentManager componentManager) throws Exception {
    Mockery mockery = new JUnit4Mockery();
    final SkinExtension ssfxMock = componentManager.registerMockComponent(mockery, SkinExtension.class, "ssfx");
    mockery.checking(new Expectations() {

        {
            String cssPath = "uicomponents/container/columns.css";
            allowing(ssfxMock).use(with(cssPath));
            allowing(ssfxMock).use(with(cssPath), with(any(Map.class)));
        }
    });
}
Also used : Expectations(org.jmock.Expectations) JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery) SkinExtension(org.xwiki.skinx.SkinExtension) JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery) Mockery(org.jmock.Mockery) Map(java.util.Map)

Example 3 with SkinExtension

use of org.xwiki.skinx.SkinExtension in project xwiki-platform by xwiki.

the class IntegrationTests method initialize.

@RenderingTestSuite.Initialized
public void initialize(MockingComponentManager componentManager) throws Exception {
    Mockery mockery = new JUnit4Mockery();
    final SkinExtension jsfx = componentManager.registerMockComponent(mockery, SkinExtension.class, "jsfx", "jsfx");
    final SkinExtension ssfx = componentManager.registerMockComponent(mockery, SkinExtension.class, "ssfx", "ssfx");
    mockery.checking(new Expectations() {

        {
            allowing(jsfx).use(with(aNonNull(String.class)), with(aNonNull(Map.class)));
            allowing(ssfx).use(with(aNonNull(String.class)));
        }
    });
}
Also used : Expectations(org.jmock.Expectations) JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery) SkinExtension(org.xwiki.skinx.SkinExtension) JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery) Mockery(org.jmock.Mockery) Map(java.util.Map)

Aggregations

Map (java.util.Map)3 Expectations (org.jmock.Expectations)3 Mockery (org.jmock.Mockery)3 JUnit4Mockery (org.jmock.integration.junit4.JUnit4Mockery)3 SkinExtension (org.xwiki.skinx.SkinExtension)3 Reader (java.io.Reader)1 Writer (java.io.Writer)1 Properties (java.util.Properties)1 VelocityContext (org.apache.velocity.VelocityContext)1 Invocation (org.jmock.api.Invocation)1 CustomAction (org.jmock.lib.action.CustomAction)1 MacroMarkerBlock (org.xwiki.rendering.block.MacroMarkerBlock)1 WordBlock (org.xwiki.rendering.block.WordBlock)1 MacroTransformationContext (org.xwiki.rendering.transformation.MacroTransformationContext)1 VelocityEngine (org.xwiki.velocity.VelocityEngine)1 VelocityManager (org.xwiki.velocity.VelocityManager)1