1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
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 |
|
@link |
46 |
|
|
47 |
|
@version |
48 |
|
@since |
49 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (88) |
Complexity: 7 |
Complexity Density: 0.09 |
|
50 |
|
public class DefaultExtendedRenderingConfigurationTest |
51 |
|
{ |
52 |
|
@Rule |
53 |
|
public MockitoComponentMockingRule<DefaultExtendedRenderingConfiguration> mocker = |
54 |
|
new MockitoComponentMockingRule<>(DefaultExtendedRenderingConfiguration.class); |
55 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
56 |
6 |
@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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
65 |
1 |
@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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
74 |
1 |
@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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
83 |
1 |
@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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (27) |
Complexity: 1 |
Complexity Density: 0.04 |
1PASS
|
|
92 |
1 |
@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 |
|
|
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (22) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
132 |
1 |
@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 |
|
|
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (21) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
167 |
1 |
@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 |
|
|
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 |
|
} |