aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org/zwobble/mammoth/tests/docx/DocumentReaderTests.java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2018-01-23 21:26:38 +0000
committerMichael Williamson <mike@zwobble.org>2018-01-23 21:26:38 +0000
commitd9a34a0836a7e41a975017fb021f5af90d954ae5 (patch)
tree0d479e2fc7d5023d9a1279406654acd5da7fed6c /src/test/java/org/zwobble/mammoth/tests/docx/DocumentReaderTests.java
parentd54918c26a0e6eae954eaa2052c7e8ec546c3409 (diff)
Find main document part using _rels/.rels
Diffstat (limited to 'src/test/java/org/zwobble/mammoth/tests/docx/DocumentReaderTests.java')
-rw-r--r--src/test/java/org/zwobble/mammoth/tests/docx/DocumentReaderTests.java60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/test/java/org/zwobble/mammoth/tests/docx/DocumentReaderTests.java b/src/test/java/org/zwobble/mammoth/tests/docx/DocumentReaderTests.java
new file mode 100644
index 0000000..d7f1a11
--- /dev/null
+++ b/src/test/java/org/zwobble/mammoth/tests/docx/DocumentReaderTests.java
@@ -0,0 +1,60 @@
+package org.zwobble.mammoth.tests.docx;
+
+import org.junit.jupiter.api.Test;
+import org.zwobble.mammoth.internal.archives.InMemoryArchive;
+import org.zwobble.mammoth.internal.documents.Document;
+import org.zwobble.mammoth.internal.docx.DocumentReader;
+import org.zwobble.mammoth.internal.results.InternalResult;
+import org.zwobble.mammoth.internal.xml.NamespacePrefixes;
+import org.zwobble.mammoth.internal.xml.XmlWriter;
+
+import java.util.Optional;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.zwobble.mammoth.internal.util.Lists.list;
+import static org.zwobble.mammoth.internal.util.Maps.map;
+import static org.zwobble.mammoth.internal.xml.XmlNodes.element;
+import static org.zwobble.mammoth.internal.xml.XmlNodes.text;
+import static org.zwobble.mammoth.tests.ResultMatchers.isInternalSuccess;
+import static org.zwobble.mammoth.tests.documents.DocumentElementMakers.*;
+
+public class DocumentReaderTests {
+ private final NamespacePrefixes mainDocumentNamespaces = NamespacePrefixes.builder()
+ .put("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main")
+ .build();
+ private final NamespacePrefixes relationshipsNamespaces = NamespacePrefixes.builder()
+ .defaultPrefix("http://schemas.openxmlformats.org/package/2006/relationships")
+ .build();
+
+ @Test
+ public void mainDocumentIsFoundUsingPackageRelationships() {
+ InternalResult<Document> result = DocumentReader.readDocument(Optional.empty(), InMemoryArchive.fromStrings(map(
+ "word/document2.xml", XmlWriter.toString(
+ element("w:document", list(
+ element("w:body", list(
+ element("w:p", list(
+ element("w:r", list(
+ element("w:t", list(text("Hello.")))
+ ))
+ ))
+ ))
+ )),
+ mainDocumentNamespaces
+ ),
+ "_rels/.rels", XmlWriter.toString(
+ element("Relationships", list(
+ element("Relationship", map(
+ "Id", "rId1",
+ "Target", "/word/document2.xml",
+ "Type", "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"
+ ))
+ )),
+ relationshipsNamespaces
+ )
+ )));
+
+ assertThat(result, isInternalSuccess(document(
+ withChildren(paragraphWithText("Hello."))
+ )));
+ }
+}