@Test public void copycss_negated_with_in_place_should_not_copy_css_to_rendered_directory() { Attributes attributes = attributes().copyCss(false).get(); Options options = options().inPlace(true).safe(SafeMode.UNSAFE) .attributes(attributes).get(); File inputFile = classpath.getResource("rendersample.asciidoc"); asciidoctor.convertFile(inputFile, options); try { File cssFile = new File(inputFile.getParent(), "asciidoctor.css"); assertThat(cssFile.exists(), is(false)); } catch (RuntimeException e) { assertThat(e.getCause(), is(instanceOf(FileNotFoundException.class))); } }
@Test public void copycss_with_in_place_should_copy_css_to_rendered_directory() { Attributes attributes = attributes().linkCss(true).copyCss(true).get(); Options options = options().inPlace(true).safe(SafeMode.UNSAFE) .attributes(attributes).get(); File inputFile = classpath.getResource("rendersample.asciidoc"); asciidoctor.convertFile(inputFile, options); File cssFile = new File(inputFile.getParent(),"asciidoctor.css"); assertThat(cssFile.exists(), is(true)); cssFile.delete(); }
@Test public void copycss_and_linkcss_negated_should_not_copy_css_to_rendered_file() { Attributes attributes = attributes().copyCss(true).linkCss(false).get(); Options options = options().inPlace(true).safe(SafeMode.UNSAFE) .attributes(attributes).get(); File inputFile = classpath.getResource("rendersample.asciidoc"); asciidoctor.convertFile(inputFile, options); try { File cssFile = new File(inputFile.getParent(), "asciidoctor.css"); assertThat(cssFile.exists(), is(false)); } catch (RuntimeException e) { assertThat(e.getCause(), is(instanceOf(FileNotFoundException.class))); } }
@Test public void copycss_with_render_to_file_should_copy_css_to_to_file_directory() { Attributes attributes = attributes().linkCss(true).copyCss(true).get(); Options options = options().inPlace(false) .toFile(new File(testFolder.getRoot(), "output.html")) .safe(SafeMode.UNSAFE).attributes(attributes).get(); asciidoctor.convert("This is Asciidoctor", options); File cssFile = new File(testFolder.getRoot(), "asciidoctor.css"); assertThat(cssFile.exists(), is(true)); }
@Test public void copycss_with_to_file_should_copy_css_to_to_file_directory() { Attributes attributes = attributes().linkCss(true).copyCss(true).get(); Options options = options().inPlace(false) .toFile(new File(testFolder.getRoot(), "output.html")) .safe(SafeMode.UNSAFE).attributes(attributes).get(); asciidoctor.convertFile(classpath.getResource("rendersample.asciidoc"), options); File cssFile = new File(testFolder.getRoot(), "asciidoctor.css"); assertThat(cssFile.exists(), is(true)); }
@Test public void copycss_with_render_to_dir_should_copy_css_to_to_dir_directory() { Attributes attributes = attributes().linkCss(true).copyCss(true).get(); Options options = options().inPlace(false).toDir(testFolder.getRoot()) .safe(SafeMode.UNSAFE).attributes(attributes).get(); asciidoctor.convert("This is Asciidoctor", options); File cssFile = new File(testFolder.getRoot(), "asciidoctor.css"); assertThat(cssFile.exists(), is(true)); }
@Test public void copycss_with_to_dir_should_copy_css_to_to_dir_directory() { Attributes attributes = attributes().linkCss(true).copyCss(true).get(); Options options = options().inPlace(false).toDir(testFolder.getRoot()) .safe(SafeMode.UNSAFE).attributes(attributes).get(); asciidoctor.convertFile(classpath.getResource("rendersample.asciidoc"), options); File cssFile = new File(testFolder.getRoot(), "asciidoctor.css"); assertThat(cssFile.exists(), is(true)); }
@Test public void api_parameters_should_be_transformed_to_cli_command() { AttributesBuilder attributesBuilder = AttributesBuilder.attributes() .attribute("myAtribute", "myValue").sectionNumbers(true) .copyCss(false); OptionsBuilder optionsBuilder = OptionsBuilder.options() .backend("docbook").templateDirs(new File("a"), new File("b")) .safe(SafeMode.UNSAFE).attributes(attributesBuilder.get()); String command = AsciidoctorUtils.toAsciidoctorCommand( optionsBuilder.asMap(), "file.adoc"); String currentDirectory = new File( "" ).getAbsolutePath() + File.separator; String parametersString = command.substring(command.indexOf(" "), command.length()); String[] parameters = parametersString.split(" "); AsciidoctorCliOptions asciidoctorCliOptions = new AsciidoctorCliOptions(); new JCommander(asciidoctorCliOptions, parameters); assertThat(asciidoctorCliOptions.getTemplateDir(), containsInAnyOrder(currentDirectory+"a", currentDirectory+"b")); assertThat(asciidoctorCliOptions.getSafeMode(), is(SafeMode.UNSAFE)); assertThat(asciidoctorCliOptions.getBackend(), is("docbook")); assertThat(asciidoctorCliOptions.getParameters(), containsInAnyOrder("file.adoc")); assertThat(asciidoctorCliOptions.getAttributes(), hasEntry("myAtribute", (Object)"myValue")); assertThat(asciidoctorCliOptions.getAttributes(), hasKey("numbered")); assertThat(asciidoctorCliOptions.getAttributes(), hasKey("copycss!")); }