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

File DefaultExtendedRenderingConfigurationTest.java

 

Code metrics

0
81
7
1
200
137
7
0.09
11.57
7
1

Classes

Class Line # Actions
DefaultExtendedRenderingConfigurationTest 50 81 0% 7 0
1.0100%
 

Contributing tests

This file is covered by 6 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.configuration;
21   
22    import java.util.Arrays;
23    import java.util.List;
24   
25    import javax.inject.Provider;
26   
27    import org.junit.Before;
28    import org.junit.Rule;
29    import org.junit.Test;
30    import org.xwiki.component.manager.ComponentManager;
31    import org.xwiki.component.util.DefaultParameterizedType;
32    import org.xwiki.configuration.ConfigurationSource;
33    import org.xwiki.rendering.parser.Parser;
34    import org.xwiki.rendering.syntax.Syntax;
35    import org.xwiki.rendering.syntax.SyntaxFactory;
36    import org.xwiki.rendering.syntax.SyntaxType;
37    import org.xwiki.test.mockito.MockitoComponentMockingRule;
38   
39    import com.xpn.xwiki.CoreConfiguration;
40   
41    import static org.junit.Assert.*;
42    import static org.mockito.Mockito.when;
43   
44    /**
45    * Unit tests for {@link org.xwiki.rendering.internal.configuration.DefaultExtendedRenderingConfiguration}.
46    *
47    * @version $Id: 0a1bf38afda4da916b8f2325175d4001b292713d $
48    * @since 8.2M1
49    */
 
50    public class DefaultExtendedRenderingConfigurationTest
51    {
52    @Rule
53    public MockitoComponentMockingRule<DefaultExtendedRenderingConfiguration> mocker =
54    new MockitoComponentMockingRule<>(DefaultExtendedRenderingConfiguration.class);
55   
 
56  6 toggle @Before
57    public void configure() throws Exception
58    {
59  6 Provider<ComponentManager> contextComponentManagerProvider =
60    this.mocker.registerMockComponent(
61    new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context");
62  6 when(contextComponentManagerProvider.get()).thenReturn(this.mocker);
63    }
64   
 
65  1 toggle @Test
66    public void getImageWidthLimit() throws Exception
67    {
68  1 ConfigurationSource source = this.mocker.getInstance(ConfigurationSource.class);
69  1 when(source.getProperty("rendering.imageWidthLimit", -1)).thenReturn(100);
70   
71  1 assertEquals(100, this.mocker.getComponentUnderTest().getImageWidthLimit());
72    }
73   
 
74  1 toggle @Test
75    public void getImageHeightLimit() throws Exception
76    {
77  1 ConfigurationSource source = this.mocker.getInstance(ConfigurationSource.class);
78  1 when(source.getProperty("rendering.imageHeightLimit", -1)).thenReturn(150);
79   
80  1 assertEquals(150, this.mocker.getComponentUnderTest().getImageHeightLimit());
81    }
82   
 
83  1 toggle @Test
84    public void isImageDimensionsIncludedInImageURL() throws Exception
85    {
86  1 ConfigurationSource source = this.mocker.getInstance(ConfigurationSource.class);
87  1 when(source.getProperty("rendering.imageDimensionsIncludedInImageURL", true)).thenReturn(false);
88   
89  1 assertFalse(this.mocker.getComponentUnderTest().isImageDimensionsIncludedInImageURL());
90    }
91   
 
92  1 toggle @Test
93    public void getConfiguredAndDisabledSyntaxesWhenNoConfigXObjectAndExistingXWikiCfgProperty() throws Exception
94    {
95  1 ConfigurationSource renderingSource = this.mocker.getInstance(ConfigurationSource.class, "rendering");
96  1 when(renderingSource.getProperty("disabledSyntaxes")).thenReturn(null);
97   
98  1 ConfigurationSource xwikiCfgSource = this.mocker.getInstance(ConfigurationSource.class, "xwikicfg");
99  1 when(xwikiCfgSource.getProperty("xwiki.rendering.syntaxes", List.class)).thenReturn(
100    Arrays.asList("xwiki/2.0", "xwiki/2.1"));
101   
102    // Register some Syntaxes for the test
103   
104  1 SyntaxFactory syntaxFactory = this.mocker.getInstance(SyntaxFactory.class);
105  1 Syntax xwikiSyntax20 = new Syntax(new SyntaxType("xwiki", "XWiki"), "2.0");
106  1 when(syntaxFactory.createSyntaxFromIdString("xwiki/2.0")).thenReturn(xwikiSyntax20);
107  1 Syntax xwikiSyntax21 = new Syntax(new SyntaxType("xwiki", "XWiki"), "2.1");
108  1 when(syntaxFactory.createSyntaxFromIdString("xwiki/2.1")).thenReturn(xwikiSyntax21);
109  1 Parser xwikiSyntax20Parser = this.mocker.registerMockComponent(Parser.class, "xwiki/2.0");
110  1 when(xwikiSyntax20Parser.getSyntax()).thenReturn(xwikiSyntax20);
111  1 Parser xwikiSyntax21Parser = this.mocker.registerMockComponent(Parser.class, "xwiki/2.1");
112  1 when(xwikiSyntax21Parser.getSyntax()).thenReturn(xwikiSyntax21);
113   
114  1 Parser syntax1Parser = this.mocker.registerMockComponent(Parser.class, "syntax1/1.0");
115  1 Syntax syntax1 = new Syntax(new SyntaxType("syntax1", "Syntax 1"), "1.0");
116  1 when(syntax1Parser.getSyntax()).thenReturn(syntax1);
117  1 Parser syntax2Parser = this.mocker.registerMockComponent(Parser.class, "syntax2/1.0");
118  1 Syntax syntax2 = new Syntax(new SyntaxType("syntax2", "Syntax 2"), "1.0");
119  1 when(syntax2Parser.getSyntax()).thenReturn(syntax2);
120   
121  1 List<Syntax> disabledSyntaxes = this.mocker.getComponentUnderTest().getDisabledSyntaxes();
122  1 assertEquals(2, disabledSyntaxes.size());
123  1 assertTrue(disabledSyntaxes.contains(syntax1));
124  1 assertTrue(disabledSyntaxes.contains(syntax2));
125   
126  1 List<Syntax> configuredSyntaxes = this.mocker.getComponentUnderTest().getConfiguredSyntaxes();
127  1 assertEquals(2, configuredSyntaxes.size());
128  1 assertTrue(configuredSyntaxes.contains(xwikiSyntax20));
129  1 assertTrue(configuredSyntaxes.contains(xwikiSyntax21));
130    }
131   
 
132  1 toggle @Test
133    public void getConfiguredAndDisabledSyntaxesWhenNoConfigXObjectAndNoXWikiCfgProperty() throws Exception
134    {
135  1 ConfigurationSource renderingSource = this.mocker.getInstance(ConfigurationSource.class, "rendering");
136  1 when(renderingSource.getProperty("disabledSyntaxes")).thenReturn(null);
137   
138  1 ConfigurationSource xwikiCfgSource = this.mocker.getInstance(ConfigurationSource.class, "xwikicfg");
139  1 when(xwikiCfgSource.getProperty("xwiki.rendering.syntaxes", List.class)).thenReturn(null);
140   
141  1 CoreConfiguration coreConfiguration = this.mocker.getInstance(CoreConfiguration.class);
142  1 Syntax defaultSyntax = new Syntax(new SyntaxType("xwiki", "XWiki"), "2.1");
143  1 when(coreConfiguration.getDefaultDocumentSyntax()).thenReturn(defaultSyntax);
144   
145    // Register some Syntaxes for the test
146   
147  1 Parser defaultSyntaxParser = this.mocker.registerMockComponent(Parser.class, "xwiki/2.1");
148  1 when(defaultSyntaxParser.getSyntax()).thenReturn(defaultSyntax);
149   
150  1 Parser syntax1Parser = this.mocker.registerMockComponent(Parser.class, "syntax1/1.0");
151  1 Syntax syntax1 = new Syntax(new SyntaxType("syntax1", "Syntax 1"), "1.0");
152  1 when(syntax1Parser.getSyntax()).thenReturn(syntax1);
153  1 Parser syntax2Parser = this.mocker.registerMockComponent(Parser.class, "syntax2/1.0");
154  1 Syntax syntax2 = new Syntax(new SyntaxType("syntax2", "Syntax 2"), "1.0");
155  1 when(syntax2Parser.getSyntax()).thenReturn(syntax2);
156   
157  1 List<Syntax> disabledSyntaxes = this.mocker.getComponentUnderTest().getDisabledSyntaxes();
158  1 assertEquals(2, disabledSyntaxes.size());
159  1 assertTrue(disabledSyntaxes.contains(syntax1));
160  1 assertTrue(disabledSyntaxes.contains(syntax2));
161   
162  1 List<Syntax> configuredSyntaxes = this.mocker.getComponentUnderTest().getConfiguredSyntaxes();
163  1 assertEquals(1, configuredSyntaxes.size());
164  1 assertTrue(configuredSyntaxes.contains(defaultSyntax));
165    }
166   
 
167  1 toggle @Test
168    public void getConfiguredAndDisabledSyntaxesWhenConfigXObjectExists() throws Exception
169    {
170  1 ConfigurationSource renderingSource = this.mocker.getInstance(ConfigurationSource.class, "rendering");
171  1 when(renderingSource.getProperty("disabledSyntaxes")).thenReturn(
172    Arrays.asList("syntax1/1.0", "syntax2/1.0"));
173   
174    // Register some Syntaxes for the test
175   
176  1 Parser syntax1Parser = this.mocker.registerMockComponent(Parser.class, "syntax1/1.0");
177  1 Syntax syntax1 = new Syntax(new SyntaxType("syntax1", "Syntax 1"), "1.0");
178  1 when(syntax1Parser.getSyntax()).thenReturn(syntax1);
179  1 Parser syntax2Parser = this.mocker.registerMockComponent(Parser.class, "syntax2/1.0");
180  1 Syntax syntax2 = new Syntax(new SyntaxType("syntax2", "Syntax 2"), "1.0");
181  1 when(syntax2Parser.getSyntax()).thenReturn(syntax2);
182   
183  1 SyntaxFactory syntaxFactory = this.mocker.getInstance(SyntaxFactory.class);
184  1 when(syntaxFactory.createSyntaxFromIdString("syntax1/1.0")).thenReturn(syntax1);
185  1 when(syntaxFactory.createSyntaxFromIdString("syntax2/1.0")).thenReturn(syntax2);
186   
187  1 Parser xwikiSyntax20Parser = this.mocker.registerMockComponent(Parser.class, "xwiki/2.0");
188  1 Syntax xwikiSyntax20 = new Syntax(new SyntaxType("xwiki", "XWiki"), "2.0");
189  1 when(xwikiSyntax20Parser.getSyntax()).thenReturn(xwikiSyntax20);
190   
191  1 List<Syntax> disabledSyntaxes = this.mocker.getComponentUnderTest().getDisabledSyntaxes();
192  1 assertEquals(2, disabledSyntaxes.size());
193  1 assertTrue(disabledSyntaxes.contains(syntax1));
194  1 assertTrue(disabledSyntaxes.contains(syntax2));
195   
196  1 List<Syntax> configuredSyntaxes = this.mocker.getComponentUnderTest().getConfiguredSyntaxes();
197  1 assertEquals(1, configuredSyntaxes.size());
198  1 assertTrue(configuredSyntaxes.contains(xwikiSyntax20));
199    }
200    }