1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.rendering.macro.dashboard

File IntegrationTest.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

0
39
6
1
166
116
6
0.15
6.5
6
1

Classes

Class Line # Actions
IntegrationTest 57 39 0% 6 0
1.0100%
 

Contributing tests

This file is covered by 2 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.rendering.macro.dashboard;
21   
22    import java.io.Reader;
23    import java.io.Writer;
24    import java.util.Arrays;
25    import java.util.Collections;
26    import java.util.Map;
27    import java.util.Properties;
28   
29    import org.apache.velocity.VelocityContext;
30    import org.hamcrest.core.AnyOf;
31    import org.jmock.Expectations;
32    import org.jmock.Mockery;
33    import org.jmock.api.Invocation;
34    import org.jmock.integration.junit4.JUnit4Mockery;
35    import org.jmock.lib.action.CustomAction;
36    import org.junit.runner.RunWith;
37    import org.xwiki.component.manager.ComponentManager;
38    import org.xwiki.rendering.block.Block;
39    import org.xwiki.rendering.block.MacroBlock;
40    import org.xwiki.rendering.block.WordBlock;
41    import org.xwiki.rendering.test.integration.RenderingTestSuite;
42    import org.xwiki.rendering.transformation.MacroTransformationContext;
43    import org.xwiki.security.authorization.ContextualAuthorizationManager;
44    import org.xwiki.skinx.SkinExtension;
45    import org.xwiki.test.jmock.MockingComponentManager;
46    import org.xwiki.velocity.VelocityEngine;
47    import org.xwiki.velocity.VelocityManager;
48   
49    /**
50    * Run all tests found in {@code *.test} files located in the classpath. These {@code *.test} files must follow the
51    * conventions described in {@link org.xwiki.rendering.test.integration.TestDataParser}.
52    *
53    * @version $Id: 573f7a7591fae543b705cffd2ebb72d0653e14cb $
54    * @since 3.0RC1
55    */
56    @RunWith(RenderingTestSuite.class)
 
57    public class IntegrationTest
58    {
 
59  2 toggle @RenderingTestSuite.Initialized
60    @SuppressWarnings("unchecked")
61    public void initialize(final MockingComponentManager componentManager) throws Exception
62    {
63  2 Mockery mockery = new JUnit4Mockery();
64   
65    // Since we have a dependency on XWiki Platform Oldcore the Context Component Manager will be found and the
66    // test will try to look up the Dashboard macro in the User and Wiki Component Manager and thus need a Current
67    // User and a Current Wiki. It's easier for this test to simply unregister the Context Component Manager rather
68    // than have to provide mocks for them.
69  2 componentManager.unregisterComponent(ComponentManager.class, "context");
70   
71  2 final SkinExtension mockSsfx =
72    componentManager.registerMockComponent(mockery, SkinExtension.class, "ssfx", "ssfxMock");
73  2 final SkinExtension mockJsfx =
74    componentManager.registerMockComponent(mockery, SkinExtension.class, "jsfx", "jsfxMock");
75  2 mockery.checking(new Expectations()
76    {
 
77  2 toggle {
78  2 allowing(mockSsfx).use(with("uicomponents/container/columns.css"), with(any(Map.class)));
79  2 allowing(mockSsfx).use(with("uicomponents/dashboard/dashboard.css"), with(any(Map.class)));
80  2 allowing(mockJsfx).use(with("js/scriptaculous/dragdrop.js"));
81  2 allowing(mockJsfx).use(with("js/scriptaculous/effects.js"));
82  2 allowing(mockJsfx).use(with("js/xwiki/wysiwyg/xwe/XWikiWysiwyg.js"), with(any(Map.class)));
83  2 allowing(mockJsfx).use(with("uicomponents/dashboard/dashboard.js"), with(any(Map.class)));
84    }
85    });
86   
87  2 final GadgetSource mockGadgetSource = componentManager.registerMockComponent(mockery, GadgetSource.class);
88  2 mockery.checking(new Expectations()
89    {
 
90  2 toggle {
91    // Mock gadget for macrodashboard_nested_velocity.test
92  2 allowing(mockGadgetSource).getGadgets(with("nested_velocity"),
93    with(any(MacroTransformationContext.class)));
94  2 will(
95    returnValue(
96    Arrays
97    .asList(
98    new Gadget("0", Arrays.<Block>asList(new WordBlock("title")),
99    Arrays.<Block>asList(new MacroBlock("velocity",
100    Collections.<String, String>emptyMap(), "someVelocityCodeHere", true)),
101    "1,1"))));
102   
103    // Mock gadget for macrodashboard1.test
104  2 allowing(mockGadgetSource).getGadgets(with(aNull(String.class)),
105    with(any(MacroTransformationContext.class)));
106  2 will(returnValue(Arrays.asList(new Gadget("0", Arrays.<Block>asList(new WordBlock("title")),
107    Arrays.<Block>asList(new WordBlock("content")), "1,1"))));
108   
109  2 allowing(mockGadgetSource).getDashboardSourceMetadata(
110    with(AnyOf.anyOf(aNull(String.class), any(String.class))),
111    with(any(MacroTransformationContext.class)));
112  2 will(returnValue(Collections.<Block>emptyList()));
113   
114  2 allowing(mockGadgetSource).isEditing();
115    // return true on is editing, to take as many paths possible
116  2 will(returnValue(true));
117    }
118    });
119   
120    // Mock VelocityManager used in macrodashboard_nested_velocity.test because we do not have an XWikiContext
121    // instance in the ExecutionContext.
122  2 final VelocityManager mockVelocityManager =
123    componentManager.registerMockComponentWithId(mockery, VelocityManager.class, "velocityManagerMock");
124  2 mockery.checking(new Expectations()
125    {
 
126  2 toggle {
127  2 allowing(mockVelocityManager).getVelocityContext();
128  2 will(returnValue(new VelocityContext()));
129  2 allowing(mockVelocityManager).getCurrentVelocityContext();
130  2 will(returnValue(new VelocityContext()));
131  2 allowing(mockVelocityManager).getVelocityEngine();
132  2 will(doAll(new CustomAction("mockGetVelocityEngine")
133    {
 
134  6 toggle @Override
135    public Object invoke(Invocation invocation) throws Throwable
136    {
137  6 VelocityEngine velocityEngine = componentManager.getInstance(VelocityEngine.class);
138  6 Properties properties = new Properties();
139  6 properties.setProperty("resource.loader", "file");
140  6 velocityEngine.initialize(properties);
141   
142  6 return velocityEngine;
143    }
144   
145    }));
146  2 allowing(mockVelocityManager).evaluate(with(any(Writer.class)), with(any(String.class)),
147    with(any(Reader.class)));
148  2 will(doAll(new CustomAction("mockEvaluate")
149    {
 
150  2 toggle @Override
151    public Object invoke(Invocation invocation) throws Throwable
152    {
153  2 VelocityEngine velocityEngine = mockVelocityManager.getVelocityEngine();
154   
155  2 return velocityEngine.evaluate(mockVelocityManager.getVelocityContext(),
156    (Writer) invocation.getParameter(0), (String) invocation.getParameter(1),
157    (Reader) invocation.getParameter(2));
158    }
159   
160    }));
161    }
162    });
163   
164  2 componentManager.registerMockComponent(mockery, ContextualAuthorizationManager.class);
165    }
166    }