From d0f8419ad5f688e409071183c7e1822f42762810 Mon Sep 17 00:00:00 2001 From: Timon Back Date: Fri, 6 Sep 2024 18:54:00 +0200 Subject: [PATCH] docs: add unit test --- docs/faq.md | 34 ++++++++++++++++++++++++++++++ src/components/HomepageFeatures.js | 27 ++++++++++++++++++++---- 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/docs/faq.md b/docs/faq.md index 83d801a..b2644a4 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -20,6 +20,40 @@ Either create a custom spring controller to serve the file or [serve static reso Note: `springwolf-ui` doesn't support the full AsyncAPI spec. +### Unit test verification + +With the AsyncApi artifact (i.e. at `src/test/resources/asyncapi.json) checked into the repository, +a unit test can verify that the current code still matches the expected AsyncApi specification. +Additionally, a diff reveals (un)expected changes. + +Example unit test: +```java +@SpringBootTest( + classes = {SpringwolfKafkaExampleApplication.class}, + webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +class ApiIntegrationTest { + + @Autowired + private TestRestTemplate restTemplate; + + @Test + void asyncApiResourceArtifactTest() throws IOException { + String url = "/springwolf/docs"; + String actual = restTemplate.getForObject(url, String.class); + + // writing the actual file can be useful for debugging (remember: gitignore) + Files.writeString(Path.of("src", "test", "resources", "asyncapi.actual.json"), actual); + + InputStream s = this.getClass().getResourceAsStream("/asyncapi.json"); + String expected = new String(s.readAllBytes(), StandardCharsets.UTF_8).trim(); + + assertEquals(expected, actual); + } +} +``` + +For a full example, check the [springwolf-kafka-example ApiIntegrationTest](https://github.com/springwolf/springwolf-core/blob/master/springwolf-examples/springwolf-kafka-example/src/test/java/io/github/springwolf/examples/kafka/ApiIntegrationTest.java) + ## Troubleshooting ### Show `debug` output in the logs diff --git a/src/components/HomepageFeatures.js b/src/components/HomepageFeatures.js index 9bcd912..0ab72c0 100644 --- a/src/components/HomepageFeatures.js +++ b/src/components/HomepageFeatures.js @@ -8,7 +8,7 @@ const FeatureList = [ title: 'Effortless API documentation', description: ( <> - Springwolf uses metadata already provided in the code + Springwolf uses metadata already provided in the code to automatically create documentation. ), @@ -26,7 +26,8 @@ const FeatureList = [ title: 'Powered by AsyncAPI v3', description: ( <> - The generated documentation is compliant with the AsyncAPI specification. + The generated documentation is compliant with the + AsyncAPI specification. ), }, @@ -34,7 +35,8 @@ const FeatureList = [ title: 'Optional web-ui', description: ( <> - Single dependency ui for API testing including event publishing. + Single dependency for API testing including event publishing + (demo). ), }, @@ -50,7 +52,24 @@ const FeatureList = [ title: 'Integrate', description: ( <> - Generate documentation in your CI/CD pipeline and publish to tools like Backstage. + Generate documentation in your CI/CD pipeline and publish to tools like + Backstage. + + ), + }, + { + title: 'Verify', + description: ( + <> + Use an unit test to check for (un)expected changes. + + ), + }, + { + title: 'Participate', + description: ( + <> + Something missing? Features requests and contributions are welcome. ), },