aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-02-13 22:38:53 +0000
committerMichael Williamson <mike@zwobble.org>2016-02-13 22:38:53 +0000
commit8d01886d494d8251c0825ca7d6df214d19415325 (patch)
tree4a6755fff27f997c815418dabba20840aafd2322 /src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java
parent6ae918357de9c9ff0b84e70016ea08aefeb48dea (diff)
Read v:imagedata
Diffstat (limited to 'src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java')
-rw-r--r--src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java b/src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java
index c8f8887..cc0815e 100644
--- a/src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java
+++ b/src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java
@@ -1,5 +1,6 @@
package org.zwobble.mammoth.tests.docx;
+import com.google.common.io.CharStreams;
import com.natpryce.makeiteasy.Maker;
import org.hamcrest.Matcher;
import org.hamcrest.Matchers;
@@ -13,12 +14,15 @@ import org.zwobble.mammoth.xml.XmlElement;
import org.zwobble.mammoth.xml.XmlNode;
import org.zwobble.mammoth.xml.XmlNodes;
+import java.io.IOException;
+import java.io.InputStreamReader;
import java.util.List;
import java.util.Optional;
import static com.natpryce.makeiteasy.MakeItEasy.*;
import static java.util.Arrays.asList;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasProperty;
import static org.zwobble.mammoth.documents.NoteReference.endnoteReference;
@@ -381,6 +385,25 @@ public class BodyXmlTests {
}
@Test
+ public void canReadImagedataElementsWithIdAttribute() throws IOException {
+ XmlElement element = element("v:imagedata", map("r:id", "rId5", "o:title", "It's a hat"));
+ Relationships relationships = new Relationships(map(
+ "rId5", new Relationship("media/hat.png")));
+ String imageBytes = "Not an image at all!";
+ DocxFile file = new InMemoryDocxFile(map("word/media/hat.png", imageBytes));
+
+ Image image = (Image) readSuccess(
+ a(bodyReader, with(RELATIONSHIPS, relationships), with(DOCX_FILE, file)),
+ element);
+ assertThat(image, allOf(
+ hasProperty("altText", deepEquals(Optional.of("It's a hat"))),
+ hasProperty("contentType", deepEquals(Optional.of("image/png")))));
+ assertThat(
+ CharStreams.toString(new InputStreamReader(image.open())),
+ equalTo("Not an image at all!"));
+ }
+
+ @Test
public void appropriateElementsHaveTheirChildrenReadNormally() {
assertChildrenAreReadNormally("w:ins");
assertChildrenAreReadNormally("w:smartTag");