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

File IntegrationTests.java

 

Coverage histogram

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

Code metrics

0
19
1
1
92
56
1
0.05
19
1
1

Classes

Class Line # Actions
IntegrationTests 57 19 0% 1 0
1.0100%
 

Contributing tests

No tests hitting this source file were found.

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.chart;
21   
22    import java.io.InputStreamReader;
23   
24    import org.junit.runner.RunWith;
25    import org.mockito.Mockito;
26    import org.xwiki.bridge.DocumentAccessBridge;
27    import org.xwiki.bridge.DocumentModelBridge;
28    import org.xwiki.display.internal.DocumentDisplayer;
29    import org.xwiki.display.internal.DocumentDisplayerParameters;
30    import org.xwiki.model.ModelContext;
31    import org.xwiki.model.reference.DocumentReference;
32    import org.xwiki.model.reference.DocumentReferenceResolver;
33    import org.xwiki.model.reference.SpaceReferenceResolver;
34    import org.xwiki.model.reference.WikiReference;
35    import org.xwiki.rendering.block.XDOM;
36    import org.xwiki.rendering.parser.Parser;
37    import org.xwiki.rendering.syntax.Syntax;
38    import org.xwiki.rendering.test.integration.RenderingTestSuite;
39    import org.xwiki.security.authorization.AuthorizationManager;
40    import org.xwiki.security.authorization.Right;
41    import org.xwiki.test.annotation.AllComponents;
42    import org.xwiki.test.mockito.MockitoComponentManager;
43   
44    import static org.mockito.Mockito.any;
45    import static org.mockito.Mockito.eq;
46    import static org.mockito.Mockito.when;
47   
48    /**
49    * Run all tests found in {@code *.test} files located in the classpath. These {@code *.test} files must follow the
50    * conventions described in {@link org.xwiki.rendering.test.integration.TestDataParser}.
51    *
52    * @version $Id: 5e6299e5b3913800958f5796d52d7f00191f3773 $
53    * @since 3.0RC1
54    */
55    @RunWith(RenderingTestSuite.class)
56    @AllComponents
 
57    public class IntegrationTests
58    {
59    private final static String WIKI_CONTENT_FILE = "wiki.txt";
60   
 
61  8 toggle @RenderingTestSuite.Initialized
62    public void initialize(MockitoComponentManager componentManager) throws Exception
63    {
64  8 ModelContext modelContext = componentManager.registerMockComponent(ModelContext.class);
65  8 when(modelContext.getCurrentEntityReference()).thenReturn(new WikiReference("currentWiki"));
66   
67    // Document Access Bridge mock
68  8 DocumentAccessBridge dab = componentManager.registerMockComponent(DocumentAccessBridge.class);
69  8 DocumentReference documentReference = new DocumentReference("wiki", "space", "page");
70  8 DocumentReference currentDocumentReference =
71    new DocumentReference("currentwiki", "currentspace", "currentpage");
72  8 DocumentModelBridge document = Mockito.mock(DocumentModelBridge.class);
73  8 when(dab.getDocumentURL(new DocumentReference("currentWiki", "space", "page"), "temp", null, null))
74    .thenReturn("temppath");
75  8 when(dab.getCurrentDocumentReference()).thenReturn(currentDocumentReference);
76  8 when(dab.exists(documentReference)).thenReturn(true);
77  8 when(dab.getDocument(documentReference)).thenReturn(document);
78  8 when(dab.getCurrentUserReference()).thenReturn(null);
79   
80  8 DocumentDisplayer displayer = componentManager.registerMockComponent(DocumentDisplayer.class);
81  8 Parser parser = componentManager.getInstance(Parser.class, Syntax.XWIKI_2_0.toIdString());
82  8 final XDOM xdom = parser.parse(new InputStreamReader(
83    getClass().getClassLoader().getResourceAsStream(WIKI_CONTENT_FILE)));
84  8 when(displayer.display(eq(document), any(DocumentDisplayerParameters.class))).thenReturn(xdom);
85   
86  8 AuthorizationManager authorizationManager = componentManager.registerMockComponent(AuthorizationManager.class);
87  8 when(authorizationManager.hasAccess(Right.VIEW, null, documentReference)).thenReturn(true);
88   
89  8 componentManager.registerMockComponent(DocumentReferenceResolver.TYPE_STRING, "current");
90  8 componentManager.registerMockComponent(SpaceReferenceResolver.TYPE_STRING, "current");
91    }
92    }