|
| 1 | +package io.github.stavshamir.springwolf.example; |
| 2 | + |
| 3 | +import org.json.JSONException; |
| 4 | +import org.junit.jupiter.api.Test; |
| 5 | +import org.skyscreamer.jsonassert.JSONAssert; |
| 6 | +import org.skyscreamer.jsonassert.JSONCompareMode; |
| 7 | +import org.testcontainers.shaded.org.apache.commons.io.IOUtils; |
| 8 | + |
| 9 | +import java.io.IOException; |
| 10 | +import java.io.InputStream; |
| 11 | +import java.nio.charset.StandardCharsets; |
| 12 | + |
| 13 | +/** |
| 14 | + * This test is strongly coupled with the configuration of the springdoc openapi plugin in build.gradle |
| 15 | + * <p> |
| 16 | + * The gradle project is configured to run the generateOpenApiDocs task before the test task. |
| 17 | + * The generateOpenApiDocs task will generate the openapi-generated.json into the test-resources so that |
| 18 | + * this test can pick up the openapi-generated.json afterwards and compare it to the reference asyncapi.json |
| 19 | + */ |
| 20 | +public class OpenApiGeneratorTest { |
| 21 | + |
| 22 | + @Test |
| 23 | + public void asyncApiResourceArtifactTest() throws JSONException, IOException { |
| 24 | + |
| 25 | + InputStream expectedStream = this.getClass().getResourceAsStream("/asyncapi.json"); |
| 26 | + |
| 27 | + // When running with EmbeddedKafka, localhost is used as hostname |
| 28 | + String expectedWithoutServersKafkaUrlPatch = IOUtils.toString(expectedStream, StandardCharsets.UTF_8); |
| 29 | + String expected = expectedWithoutServersKafkaUrlPatch.replace("kafka:29092", "localhost:29092"); |
| 30 | + |
| 31 | + InputStream actualStream = this.getClass().getResourceAsStream("/openapi-generated.json"); |
| 32 | + String actual = IOUtils.toString(actualStream, StandardCharsets.UTF_8); |
| 33 | + |
| 34 | + JSONAssert.assertEquals(expected, actual, JSONCompareMode.STRICT_ORDER); |
| 35 | + } |
| 36 | +} |
0 commit comments