1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.annotation.io.internal; |
21 |
|
|
22 |
|
import org.jmock.Expectations; |
23 |
|
import org.junit.Test; |
24 |
|
import org.xwiki.annotation.io.IOTargetService; |
25 |
|
import org.xwiki.bridge.DocumentAccessBridge; |
26 |
|
import org.xwiki.bridge.DocumentModelBridge; |
27 |
|
import org.xwiki.component.descriptor.DefaultComponentDescriptor; |
28 |
|
import org.xwiki.component.manager.ComponentManager; |
29 |
|
import org.xwiki.model.reference.DocumentReference; |
30 |
|
import org.xwiki.model.reference.DocumentReferenceResolver; |
31 |
|
import org.xwiki.rendering.syntax.Syntax; |
32 |
|
import org.xwiki.rendering.syntax.SyntaxType; |
33 |
|
import org.xwiki.test.jmock.AbstractComponentTestCase; |
34 |
|
|
35 |
|
import com.xpn.xwiki.web.Utils; |
36 |
|
|
37 |
|
import static org.junit.Assert.assertEquals; |
38 |
|
|
39 |
|
|
40 |
|
@link |
41 |
|
|
42 |
|
|
43 |
|
@version |
44 |
|
@since |
45 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (164) |
Complexity: 25 |
Complexity Density: 0.18 |
|
46 |
|
public class DefaultIOTargetServiceTest extends AbstractComponentTestCase |
47 |
|
{ |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
private IOTargetService ioTargetService; |
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
private DocumentAccessBridge dabMock; |
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
private DocumentReferenceResolver<String> classResolver; |
62 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
63 |
11 |
@Override... |
64 |
|
protected void registerComponents() throws Exception |
65 |
|
{ |
66 |
11 |
super.registerComponents(); |
67 |
|
|
68 |
|
|
69 |
11 |
this.dabMock = registerMockComponent(DocumentAccessBridge.class); |
70 |
11 |
getMockery().checking(new Expectations() |
71 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
72 |
11 |
{... |
73 |
11 |
allowing(dabMock).getCurrentUserReference(); |
74 |
|
} |
75 |
|
}); |
76 |
11 |
this.classResolver = registerMockComponent(DocumentReferenceResolver.TYPE_STRING); |
77 |
|
|
78 |
|
|
79 |
11 |
DefaultComponentDescriptor<ComponentManager> componentDescriptor = new DefaultComponentDescriptor<>(); |
80 |
11 |
componentDescriptor.setRoleType(ComponentManager.class); |
81 |
11 |
componentDescriptor.setRoleHint("context"); |
82 |
11 |
getComponentManager().registerComponent(componentDescriptor, getComponentManager()); |
83 |
|
} |
84 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
85 |
11 |
@Override... |
86 |
|
public void setUp() throws Exception |
87 |
|
{ |
88 |
11 |
super.setUp(); |
89 |
|
|
90 |
|
|
91 |
11 |
ioTargetService = getComponentManager().getInstance(IOTargetService.class); |
92 |
11 |
Utils.setComponentManager(getComponentManager()); |
93 |
|
} |
94 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
95 |
1 |
@Test... |
96 |
|
public void testGettersWhenTargetIsTypedDocument() throws Exception |
97 |
|
{ |
98 |
1 |
final DocumentModelBridge dmb = getMockery().mock(DocumentModelBridge.class); |
99 |
1 |
getMockery().checking(new Expectations() |
100 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
101 |
1 |
{... |
102 |
1 |
allowing(dabMock).getDocument(new DocumentReference("wiki", "Space", "Page")); |
103 |
1 |
will(returnValue(dmb)); |
104 |
1 |
oneOf(dmb).getContent(); |
105 |
1 |
will(returnValue("defcontent")); |
106 |
1 |
oneOf(dmb).getSyntax(); |
107 |
1 |
will(returnValue(new Syntax(SyntaxType.XWIKI,"2.0"))); |
108 |
|
} |
109 |
|
}); |
110 |
|
|
111 |
1 |
String reference = "DOCUMENT://wiki:Space.Page"; |
112 |
1 |
assertEquals("defcontent", ioTargetService.getSource(reference)); |
113 |
1 |
assertEquals("xwiki/2.0", ioTargetService.getSourceSyntax(reference)); |
114 |
|
} |
115 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
116 |
1 |
@Test... |
117 |
|
public void testGettersWhenTargetIsNonTypedDocument() throws Exception |
118 |
|
{ |
119 |
1 |
final DocumentModelBridge dmb = getMockery().mock(DocumentModelBridge.class); |
120 |
1 |
getMockery().checking(new Expectations() |
121 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
122 |
1 |
{... |
123 |
1 |
allowing(dabMock).getDocument(new DocumentReference("wiki", "Space", "Page")); |
124 |
1 |
will(returnValue(dmb)); |
125 |
1 |
oneOf(dmb).getContent(); |
126 |
1 |
will(returnValue("defcontent")); |
127 |
1 |
oneOf(dmb).getSyntax(); |
128 |
1 |
will(returnValue(new Syntax(SyntaxType.XWIKI,"2.0"))); |
129 |
|
} |
130 |
|
}); |
131 |
|
|
132 |
1 |
String reference = "wiki:Space.Page"; |
133 |
1 |
assertEquals("defcontent", ioTargetService.getSource(reference)); |
134 |
1 |
assertEquals("xwiki/2.0", ioTargetService.getSourceSyntax(reference)); |
135 |
|
} |
136 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
137 |
1 |
@Test... |
138 |
|
public void testGettersWhenTargetIsNonTypedRelativeDocument() throws Exception |
139 |
|
{ |
140 |
1 |
final DocumentModelBridge dmb = getMockery().mock(DocumentModelBridge.class); |
141 |
1 |
getMockery().checking(new Expectations() |
142 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
143 |
1 |
{... |
144 |
|
|
145 |
1 |
allowing(dabMock).getDocument(new DocumentReference("xwiki", "Space", "Page")); |
146 |
1 |
will(returnValue(dmb)); |
147 |
1 |
oneOf(dmb).getContent(); |
148 |
1 |
will(returnValue("defcontent")); |
149 |
1 |
oneOf(dmb).getSyntax(); |
150 |
1 |
will(returnValue(new Syntax(SyntaxType.XWIKI,"2.0"))); |
151 |
|
} |
152 |
|
}); |
153 |
|
|
154 |
1 |
String reference = "Space.Page"; |
155 |
1 |
assertEquals("defcontent", ioTargetService.getSource(reference)); |
156 |
1 |
assertEquals("xwiki/2.0", ioTargetService.getSourceSyntax(reference)); |
157 |
|
} |
158 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
159 |
1 |
@Test... |
160 |
|
public void testGettersWhenTargetIsTypedRelativeDocument() throws Exception |
161 |
|
{ |
162 |
1 |
final DocumentModelBridge dmb = getMockery().mock(DocumentModelBridge.class); |
163 |
1 |
getMockery().checking(new Expectations() |
164 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
165 |
1 |
{... |
166 |
|
|
167 |
1 |
allowing(dabMock).getDocument(new DocumentReference("xwiki", "Space", "Page")); |
168 |
1 |
will(returnValue(dmb)); |
169 |
1 |
oneOf(dmb).getContent(); |
170 |
1 |
will(returnValue("defcontent")); |
171 |
1 |
oneOf(dmb).getSyntax(); |
172 |
1 |
will(returnValue(new Syntax(SyntaxType.XWIKI,"2.0"))); |
173 |
|
} |
174 |
|
}); |
175 |
|
|
176 |
1 |
String reference = "DOCUMENT://Space.Page"; |
177 |
1 |
assertEquals("defcontent", ioTargetService.getSource(reference)); |
178 |
1 |
assertEquals("xwiki/2.0", ioTargetService.getSourceSyntax(reference)); |
179 |
|
} |
180 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
181 |
1 |
@Test... |
182 |
|
public void testGettersWhenTargetIsTypedSpace() throws Exception |
183 |
|
{ |
184 |
1 |
final DocumentModelBridge dmb = getMockery().mock(DocumentModelBridge.class); |
185 |
1 |
getMockery().checking(new Expectations() |
186 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
187 |
1 |
{... |
188 |
|
|
189 |
1 |
oneOf(dabMock).getDocumentContent("SPACE://wiki:Space"); |
190 |
1 |
will(returnValue("defcontent")); |
191 |
1 |
oneOf(dabMock).getDocumentSyntaxId("SPACE://wiki:Space"); |
192 |
1 |
will(returnValue("xwiki/2.0")); |
193 |
|
} |
194 |
|
}); |
195 |
|
|
196 |
|
|
197 |
1 |
String reference = "SPACE://wiki:Space"; |
198 |
1 |
assertEquals("defcontent", ioTargetService.getSource(reference)); |
199 |
1 |
assertEquals("xwiki/2.0", ioTargetService.getSourceSyntax(reference)); |
200 |
|
} |
201 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
202 |
1 |
@Test... |
203 |
|
public void testGettersWhenTargetIsEmptyString() throws Exception |
204 |
|
{ |
205 |
1 |
final DocumentModelBridge dmb = getMockery().mock(DocumentModelBridge.class); |
206 |
1 |
getMockery().checking(new Expectations() |
207 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
208 |
1 |
{... |
209 |
|
|
210 |
|
|
211 |
1 |
allowing(dabMock).getDocument(new DocumentReference("xwiki", "Main", "WebHome")); |
212 |
1 |
will(returnValue(dmb)); |
213 |
1 |
oneOf(dmb).getContent(); |
214 |
1 |
will(returnValue("defcontent")); |
215 |
1 |
oneOf(dmb).getSyntax(); |
216 |
1 |
will(returnValue(new Syntax(SyntaxType.XWIKI,"2.0"))); |
217 |
|
} |
218 |
|
}); |
219 |
|
|
220 |
|
|
221 |
1 |
String reference = ""; |
222 |
1 |
assertEquals("defcontent", ioTargetService.getSource(reference)); |
223 |
1 |
assertEquals("xwiki/2.0", ioTargetService.getSourceSyntax(reference)); |
224 |
|
} |
225 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
226 |
1 |
@Test... |
227 |
|
public void testGetterWhenTargetIsTypedIndexedObjectProperty() throws Exception |
228 |
|
{ |
229 |
1 |
final DocumentModelBridge dmb = getMockery().mock(DocumentModelBridge.class); |
230 |
1 |
getMockery().checking(new Expectations() |
231 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
232 |
1 |
{... |
233 |
1 |
allowing(classResolver).resolve("XWiki.Class"); |
234 |
1 |
will(returnValue(new DocumentReference("wiki", "XWiki", "Class"))); |
235 |
1 |
oneOf(dabMock).getProperty(new DocumentReference("wiki", "Space", "Page"), |
236 |
|
new DocumentReference("wiki", "XWiki", "Class"), 1, "property"); |
237 |
1 |
will(returnValue("defcontent")); |
238 |
1 |
oneOf(dabMock).getDocument(new DocumentReference("wiki", "Space", "Page")); |
239 |
1 |
will(returnValue(dmb)); |
240 |
1 |
oneOf(dmb).getSyntax(); |
241 |
1 |
will(returnValue(new Syntax(SyntaxType.XWIKI,"2.0"))); |
242 |
|
} |
243 |
|
}); |
244 |
|
|
245 |
1 |
String reference = "OBJECT_PROPERTY://wiki:Space.Page^XWiki.Class[1].property"; |
246 |
1 |
assertEquals("defcontent", ioTargetService.getSource(reference)); |
247 |
1 |
assertEquals("xwiki/2.0", ioTargetService.getSourceSyntax(reference)); |
248 |
|
} |
249 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
250 |
1 |
@Test... |
251 |
|
public void testGetterWhenTargetIsTypedDefaultObjectProperty() throws Exception |
252 |
|
{ |
253 |
1 |
final DocumentModelBridge dmb = getMockery().mock(DocumentModelBridge.class); |
254 |
1 |
getMockery().checking(new Expectations() |
255 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
256 |
1 |
{... |
257 |
1 |
allowing(classResolver).resolve("XWiki.Class"); |
258 |
1 |
will(returnValue(new DocumentReference("wiki", "XWiki", "Class"))); |
259 |
1 |
oneOf(dabMock).getProperty(new DocumentReference("wiki", "Space", "Page"), |
260 |
|
new DocumentReference("wiki", "XWiki", "Class"), "property"); |
261 |
1 |
will(returnValue("defcontent")); |
262 |
1 |
oneOf(dabMock).getDocument(new DocumentReference("wiki", "Space", "Page")); |
263 |
1 |
will(returnValue(dmb)); |
264 |
1 |
oneOf(dmb).getSyntax(); |
265 |
1 |
will(returnValue(new Syntax(SyntaxType.XWIKI,"2.0"))); |
266 |
|
} |
267 |
|
}); |
268 |
|
|
269 |
1 |
String reference = "OBJECT_PROPERTY://wiki:Space.Page^XWiki.Class.property"; |
270 |
1 |
assertEquals("defcontent", ioTargetService.getSource(reference)); |
271 |
1 |
assertEquals("xwiki/2.0", ioTargetService.getSourceSyntax(reference)); |
272 |
|
} |
273 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
274 |
1 |
@Test... |
275 |
|
public void testGetterWhenTargetIsTypedObjectPropertyInRelativeDocument() throws Exception |
276 |
|
{ |
277 |
1 |
final DocumentModelBridge dmb = getMockery().mock(DocumentModelBridge.class); |
278 |
1 |
getMockery().checking(new Expectations() |
279 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
280 |
1 |
{... |
281 |
1 |
allowing(classResolver).resolve("XWiki.Class"); |
282 |
1 |
will(returnValue(new DocumentReference("xwiki", "XWiki", "Class"))); |
283 |
1 |
oneOf(dabMock).getProperty(new DocumentReference("xwiki", "Main", "Page"), |
284 |
|
new DocumentReference("xwiki", "XWiki", "Class"), "property"); |
285 |
1 |
will(returnValue("defcontent")); |
286 |
1 |
oneOf(dabMock).getDocument(new DocumentReference("xwiki", "Main", "Page")); |
287 |
1 |
will(returnValue(dmb)); |
288 |
1 |
oneOf(dmb).getSyntax(); |
289 |
1 |
will(returnValue(new Syntax(SyntaxType.XWIKI,"2.0"))); |
290 |
|
} |
291 |
|
}); |
292 |
|
|
293 |
1 |
String reference = "OBJECT_PROPERTY://Page^XWiki.Class.property"; |
294 |
1 |
assertEquals("defcontent", ioTargetService.getSource(reference)); |
295 |
1 |
assertEquals("xwiki/2.0", ioTargetService.getSourceSyntax(reference)); |
296 |
|
} |
297 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
298 |
1 |
@Test... |
299 |
|
public void testGetterWhenTargetIsNonTypedObjectProperty() throws Exception |
300 |
|
{ |
301 |
1 |
final DocumentModelBridge dmb = getMockery().mock(DocumentModelBridge.class); |
302 |
1 |
getMockery().checking(new Expectations() |
303 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
304 |
1 |
{... |
305 |
|
|
306 |
1 |
allowing(dabMock).getDocument(new DocumentReference("wiki", "Space.Page^XWiki.Class", "property")); |
307 |
1 |
will(returnValue(dmb)); |
308 |
1 |
oneOf(dmb).getContent(); |
309 |
1 |
will(returnValue("defcontent")); |
310 |
1 |
oneOf(dmb).getSyntax(); |
311 |
1 |
will(returnValue(new Syntax(SyntaxType.XWIKI,"2.0"))); |
312 |
|
} |
313 |
|
}); |
314 |
|
|
315 |
1 |
String reference = "wiki:Space\\.Page^XWiki\\.Class.property"; |
316 |
1 |
assertEquals("defcontent", ioTargetService.getSource(reference)); |
317 |
1 |
assertEquals("xwiki/2.0", ioTargetService.getSourceSyntax(reference)); |
318 |
|
} |
319 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
320 |
1 |
@Test... |
321 |
|
public void testGetterWhenTargetIsTypedIndexedRelativeObjectProperty() throws Exception |
322 |
|
{ |
323 |
1 |
final DocumentModelBridge dmb = getMockery().mock(DocumentModelBridge.class); |
324 |
1 |
getMockery().checking(new Expectations() |
325 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
326 |
1 |
{... |
327 |
|
|
328 |
1 |
allowing(classResolver).resolve("Classes.Class"); |
329 |
1 |
will(returnValue(new DocumentReference("xwiki", "Classes", "Class"))); |
330 |
1 |
oneOf(dabMock).getProperty(new DocumentReference("xwiki", "Main", "WebHome"), |
331 |
|
new DocumentReference("xwiki", "Classes", "Class"), 3, "property"); |
332 |
1 |
will(returnValue("defcontent")); |
333 |
1 |
oneOf(dabMock).getDocument(new DocumentReference("xwiki", "Main", "WebHome")); |
334 |
1 |
will(returnValue(dmb)); |
335 |
1 |
oneOf(dmb).getSyntax(); |
336 |
1 |
will(returnValue(new Syntax(SyntaxType.XWIKI,"2.0"))); |
337 |
|
} |
338 |
|
}); |
339 |
|
|
340 |
1 |
String reference = "OBJECT_PROPERTY://Classes.Class[3].property"; |
341 |
1 |
assertEquals("defcontent", ioTargetService.getSource(reference)); |
342 |
1 |
assertEquals("xwiki/2.0", ioTargetService.getSourceSyntax(reference)); |
343 |
|
} |
344 |
|
} |