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

File AbstractMacroContentTableBlockDataSourceTest.java

 

Coverage histogram

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

Code metrics

2
11
5
1
122
81
6
0.55
2.2
5
1.2

Classes

Class Line # Actions
AbstractMacroContentTableBlockDataSourceTest 81 11 0% 6 0
1.0100%
 

Contributing tests

This file is covered by 9 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.internal.macro.chart.source.table;
21   
22    import java.io.StringReader;
23    import java.util.HashMap;
24    import java.util.Map;
25   
26    import org.jmock.Expectations;
27    import org.junit.Before;
28    import org.xwiki.component.manager.ComponentManager;
29    import org.xwiki.model.internal.DefaultModelConfiguration;
30    import org.xwiki.model.internal.reference.DefaultEntityReferenceProvider;
31    import org.xwiki.model.internal.reference.RelativeStringEntityReferenceResolver;
32    import org.xwiki.rendering.block.XDOM;
33    import org.xwiki.rendering.internal.macro.chart.source.DataSource;
34    import org.xwiki.rendering.internal.parser.reference.DefaultUntypedLinkReferenceParser;
35    import org.xwiki.rendering.internal.parser.reference.type.AttachmentResourceReferenceTypeParser;
36    import org.xwiki.rendering.internal.parser.reference.type.DocumentResourceReferenceTypeParser;
37    import org.xwiki.rendering.internal.parser.reference.type.SpaceResourceReferenceTypeParser;
38    import org.xwiki.rendering.internal.parser.reference.type.URLResourceReferenceTypeParser;
39    import org.xwiki.rendering.internal.parser.xwiki20.XWiki20ImageReferenceParser;
40    import org.xwiki.rendering.internal.parser.xwiki20.XWiki20LinkReferenceParser;
41    import org.xwiki.rendering.internal.parser.xwiki20.XWiki20Parser;
42    import org.xwiki.rendering.internal.renderer.DefaultLinkLabelGenerator;
43    import org.xwiki.rendering.internal.renderer.plain.PlainTextBlockRenderer;
44    import org.xwiki.rendering.internal.renderer.plain.PlainTextRenderer;
45    import org.xwiki.rendering.internal.renderer.plain.PlainTextRendererFactory;
46    import org.xwiki.rendering.macro.MacroContentParser;
47    import org.xwiki.rendering.parser.Parser;
48    import org.xwiki.rendering.renderer.BlockRenderer;
49    import org.xwiki.rendering.syntax.Syntax;
50    import org.xwiki.test.annotation.ComponentList;
51    import org.xwiki.test.jmock.AbstractMockingComponentTestCase;
52    import org.xwiki.test.jmock.annotation.MockingRequirement;
53   
54    /**
55    * Helper to write unit tests for Table-based data sources.
56    *
57    * @version $Id: a054f87617b600da3a4b45d83c0bdcfc2e27f362 $
58    * @since 4.2M1
59    */
60    // @formatter:off
61    @ComponentList({
62    PlainTextBlockRenderer.class,
63    PlainTextRendererFactory.class,
64    XWiki20Parser.class,
65    XWiki20LinkReferenceParser.class,
66    DefaultUntypedLinkReferenceParser.class,
67    URLResourceReferenceTypeParser.class,
68    XWiki20ImageReferenceParser.class,
69    PlainTextRenderer.class,
70    DefaultLinkLabelGenerator.class,
71    DefaultEntityReferenceProvider.class,
72    DefaultModelConfiguration.class,
73    DocumentResourceReferenceTypeParser.class,
74    SpaceResourceReferenceTypeParser.class,
75    AttachmentResourceReferenceTypeParser.class,
76    RelativeStringEntityReferenceResolver.class
77    })
78    //@formatter:on
79    @MockingRequirement(value = MacroContentTableBlockDataSource.class,
80    exceptions={ComponentManager.class, BlockRenderer.class})
 
81    public abstract class AbstractMacroContentTableBlockDataSourceTest extends AbstractMockingComponentTestCase
82    {
83    private MacroContentTableBlockDataSource source;
84   
 
85  9 toggle @Before
86    public void configure() throws Exception
87    {
88  9 this.source = getComponentManager().getInstance(DataSource.class, "inline");
89    }
90   
 
91  15 toggle protected MacroContentTableBlockDataSource getDataSource()
92    {
93  15 return this.source;
94    }
95   
 
96  6 toggle protected Map<String, String> map(String... keyValues)
97    {
98  6 Map<String, String> map = new HashMap<String, String>();
99   
100  29 for (int i = 0; i < keyValues.length; i += 2) {
101  23 map.put(keyValues[i], keyValues[i + 1]);
102    }
103   
104  6 return map;
105    }
106   
 
107  7 toggle protected void setUpContentExpectation(final String macroContent) throws Exception
108    {
109  7 final MacroContentParser parser = getComponentManager().getInstance(MacroContentParser.class);
110   
111    // In order to make it easy to write unit tests, we allow tests to pass a string written in XWiki/2.0 synyax
112    // which we then parser to generate an XDOM that we use in the expectation.
113  7 final XDOM expectedXDOM = getComponentManager().<Parser>getInstance(Parser.class,
114    Syntax.XWIKI_2_0.toIdString()).parse(new StringReader(macroContent));
115   
 
116  7 toggle getMockery().checking(new Expectations() {{
117    // Simulate parsing the macro content that returns a XDOM not containing a table
118  7 oneOf(parser).parse(macroContent, null, true, false);
119  7 will(returnValue(expectedXDOM));
120    }});
121    }
122    }