1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.model.internal.reference; |
21 |
|
|
22 |
|
import org.junit.Assert; |
23 |
|
import org.junit.Before; |
24 |
|
import org.junit.Test; |
25 |
|
import org.xwiki.model.EntityType; |
26 |
|
import org.xwiki.model.reference.DocumentReference; |
27 |
|
import org.xwiki.model.reference.EntityReference; |
28 |
|
import org.xwiki.model.reference.EntityReferenceResolver; |
29 |
|
|
30 |
|
|
31 |
|
@link |
32 |
|
|
33 |
|
@version |
34 |
|
@since |
35 |
|
|
|
|
| 93.9% |
Uncovered Elements: 3 (49) |
Complexity: 11 |
Complexity Density: 0.27 |
|
36 |
|
public class ExplicitReferenceEntityReferenceResolverTest |
37 |
|
{ |
38 |
|
private EntityReferenceResolver<EntityReference> resolver; |
39 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
40 |
7 |
@Before... |
41 |
|
public void setUp() throws Exception |
42 |
|
{ |
43 |
7 |
this.resolver = new ExplicitReferenceEntityReferenceResolver(); |
44 |
|
} |
45 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
46 |
1 |
@Test... |
47 |
|
public void testResolveWithExplicitDocumentReference() |
48 |
|
{ |
49 |
1 |
EntityReference reference = |
50 |
|
this.resolver.resolve(null, EntityType.DOCUMENT, new DocumentReference("wiki", "space", "page")); |
51 |
|
|
52 |
1 |
Assert.assertEquals("page", reference.getName()); |
53 |
1 |
Assert.assertEquals(EntityType.DOCUMENT, reference.getType()); |
54 |
1 |
Assert.assertEquals("space", reference.getParent().getName()); |
55 |
1 |
Assert.assertEquals(EntityType.SPACE, reference.getParent().getType()); |
56 |
1 |
Assert.assertEquals("wiki", reference.getParent().getParent().getName()); |
57 |
1 |
Assert.assertEquals(EntityType.WIKI, reference.getParent().getParent().getType()); |
58 |
|
} |
59 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
60 |
1 |
@Test... |
61 |
|
public void testResolveWithExplicitEntityReference() |
62 |
|
{ |
63 |
1 |
EntityReference reference = |
64 |
|
this.resolver.resolve(new EntityReference("page", EntityType.DOCUMENT, new EntityReference("space", EntityType.SPACE)), EntityType.DOCUMENT, new EntityReference("wiki", EntityType.WIKI)); |
65 |
|
|
66 |
1 |
Assert.assertEquals("page", reference.getName()); |
67 |
1 |
Assert.assertEquals(EntityType.DOCUMENT, reference.getType()); |
68 |
1 |
Assert.assertEquals("space", reference.getParent().getName()); |
69 |
1 |
Assert.assertEquals(EntityType.SPACE, reference.getParent().getType()); |
70 |
1 |
Assert.assertEquals("wiki", reference.getParent().getParent().getName()); |
71 |
1 |
Assert.assertEquals(EntityType.WIKI, reference.getParent().getParent().getType()); |
72 |
|
} |
73 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
74 |
1 |
@Test... |
75 |
|
public void testResolveWithAbsoluteReferenceAndNoExplicitReference() |
76 |
|
{ |
77 |
1 |
EntityReference reference = this.resolver.resolve(new EntityReference("page", EntityType.DOCUMENT, new EntityReference("space", EntityType.SPACE, new EntityReference("wiki", EntityType.WIKI))), EntityType.DOCUMENT); |
78 |
|
|
79 |
1 |
Assert.assertEquals("page", reference.getName()); |
80 |
1 |
Assert.assertEquals(EntityType.DOCUMENT, reference.getType()); |
81 |
1 |
Assert.assertEquals("space", reference.getParent().getName()); |
82 |
1 |
Assert.assertEquals(EntityType.SPACE, reference.getParent().getType()); |
83 |
1 |
Assert.assertEquals("wiki", reference.getParent().getParent().getName()); |
84 |
1 |
Assert.assertEquals(EntityType.WIKI, reference.getParent().getParent().getType()); |
85 |
|
} |
86 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
87 |
1 |
@Test... |
88 |
|
public void testResolveWithExplicitReferenceWithHoles() |
89 |
|
{ |
90 |
1 |
EntityReference reference = this.resolver.resolve(new EntityReference("page", EntityType.DOCUMENT, new EntityReference("space", EntityType.SPACE)), EntityType.DOCUMENT, |
91 |
|
new EntityReference("page", EntityType.DOCUMENT, new EntityReference("wiki", EntityType.WIKI))); |
92 |
|
|
93 |
1 |
Assert.assertEquals("page", reference.getName()); |
94 |
1 |
Assert.assertEquals(EntityType.DOCUMENT, reference.getType()); |
95 |
1 |
Assert.assertEquals("space", reference.getParent().getName()); |
96 |
1 |
Assert.assertEquals(EntityType.SPACE, reference.getParent().getType()); |
97 |
1 |
Assert.assertEquals("wiki", reference.getParent().getParent().getName()); |
98 |
1 |
Assert.assertEquals(EntityType.WIKI, reference.getParent().getParent().getType()); |
99 |
|
} |
100 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
1PASS
|
|
101 |
1 |
@Test... |
102 |
|
public void testResolveWithNoExplicitAndPartialReference() |
103 |
|
{ |
104 |
1 |
try { |
105 |
1 |
this.resolver.resolve(null, EntityType.DOCUMENT); |
106 |
0 |
Assert.fail("Should have raised an exception"); |
107 |
|
} catch (IllegalArgumentException expected) { |
108 |
1 |
Assert.assertEquals("The resolver parameter doesn't contain an Entity Reference of type [DOCUMENT]", |
109 |
|
expected.getMessage()); |
110 |
|
} |
111 |
|
} |
112 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
1PASS
|
|
113 |
1 |
@Test... |
114 |
|
public void testResolveWithInvalidParameterType() |
115 |
|
{ |
116 |
1 |
try { |
117 |
1 |
this.resolver.resolve(null, EntityType.DOCUMENT, "wrong type"); |
118 |
0 |
Assert.fail("Should have raised an exception"); |
119 |
|
} catch (IllegalArgumentException expected) { |
120 |
1 |
Assert.assertEquals("The resolver parameter doesn't contain an Entity Reference of type [DOCUMENT]", |
121 |
|
expected.getMessage()); |
122 |
|
} |
123 |
|
} |
124 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
1PASS
|
|
125 |
1 |
@Test... |
126 |
|
public void testResolveWithIncompleteExplicitReference() |
127 |
|
{ |
128 |
1 |
try { |
129 |
1 |
this.resolver.resolve(null, EntityType.DOCUMENT, new EntityReference("wiki", EntityType.WIKI)); |
130 |
0 |
Assert.fail("Should have raised an exception"); |
131 |
|
} catch (IllegalArgumentException expected) { |
132 |
1 |
Assert.assertEquals("The resolver parameter doesn't contain an Entity Reference of type [DOCUMENT]", |
133 |
|
expected.getMessage()); |
134 |
|
} |
135 |
|
} |
136 |
|
} |