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.filter; |
21 |
|
|
22 |
|
import java.io.IOException; |
23 |
|
import java.net.URL; |
24 |
|
|
25 |
|
import org.apache.commons.io.IOUtils; |
26 |
|
import org.apache.commons.lang3.StringUtils; |
27 |
|
import org.junit.Rule; |
28 |
|
import org.junit.Test; |
29 |
|
import org.xwiki.component.internal.ContextComponentManagerProvider; |
30 |
|
import org.xwiki.component.manager.ComponentLookupException; |
31 |
|
import org.xwiki.filter.FilterException; |
32 |
|
import org.xwiki.filter.input.DefaultURLInputSource; |
33 |
|
import org.xwiki.test.annotation.ComponentList; |
34 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
35 |
|
|
36 |
|
import com.xpn.xwiki.objects.BaseObject; |
37 |
|
import com.xpn.xwiki.objects.classes.BaseClass; |
38 |
|
import com.xpn.xwiki.test.MockitoOldcoreRule; |
39 |
|
import com.xpn.xwiki.test.component.XWikiDocumentFilterUtilsComponentList; |
40 |
|
|
41 |
|
import static org.junit.Assert.assertEquals; |
42 |
|
import static org.junit.Assert.assertNotNull; |
43 |
|
|
44 |
|
|
45 |
|
@link |
46 |
|
|
47 |
|
@version |
48 |
|
|
49 |
|
@XWikiDocumentFilterUtilsComponentList |
50 |
|
@ComponentList(ContextComponentManagerProvider.class) |
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
|
51 |
|
public class XWikiDocumentFilterUtilsTest |
52 |
|
{ |
53 |
|
public final MockitoComponentMockingRule<XWikiDocumentFilterUtils> mocker = |
54 |
|
new MockitoComponentMockingRule<>(XWikiDocumentFilterUtils.class); |
55 |
|
|
56 |
|
@Rule |
57 |
|
public final MockitoOldcoreRule oldcore = new MockitoOldcoreRule(this.mocker); |
58 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
59 |
1 |
private void assertXML(Object entity, String resource) throws FilterException, IOException, ComponentLookupException... |
60 |
|
{ |
61 |
1 |
URL url = getClass().getResource("/filter/xar/" + resource + ".xml"); |
62 |
|
|
63 |
1 |
assertNotNull(url); |
64 |
|
|
65 |
1 |
String expected = IOUtils.toString(url, "UTF-8"); |
66 |
1 |
expected = StringUtils.removeStart(expected, "<?xml version=\"1.1\" encoding=\"UTF-8\"?>\n\n"); |
67 |
|
|
68 |
|
|
69 |
|
|
70 |
1 |
Object importedEntity = |
71 |
|
this.mocker.getComponentUnderTest().importEntity(entity, new DefaultURLInputSource(url)); |
72 |
|
|
73 |
|
|
74 |
|
|
75 |
1 |
String actual = this.mocker.getComponentUnderTest().exportEntity(importedEntity); |
76 |
|
|
77 |
|
|
78 |
|
|
79 |
1 |
assertEquals(expected, actual); |
80 |
|
} |
81 |
|
|
82 |
|
|
83 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
84 |
1 |
@Test... |
85 |
|
public void class1() throws FilterException, IOException, ComponentLookupException |
86 |
|
{ |
87 |
1 |
assertXML(BaseClass.class, "class1"); |
88 |
|
} |
89 |
|
} |