1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.model.reference; |
21 |
|
|
22 |
|
import java.io.ByteArrayInputStream; |
23 |
|
import java.io.ByteArrayOutputStream; |
24 |
|
import java.io.ObjectInputStream; |
25 |
|
import java.io.ObjectOutputStream; |
26 |
|
import java.io.Serializable; |
27 |
|
import java.util.ArrayList; |
28 |
|
import java.util.Collections; |
29 |
|
import java.util.HashMap; |
30 |
|
import java.util.List; |
31 |
|
import java.util.Map; |
32 |
|
import java.util.UUID; |
33 |
|
|
34 |
|
import org.junit.Assert; |
35 |
|
import org.junit.Test; |
36 |
|
import org.xwiki.model.EntityType; |
37 |
|
|
38 |
|
import static org.junit.Assert.*; |
39 |
|
|
40 |
|
|
41 |
|
@link |
42 |
|
|
43 |
|
@version |
44 |
|
@since |
45 |
|
|
|
|
| 98.1% |
Uncovered Elements: 5 (269) |
Complexity: 27 |
Complexity Density: 0.11 |
|
46 |
|
public class EntityReferenceTest |
47 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
48 |
14 |
private Map<String, Serializable> getParamMap(int nb)... |
49 |
|
{ |
50 |
14 |
Map<String, Serializable> map = new HashMap<>(nb); |
51 |
46 |
for (int i=0; i < nb; i++) { |
52 |
32 |
map.put(UUID.randomUUID().toString(), UUID.randomUUID()); |
53 |
|
} |
54 |
14 |
return map; |
55 |
|
} |
56 |
|
|
|
|
| 66.7% |
Uncovered Elements: 2 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
57 |
8 |
private boolean checkParamMap(EntityReference ref, Map<String,Serializable> map)... |
58 |
|
{ |
59 |
8 |
for (Map.Entry<String, Serializable> entry : map.entrySet()) { |
60 |
20 |
if (entry.getValue() != ref.getParameter(entry.getKey())) { |
61 |
0 |
return false; |
62 |
|
} |
63 |
|
} |
64 |
8 |
return true; |
65 |
|
} |
66 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
67 |
1 |
@Test... |
68 |
|
public void extractReference() |
69 |
|
{ |
70 |
1 |
EntityReference wiki = new EntityReference("wiki", EntityType.WIKI, null); |
71 |
1 |
EntityReference space1 = new EntityReference("space1", EntityType.SPACE, wiki); |
72 |
1 |
EntityReference space2 = new EntityReference("space2", EntityType.SPACE, space1); |
73 |
1 |
EntityReference reference = new EntityReference("page", EntityType.DOCUMENT, space2); |
74 |
|
|
75 |
1 |
Assert.assertSame(wiki, reference.extractReference(EntityType.WIKI)); |
76 |
1 |
Assert.assertSame(space2, reference.extractReference(EntityType.SPACE)); |
77 |
1 |
Assert.assertSame(reference, reference.extractReference(EntityType.DOCUMENT)); |
78 |
1 |
Assert.assertNull(reference.extractReference(EntityType.ATTACHMENT)); |
79 |
|
} |
80 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
81 |
1 |
@Test... |
82 |
|
public void extractFirstReference() |
83 |
|
{ |
84 |
1 |
EntityReference wiki = new EntityReference("wiki", EntityType.WIKI, null); |
85 |
1 |
EntityReference space1 = new EntityReference("space1", EntityType.SPACE, wiki); |
86 |
1 |
EntityReference space2 = new EntityReference("space2", EntityType.SPACE, space1); |
87 |
1 |
EntityReference reference = new EntityReference("page", EntityType.DOCUMENT, space2); |
88 |
|
|
89 |
1 |
Assert.assertSame(wiki, reference.extractFirstReference(EntityType.WIKI)); |
90 |
1 |
Assert.assertSame(space1, reference.extractFirstReference(EntityType.SPACE)); |
91 |
1 |
Assert.assertSame(reference, reference.extractFirstReference(EntityType.DOCUMENT)); |
92 |
1 |
Assert.assertNull(reference.extractFirstReference(EntityType.ATTACHMENT)); |
93 |
|
} |
94 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
95 |
1 |
@Test... |
96 |
|
public void getRoot() |
97 |
|
{ |
98 |
1 |
EntityReference wiki = new EntityReference("wiki", EntityType.WIKI, null); |
99 |
1 |
EntityReference reference = new EntityReference("page", EntityType.DOCUMENT, |
100 |
|
new EntityReference("space", EntityType.SPACE, wiki)); |
101 |
1 |
Assert.assertSame(wiki, reference.getRoot()); |
102 |
|
} |
103 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
104 |
1 |
@Test... |
105 |
|
public void getReversedReferenceChain() |
106 |
|
{ |
107 |
1 |
EntityReference wiki = new EntityReference("wiki", EntityType.WIKI, null); |
108 |
1 |
EntityReference space = new EntityReference("space", EntityType.SPACE, wiki); |
109 |
1 |
EntityReference reference = new EntityReference("page", EntityType.DOCUMENT, space); |
110 |
|
|
111 |
1 |
List<EntityReference> list = reference.getReversedReferenceChain(); |
112 |
|
|
113 |
1 |
Assert.assertEquals(3,list.size()); |
114 |
1 |
Assert.assertSame(wiki, list.get(0)); |
115 |
1 |
Assert.assertSame(space, list.get(1)); |
116 |
1 |
Assert.assertSame(reference, list.get(2)); |
117 |
|
} |
118 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
119 |
1 |
@Test... |
120 |
|
public void copyConstructor() |
121 |
|
{ |
122 |
1 |
Map<String, Serializable> map1 = getParamMap(3); |
123 |
1 |
Map<String, Serializable> map2 = getParamMap(1); |
124 |
|
|
125 |
1 |
EntityReference parent = new EntityReference("space", EntityType.SPACE, |
126 |
|
new EntityReference("wiki", EntityType.WIKI, null, map2)); |
127 |
|
|
128 |
1 |
EntityReference reference = new EntityReference("page", EntityType.DOCUMENT, parent, map1); |
129 |
|
|
130 |
1 |
Assert.assertEquals("page",reference.getName()); |
131 |
1 |
Assert.assertSame(EntityType.DOCUMENT,reference.getType()); |
132 |
1 |
Assert.assertSame(parent,reference.getParent()); |
133 |
1 |
Assert.assertTrue(checkParamMap(reference, map1)); |
134 |
1 |
Assert.assertTrue(checkParamMap(reference.getParent().getParent(), map2)); |
135 |
|
} |
136 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (24) |
Complexity: 1 |
Complexity Density: 0.04 |
1PASS
|
|
137 |
1 |
@Test... |
138 |
|
public void validateEquals() |
139 |
|
{ |
140 |
1 |
EntityReference reference1 = new EntityReference("page", EntityType.DOCUMENT, |
141 |
|
new EntityReference("space", EntityType.SPACE, |
142 |
|
new EntityReference("wiki", EntityType.WIKI))); |
143 |
|
|
144 |
1 |
EntityReference reference2 = new EntityReference("page", EntityType.DOCUMENT, |
145 |
|
new EntityReference("space", EntityType.SPACE, |
146 |
|
new EntityReference("wiki", EntityType.WIKI))); |
147 |
|
|
148 |
1 |
EntityReference reference3 = new EntityReference("page", EntityType.DOCUMENT, |
149 |
|
new EntityReference("space", EntityType.SPACE, |
150 |
|
new EntityReference("wiki2", EntityType.WIKI))); |
151 |
|
|
152 |
1 |
EntityReference reference4 = new EntityReference("page", EntityType.DOCUMENT, |
153 |
|
new EntityReference("space2", EntityType.SPACE, |
154 |
|
new EntityReference("wiki", EntityType.WIKI))); |
155 |
|
|
156 |
1 |
EntityReference reference5 = new EntityReference("page2", EntityType.DOCUMENT, |
157 |
|
new EntityReference("space", EntityType.SPACE, |
158 |
|
new EntityReference("wiki", EntityType.WIKI))); |
159 |
|
|
160 |
1 |
EntityReference reference6 = new EntityReference("page", EntityType.DOCUMENT, null); |
161 |
|
|
162 |
1 |
Map<String, Serializable> map = getParamMap(3); |
163 |
1 |
EntityReference reference7 = new EntityReference("page", EntityType.DOCUMENT, |
164 |
|
new EntityReference("space", EntityType.SPACE, |
165 |
|
new EntityReference("wiki", EntityType.WIKI)), map); |
166 |
|
|
167 |
1 |
EntityReference reference8 = new EntityReference("page", EntityType.DOCUMENT, |
168 |
|
new EntityReference("space", EntityType.SPACE, |
169 |
|
new EntityReference("wiki", EntityType.WIKI)), map); |
170 |
|
|
171 |
1 |
EntityReference reference9 = new EntityReference("page", EntityType.DOCUMENT, |
172 |
|
new EntityReference("space", EntityType.SPACE, |
173 |
|
new EntityReference("wiki", EntityType.WIKI), map)); |
174 |
|
|
175 |
1 |
EntityReference reference10 = new EntityReference("page", EntityType.DOCUMENT, |
176 |
|
new EntityReference("space", EntityType.SPACE, |
177 |
|
new EntityReference("wiki", EntityType.WIKI, null, map))); |
178 |
|
|
179 |
1 |
Assert.assertTrue(reference1.equals(reference1)); |
180 |
1 |
Assert.assertTrue(reference1.equals(reference2)); |
181 |
1 |
Assert.assertFalse(reference1.equals(reference3)); |
182 |
1 |
Assert.assertFalse(reference1.equals(reference4)); |
183 |
1 |
Assert.assertFalse(reference1.equals(reference5)); |
184 |
1 |
Assert.assertFalse(reference1.equals(reference6)); |
185 |
1 |
Assert.assertEquals(reference6, new EntityReference("page", EntityType.DOCUMENT, null)); |
186 |
1 |
Assert.assertFalse(reference1.equals(reference7)); |
187 |
1 |
Assert.assertTrue(reference7.equals(reference8)); |
188 |
1 |
Assert.assertFalse(reference1.equals(reference9)); |
189 |
1 |
Assert.assertFalse(reference7.equals(reference9)); |
190 |
1 |
Assert.assertFalse(reference1.equals(reference10)); |
191 |
1 |
Assert.assertFalse(reference7.equals(reference10)); |
192 |
|
} |
193 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
194 |
1 |
@Test... |
195 |
|
public void equalsTo() |
196 |
|
{ |
197 |
1 |
EntityReference documentReference = new EntityReference("page", EntityType.DOCUMENT, |
198 |
|
new EntityReference("space", EntityType.SPACE, |
199 |
|
new EntityReference("wiki", EntityType.WIKI))); |
200 |
|
|
201 |
1 |
EntityReference localdocumentReference = new EntityReference("page", EntityType.DOCUMENT, |
202 |
|
new EntityReference("space", EntityType.SPACE)); |
203 |
|
|
204 |
1 |
assertTrue(localdocumentReference.equals(documentReference, EntityType.SPACE)); |
205 |
1 |
assertTrue(documentReference.equals(localdocumentReference, EntityType.SPACE)); |
206 |
|
} |
207 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
208 |
1 |
@Test... |
209 |
|
public void equalsFromTo() |
210 |
|
{ |
211 |
1 |
EntityReference documentReference = |
212 |
|
new EntityReference("page1", EntityType.DOCUMENT, new EntityReference("space", EntityType.SPACE, |
213 |
|
new EntityReference("wiki", EntityType.WIKI))); |
214 |
|
|
215 |
1 |
EntityReference spaceReference = |
216 |
|
new EntityReference("space", EntityType.SPACE, new EntityReference("wiki2", EntityType.WIKI)); |
217 |
|
|
218 |
1 |
assertTrue(spaceReference.equals(documentReference, EntityType.SPACE, EntityType.SPACE)); |
219 |
1 |
assertTrue(documentReference.equals(spaceReference, EntityType.SPACE, EntityType.SPACE)); |
220 |
|
} |
221 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
222 |
1 |
@Test... |
223 |
|
public void equalsNonRecursive() |
224 |
|
{ |
225 |
1 |
EntityReference documentReference1 = |
226 |
|
new EntityReference("page", EntityType.DOCUMENT, new EntityReference("space", EntityType.SPACE, |
227 |
|
new EntityReference("wiki", EntityType.WIKI))); |
228 |
1 |
EntityReference documentReference2 = |
229 |
|
new EntityReference("page", EntityType.DOCUMENT, new EntityReference("space2", EntityType.SPACE, |
230 |
|
new EntityReference("wiki2", EntityType.WIKI))); |
231 |
|
|
232 |
1 |
assertTrue(documentReference1.equalsNonRecursive(documentReference2)); |
233 |
|
|
234 |
1 |
assertFalse(documentReference1.getParent().equalsNonRecursive(documentReference2.getParent())); |
235 |
|
} |
236 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (24) |
Complexity: 1 |
Complexity Density: 0.04 |
1PASS
|
|
237 |
1 |
@Test... |
238 |
|
public void validateHashCode() |
239 |
|
{ |
240 |
1 |
EntityReference reference1 = new EntityReference("page", EntityType.DOCUMENT, |
241 |
|
new EntityReference("space", EntityType.SPACE, |
242 |
|
new EntityReference("wiki", EntityType.WIKI))); |
243 |
|
|
244 |
1 |
EntityReference reference2 = new EntityReference("page", EntityType.DOCUMENT, |
245 |
|
new EntityReference("space", EntityType.SPACE, |
246 |
|
new EntityReference("wiki", EntityType.WIKI))); |
247 |
|
|
248 |
1 |
EntityReference reference3 = new EntityReference("page", EntityType.DOCUMENT, |
249 |
|
new EntityReference("space", EntityType.SPACE, |
250 |
|
new EntityReference("wiki2", EntityType.WIKI))); |
251 |
|
|
252 |
1 |
EntityReference reference4 = new EntityReference("page", EntityType.DOCUMENT, |
253 |
|
new EntityReference("space2", EntityType.SPACE, |
254 |
|
new EntityReference("wiki", EntityType.WIKI))); |
255 |
|
|
256 |
1 |
EntityReference reference5 = new EntityReference("page2", EntityType.DOCUMENT, |
257 |
|
new EntityReference("space", EntityType.SPACE, |
258 |
|
new EntityReference("wiki", EntityType.WIKI))); |
259 |
|
|
260 |
1 |
EntityReference reference6 = new EntityReference("page", EntityType.DOCUMENT, null); |
261 |
|
|
262 |
1 |
Map<String, Serializable> map = getParamMap(3); |
263 |
1 |
EntityReference reference7 = new EntityReference("page", EntityType.DOCUMENT, |
264 |
|
new EntityReference("space", EntityType.SPACE, |
265 |
|
new EntityReference("wiki", EntityType.WIKI)), map); |
266 |
|
|
267 |
1 |
EntityReference reference8 = new EntityReference("page", EntityType.DOCUMENT, |
268 |
|
new EntityReference("space", EntityType.SPACE, |
269 |
|
new EntityReference("wiki", EntityType.WIKI)), map); |
270 |
|
|
271 |
1 |
EntityReference reference9 = new EntityReference("page", EntityType.DOCUMENT, |
272 |
|
new EntityReference("space", EntityType.SPACE, |
273 |
|
new EntityReference("wiki", EntityType.WIKI), map)); |
274 |
|
|
275 |
1 |
EntityReference reference10 = new EntityReference("page", EntityType.DOCUMENT, |
276 |
|
new EntityReference("space", EntityType.SPACE, |
277 |
|
new EntityReference("wiki", EntityType.WIKI, null, map))); |
278 |
|
|
279 |
1 |
Assert.assertEquals(reference1.hashCode(), reference1.hashCode()); |
280 |
1 |
Assert.assertEquals(reference1.hashCode(), reference2.hashCode()); |
281 |
1 |
Assert.assertFalse(reference1.hashCode() == reference3.hashCode()); |
282 |
1 |
Assert.assertFalse(reference1.hashCode() == reference4.hashCode()); |
283 |
1 |
Assert.assertFalse(reference1.hashCode() == reference5.hashCode()); |
284 |
1 |
Assert.assertFalse(reference1.hashCode() == reference6.hashCode()); |
285 |
1 |
Assert.assertEquals(reference6.hashCode(), new EntityReference("page", EntityType.DOCUMENT, null).hashCode()); |
286 |
1 |
Assert.assertFalse(reference1.hashCode() == reference7.hashCode()); |
287 |
1 |
Assert.assertEquals(reference7.hashCode(), reference8.hashCode()); |
288 |
1 |
Assert.assertFalse(reference1.hashCode() == reference9.hashCode()); |
289 |
1 |
Assert.assertFalse(reference7.hashCode() == reference9.hashCode()); |
290 |
1 |
Assert.assertFalse(reference1.hashCode() == reference10.hashCode()); |
291 |
1 |
Assert.assertFalse(reference7.hashCode() == reference10.hashCode()); |
292 |
|
} |
293 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (37) |
Complexity: 1 |
Complexity Density: 0.03 |
1PASS
|
|
294 |
1 |
@Test... |
295 |
|
public void compareTo() |
296 |
|
{ |
297 |
1 |
EntityReference reference = new EntityReference("f", EntityType.DOCUMENT, |
298 |
|
new EntityReference("e", EntityType.SPACE, |
299 |
|
new EntityReference("d", EntityType.WIKI))); |
300 |
|
|
301 |
1 |
EntityReference reference2 = new EntityReference("c", EntityType.DOCUMENT, |
302 |
|
new EntityReference("b", EntityType.SPACE, |
303 |
|
new EntityReference("a", EntityType.WIKI))); |
304 |
|
|
305 |
1 |
EntityReference reference3 = new EntityReference("c", EntityType.DOCUMENT, |
306 |
|
new EntityReference("a", EntityType.SPACE, |
307 |
|
new EntityReference("a", EntityType.WIKI))); |
308 |
|
|
309 |
1 |
EntityReference reference31 = |
310 |
|
new EntityReference("c", EntityType.DOCUMENT, new EntityReference("x", EntityType.SPACE, |
311 |
|
new EntityReference("a", EntityType.SPACE, new EntityReference("a", EntityType.WIKI)))); |
312 |
|
|
313 |
1 |
Map<String, Serializable> map1 = new HashMap<>(3); |
314 |
1 |
map1.put("param1", "a"); |
315 |
1 |
map1.put("param2", "b"); |
316 |
1 |
map1.put("param3", "c"); |
317 |
1 |
Map<String, Serializable> map2 = new HashMap<>(2); |
318 |
1 |
map2.put("param1", "a"); |
319 |
1 |
map2.put("param3", "c"); |
320 |
1 |
Map<String, Serializable> map3 = new HashMap<>(2); |
321 |
1 |
map3.put("param1", "b"); |
322 |
1 |
map3.put("param3", "c"); |
323 |
|
|
324 |
1 |
EntityReference reference4 = new EntityReference("c", EntityType.DOCUMENT, |
325 |
|
new EntityReference("a", EntityType.SPACE, |
326 |
|
new EntityReference("a", EntityType.WIKI)), map1); |
327 |
|
|
328 |
1 |
EntityReference reference5 = new EntityReference("c", EntityType.DOCUMENT, |
329 |
|
new EntityReference("a", EntityType.SPACE, |
330 |
|
new EntityReference("a", EntityType.WIKI)), map2); |
331 |
|
|
332 |
1 |
EntityReference reference6 = new EntityReference("c", EntityType.DOCUMENT, |
333 |
|
new EntityReference("a", EntityType.SPACE, |
334 |
|
new EntityReference("a", EntityType.WIKI)), map3); |
335 |
|
|
336 |
1 |
EntityReference reference61 = |
337 |
|
new EntityReference("c", EntityType.DOCUMENT, new EntityReference("x", EntityType.SPACE, |
338 |
|
new EntityReference("a", EntityType.SPACE, new EntityReference("a", EntityType.WIKI)), map3)); |
339 |
|
|
340 |
1 |
Assert.assertEquals(0, reference.compareTo(reference)); |
341 |
|
|
342 |
1 |
List<EntityReference> list = new ArrayList<>(); |
343 |
1 |
list.add(reference); |
344 |
1 |
list.add(reference2); |
345 |
1 |
list.add(reference3); |
346 |
1 |
list.add(reference31); |
347 |
1 |
list.add(reference4); |
348 |
1 |
list.add(reference5); |
349 |
1 |
list.add(reference6); |
350 |
1 |
list.add(reference61); |
351 |
1 |
Collections.sort(list); |
352 |
|
|
353 |
|
|
354 |
1 |
Assert.assertSame(reference3, list.get(0)); |
355 |
1 |
Assert.assertSame(reference4, list.get(1)); |
356 |
1 |
Assert.assertSame(reference5, list.get(2)); |
357 |
1 |
Assert.assertSame(reference6, list.get(3)); |
358 |
1 |
Assert.assertSame(reference31, list.get(4)); |
359 |
1 |
Assert.assertSame(reference61, list.get(5)); |
360 |
1 |
Assert.assertSame(reference2, list.get(6)); |
361 |
1 |
Assert.assertSame(reference, list.get(7)); |
362 |
|
} |
363 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
1PASS
|
|
364 |
1 |
@Test... |
365 |
|
public void nullTypeInConstructor() |
366 |
|
{ |
367 |
1 |
try { |
368 |
1 |
new EntityReference("name", null); |
369 |
0 |
Assert.fail("Should have thrown an exception here"); |
370 |
|
} catch (IllegalArgumentException expected) { |
371 |
1 |
Assert.assertEquals("An Entity Reference type cannot be null", expected.getMessage()); |
372 |
|
} |
373 |
|
} |
374 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
1PASS
|
|
375 |
1 |
@Test... |
376 |
|
public void nullNameInConstructor() |
377 |
|
{ |
378 |
1 |
try { |
379 |
1 |
new EntityReference(null, EntityType.WIKI); |
380 |
0 |
Assert.fail("Should have thrown an exception here"); |
381 |
|
} catch (IllegalArgumentException expected) { |
382 |
1 |
Assert.assertEquals("An Entity Reference name cannot be null or empty", expected.getMessage()); |
383 |
|
} |
384 |
|
} |
385 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
1PASS
|
|
386 |
1 |
@Test... |
387 |
|
public void emptyNameInConstructor() |
388 |
|
{ |
389 |
1 |
try { |
390 |
1 |
new EntityReference("", EntityType.WIKI); |
391 |
0 |
Assert.fail("Should have thrown an exception here"); |
392 |
|
} catch (IllegalArgumentException expected) { |
393 |
1 |
Assert.assertEquals("An Entity Reference name cannot be null or empty", expected.getMessage()); |
394 |
|
} |
395 |
|
} |
396 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (20) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
397 |
1 |
@Test... |
398 |
|
public void replaceParent() |
399 |
|
{ |
400 |
1 |
Map<String, Serializable> map1 = getParamMap(3); |
401 |
1 |
Map<String, Serializable> map2 = getParamMap(2); |
402 |
1 |
Map<String, Serializable> map3 = getParamMap(1); |
403 |
|
|
404 |
1 |
EntityReference wiki = new EntityReference("wiki", EntityType.WIKI, null, map3); |
405 |
1 |
EntityReference wiki2 = new EntityReference("wiki2", EntityType.WIKI, null); |
406 |
|
|
407 |
1 |
EntityReference space = new EntityReference("space", EntityType.SPACE, wiki, map2); |
408 |
1 |
EntityReference space2 = new EntityReference("space2", EntityType.SPACE, wiki); |
409 |
|
|
410 |
1 |
EntityReference reference = new EntityReference("page", EntityType.DOCUMENT, space, map1); |
411 |
1 |
EntityReference referenceSpace2 = reference.replaceParent(space, space2); |
412 |
1 |
EntityReference referenceWiki2 = reference.replaceParent(wiki, wiki2); |
413 |
|
|
414 |
|
|
415 |
1 |
Assert.assertNotSame(reference,referenceSpace2); |
416 |
1 |
Assert.assertTrue(checkParamMap(referenceSpace2, map1)); |
417 |
1 |
Assert.assertSame(space2,referenceSpace2.getParent()); |
418 |
|
|
419 |
1 |
Assert.assertNotSame(reference,referenceWiki2); |
420 |
1 |
Assert.assertTrue(checkParamMap(referenceWiki2, map1)); |
421 |
1 |
Assert.assertNotSame(space,referenceWiki2.getParent()); |
422 |
1 |
Assert.assertTrue(checkParamMap(referenceWiki2.getParent(), map2)); |
423 |
1 |
Assert.assertSame(wiki2,referenceWiki2.getParent().getParent()); |
424 |
|
|
425 |
1 |
Assert.assertSame(reference.replaceParent(wiki, wiki), reference); |
426 |
1 |
Assert.assertSame(reference.replaceParent(space, space), reference); |
427 |
|
} |
428 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
429 |
1 |
@Test... |
430 |
|
public void appendParent() |
431 |
|
{ |
432 |
1 |
Map<String, Serializable> map1 = getParamMap(3); |
433 |
1 |
Map<String, Serializable> map2 = getParamMap(2); |
434 |
|
|
435 |
1 |
EntityReference wiki = new EntityReference("wiki", EntityType.WIKI, null, map2); |
436 |
|
|
437 |
1 |
EntityReference space = new EntityReference("space", EntityType.SPACE, wiki, map1); |
438 |
1 |
EntityReference spaceAlone = new EntityReference("space", EntityType.SPACE, null, map1); |
439 |
|
|
440 |
1 |
EntityReference reference = new EntityReference("page", EntityType.DOCUMENT, space); |
441 |
1 |
EntityReference referenceSpace = new EntityReference("page", EntityType.DOCUMENT).appendParent(space); |
442 |
1 |
EntityReference referenceWiki = new EntityReference("page", EntityType.DOCUMENT, spaceAlone).appendParent(wiki); |
443 |
|
|
444 |
|
|
445 |
1 |
Assert.assertNotSame(reference,referenceSpace); |
446 |
1 |
Assert.assertEquals(reference,referenceSpace); |
447 |
1 |
Assert.assertSame(reference.getParent(),referenceSpace.getParent()); |
448 |
|
|
449 |
1 |
Assert.assertNotSame(reference,referenceWiki); |
450 |
1 |
Assert.assertEquals(reference,referenceWiki); |
451 |
1 |
Assert.assertSame(reference.getParent().getParent(),referenceSpace.getParent().getParent()); |
452 |
|
} |
453 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
454 |
1 |
@Test... |
455 |
|
public void removeParent() |
456 |
|
{ |
457 |
1 |
Map<String, Serializable> map1 = getParamMap(3); |
458 |
1 |
Map<String, Serializable> map2 = getParamMap(2); |
459 |
|
|
460 |
1 |
EntityReference wiki = new EntityReference("wiki", EntityType.WIKI); |
461 |
1 |
EntityReference space = new EntityReference("space", EntityType.SPACE, wiki, map2); |
462 |
1 |
EntityReference reference = new EntityReference("page", EntityType.DOCUMENT, space, map1); |
463 |
1 |
EntityReference referenceSpace = reference.removeParent(space); |
464 |
1 |
EntityReference referenceWiki = reference.removeParent(wiki); |
465 |
|
|
466 |
1 |
Assert.assertEquals(reference.getName(),referenceSpace.getName()); |
467 |
1 |
Assert.assertTrue(checkParamMap(referenceSpace, map1)); |
468 |
1 |
Assert.assertNull(referenceSpace.getParent()); |
469 |
1 |
Assert.assertEquals(reference.getName(),referenceWiki.getName()); |
470 |
|
|
471 |
1 |
Assert.assertTrue(checkParamMap(referenceWiki, map1)); |
472 |
1 |
Assert.assertEquals(reference.getParent().getName(),referenceWiki.getParent().getName()); |
473 |
1 |
Assert.assertTrue(checkParamMap(referenceWiki.getParent(), map2)); |
474 |
1 |
Assert.assertNull(referenceWiki.getParent().getParent()); |
475 |
|
} |
476 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (21) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
477 |
1 |
@Test... |
478 |
|
public void hasParent() |
479 |
|
{ |
480 |
1 |
EntityReference wiki = new EntityReference("wiki", EntityType.WIKI); |
481 |
1 |
EntityReference alice = new EntityReference("alice", EntityType.SPACE, wiki); |
482 |
1 |
EntityReference bob = new EntityReference("bob", EntityType.SPACE, alice); |
483 |
1 |
EntityReference carol = new EntityReference("carol", EntityType.DOCUMENT, bob); |
484 |
|
|
485 |
1 |
assertTrue(wiki.hasParent(null)); |
486 |
1 |
assertFalse(wiki.hasParent(wiki)); |
487 |
1 |
assertFalse(wiki.hasParent(alice)); |
488 |
|
|
489 |
1 |
assertFalse(alice.hasParent(null)); |
490 |
1 |
assertTrue(alice.hasParent(wiki)); |
491 |
1 |
assertFalse(alice.hasParent(alice)); |
492 |
1 |
assertFalse(alice.hasParent(bob)); |
493 |
1 |
assertFalse(alice.hasParent(carol)); |
494 |
|
|
495 |
1 |
assertTrue(bob.hasParent(wiki)); |
496 |
1 |
assertTrue(bob.hasParent(alice)); |
497 |
|
|
498 |
1 |
assertFalse(carol.hasParent(null)); |
499 |
1 |
assertTrue(carol.hasParent(wiki)); |
500 |
1 |
assertTrue(carol.hasParent(alice)); |
501 |
1 |
assertTrue(carol.hasParent(bob)); |
502 |
1 |
assertFalse(carol.hasParent(carol)); |
503 |
|
|
504 |
1 |
assertFalse(carol.hasParent(bob.removeParent(alice))); |
505 |
1 |
assertFalse(carol.hasParent(bob.removeParent(wiki))); |
506 |
|
} |
507 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
508 |
1 |
@Test... |
509 |
|
public void entityReferenceSerialization() throws Exception |
510 |
|
{ |
511 |
1 |
ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
512 |
1 |
ObjectOutputStream oos = new ObjectOutputStream(baos); |
513 |
|
|
514 |
1 |
EntityReference reference = new EntityReference("page", EntityType.DOCUMENT, |
515 |
|
new EntityReference("space", EntityType.SPACE, |
516 |
|
new EntityReference("wiki", EntityType.WIKI, null, getParamMap(1)), |
517 |
|
getParamMap(2)), |
518 |
|
getParamMap(3)); |
519 |
|
|
520 |
1 |
oos.writeObject(reference); |
521 |
|
|
522 |
1 |
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); |
523 |
1 |
ObjectInputStream ois = new ObjectInputStream(bais); |
524 |
|
|
525 |
1 |
EntityReference outRefs = (EntityReference) ois.readObject(); |
526 |
|
|
527 |
1 |
Assert.assertEquals(reference, outRefs); |
528 |
|
} |
529 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
530 |
1 |
@Test... |
531 |
|
public void validateToString() |
532 |
|
{ |
533 |
1 |
EntityReference reference1 = new EntityReference("page", EntityType.DOCUMENT, |
534 |
|
new EntityReference("space", EntityType.SPACE, |
535 |
|
new EntityReference("wiki", EntityType.WIKI))); |
536 |
1 |
Assert.assertEquals("Document wiki:space.page", reference1.toString()); |
537 |
|
|
538 |
1 |
EntityReference reference2 = new EntityReference("page", EntityType.DOCUMENT, null); |
539 |
1 |
Assert.assertEquals("Document page", reference2.toString()); |
540 |
|
|
541 |
1 |
EntityReference reference3 = new EntityReference("page", EntityType.DOCUMENT, |
542 |
|
new EntityReference("space", EntityType.SPACE)); |
543 |
1 |
Assert.assertEquals("Document space.page", reference3.toString()); |
544 |
|
|
545 |
|
|
546 |
|
|
547 |
1 |
Map<String, Serializable> map = new HashMap<>(); |
548 |
1 |
map.put("key1", "value1"); |
549 |
1 |
EntityReference reference4 = new EntityReference("page", EntityType.DOCUMENT, |
550 |
|
new EntityReference("space", EntityType.SPACE), map); |
551 |
1 |
Assert.assertEquals("Document space.page", reference4.toString()); |
552 |
|
|
553 |
1 |
EntityReference reference5 = new EntityReference("attachment", EntityType.ATTACHMENT, reference1); |
554 |
1 |
Assert.assertEquals("Attachment wiki:space.page@attachment", reference5.toString()); |
555 |
|
} |
556 |
|
} |