-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example configuration for springdoc-openapi-gradle-plugin to spri…
…ngwolf-kafka-example, use springdoc-openapi-gradle-plugin to generate the api spec before test execution and added a test to ensure that the plugin still works for springwolf
- Loading branch information
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...a-example/src/test/java/io/github/stavshamir/springwolf/example/OpenApiGeneratorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package io.github.stavshamir.springwolf.example; | ||
|
||
import org.json.JSONException; | ||
import org.junit.jupiter.api.Test; | ||
import org.skyscreamer.jsonassert.JSONAssert; | ||
import org.skyscreamer.jsonassert.JSONCompareMode; | ||
import org.testcontainers.shaded.org.apache.commons.io.IOUtils; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
/** | ||
* This test is strongly coupled with the configuration of the springdoc openapi plugin in build.gradle | ||
* <p> | ||
* The gradle project is configured tp run the generateOpenApiDocs task before the test task. | ||
* The generateOpenApiDocs task will then generate the openapi-generated.json into the test-resources so that | ||
* this test can pick up the openapi-generated.json and compare it to the reference asyncapi.json | ||
*/ | ||
public class OpenApiGeneratorTest { | ||
|
||
@Test | ||
public void asyncApiResourceArtifactTest() throws JSONException, IOException { | ||
|
||
InputStream expectedStream = this.getClass().getResourceAsStream("/asyncapi.json"); | ||
|
||
// When running with EmbeddedKafka, localhost is used as hostname | ||
String expectedWithoutServersKafkaUrlPatch = IOUtils.toString(expectedStream, StandardCharsets.UTF_8); | ||
String expected = expectedWithoutServersKafkaUrlPatch.replace("kafka:29092", "localhost:29092"); | ||
|
||
InputStream actualStream = this.getClass().getResourceAsStream("/openapi-generated.json"); | ||
String actual = IOUtils.toString(actualStream, StandardCharsets.UTF_8); | ||
|
||
JSONAssert.assertEquals(expected, actual, JSONCompareMode.STRICT_ORDER); | ||
} | ||
} |