@Override public void register(Asciidoctor asciidoctor) { JavaExtensionRegistry javaExtensionRegistry = asciidoctor.javaExtensionRegistry(); javaExtensionRegistry.postprocessor(ArrowsAndBoxesIncludesPostProcessor.class); javaExtensionRegistry.block("arrowsAndBoxes", ArrowsAndBoxesBlock.class); }
@Test(expected = IllegalArgumentException.class) public void testRegisterClassWithoutExplicitName() { asciidoctor.javaExtensionRegistry().block(AbstractTestProcessor.class); }
@Test(expected = IllegalArgumentException.class) public void testRegisterClassWithNameAsClass() { asciidoctor.javaExtensionRegistry().block(TestProcessorWithName.class); }
@Test(expected = IllegalArgumentException.class) public void testRegisterClassAsClass() { asciidoctor.javaExtensionRegistry().block(AbstractTestProcessor.class); }
@Test public void a_block_processor_as_string_should_be_executed_when_registered_block_is_found_in_document() { JavaExtensionRegistry javaExtensionRegistry = this.asciidoctor.javaExtensionRegistry(); javaExtensionRegistry.block("yell", "org.asciidoctor.extension.YellStaticBlock"); String content = asciidoctor.convertFile( classpath.getResource("sample-with-yell-block.ad"), options().toFile(false).get()); org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8"); Elements elements = doc.getElementsByClass("paragraph"); assertThat(elements.size(), is(1)); assertThat(elements.get(0).text(), is("THE TIME IS NOW. GET A MOVE ON.")); }
@Test public void a_block_processor_should_be_executed_when_registered_block_is_found_in_document() { JavaExtensionRegistry javaExtensionRegistry = this.asciidoctor.javaExtensionRegistry(); javaExtensionRegistry.block("yell", YellStaticBlock.class); String content = asciidoctor.convertFile( classpath.getResource("sample-with-yell-block.ad"), options().toFile(false).get()); org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8"); Elements elements = doc.getElementsByClass("paragraph"); assertThat(elements.size(), is(1)); assertThat(elements.get(0).text(), is("THE TIME IS NOW. GET A MOVE ON.")); }
@Test public void a_block_processor_should_be_executed_when_registered_listing_block_is_found_in_document() { JavaExtensionRegistry javaExtensionRegistry = this.asciidoctor.javaExtensionRegistry(); javaExtensionRegistry.block("yell", YellStaticListingBlock.class); String content = asciidoctor.convertFile( classpath.getResource("sample-with-yell-listing-block.ad"), options().toFile(false).get()); org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8"); Elements elements = doc.getElementsByClass("paragraph"); assertThat(elements.size(), is(1)); assertThat(elements.get(0).text(), is("THE TIME IS NOW. GET A MOVE ON.")); }
@Test public void a_block_processor_instance_should_be_executed_when_registered_block_is_found_in_document() { JavaExtensionRegistry javaExtensionRegistry = this.asciidoctor.javaExtensionRegistry(); Map<String, Object> config = new HashMap<>(); config.put(Contexts.KEY, Arrays.asList(Contexts.PARAGRAPH)); config.put(ContentModel.KEY, ContentModel.SIMPLE); YellBlock yellBlock = new YellBlock("yell", config); javaExtensionRegistry.block(yellBlock); String content = asciidoctor.convertFile( classpath.getResource("sample-with-yell-block.ad"), options().toFile(false).get()); org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8"); Elements elements = doc.getElementsByClass("paragraph"); assertThat(elements.size(), is(1)); assertThat(elements.get(0).text(), is("THE TIME IS NOW. GET A MOVE ON.")); }
@Test public void a_block_processor_class_should_be_executed_twice() { JavaExtensionRegistry javaExtensionRegistry = this.asciidoctor.javaExtensionRegistry(); javaExtensionRegistry.block("yell", YellStaticBlock.class); for (int i = 0; i < 2; i++) { String content = asciidoctor.convertFile( classpath.getResource("sample-with-yell-block.ad"), options().toFile(false).get()); org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8"); Elements elements = doc.getElementsByClass("paragraph"); assertThat(elements.size(), is(1)); assertThat(elements.get(0).text(), is("THE TIME IS NOW. GET A MOVE ON.")); } }
@Test public void should_invoke_block_processor() throws Exception { //tag::include[] File yellblock_adoc = //... //end::include[] classpathResources.getResource("yell-block.adoc"); //tag::include[] asciidoctor.javaExtensionRegistry().block(YellBlockProcessor.class); // <1> String result = asciidoctor.convertFile(yellblock_adoc, OptionsBuilder.options().toFile(false)); assertThat(result, containsString("I REALLY MEAN IT")); // <2> //end::include[] } }
@Test(expected = AsciidoctorCoreException.class) public void testRegisterClassAsInstance() { asciidoctor.javaExtensionRegistry().block(new AbstractTestProcessor()); asciidoctor.convert(document("foo", "Hello Explicit Instance"), OptionsBuilder.options()); }
@Test public void testRegisterClassAsClassWithExplicitName() { final String explicitblockname = "anotherexplicitname"; asciidoctor.javaExtensionRegistry().block(explicitblockname, AbstractTestProcessor.class); final String result = asciidoctor.convert(document(explicitblockname, "Hello Explicit Class"), OptionsBuilder.options()); check("H e l l o E x p l i c i t C l a s s", result); }
@Test public void testRegisterClassWithNameAsClassWithExplicitName() { final String explicitblockname = "explicitblockname"; asciidoctor.javaExtensionRegistry().block(explicitblockname, TestProcessorWithName.class); final String result = asciidoctor.convert(document(explicitblockname, "Hello Explicit"), OptionsBuilder.options()); check("H e l l o E x p l i c i t", result); }
@Test public void testRegisterNamedClassAsClass() { asciidoctor.javaExtensionRegistry().block(AnnotatedTestProcessor.class); final String result = asciidoctor.convert(document(AnnotatedTestProcessor.NAME, "Hello World"), OptionsBuilder.options()); check("H e l l o W o r l d", result); }
@Test public void testRegisterNamedClassAsClassWithExplicitName() { final String explicitblockname = "explicitblockname"; asciidoctor.javaExtensionRegistry().block(explicitblockname, AnnotatedTestProcessor.class); final String result = asciidoctor.convert(document(explicitblockname, "Hello Explicit"), OptionsBuilder.options()); check("H e l l o E x p l i c i t", result); }
@Test public void testRegisterClassWithNameAsInstance() { asciidoctor.javaExtensionRegistry().block(new TestProcessorWithName()); final String result = asciidoctor.convert(document(TestProcessorWithName.NAME, "Another Test"), OptionsBuilder.options()); check("A n o t h e r T e s t", result); }
@Test public void testRegisterClassAsInstanceWithExplicitName() { final String explicitblockname = "aname"; asciidoctor.javaExtensionRegistry().block(explicitblockname, new AbstractTestProcessor()); final String result = asciidoctor.convert(document(explicitblockname, "Hello Explicit Instance"), OptionsBuilder.options()); check("H e l l o E x p l i c i t I n s t a n c e", result); }
@Test public void testRegisterClassWithNameAsInstanceWithExplicitName() { final String blockName = "somename"; asciidoctor.javaExtensionRegistry().block(blockName, new TestProcessorWithName()); final String result = asciidoctor.convert(document(blockName, "Yet Another Test"), OptionsBuilder.options()); check("Y e t A n o t h e r T e s t", result); }
@Test public void testRegisterNamedClassAsInstanceWithExplicitName() { final String blockName = "somename"; asciidoctor.javaExtensionRegistry().block(blockName, new AnnotatedTestProcessor()); final String result = asciidoctor.convert(document(blockName, "Yet Another Test"), OptionsBuilder.options()); check("Y e t A n o t h e r T e s t", result); }
@Test public void testRegisterNamedClassAsInstance() { asciidoctor.javaExtensionRegistry().block(new AnnotatedTestProcessor()); final String result = asciidoctor.convert(document(AnnotatedTestProcessor.NAME, "Another Test"), OptionsBuilder.options()); check("A n o t h e r T e s t", result); }