1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.internal.model.reference; |
21 |
|
|
22 |
|
import java.util.Arrays; |
23 |
|
|
24 |
|
import org.junit.Assert; |
25 |
|
import org.junit.Rule; |
26 |
|
import org.junit.Test; |
27 |
|
import org.xwiki.component.manager.ComponentLookupException; |
28 |
|
import org.xwiki.model.EntityType; |
29 |
|
import org.xwiki.model.internal.DefaultModelConfiguration; |
30 |
|
import org.xwiki.model.internal.reference.DefaultSymbolScheme; |
31 |
|
import org.xwiki.model.reference.AttachmentReference; |
32 |
|
import org.xwiki.model.reference.DocumentReference; |
33 |
|
import org.xwiki.model.reference.EntityReference; |
34 |
|
import org.xwiki.model.reference.EntityReferenceSerializer; |
35 |
|
import org.xwiki.test.annotation.ComponentList; |
36 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
37 |
|
|
38 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
39 |
|
import com.xpn.xwiki.test.MockitoOldcoreRule; |
40 |
|
|
41 |
|
|
42 |
|
@link |
43 |
|
|
44 |
|
@version |
45 |
|
|
46 |
|
@ComponentList({ |
47 |
|
DefaultSymbolScheme.class, |
48 |
|
CurrentEntityReferenceProvider.class, |
49 |
|
DefaultModelConfiguration.class |
50 |
|
}) |
|
|
| 100% |
Uncovered Elements: 0 (67) |
Complexity: 8 |
Complexity Density: 0.14 |
|
51 |
|
public class CompactStringEntityReferenceSerializerTest |
52 |
|
{ |
53 |
|
public MockitoComponentMockingRule<EntityReferenceSerializer<String>> mocker = |
54 |
|
new MockitoComponentMockingRule<EntityReferenceSerializer<String>>(CompactStringEntityReferenceSerializer.class); |
55 |
|
|
56 |
|
@Rule |
57 |
|
public MockitoOldcoreRule oldcore = new MockitoOldcoreRule(this.mocker); |
58 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
59 |
1 |
@Test... |
60 |
|
public void testSerializeWhenNoContext() throws Exception |
61 |
|
{ |
62 |
1 |
DocumentReference reference = new DocumentReference("wiki", "space", "page"); |
63 |
1 |
Assert.assertEquals("wiki:space.page", this.mocker.getComponentUnderTest().serialize(reference)); |
64 |
|
} |
65 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
66 |
1 |
@Test... |
67 |
|
public void testSerializeWhenNoContextDocument() throws Exception |
68 |
|
{ |
69 |
1 |
DocumentReference reference = new DocumentReference("wiki", "space", "page"); |
70 |
1 |
Assert.assertEquals("wiki:space.page", this.mocker.getComponentUnderTest().serialize(reference)); |
71 |
|
} |
72 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (25) |
Complexity: 1 |
Complexity Density: 0.04 |
1PASS
|
|
73 |
1 |
@Test... |
74 |
|
public void testSerializeDocumentReferenceWhenContextDocument() throws Exception |
75 |
|
{ |
76 |
1 |
DocumentReference reference = new DocumentReference("wiki", "space", "page"); |
77 |
|
|
78 |
1 |
this.oldcore.getXWikiContext().setWikiReference(reference.getWikiReference()); |
79 |
1 |
this.oldcore.getXWikiContext().setDoc(new XWikiDocument(reference)); |
80 |
1 |
Assert.assertEquals("page", this.mocker.getComponentUnderTest().serialize(reference)); |
81 |
|
|
82 |
1 |
this.oldcore.getXWikiContext().setWikiReference(reference.getWikiReference()); |
83 |
1 |
this.oldcore.getXWikiContext().setDoc(new XWikiDocument(new DocumentReference("wiki", "space", "otherpage"))); |
84 |
1 |
Assert.assertEquals("page", this.mocker.getComponentUnderTest().serialize(reference)); |
85 |
|
|
86 |
1 |
this.oldcore.getXWikiContext().setWikiReference(reference.getWikiReference()); |
87 |
1 |
this.oldcore.getXWikiContext().setDoc( |
88 |
|
new XWikiDocument(new DocumentReference("wiki", "otherspace", "otherpage"))); |
89 |
1 |
Assert.assertEquals("space.page", this.mocker.getComponentUnderTest().serialize(reference)); |
90 |
|
|
91 |
1 |
this.oldcore.getXWikiContext().setWikiId("otherwiki"); |
92 |
1 |
this.oldcore.getXWikiContext().setDoc( |
93 |
|
new XWikiDocument(new DocumentReference("otherwiki", "otherspace", "otherpage"))); |
94 |
1 |
Assert.assertEquals("wiki:space.page", this.mocker.getComponentUnderTest().serialize(reference)); |
95 |
|
|
96 |
1 |
this.oldcore.getXWikiContext().setWikiReference(reference.getWikiReference()); |
97 |
1 |
this.oldcore.getXWikiContext().setDoc(new XWikiDocument(new DocumentReference("wiki", "otherspace", "page"))); |
98 |
1 |
Assert.assertEquals("space.page", this.mocker.getComponentUnderTest().serialize(reference)); |
99 |
|
|
100 |
1 |
this.oldcore.getXWikiContext().setWikiId("otherwiki"); |
101 |
1 |
this.oldcore.getXWikiContext().setDoc( |
102 |
|
new XWikiDocument(new DocumentReference("otherwiki", "otherspace", "page"))); |
103 |
1 |
Assert.assertEquals("wiki:space.page", this.mocker.getComponentUnderTest().serialize(reference)); |
104 |
|
|
105 |
1 |
this.oldcore.getXWikiContext().setWikiId("otherwiki"); |
106 |
1 |
this.oldcore.getXWikiContext().setDoc(new XWikiDocument(new DocumentReference("otherwiki", "space", "page"))); |
107 |
1 |
Assert.assertEquals("wiki:space.page", this.mocker.getComponentUnderTest().serialize(reference)); |
108 |
|
|
109 |
1 |
this.oldcore.getXWikiContext().setWikiId("otherwiki"); |
110 |
1 |
this.oldcore.getXWikiContext().setDoc( |
111 |
|
new XWikiDocument(new DocumentReference("otherwiki", "space", "otherpage"))); |
112 |
1 |
Assert.assertEquals("wiki:space.page", this.mocker.getComponentUnderTest().serialize(reference)); |
113 |
|
} |
114 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
115 |
1 |
@Test... |
116 |
|
public void testSerializeSpaceReferenceWhenHasChildren() throws Exception |
117 |
|
{ |
118 |
1 |
AttachmentReference reference = |
119 |
|
new AttachmentReference("filename", new DocumentReference("wiki", "space", "page")); |
120 |
|
|
121 |
1 |
this.oldcore.getXWikiContext().setWikiId("wiki"); |
122 |
1 |
this.oldcore.getXWikiContext().setDoc(new XWikiDocument(new DocumentReference("wiki", "space", "page"))); |
123 |
1 |
Assert.assertEquals("page", this.mocker.getComponentUnderTest().serialize(reference.getParent())); |
124 |
1 |
Assert.assertEquals("space", this.mocker.getComponentUnderTest().serialize(reference.getParent().getParent())); |
125 |
|
|
126 |
1 |
this.oldcore.getXWikiContext().setWikiId("xwiki"); |
127 |
1 |
this.oldcore.getXWikiContext().setDoc(new XWikiDocument(new DocumentReference("xwiki", "xspace", "xpage"))); |
128 |
1 |
Assert.assertEquals("wiki:space.page", this.mocker.getComponentUnderTest().serialize(reference.getParent())); |
129 |
1 |
Assert.assertEquals("wiki:space", |
130 |
|
this.mocker.getComponentUnderTest().serialize(reference.getParent().getParent())); |
131 |
|
|
132 |
|
} |
133 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
134 |
1 |
@Test... |
135 |
|
public void testSerializeAttachmentReferenceWhenContextDocument() throws Exception |
136 |
|
{ |
137 |
1 |
AttachmentReference reference = |
138 |
|
new AttachmentReference("filename", new DocumentReference("wiki", "space", "page")); |
139 |
|
|
140 |
1 |
this.oldcore.getXWikiContext().setWikiId("wiki"); |
141 |
1 |
this.oldcore.getXWikiContext().setDoc(new XWikiDocument(new DocumentReference("wiki", "space", "page"))); |
142 |
1 |
Assert.assertEquals("filename", this.mocker.getComponentUnderTest().serialize(reference)); |
143 |
|
|
144 |
1 |
this.oldcore.getXWikiContext().setWikiId("wiki"); |
145 |
1 |
this.oldcore.getXWikiContext().setDoc(new XWikiDocument(new DocumentReference("wiki", "space", "otherpage"))); |
146 |
1 |
Assert.assertEquals("page@filename", this.mocker.getComponentUnderTest().serialize(reference)); |
147 |
|
|
148 |
1 |
this.oldcore.getXWikiContext().setWikiId("otherwiki"); |
149 |
1 |
this.oldcore.getXWikiContext().setDoc(new XWikiDocument(new DocumentReference("otherwiki", "space", "page"))); |
150 |
1 |
Assert.assertEquals("wiki:space.page@filename", this.mocker.getComponentUnderTest().serialize(reference)); |
151 |
|
} |
152 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
153 |
1 |
@Test... |
154 |
|
public void testSerializeEntityReferenceWithExplicit() throws ComponentLookupException |
155 |
|
{ |
156 |
1 |
DocumentReference reference = new DocumentReference("wiki", "space", "page"); |
157 |
|
|
158 |
1 |
this.oldcore.getXWikiContext().setWikiId("wiki"); |
159 |
1 |
this.oldcore.getXWikiContext().setDoc(new XWikiDocument(new DocumentReference("wiki", "space", "page"))); |
160 |
1 |
Assert.assertEquals( |
161 |
|
"space.page", |
162 |
|
this.mocker.getComponentUnderTest().serialize(reference, |
163 |
|
new EntityReference("otherspace", EntityType.SPACE))); |
164 |
|
} |
165 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
166 |
1 |
@Test... |
167 |
|
public void testSerializeNestedSpaceFromBaseReference() throws ComponentLookupException |
168 |
|
{ |
169 |
1 |
DocumentReference baseReference = new DocumentReference("wiki", "space", "page"); |
170 |
1 |
DocumentReference reference = new DocumentReference("wiki", Arrays.asList("space", "nested"), "page"); |
171 |
|
|
172 |
1 |
Assert.assertEquals("space.nested.page", this.mocker.getComponentUnderTest().serialize(reference, baseReference)); |
173 |
|
} |
174 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
175 |
1 |
@Test... |
176 |
|
public void testSerializeNestedSpaceFromContext() throws ComponentLookupException |
177 |
|
{ |
178 |
1 |
DocumentReference reference = new DocumentReference("wiki", Arrays.asList("space", "nested"), "page"); |
179 |
|
|
180 |
1 |
this.oldcore.getXWikiContext().setWikiId("wiki"); |
181 |
1 |
this.oldcore.getXWikiContext().setDoc(new XWikiDocument(new DocumentReference("wiki", "space", "page2"))); |
182 |
|
|
183 |
1 |
Assert.assertEquals("space.nested.page", this.mocker.getComponentUnderTest().serialize(reference)); |
184 |
|
} |
185 |
|
} |