1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.configuration.internal; |
21 |
|
|
22 |
|
import static org.mockito.Mockito.when; |
23 |
|
|
24 |
|
import java.util.Arrays; |
25 |
|
import java.util.HashSet; |
26 |
|
import java.util.List; |
27 |
|
import java.util.Locale; |
28 |
|
|
29 |
|
import org.junit.Assert; |
30 |
|
import org.junit.Test; |
31 |
|
import org.xwiki.component.manager.ComponentLookupException; |
32 |
|
import org.xwiki.configuration.internal.test.AbstractTestDocumentConfigurationSource; |
33 |
|
import org.xwiki.model.reference.DocumentReference; |
34 |
|
import org.xwiki.model.reference.LocalDocumentReference; |
35 |
|
import org.xwiki.properties.converter.ConversionException; |
36 |
|
|
37 |
|
import com.xpn.xwiki.XWikiException; |
38 |
|
|
39 |
|
|
40 |
|
@link |
41 |
|
|
42 |
|
@version |
43 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (50) |
Complexity: 9 |
Complexity Density: 0.22 |
|
44 |
|
public class WikiPreferencesConfigurationSourceTest extends AbstractTestDocumentConfigurationSource |
45 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
46 |
6 |
public WikiPreferencesConfigurationSourceTest()... |
47 |
|
{ |
48 |
6 |
super(WikiPreferencesConfigurationSource.class); |
49 |
|
} |
50 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
51 |
22 |
@Override... |
52 |
|
protected LocalDocumentReference getClassReference() |
53 |
|
{ |
54 |
22 |
return WikiPreferencesConfigurationSource.CLASS_REFERENCE; |
55 |
|
} |
56 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
57 |
6 |
@Override... |
58 |
|
public void before() throws Exception |
59 |
|
{ |
60 |
6 |
super.before(); |
61 |
|
|
62 |
6 |
this.oldcore.getXWikiContext().setLocale(Locale.ENGLISH); |
63 |
|
} |
64 |
|
|
65 |
|
|
66 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
67 |
1 |
@Test... |
68 |
|
public void testGetProperty() throws Exception |
69 |
|
{ |
70 |
1 |
Assert.assertEquals(null, this.componentManager.getComponentUnderTest().getProperty("key", String.class)); |
71 |
1 |
Assert.assertEquals("default", this.componentManager.getComponentUnderTest().getProperty("key", "default")); |
72 |
1 |
Assert.assertEquals(null, this.componentManager.getComponentUnderTest().getProperty("key")); |
73 |
1 |
Assert.assertEquals(null, this.componentManager.getComponentUnderTest().getProperty("key", Integer.class)); |
74 |
|
|
75 |
|
|
76 |
|
|
77 |
1 |
setStringProperty(new DocumentReference(CURRENT_WIKI, WikiPreferencesConfigurationSource.CLASS_SPACE_NAME, |
78 |
|
WikiPreferencesConfigurationSource.CLASS_PAGE_NAME), "key", "value"); |
79 |
|
|
80 |
1 |
Assert.assertEquals("value", this.componentManager.getComponentUnderTest().getProperty("key", String.class)); |
81 |
1 |
Assert.assertEquals("value", this.componentManager.getComponentUnderTest().getProperty("key", "default")); |
82 |
1 |
Assert.assertEquals("value", this.componentManager.getComponentUnderTest().getProperty("key")); |
83 |
|
|
84 |
|
|
85 |
|
|
86 |
1 |
Assert.assertEquals(null, this.componentManager.getComponentUnderTest().getProperty("wrongkey", String.class)); |
87 |
1 |
Assert |
88 |
|
.assertEquals("default", this.componentManager.getComponentUnderTest().getProperty("wrongkey", "default")); |
89 |
1 |
Assert.assertEquals(null, this.componentManager.getComponentUnderTest().getProperty("wrongkey")); |
90 |
1 |
Assert.assertEquals(null, this.componentManager.getComponentUnderTest().getProperty("wrongkey", Integer.class)); |
91 |
|
|
92 |
|
|
93 |
|
|
94 |
1 |
setStringProperty(new DocumentReference(CURRENT_WIKI, WikiPreferencesConfigurationSource.CLASS_SPACE_NAME, |
95 |
|
WikiPreferencesConfigurationSource.CLASS_PAGE_NAME), "key", WikiPreferencesConfigurationSource.NO_VALUE); |
96 |
|
|
97 |
1 |
Assert.assertEquals(null, this.componentManager.getComponentUnderTest().getProperty("key", String.class)); |
98 |
1 |
Assert.assertEquals("default", this.componentManager.getComponentUnderTest().getProperty("key", "default")); |
99 |
1 |
Assert.assertEquals(null, this.componentManager.getComponentUnderTest().getProperty("key")); |
100 |
1 |
Assert.assertEquals(null, this.componentManager.getComponentUnderTest().getProperty("key", Integer.class)); |
101 |
|
} |
102 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
103 |
1 |
@Test... |
104 |
|
public void testGetPropertyTwiceWithDifferentType() throws Exception |
105 |
|
{ |
106 |
1 |
when(this.mockConverter.convert(String.class, "10")).thenReturn("10"); |
107 |
1 |
when(this.mockConverter.convert(Integer.class, "10")).thenReturn(10); |
108 |
|
|
109 |
1 |
setStringProperty(new DocumentReference(CURRENT_WIKI, WikiPreferencesConfigurationSource.CLASS_SPACE_NAME, |
110 |
|
WikiPreferencesConfigurationSource.CLASS_PAGE_NAME), "key", "10"); |
111 |
|
|
112 |
1 |
Assert.assertEquals("10", this.componentManager.getComponentUnderTest().getProperty("key", String.class)); |
113 |
1 |
Assert.assertEquals((Integer) 10, |
114 |
|
this.componentManager.getComponentUnderTest().<Integer>getProperty("key", Integer.class)); |
115 |
|
} |
116 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
117 |
1 |
@Test(expected = ConversionException.class)... |
118 |
|
public void testGetPropertyWithWrongType() throws Exception |
119 |
|
{ |
120 |
1 |
when(this.mockConverter.convert(Integer.class, "value")).thenThrow(ConversionException.class); |
121 |
|
|
122 |
1 |
setStringProperty(new DocumentReference(CURRENT_WIKI, WikiPreferencesConfigurationSource.CLASS_SPACE_NAME, |
123 |
|
WikiPreferencesConfigurationSource.CLASS_PAGE_NAME), "key", "value"); |
124 |
|
|
125 |
1 |
Assert.assertEquals("values", this.componentManager.getComponentUnderTest().getProperty("key", Integer.class)); |
126 |
|
} |
127 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
128 |
1 |
@Test... |
129 |
|
public void testGetKeys() throws ComponentLookupException, XWikiException |
130 |
|
{ |
131 |
1 |
setStringProperty(new DocumentReference(CURRENT_WIKI, WikiPreferencesConfigurationSource.CLASS_SPACE_NAME, |
132 |
|
WikiPreferencesConfigurationSource.CLASS_PAGE_NAME), "key1", "value"); |
133 |
1 |
setStringProperty(new DocumentReference(CURRENT_WIKI, WikiPreferencesConfigurationSource.CLASS_SPACE_NAME, |
134 |
|
WikiPreferencesConfigurationSource.CLASS_PAGE_NAME), "key2", "value"); |
135 |
1 |
setStringProperty(new DocumentReference(CURRENT_WIKI, WikiPreferencesConfigurationSource.CLASS_SPACE_NAME, |
136 |
|
WikiPreferencesConfigurationSource.CLASS_PAGE_NAME), "emptykey", ""); |
137 |
1 |
setStringProperty(new DocumentReference(CURRENT_WIKI, WikiPreferencesConfigurationSource.CLASS_SPACE_NAME, |
138 |
|
WikiPreferencesConfigurationSource.CLASS_PAGE_NAME), "emptykey2", "---"); |
139 |
|
|
140 |
1 |
List<String> result = this.componentManager.getComponentUnderTest().getKeys(); |
141 |
|
|
142 |
1 |
Assert.assertEquals(new HashSet<String>(Arrays.asList("key1", "key2")), new HashSet<String>(result)); |
143 |
|
} |
144 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
145 |
1 |
@Test... |
146 |
|
public void testContainsKey() throws XWikiException, ComponentLookupException |
147 |
|
{ |
148 |
1 |
setStringProperty(new DocumentReference(CURRENT_WIKI, WikiPreferencesConfigurationSource.CLASS_SPACE_NAME, |
149 |
|
WikiPreferencesConfigurationSource.CLASS_PAGE_NAME), "key", "value"); |
150 |
|
|
151 |
1 |
Assert.assertTrue(this.componentManager.getComponentUnderTest().containsKey("key")); |
152 |
1 |
Assert.assertFalse(this.componentManager.getComponentUnderTest().containsKey("wrongkey")); |
153 |
|
} |
154 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
155 |
1 |
@Test... |
156 |
|
public void testIsEmpty() throws ComponentLookupException, XWikiException |
157 |
|
{ |
158 |
1 |
Assert.assertTrue(this.componentManager.getComponentUnderTest().isEmpty()); |
159 |
|
|
160 |
1 |
setStringProperty(new DocumentReference(CURRENT_WIKI, WikiPreferencesConfigurationSource.CLASS_SPACE_NAME, |
161 |
|
WikiPreferencesConfigurationSource.CLASS_PAGE_NAME), "key", "value"); |
162 |
|
|
163 |
1 |
Assert.assertFalse(this.componentManager.getComponentUnderTest().isEmpty()); |
164 |
|
} |
165 |
|
} |