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 |
|
import java.text.ParseException; |
25 |
|
import java.text.SimpleDateFormat; |
26 |
|
import java.util.Date; |
27 |
|
import java.util.Locale; |
28 |
|
|
29 |
|
import org.junit.Before; |
30 |
|
import org.junit.Rule; |
31 |
|
import org.xwiki.filter.FilterException; |
32 |
|
import org.xwiki.filter.filterxml.input.FilterXMLInputProperties; |
33 |
|
import org.xwiki.filter.input.BeanInputFilterStreamFactory; |
34 |
|
import org.xwiki.filter.input.DefaultURLInputSource; |
35 |
|
import org.xwiki.filter.input.InputFilterStream; |
36 |
|
import org.xwiki.filter.input.InputFilterStreamFactory; |
37 |
|
import org.xwiki.filter.instance.output.InstanceOutputProperties; |
38 |
|
import org.xwiki.filter.output.BeanOutputFilterStreamFactory; |
39 |
|
import org.xwiki.filter.output.OutputFilterStream; |
40 |
|
import org.xwiki.filter.output.OutputFilterStreamFactory; |
41 |
|
import org.xwiki.filter.type.FilterStreamType; |
42 |
|
import org.xwiki.test.annotation.AllComponents; |
43 |
|
|
44 |
|
import com.xpn.xwiki.test.MockitoOldcoreRule; |
45 |
|
|
46 |
|
import static com.xpn.xwiki.test.mockito.OldcoreMatchers.anyXWikiContext; |
47 |
|
import static org.mockito.Mockito.doReturn; |
48 |
|
|
49 |
|
|
50 |
|
@link |
51 |
|
|
52 |
|
@version |
53 |
|
|
54 |
|
@AllComponents |
|
|
| 74.1% |
Uncovered Elements: 7 (27) |
Complexity: 7 |
Complexity Density: 0.33 |
|
55 |
|
public class AbstractInstanceFilterStreamTest |
56 |
|
{ |
57 |
|
private static final SimpleDateFormat DATE_PARSER = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S z", Locale.ENGLISH); |
58 |
|
|
59 |
|
@Rule |
60 |
|
public MockitoOldcoreRule oldcore = new MockitoOldcoreRule(); |
61 |
|
|
62 |
|
protected BeanInputFilterStreamFactory<FilterXMLInputProperties> xmlInputFilterStreamFactory; |
63 |
|
|
64 |
|
protected BeanOutputFilterStreamFactory<InstanceOutputProperties> outputFilterStreamFactory; |
65 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
66 |
10 |
@Before... |
67 |
|
public void before() throws Exception |
68 |
|
{ |
69 |
10 |
this.xmlInputFilterStreamFactory = this.oldcore.getMocker().getInstance(InputFilterStreamFactory.class, |
70 |
|
FilterStreamType.FILTER_XML.serialize()); |
71 |
10 |
this.outputFilterStreamFactory = this.oldcore.getMocker().getInstance(OutputFilterStreamFactory.class, |
72 |
|
FilterStreamType.XWIKI_INSTANCE.serialize()); |
73 |
|
|
74 |
10 |
this.oldcore.getXWikiContext().setWikiId("wiki"); |
75 |
|
|
76 |
|
|
77 |
|
|
78 |
10 |
doReturn(true).when(this.oldcore.getSpyXWiki()).hasAttachmentRecycleBin(anyXWikiContext()); |
79 |
|
} |
80 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
81 |
0 |
protected void importFromXML(String resource) throws FilterException... |
82 |
|
{ |
83 |
0 |
importFromXML(resource, null); |
84 |
|
} |
85 |
|
|
|
|
| 70.6% |
Uncovered Elements: 5 (17) |
Complexity: 4 |
Complexity Density: 0.27 |
|
86 |
10 |
protected void importFromXML(String resource, InstanceOutputProperties instanceProperties) throws FilterException... |
87 |
|
{ |
88 |
10 |
if (instanceProperties == null) { |
89 |
0 |
instanceProperties = new InstanceOutputProperties(); |
90 |
0 |
instanceProperties.setVerbose(false); |
91 |
|
} |
92 |
|
|
93 |
10 |
OutputFilterStream outputFilterStream = |
94 |
|
this.outputFilterStreamFactory.createOutputFilterStream(instanceProperties); |
95 |
|
|
96 |
10 |
URL url = getClass().getResource("/filter/" + resource + ".xml"); |
97 |
|
|
98 |
10 |
FilterXMLInputProperties properties = new FilterXMLInputProperties(); |
99 |
10 |
properties.setSource(new DefaultURLInputSource(url)); |
100 |
|
|
101 |
10 |
InputFilterStream inputFilterStream = this.xmlInputFilterStreamFactory.createInputFilterStream(properties); |
102 |
|
|
103 |
10 |
inputFilterStream.read(outputFilterStream.getFilter()); |
104 |
|
|
105 |
10 |
try { |
106 |
10 |
inputFilterStream.close(); |
107 |
|
} catch (IOException e) { |
108 |
0 |
throw new FilterException("Failed to close input wiki stream", e); |
109 |
|
} |
110 |
10 |
try { |
111 |
10 |
outputFilterStream.close(); |
112 |
|
} catch (IOException e) { |
113 |
0 |
throw new FilterException("Failed to close output wiki stream", e); |
114 |
|
} |
115 |
|
} |
116 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
117 |
17 |
protected Date toDate(String date) throws ParseException... |
118 |
|
{ |
119 |
17 |
return DATE_PARSER.parse(date); |
120 |
|
} |
121 |
|
} |