1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.rendering.internal.configuration

File DefaultExtendedRenderingConfigurationTest.java

 

Code metrics

0
78
8
1
207
145
8
0.1
9.75
8
1

Classes

Class Line # Actions
DefaultExtendedRenderingConfigurationTest 58 78 0% 8 0
1.0100%
 

Contributing tests

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