Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a6a4934
commit 5a2a4a1
Showing
3 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
asciidoctorj-distribution/src/test/java/org/asciidoctor/WhenPlantumlDiagramIsRendered.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package org.asciidoctor; | ||
|
||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
import org.junit.rules.TemporaryFolder; | ||
|
||
import java.io.File; | ||
import java.util.UUID; | ||
|
||
import static org.hamcrest.CoreMatchers.containsString; | ||
import static org.hamcrest.Matchers.greaterThan; | ||
import static org.hamcrest.core.Is.is; | ||
import static org.junit.Assert.assertThat; | ||
|
||
public class WhenPlantumlDiagramIsRendered { | ||
|
||
@ClassRule | ||
public static TemporaryFolder tmp = new TemporaryFolder(); | ||
|
||
@Test | ||
public void should_render_plantuml_diagram() throws Exception { | ||
// given: | ||
final String imageFileName = UUID.randomUUID().toString(); | ||
final String document = getTestDocument(imageFileName); | ||
|
||
Asciidoctor asciidoctor = Asciidoctor.Factory.create(); | ||
asciidoctor.requireLibrary("asciidoctor-diagram"); | ||
|
||
// when: | ||
final String result = asciidoctor.convert( | ||
document, | ||
OptionsBuilder.options() | ||
.toFile(false) | ||
.attributes(AttributesBuilder.attributes() | ||
.attribute("imagesoutdir", "build"))); | ||
|
||
// then: | ||
assertThat(result, containsString("src=\"" + imageFileName + ".png\"")); | ||
assertThat("PNG file not created!", new File("build/" + imageFileName + ".png").exists(), is(true)); | ||
assertThat("PNG cache file not created!", new File("build/" + imageFileName + ".png.cache").exists(), is(true)); | ||
} | ||
|
||
@Test | ||
public void should_render_plantuml_diagram_to_PDF() throws Exception { | ||
// given: | ||
final String imageFileName = UUID.randomUUID().toString(); | ||
|
||
final File destinationFile = new File("build/plantuml.pdf"); | ||
|
||
final String document = getTestDocument(imageFileName); | ||
|
||
Asciidoctor asciidoctor = Asciidoctor.Factory.create(); | ||
asciidoctor.requireLibrary("asciidoctor-diagram"); | ||
|
||
// when: | ||
asciidoctor.convert( | ||
document, | ||
OptionsBuilder.options() | ||
.backend("pdf") | ||
.toFile(destinationFile) | ||
.attributes(AttributesBuilder.attributes() | ||
.attribute("imagesoutdir", "build"))); | ||
|
||
// then: | ||
assertThat(destinationFile.exists(), is(true)); | ||
assertThat(destinationFile.length(), greaterThan(0L)); | ||
assertThat("PNG file not created!", new File("build/" + imageFileName + ".png").exists(), is(true)); | ||
assertThat("PNG cache file not created!", new File("build/" + imageFileName + ".png.cache").exists(), is(true)); | ||
} | ||
|
||
private String getTestDocument(String imageFileName) { | ||
return "= Document Title\n" + | ||
"\n" + | ||
"Hello World\n" + | ||
"\n" + | ||
"[plantuml," + imageFileName + "]\n" + | ||
"....\n" + | ||
"A --|> B\n" + | ||
"....\n" + | ||
"\n"; | ||
} | ||
} |