From 38e6e7e0a0c214a17b251cea8c767655dfaecc67 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 13 Nov 2016 20:10:54 +0000 Subject: Add basic embedded of style maps --- .../mammoth/tests/docx/EmbeddedStyleMapTests.java | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/test/java/org/zwobble/mammoth/tests/docx/EmbeddedStyleMapTests.java (limited to 'src/test/java/org/zwobble/mammoth/tests/docx/EmbeddedStyleMapTests.java') diff --git a/src/test/java/org/zwobble/mammoth/tests/docx/EmbeddedStyleMapTests.java b/src/test/java/org/zwobble/mammoth/tests/docx/EmbeddedStyleMapTests.java new file mode 100644 index 0000000..1c1f9a8 --- /dev/null +++ b/src/test/java/org/zwobble/mammoth/tests/docx/EmbeddedStyleMapTests.java @@ -0,0 +1,46 @@ +package org.zwobble.mammoth.tests.docx; + +import org.junit.Test; +import org.zwobble.mammoth.internal.docx.*; +import org.zwobble.mammoth.internal.util.Streams; + +import java.io.IOException; +import java.util.Optional; + +import static org.junit.Assert.assertEquals; +import static org.zwobble.mammoth.internal.util.Maps.map; + +public class EmbeddedStyleMapTests { + private static final String ORIGINAL_RELATIONSHIPS_XML = "" + + "" + + "" + + ""; + + private static final String ORIGINAL_CONTENT_TYPES_XML = "" + + "" + + "" + + ""; + + @Test + public void embeddedStyleMapPreservesUnrelatedFiles() throws IOException { + MutableArchive archive = normalDocx(); + EmbeddedStyleMap.embedStyleMap(archive, "p => h1"); + assertEquals("placeholder text", Streams.toString(Archives.getInputStream(archive, "placeholder"))); + } + + @Test + public void embeddedStyleMapCanBeReadAfterBeingEmbedded() throws IOException { + MutableArchive archive = normalDocx(); + EmbeddedStyleMap.embedStyleMap(archive, "p => h1"); + assertEquals(Optional.of("p => h1"), EmbeddedStyleMap.readStyleMap(archive)); + } + + private static MutableArchive normalDocx() { + return InMemoryArchive.fromStrings(map( + "placeholder", "placeholder text", + "word/_rels/document.xml.rels", ORIGINAL_RELATIONSHIPS_XML, + "[Content_Types].xml", ORIGINAL_CONTENT_TYPES_XML + )); + } + +} -- cgit v1.2.3