1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.officeimporter.internal.builder; |
21 |
|
|
22 |
|
import java.io.ByteArrayInputStream; |
23 |
|
import java.io.InputStream; |
24 |
|
import java.util.HashMap; |
25 |
|
import java.util.Map; |
26 |
|
|
27 |
|
import org.jmock.Expectations; |
28 |
|
import org.junit.Before; |
29 |
|
import org.junit.Test; |
30 |
|
import org.xwiki.model.reference.DocumentReference; |
31 |
|
import org.xwiki.officeimporter.builder.XDOMOfficeDocumentBuilder; |
32 |
|
import org.xwiki.officeimporter.converter.OfficeConverter; |
33 |
|
import org.xwiki.officeimporter.document.OfficeDocument; |
34 |
|
import org.xwiki.officeimporter.document.XDOMOfficeDocument; |
35 |
|
import org.xwiki.officeimporter.internal.AbstractOfficeImporterTest; |
36 |
|
import org.xwiki.rendering.listener.MetaData; |
37 |
|
|
38 |
|
import static org.junit.Assert.*; |
39 |
|
|
40 |
|
|
41 |
|
@link |
42 |
|
|
43 |
|
@version |
44 |
|
@since |
45 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (25) |
Complexity: 3 |
Complexity Density: 0.14 |
|
46 |
|
public class DefaultXDOMOfficeDocumentBuilderTest extends AbstractOfficeImporterTest |
47 |
|
{ |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
private static final String INPUT_FILE_NAME = "office.doc"; |
52 |
|
|
53 |
|
|
54 |
|
@link |
55 |
|
|
56 |
|
private static final String OUTPUT_FILE_NAME = "office.html"; |
57 |
|
|
58 |
|
|
59 |
|
@link |
60 |
|
|
61 |
|
private XDOMOfficeDocumentBuilder xdomOfficeDocumentBuilder; |
62 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
63 |
1 |
@Override... |
64 |
|
@Before |
65 |
|
public void setUp() throws Exception |
66 |
|
{ |
67 |
1 |
super.setUp(); |
68 |
1 |
this.xdomOfficeDocumentBuilder = getComponentManager().getInstance(XDOMOfficeDocumentBuilder.class); |
69 |
|
} |
70 |
|
|
71 |
|
|
72 |
|
@link |
73 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
74 |
1 |
@Test... |
75 |
|
public void testXDOMOfficeDocumentBuilding() throws Exception |
76 |
|
{ |
77 |
|
|
78 |
1 |
final InputStream mockOfficeFileStream = new ByteArrayInputStream(new byte[1024]); |
79 |
1 |
final Map<String, InputStream> mockInput = new HashMap<String, InputStream>(); |
80 |
1 |
mockInput.put(INPUT_FILE_NAME, mockOfficeFileStream); |
81 |
1 |
final Map<String, byte[]> mockOutput = new HashMap<String, byte[]>(); |
82 |
1 |
mockOutput.put(OUTPUT_FILE_NAME, |
83 |
|
"<html><head><title></tile></head><body><p><strong>Hello There</strong></p></body></html>".getBytes()); |
84 |
|
|
85 |
1 |
final OfficeConverter mockDocumentConverter = getMockery().mock(OfficeConverter.class); |
86 |
1 |
final DocumentReference documentReference = new DocumentReference("xwiki", "Main", "Test"); |
87 |
|
|
88 |
1 |
getMockery().checking(new Expectations() |
89 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
90 |
1 |
{... |
91 |
1 |
oneOf(mockOfficeServer).getConverter(); |
92 |
1 |
will(returnValue(mockDocumentConverter)); |
93 |
|
|
94 |
1 |
allowing(mockDocumentConverter).convert(mockInput, INPUT_FILE_NAME, OUTPUT_FILE_NAME); |
95 |
1 |
will(returnValue(mockOutput)); |
96 |
|
|
97 |
1 |
allowing(mockDocumentReferenceResolver).resolve("xwiki:Main.Test"); |
98 |
1 |
will(returnValue(documentReference)); |
99 |
|
|
100 |
1 |
allowing(mockDefaultStringEntityReferenceSerializer).serialize(documentReference); |
101 |
1 |
will(returnValue("xwiki:Main.Test")); |
102 |
|
} |
103 |
|
}); |
104 |
|
|
105 |
1 |
XDOMOfficeDocument document = |
106 |
|
xdomOfficeDocumentBuilder.build(mockOfficeFileStream, INPUT_FILE_NAME, documentReference, true); |
107 |
1 |
assertEquals("xwiki:Main.Test", document.getContentDocument().getMetaData().getMetaData(MetaData.BASE)); |
108 |
1 |
assertEquals("**Hello There**", document.getContentAsString()); |
109 |
1 |
assertEquals(0, document.getArtifacts().size()); |
110 |
|
} |
111 |
|
} |