@Test public void testDocFileNotFound() throws Exception { Compiler<TestGenProcessor> compiler = buildCompiler(new TestGenProcessor(), "io.vertx.test.file"); compiler.setOption("docgen.source", new File(new File("."), "does_not_exists").getAbsolutePath()); compiler.failCompile(); }
private Map<String, String> failDoc(String pkg) throws Exception { Compiler<TestGenProcessor> compiler = buildCompiler(new TestGenProcessor(), pkg); compiler.failCompile(); return compiler.processor.failures; }
@Test public void testDocFileNotFile() throws Exception { Compiler<TestGenProcessor> compiler = buildCompiler(new TestGenProcessor(), "io.vertx.test.file"); compiler.setOption("docgen.source", new File(".").getAbsolutePath()); compiler.failCompile(); }
@Test public void testLinkGenerationWithAnnotation() throws Exception { String pkg = "io.vertx.test.linktomethod"; Compiler<DocGenProcessor> compiler = BaseProcessorTest.buildCompiler(new DocGenProcessor(new JavaDocGenerator()), pkg); File dir = Files.createTempDirectory("docgen").toFile(); dir.deleteOnExit(); compiler.setOption("docgen.output", dir.getAbsolutePath()); compiler.assertCompile(); File file = new File(dir, pkg + ".adoc"); List<String> lines = Files.readAllLines(file.toPath()); for (String line : lines) { // The :: is used when the annotated type is used. assertFalse(line.contains("::")); } }
@Test public void testOutputInterpolation() throws Exception { for (String pkg : Arrays.asList("io.vertx.test.linktoclass", "io.vertx.test.linktoconstructor", "io.vertx.test.linktomethod", "io.vertx.test.linktofield")) { Compiler<DocGenProcessor> compiler = BaseProcessorTest.buildCompiler(new DocGenProcessor(new JavaDocGenerator()), pkg); File dir = Files.createTempDirectory("docgen").toFile(); dir.deleteOnExit(); compiler.setOption("docgen.output", new File(dir, "$lang").getAbsolutePath()); compiler.setOption("docgen.extension", ".ad.txt"); compiler.assertCompile(); File file = new File(new File(dir, "java"), pkg + ".ad.txt"); assertTrue(file.exists()); assertTrue(file.isFile()); } } }
@Test public void testGeneration() throws Exception { for (String pkg : Arrays.asList("io.vertx.test.linktoclass", "io.vertx.test.linktoconstructor", "io.vertx.test.linktomethod", "io.vertx.test.linktofield")) { Compiler<DocGenProcessor> compiler = BaseProcessorTest.buildCompiler(new DocGenProcessor(new JavaDocGenerator()), pkg); File dir = Files.createTempDirectory("docgen").toFile(); dir.deleteOnExit(); compiler.setOption("docgen.output", dir.getAbsolutePath()); compiler.assertCompile(); File file = new File(dir, pkg + ".adoc"); assertTrue(file.exists()); assertTrue(file.isFile()); } }
@Test public void testFileName() throws Exception { Compiler<DocGenProcessor> compiler = BaseProcessorTest.buildCompiler(new DocGenProcessor(new JavaDocGenerator()), "io.vertx.test.filename"); File dir = Files.createTempDirectory("docgen").toFile(); dir.deleteOnExit(); compiler.setOption("docgen.output", dir.getAbsolutePath()); compiler.assertCompile(); File f1 = new File(dir, "index.adoc"); assertTrue(f1.exists()); assertTrue(f1.isFile()); File f2 = new File(dir, "sub" + File.separator + "index.adoc"); assertTrue(f2.exists()); assertTrue(f2.isFile()); assertEquals("sub/index.adoc", new String(Files.readAllBytes(f1.toPath()))); }
private String assertDoc(String pkg) throws Exception { Compiler<TestGenProcessor> compiler = buildCompiler(new TestGenProcessor(), pkg); compiler.assertCompile(); return compiler.processor.getDoc(pkg); }
@Test public void testNestedBlocks() throws Exception { Compiler<TestGenProcessor> compiler = buildCompiler(new TestGenProcessor(), "io.vertx.test.postprocessors.nested"); compiler.assertCompile(); String content = compiler.processor.getDoc("io.vertx.test.postprocessors.nested"); assertThat(content, containsString("[source,java]")); assertThat(content, containsString("----")); assertThat(content, not(containsString("\\----"))); assertThat(content, containsString("System.out.println(\"Hello\");")); }
private String assertDocFile(String relativeName) throws Exception { File src = docFile(relativeName); Compiler<TestGenProcessor> compiler = buildCompiler(new TestGenProcessor(), "io.vertx.test.file"); compiler.setOption("docgen.source", src.getAbsolutePath()); compiler.assertCompile(); return compiler.processor.getDoc(src.getName()); }
@Test public void testExtension() throws Exception { for (String pkg : Arrays.asList("io.vertx.test.linktoclass", "io.vertx.test.linktoconstructor", "io.vertx.test.linktomethod", "io.vertx.test.linktofield")) { Compiler<DocGenProcessor> compiler = BaseProcessorTest.buildCompiler(new DocGenProcessor(new JavaDocGenerator()), pkg); File dir = Files.createTempDirectory("docgen").toFile(); dir.deleteOnExit(); compiler.setOption("docgen.output", dir.getAbsolutePath()); compiler.setOption("docgen.extension", ".ad.txt"); compiler.assertCompile(); File file = new File(dir, pkg + ".ad.txt"); assertTrue(file.exists()); assertTrue(file.isFile()); } }
private String assertDocWithCustomGenerator(String pkg) throws Exception { Compiler<CustomTestGenProcessor> compiler = buildCompiler(new CustomTestGenProcessor(), pkg); compiler.assertCompile(); return compiler.processor.getDoc(pkg); }
@Test public void testDocFileWithLinkToUnresolvableType() throws Exception { Compiler<TestGenProcessor> compiler = buildCompiler(new TestGenProcessor(), "io.vertx.test.file"); compiler.setOption("docgen.source", docFile("docs/linktounresolvabletype.adoc").getAbsolutePath()); compiler.failCompile(); }
@Test public void testMissingPostProcessor() throws Exception { Compiler<TestGenProcessor> compiler = buildCompiler(new TestGenProcessor(), "io.vertx.test.postprocessors.missing"); compiler.assertCompile(); String content = compiler.processor.getDoc("io.vertx.test.postprocessors.missing"); // String processed = compiler.processor.applyPostProcessors(content); assertThat(content, containsString("This should be included.")); assertThat(content, containsString("[missing]")); assertThat(content, containsString("----")); }
@Test public void testResolveLinkWithSourceAndClass() throws Exception { Compiler<TestGenProcessor> compiler = buildCompiler(new TestGenProcessor(), "io.vertx.test.linkresolution.resolvable"); compiler.assertCompile(); File dependency = compiler.classOutput; compiler = buildCompiler(new TestGenProcessor() { @Override protected String resolveTypeLink(TypeElement elt, Coordinate coordinate) {
@Test public void testCodeBlocks() throws Exception { // Code blocks must not be touched by pre-processors. Compiler<TestGenProcessor> compiler = buildCompiler(new TestGenProcessor(), "io.vertx.test.postprocessors.code"); compiler.assertCompile(); String content = compiler.processor.getDoc("io.vertx.test.postprocessors.code"); assertThat(content, containsString("[source,java]")); assertThat(content, containsString("[source]")); assertThat(content, containsString("----")); assertThat(content, containsString("System.out.println(\"Hello\");")); assertThat(content, containsString(" System.out.println(\"Bye\");")); }
@Test public void testLinkUnresolved() throws Exception { Compiler<TestGenProcessor> compiler = buildCompiler(new TestGenProcessor() { @Override protected String resolveTypeLink(TypeElement elt, Coordinate coordinate) { return null; } }, "io.vertx.test.linkunresolved"); compiler.assertCompile(); String s = compiler.processor.getDoc("io.vertx.test.linkunresolved"); assertEquals("`TheClass`", s); }
@Test public void testGen() throws Exception { AtomicInteger count = new AtomicInteger(); AbstractProcessor proc = new AbstractProcessor() { @Override public Set<String> getSupportedAnnotationTypes() { return Collections.singleton("*"); } @Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { if (count.getAndIncrement() == 0) { try { Filer filer = processingEnv.getFiler(); Element elt = processingEnv.getElementUtils().getTypeElement("gen.GeneratedClass"); JavaFileObject src = filer.createSourceFile("io.vertx.test.gen.GeneratedClass", elt); try (Writer writer = src.openWriter()) { writer.append("package io.vertx.test.gen;\npublic class GeneratedClass {\n}"); } } catch (Exception e) { e.printStackTrace(); } } return true; } }; Compiler<TestGenProcessor> compiler = buildCompiler(new TestGenProcessor(), "io.vertx.test.gen"); compiler.addProcessor(proc); compiler.assertCompile(); assertEquals(3, count.get()); }
@Test public void testVariableSubstitution() throws Exception { Compiler<TestGenProcessor> compiler = buildCompiler(new TestGenProcessor(), "io.vertx.test.variables"); compiler.setOption("foo", "hello"); compiler.setOption("bar", "not-used"); compiler.setOption("baz", "vert.x"); compiler.assertCompile(); String content = compiler.processor.getDoc("io.vertx.test.variables"); String processed = compiler.processor.applyVariableSubstitution(content); assertThat(processed, containsString("hello")); assertThat(processed, containsString("${missing}")); assertThat(processed, containsString("vert.x")); assertThat(processed, containsString("${}")); assertThat(processed, not(containsString("not"))); }
@Test public void testLinksInPostProcessedContent() throws Exception { Compiler<TestGenProcessor> compiler = buildCompiler(new TestGenProcessor(), "io.vertx.test.postprocessors.links"); compiler.assertCompile(); compiler.processor.registerPostProcessor(new PostProcessor() { @Override public String getName() { return "test"; } @Override public String process(String name, String content, String... args) { return content; } }); String content = compiler.processor.getDoc("io.vertx.test.postprocessors.links"); assertThat(content, containsString("`link:type[BaseProcessor]`")); }