aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org/zwobble/mammoth/tests/docx/EmbeddedStyleMapTests.java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-11-13 20:10:54 +0000
committerMichael Williamson <mike@zwobble.org>2016-11-13 20:10:54 +0000
commit38e6e7e0a0c214a17b251cea8c767655dfaecc67 (patch)
tree3718fff1163b979f7d0ac34c60d1215828d3fc70 /src/test/java/org/zwobble/mammoth/tests/docx/EmbeddedStyleMapTests.java
parent90be34b20ed99409523a2d5ff174f48058969684 (diff)
Add basic embedded of style maps
Diffstat (limited to 'src/test/java/org/zwobble/mammoth/tests/docx/EmbeddedStyleMapTests.java')
-rw-r--r--src/test/java/org/zwobble/mammoth/tests/docx/EmbeddedStyleMapTests.java46
1 files changed, 46 insertions, 0 deletions
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 = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" +
+ "<Relationships xmlns=\"http://schemas.openxmlformats.org/package/2006/relationships\">" +
+ "<Relationship Id=\"rId3\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings\" Target=\"settings.xml\"/>" +
+ "</Relationships>";
+
+ private static final String ORIGINAL_CONTENT_TYPES_XML = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" +
+ "<Types xmlns=\"http://schemas.openxmlformats.org/package/2006/content-types\">" +
+ "<Default Extension=\"png\" ContentType=\"image/png\"/>" +
+ "</Types>";
+
+ @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
+ ));
+ }
+
+}