Skip to content

Commit

Permalink
Safe mode unit test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pepijnve committed Oct 1, 2020
1 parent 0213206 commit db8c0a2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ public class WhenDocumentContainsDitaaDiagram {
@Test
public void png_should_be_rendered_for_diagram() {

File inputFile = new File("build/resources/test/sample.adoc");
File buildDir = new File("build/resources/test");

File inputFile = new File(buildDir, "sample.adoc");
File outputFile1 = new File(inputFile.getParentFile(), "asciidoctor-diagram-process.png");
File outputFile2 = new File(inputFile.getParentFile(), ".asciidoctor/diagram/asciidoctor-diagram-process.png.cache");
asciidoctor.requireLibrary("asciidoctor-diagram");
asciidoctor.convertFile(inputFile,
options()
.backend("html5")
.toDir(new File("build"))
.toFile(new File(buildDir, "sample.html"))
.get());
assertThat(outputFile1.exists(), is(true));
assertThat(outputFile2.exists(), is(true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import org.junit.Test;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;

import static org.asciidoctor.OptionsBuilder.options;
import static org.hamcrest.CoreMatchers.is;
Expand All @@ -18,23 +21,25 @@ public class WhenDocumentWantsDataUris {
private Asciidoctor asciidoctor = Asciidoctor.Factory.create();

@Test
public void png_should_be_rendered_for_diagram() {
public void png_should_be_rendered_for_diagram() throws IOException {
File buildDir = new File("build/resources/test");

File inputFile = new File("build/resources/test/data-uri.adoc");
File inputFile = new File(buildDir, "data-uri.adoc");
File outputFile = new File(buildDir, "data-uri.html");
File outputFile1 = new File(inputFile.getParentFile(), "data-uri-test.png");
File outputFile2 = new File(inputFile.getParentFile(), ".asciidoctor/diagram/data-uri-test.png.cache");
asciidoctor.requireLibrary("asciidoctor-diagram");
final String html = asciidoctor.convertFile(inputFile,
asciidoctor.convertFile(inputFile,
options().backend("html5")
.toFile(false)
.toDir(new File("build"))
.toFile(outputFile)
.safe(SafeMode.SERVER)
.get());
assertThat(outputFile1.exists(), is(true));
assertThat(outputFile2.exists(), is(true));
outputFile1.delete();
outputFile2.delete();

String html = new String(Files.readAllBytes(outputFile.toPath()), StandardCharsets.UTF_8);
final Document doc = Jsoup.parse(html);
System.out.println(doc);
Elements images = doc.getElementsByTag("img");
Expand Down

0 comments on commit db8c0a2

Please sign in to comment.