aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/zwobble/mammoth/tests/MammothTests.java47
-rw-r--r--src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java4
-rw-r--r--src/test/java/org/zwobble/mammoth/tests/docx/InMemoryDocxFile.java28
3 files changed, 34 insertions, 45 deletions
diff --git a/src/test/java/org/zwobble/mammoth/tests/MammothTests.java b/src/test/java/org/zwobble/mammoth/tests/MammothTests.java
index 603d39a..52efde2 100644
--- a/src/test/java/org/zwobble/mammoth/tests/MammothTests.java
+++ b/src/test/java/org/zwobble/mammoth/tests/MammothTests.java
@@ -16,42 +16,42 @@ import static org.zwobble.mammoth.tests.DeepReflectionMatcher.deepEquals;
public class MammothTests {
@Test
- public void docxContainingOneParagraphIsConvertedToSingleParagraphElement() {
+ public void docxContainingOneParagraphIsConvertedToSingleParagraphElement() throws IOException {
assertThat(
convertToHtml("single-paragraph.docx"),
deepEquals(success("<p>Walking on imported air</p>")));
}
@Test
- public void canReadFilesWithUtf8Bom() {
+ public void canReadFilesWithUtf8Bom() throws IOException {
assertThat(
convertToHtml("utf8-bom.docx"),
deepEquals(success("<p>This XML has a byte order mark.</p>")));
}
@Test
- public void emptyParagraphsAreIgnoredByDefault() {
+ public void emptyParagraphsAreIgnoredByDefault() throws IOException {
assertThat(
convertToHtml("empty.docx"),
deepEquals(success("")));
}
@Test
- public void emptyParagraphsArePreservedIfIgnoreEmptyParagraphsIsFalse() {
+ public void emptyParagraphsArePreservedIfIgnoreEmptyParagraphsIsFalse() throws IOException {
assertThat(
convertToHtml("empty.docx", Mammoth.Options.DEFAULT.preserveEmptyParagraphs()),
deepEquals(success("<p></p>")));
}
@Test
- public void simpleListIsConvertedToListElements() {
+ public void simpleListIsConvertedToListElements() throws IOException {
assertThat(
convertToHtml("simple-list.docx"),
deepEquals(success("<ul><li>Apple</li><li>Banana</li></ul>")));
}
@Test
- public void wordTablesAreConvertedToHtmlTables() {
+ public void wordTablesAreConvertedToHtmlTables() throws IOException {
assertThat(
convertToHtml("tables.docx"),
deepEquals(success(
@@ -64,7 +64,7 @@ public class MammothTests {
}
@Test
- public void inlineImagesAreIncludedInOutput() {
+ public void inlineImagesAreIncludedInOutput() throws IOException {
assertThat(
convertToHtml("tiny-picture.docx"),
deepEquals(success("<p><img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAIAAAACUFjqAAAAAXNSR0IArs4c6QAAAAlwSFlzAAAOvgAADr4B6kKxwAAAABNJREFUKFNj/M+ADzDhlWUYqdIAQSwBE8U+X40AAAAASUVORK5CYII=\" /></p>")));
@@ -86,6 +86,23 @@ public class MammothTests {
}
@Test
+ public void warnIfDocumentHasImagesStoredOutsideOfDocumentWhenPathOfDocumentIsUnknown() throws IOException {
+ Path tempDirectory = Files.createTempDirectory("mammoth-");
+ try {
+ Path documentPath = tempDirectory.resolve("external-picture.docx");
+ Files.copy(TestData.file("external-picture.docx").toPath(), documentPath);
+ assertThat(
+ Mammoth.convertToHtml(documentPath.toUri().toURL().openStream()),
+ allOf(
+ hasProperty("value", equalTo("")),
+ hasProperty("warnings", contains(
+ hasProperty("message", startsWith("could not open external image 'tiny-picture.png': path of document is unknown, but is required for relative URI"))))));
+ } finally {
+ tempDirectory.toFile().delete();
+ }
+ }
+
+ @Test
public void warnIfImagesStoredOutsideOfDocumentAreNotFound() throws IOException {
Path tempDirectory = Files.createTempDirectory("mammoth-");
try {
@@ -103,14 +120,14 @@ public class MammothTests {
}
@Test
- public void contentTypesAreRead() {
+ public void contentTypesAreRead() throws IOException {
assertThat(
convertToHtml("tiny-picture-custom-content-type.docx"),
deepEquals(success("<p><img src=\"data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAIAAAACUFjqAAAAAXNSR0IArs4c6QAAAAlwSFlzAAAOvgAADr4B6kKxwAAAABNJREFUKFNj/M+ADzDhlWUYqdIAQSwBE8U+X40AAAAASUVORK5CYII=\" /></p>")));
}
@Test
- public void footnotesAreAppendedToText() {
+ public void footnotesAreAppendedToText() throws IOException {
assertThat(
convertToHtml("footnotes.docx", Mammoth.Options.DEFAULT.idPrefix("doc-42-")),
deepEquals(success(
@@ -122,7 +139,7 @@ public class MammothTests {
}
@Test
- public void endNotesAreAppendedToText() {
+ public void endNotesAreAppendedToText() throws IOException {
assertThat(
convertToHtml("endnotes.docx", Mammoth.Options.DEFAULT.idPrefix("doc-42-")),
deepEquals(success(
@@ -134,7 +151,7 @@ public class MammothTests {
}
@Test
- public void relationshipsAreReadForEachFileContainingBodyXml() {
+ public void relationshipsAreReadForEachFileContainingBodyXml() throws IOException {
assertThat(
convertToHtml("footnote-hyperlink.docx", Mammoth.Options.DEFAULT.idPrefix("doc-42-")),
deepEquals(success(
@@ -143,25 +160,25 @@ public class MammothTests {
}
@Test
- public void textBoxesAreRead() {
+ public void textBoxesAreRead() throws IOException {
assertThat(
convertToHtml("text-box.docx"),
deepEquals(success("<p>Datum plane</p>")));
}
@Test
- public void canExtractRawText() {
+ public void canExtractRawText() throws IOException {
assertThat(
Mammoth.extractRawText(TestData.file("simple-list.docx")),
deepEquals(success("Apple\n\nBanana\n\n")));
}
- private Result<String> convertToHtml(String name) {
+ private Result<String> convertToHtml(String name) throws IOException {
File file = TestData.file(name);
return Mammoth.convertToHtml(file);
}
- private Result<String> convertToHtml(String name, Mammoth.Options options) {
+ private Result<String> convertToHtml(String name, Mammoth.Options options) throws IOException {
File file = TestData.file(name);
return Mammoth.convertToHtml(file, options);
}
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 2c1d505..8b31452 100644
--- a/src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java
+++ b/src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java
@@ -437,7 +437,7 @@ public class BodyXmlTests {
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));
+ DocxFile file = InMemoryDocxFile.fromStrings(map("word/media/hat.png", imageBytes));
Image image = (Image) readSuccess(
a(bodyReader, with(RELATIONSHIPS, relationships), with(DOCX_FILE, file)),
@@ -465,7 +465,7 @@ public class BodyXmlTests {
XmlElement element = inlineImageXml(embeddedBlipXml("rId5"), "");
Relationships relationships = new Relationships(map(
"rId5", new Relationship("media/hat.emf")));
- DocxFile file = new InMemoryDocxFile(map("word/media/hat.emf", "Not an image at all!"));
+ DocxFile file = InMemoryDocxFile.fromStrings(map("word/media/hat.emf", "Not an image at all!"));
ContentTypes contentTypes = new ContentTypes(map("emf", "image/x-emf"), map());
Result<?> result = read(
diff --git a/src/test/java/org/zwobble/mammoth/tests/docx/InMemoryDocxFile.java b/src/test/java/org/zwobble/mammoth/tests/docx/InMemoryDocxFile.java
deleted file mode 100644
index 4aef42e..0000000
--- a/src/test/java/org/zwobble/mammoth/tests/docx/InMemoryDocxFile.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package org.zwobble.mammoth.tests.docx;
-
-import org.zwobble.mammoth.docx.DocxFile;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.charset.StandardCharsets;
-import java.util.Map;
-import java.util.Optional;
-
-public class InMemoryDocxFile implements DocxFile {
- private final Map<String, String> entries;
-
- public InMemoryDocxFile(Map<String, String> entries) {
- this.entries = entries;
- }
-
- @Override
- public Optional<InputStream> tryGetInputStream(String name) throws IOException {
- return Optional.ofNullable(entries.get(name))
- .map(value -> new ByteArrayInputStream(value.getBytes(StandardCharsets.UTF_8)));
- }
-
- @Override
- public void close() throws IOException {
- }
-}