@Test public void testFromResourceURI() throws IOException, URISyntaxException { //Given Path outputDirectory = Paths.get("build/test/asciidoc/fileUri"); FileUtils.deleteQuietly(outputDirectory.toFile()); //When Swagger2MarkupConverter.from(GeneralConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()).build() .toFolder(outputDirectory); //Then String[] files = outputDirectory.toFile().list(); assertThat(files).hasSize(4).containsAll(expectedFiles); }
@Test public void testFromPathURI() throws IOException, URISyntaxException { //Given Path outputDirectory = Paths.get("build/test/asciidoc/pathUri"); FileUtils.deleteQuietly(outputDirectory.toFile()); //When Swagger2MarkupConverter.from(Paths.get("src/test/resources/yaml/swagger_petstore.yaml").toUri()).build() .toFolder(outputDirectory); //Then String[] files = outputDirectory.toFile().list(); assertThat(files).hasSize(4).containsAll(expectedFiles); }
@Test public void testFromHttpURI() throws IOException, URISyntaxException { //Given Path outputDirectory = Paths.get("build/test/asciidoc/fromUri"); FileUtils.deleteQuietly(outputDirectory.toFile()); //When Swagger2MarkupConverter.from(URI.create("http://petstore.swagger.io/v2/swagger.json")).build() .toFolder(outputDirectory); //Then String[] files = outputDirectory.toFile().list(); assertThat(files).hasSize(4).containsAll(expectedFiles); }
@Test public void testFromStringURIWithoutScheme() throws IOException, URISyntaxException { //Given Path outputDirectory = Paths.get("build/test/asciidoc/pathUri"); FileUtils.deleteQuietly(outputDirectory.toFile()); //When Swagger2MarkupConverter.from(URI.create("src/test/resources/yaml/swagger_petstore.yaml")).build() .toFolder(outputDirectory); //Then String[] files = outputDirectory.toFile().list(); assertThat(files).hasSize(4).containsAll(expectedFiles); }
@Test public void testFromURL() throws IOException, URISyntaxException { //Given Path outputDirectory = Paths.get("build/test/asciidoc/fromUrl"); FileUtils.deleteQuietly(outputDirectory.toFile()); //When Swagger2MarkupConverter.from(new URL("http://petstore.swagger.io/v2/swagger.json")).build() .toFolder(outputDirectory); //Then String[] files = outputDirectory.toFile().list(); assertThat(files).hasSize(4).containsAll(expectedFiles); }
@Test public void testSwagger2AsciiDocConversionFromString() throws IOException, URISyntaxException { //Given String swaggerJsonString = IOUtils.toString(getClass().getResourceAsStream("/yaml/swagger_petstore.yaml")); Path outputDirectory = Paths.get("build/test/asciidoc/to_folder"); FileUtils.deleteQuietly(outputDirectory.toFile()); //When Swagger2MarkupConverter.from(swaggerJsonString).build() .toFolder(outputDirectory); //Then String[] files = outputDirectory.toFile().list(); assertThat(files).hasSize(4).containsAll(expectedFiles); Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/expected/asciidoc/to_folder").toURI()); DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testSwagger2AsciiDocConversion.html"); }
@Test public void testContainsUriScheme() throws IOException, URISyntaxException { //Given Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_should_contain_uri_scheme.yaml").toURI()); Path outputDirectory = Paths.get("build/test/asciidoc/generated"); FileUtils.deleteQuietly(outputDirectory.toFile()); //When Swagger2MarkupConverter.from(file).build() .toFolder(outputDirectory); //Then String[] files = outputDirectory.toFile().list(); assertThat(files).hasSize(4).containsAll(expectedFiles); assertThat(new String(Files.readAllBytes(outputDirectory.resolve("overview.adoc")))) .contains("=== URI scheme"); }
@Test public void testToFolder() throws IOException, URISyntaxException { //Given Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); Path outputDirectory = Paths.get("build/test/asciidoc/to_folder"); FileUtils.deleteQuietly(outputDirectory.toFile()); //When Swagger2MarkupConverter.from(file).build() .toFolder(outputDirectory); //Then String[] files = outputDirectory.toFile().list(); assertThat(files).hasSize(4).containsAll(expectedFiles); Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/expected/asciidoc/to_folder").toURI()); DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testToFolder.html"); }
@Test public void tesDoesNotContainUriScheme() throws IOException, URISyntaxException { //Given Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_should_not_contain_uri_scheme.yaml").toURI()); Path outputDirectory = Paths.get("build/test/asciidoc/generated"); FileUtils.deleteQuietly(outputDirectory.toFile()); //When Swagger2MarkupConverter.from(file).build() .toFolder(outputDirectory); //Then String[] files = outputDirectory.toFile().list(); assertThat(files).hasSize(4).containsAll(expectedFiles); assertThat(new String(Files.readAllBytes(outputDirectory.resolve("overview.adoc")))) .doesNotContain("=== URI scheme"); }
@Test public void testWithGeneratedExamples() throws IOException, URISyntaxException { //Given String swaggerJsonString = IOUtils.toString(getClass().getResourceAsStream("/json/swagger_examples.json")); Path outputDirectory = Paths.get("build/test/asciidoc/generated_examples"); FileUtils.deleteQuietly(outputDirectory.toFile()); //When Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() .withGeneratedExamples() .build(); Swagger2MarkupConverter.from(swaggerJsonString) .withConfig(config) .build() .toFolder(outputDirectory); //Then String[] files = outputDirectory.toFile().list(); assertThat(files).hasSize(4).containsAll(expectedFiles); Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/expected/asciidoc/generated_examples").toURI()); DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testWithGeneratedExamples.html"); }
@Test public void testWithMinMaxItems() throws IOException, URISyntaxException { //Given Path file = Paths.get(MarkdownConverterTest.class.getResource("/yaml/swagger_petstore_min_max_items.yaml").toURI()); Path outputDirectory = Paths.get("build/test/markdown/to_folder"); FileUtils.deleteQuietly(outputDirectory.toFile()); //When Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() .withMarkupLanguage(MarkupLanguage.MARKDOWN) .build(); Swagger2MarkupConverter.from(file) .withConfig(config) .build() .toFolder(outputDirectory); //Then String[] files = outputDirectory.toFile().list(); assertThat(files).hasSize(4).containsAll(expectedFiles); Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/expected/markdown/min_max_items").toURI()); DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "min_max_items.html"); }
@Test public void testWithGeneratedRecursiveExamples() throws IOException, URISyntaxException { // Given String swaggerJsonString = IOUtils.toString(getClass().getResourceAsStream("/json/swagger_recursion.json")); Path outputDirectory = Paths.get("build/test/asciidoc/generated_recursion_examples"); FileUtils.deleteQuietly(outputDirectory.toFile()); // When Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder().withoutInlineSchema().withGeneratedExamples().build(); Swagger2MarkupConverter.from(swaggerJsonString).withConfig(config).build().toFolder(outputDirectory); // Then String[] files = outputDirectory.toFile().list(); assertThat(files).hasSize(4).containsAll(expectedFiles); Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/expected/asciidoc/generated_recursion_examples").toURI()); DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testWithGeneratedRecursiveExamples.html"); }
@Test public void testWithPolymorphism() throws IOException, URISyntaxException { //Given Path file = Paths.get(AsciidocConverterTest.class.getResource("/json/swagger_polymorphism.json").toURI()); Path outputDirectory = Paths.get("build/test/asciidoc/polymorphism"); FileUtils.deleteQuietly(outputDirectory.toFile()); //When Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() .build(); Swagger2MarkupConverter.from(file) .withConfig(config) .build() .toFolder(outputDirectory); //Then String[] files = outputDirectory.toFile().list(); assertThat(files).hasSize(4).containsAll(expectedFiles); Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/expected/asciidoc/polymorphism").toURI()); DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testWithPolymorphism.html"); }
@Test public void testWithValidators() throws IOException, URISyntaxException { //Given Path file = Paths.get(AsciidocConverterTest.class.getResource("/json/swagger_validators.json").toURI()); Path outputDirectory = Paths.get("build/test/asciidoc/validators"); FileUtils.deleteQuietly(outputDirectory.toFile()); //When Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() .build(); Swagger2MarkupConverter.from(file) .withConfig(config) .build() .toFolder(outputDirectory); //Then String[] files = outputDirectory.toFile().list(); assertThat(files).hasSize(4).containsAll(expectedFiles); Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/expected/asciidoc/validators").toURI()); DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testWithValidators.html"); }
@Test public void testWithEmptyContactUsingJSON() throws IOException, URISyntaxException { //Given Path file = Paths.get(AsciidocConverterTest.class.getResource("/json/swagger_emptycontact.json").toURI()); Path outputDirectory = Paths.get("build/test/asciidoc/emptycontact"); FileUtils.deleteQuietly(outputDirectory.toFile()); //When Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() .build(); Swagger2MarkupConverter.from(file) .withConfig(config) .build() .toFolder(outputDirectory); //Then String[] files = outputDirectory.toFile().list(); assertThat(files).hasSize(4).containsAll(expectedFiles); Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/expected/asciidoc/emptycontact").toURI()); DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testWithEmptyContactUsingJSON.html"); }
@Test public void testWithFormat() throws IOException, URISyntaxException { //Given Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_format.yaml").toURI()); Path outputDirectory = Paths.get("build/test/asciidoc/format"); FileUtils.deleteQuietly(outputDirectory.toFile()); //When Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() .build(); Swagger2MarkupConverter.from(file) .withConfig(config) .build() .toFolder(outputDirectory); //Then String[] files = outputDirectory.toFile().list(); assertThat(files).hasSize(4).containsAll(expectedFiles); Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/expected/asciidoc/format").toURI()); DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testWithFormat.html"); }
@Test public void testMarkupRenderingInInstagram() throws IOException, URISyntaxException { //Given Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_instagram.yaml").toURI()); Path outputDirectory = Paths.get("build/test/asciidoc/instagram"); FileUtils.deleteQuietly(outputDirectory.toFile()); //When Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() .withTagOrdering(OrderBy.AS_IS) .build(); Swagger2MarkupConverter.from(file).withConfig(config).build() .toFolder(outputDirectory); //Then String[] files = outputDirectory.toFile().list(); assertThat(files).hasSize(4).containsAll(expectedFiles); Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/expected/asciidoc/instagram").toURI()); DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testMarkupRenderingInInstagram.html"); }
@Test public void testInterDocumentCrossReferences() throws IOException, URISyntaxException { //Given Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); Path outputDirectory = Paths.get("build/test/asciidoc/idxref"); FileUtils.deleteQuietly(outputDirectory.toFile()); //When Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() .withInterDocumentCrossReferences() .build(); Swagger2MarkupConverter.from(file).withConfig(config).build() .toFolder(outputDirectory); //Then String[] files = outputDirectory.toFile().list(); assertThat(files).hasSize(4).containsAll(expectedFiles); Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/expected/asciidoc/idxref").toURI()); DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testInterDocumentCrossReferences.html"); }
@Test public void testWithAsciidocContentInTables() throws URISyntaxException { //Given Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_petstore_with_adoc_content.yaml").toURI()); Path outputDirectory = Paths.get("build/test/asciidoc/generated"); FileUtils.deleteQuietly(outputDirectory.toFile()); //When Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() .withSwaggerMarkupLanguage(MarkupLanguage.ASCIIDOC) .build(); Swagger2MarkupConverter.from(file).withConfig(config).build() .toFolder(outputDirectory); //Then String[] files = outputDirectory.toFile().list(); assertThat(files).hasSize(4).containsAll(expectedFiles); }
@Test public void testWithBasePathPrefix() throws IOException, URISyntaxException { //Given Path file = Paths.get(AsciidocConverterTest.class.getResource("/json/swagger_examples.json").toURI()); Path outputDirectory = Paths.get("build/test/asciidoc/basepathprefix"); FileUtils.deleteQuietly(outputDirectory.toFile()); //When Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() .withBasePathPrefix() .withGeneratedExamples() .build(); Swagger2MarkupConverter.from(file).withConfig(config).build() .toFolder(outputDirectory); //Then String[] files = outputDirectory.toFile().list(); assertThat(files).hasSize(4).containsAll(expectedFiles); Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/expected/asciidoc/basepathprefix").toURI()); DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testWithBasePathPrefix.html"); }