From 29a3d3491a2796c5a1e772c2f15deb2a9a2e9376 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 27 Jan 2018 18:17:22 +0000 Subject: Find comments part using document relationships --- .../mammoth/tests/docx/DocumentReaderTests.java | 52 +++++++++++++++++++++- 1 file changed, 50 insertions(+), 2 deletions(-) (limited to 'src/test/java') diff --git a/src/test/java/org/zwobble/mammoth/tests/docx/DocumentReaderTests.java b/src/test/java/org/zwobble/mammoth/tests/docx/DocumentReaderTests.java index ddccd9c..bce431a 100644 --- a/src/test/java/org/zwobble/mammoth/tests/docx/DocumentReaderTests.java +++ b/src/test/java/org/zwobble/mammoth/tests/docx/DocumentReaderTests.java @@ -103,7 +103,6 @@ public class DocumentReaderTests { )); DocumentReader.PartPaths partPaths = DocumentReader.findPartPaths(archive); - assertThat(partPaths.getMainDocument(), equalTo("word/document2.xml")); } @@ -114,8 +113,57 @@ public class DocumentReaderTests { )); DocumentReader.PartPaths partPaths = DocumentReader.findPartPaths(archive); - assertThat(partPaths.getMainDocument(), equalTo("word/document.xml")); } + @Test + public void commentsPartIsFoundUsingMainDocumentRelationships() { + InMemoryArchive archive = InMemoryArchive.fromStrings(map( + "_rels/.rels", XmlWriter.toString( + element("Relationships", list( + element("Relationship", map( + "Id", "rId1", + "Target", "/word/document.xml", + "Type", "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" + )) + )), + relationshipsNamespaces + ), + "word/document.xml", " ", + "word/_rels/document.xml.rels", XmlWriter.toString( + element("Relationships", list( + element("Relationship", map( + "Id", "rId2", + "Target", "target-path.xml", + "Type", "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments" + )) + )), + relationshipsNamespaces + ), + "word/target-path.xml", " " + )); + + DocumentReader.PartPaths partPaths = DocumentReader.findPartPaths(archive); + assertThat(partPaths.getComments(), equalTo("word/target-path.xml")); + } + + @Test + public void whenRelationshipsForCommentsCannotBeFoundThenFallbackIsUsed() { + InMemoryArchive archive = InMemoryArchive.fromStrings(map( + "word/document.xml", " ", + "_rels/.rels", XmlWriter.toString( + element("Relationships", list( + element("Relationship", map( + "Id", "rId1", + "Target", "/word/document.xml", + "Type", "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" + )) + )), + relationshipsNamespaces + ) + )); + + DocumentReader.PartPaths partPaths = DocumentReader.findPartPaths(archive); + assertThat(partPaths.getComments(), equalTo("word/comments.xml")); + } } } -- cgit v1.2.3