diff --git a/pom.xml b/pom.xml index db69e59..7eba937 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ UTF-8 quarkus-bom io.quarkus.platform - 3.17.4 + 3.20.0 true 3.5.0 1.6.3 @@ -82,7 +82,7 @@ io.quarkiverse.resteasy-problem quarkus-resteasy-problem - 3.15.0 + 3.21.0 io.quarkus @@ -113,7 +113,6 @@ archunit-junit5 ${archunit-junit5.version} - @@ -129,7 +128,6 @@ build generate-code generate-code-tests - native-image-agent diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index c14ce19..12ab4eb 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -6,6 +6,7 @@ quarkus.rest-client.extensions-api.verify-host=false # -------------------------- ## KAFKA Client configuration # -------------------------- + quarkus.kafka.devservices.topic-partitions.guitar-requests=1 mp.messaging.outgoing.guitar-requests-out.connector=smallrye-kafka mp.messaging.outgoing.guitar-requests-out.topic=guitar-requests diff --git a/src/main/resources/asyncapi/supplychain-asyncapi.yaml b/src/main/resources/asyncapi/supplychain-asyncapi.yaml new file mode 100644 index 0000000..bf21740 --- /dev/null +++ b/src/main/resources/asyncapi/supplychain-asyncapi.yaml @@ -0,0 +1,59 @@ +asyncapi: 3.0.0 +info: + title: Guitar Supply Chain API + version: 1.0.0 + description: This API is notified whenever the stock is too low + +servers: + dev: + host: kafka://localhost:8092 + description: Kafka broker running in a Quarkus Dev Service + protocol: kafka + +operations: + onGuitarRequestOut: + action: send + channel: + $ref: '#/channels/guitar-requests-out' + onGuitarRequestIn: + action: receive + channel: + $ref: '#/channels/guitar-requests-in' + +channels: + guitar-requests-out: + description: This channel is used to broadcast guitars supply requests + address: guitar-requests + messages: + guitarRequest: + $ref: '#/components/messages/guitarRequest' + guitar-requests-in: + description: This channel is used to fetch guitar requests + address: guitar-requests + messages: + guitarRequest: + $ref: '#/components/messages/guitarRequest' +components: + messages: + guitarRequest: + name: guitarRequest + title: Guitar Request + contentType: application/json + payload: + $id: "GuitarRequest" + $ref: '#/components/schemas/guitarRequest' + schemas: + guitarRequest: + additionalProperties: false + type: object + properties: + requestId: + type: string + format: uuid + description: This property describes the UUID of the request + guitarName: + type: string + description: This property describes the name of the guitar + quantity: + type: integer + description: The quantity to order and supply diff --git a/src/main/resources/asyncapi/supplychain-with-examples-asyncapi.yaml b/src/main/resources/asyncapi/supplychain-with-examples-asyncapi.yaml new file mode 100644 index 0000000..2a1130e --- /dev/null +++ b/src/main/resources/asyncapi/supplychain-with-examples-asyncapi.yaml @@ -0,0 +1,90 @@ +asyncapi: 3.0.0 +info: + title: Guitar Supply Chain API + version: 1.0.0 + description: This API is notified whenever the stock is too low + +defaultContentType: application/json +channels: + guitar-requests-out: + address: guitar-requests + description: Requests + messages: + guitarRequest.message: + description: Event to ask a guitar + payload: + type: object + additionalProperties: false + properties: + requestId: + type: string + format: uuid + guitarName: + type: string + quantity: + type: integer + examples: + - name: "Gibson ES 335" + summary: "Example for Gibson ES 335" + payload: + requestId: ba4bf043-ee08-47c7-8b4f-75427d7213bf + guitarName: "Gibson ES 335" + quantity: 10 + - name: "Fender Stratocaster" + summary: "Example for Fender Stratocaster" + payload: + requestId: ba4bf043-ee08-47c7-8b4f-75427d7213be + guitarName: "Fender Stratocaster" + quantity: 5 + guitar-requests-in: + address: guitar-requests + description: Requests + messages: + guitarRequest.message: + description: Event to ask a guitar + payload: + type: object + additionalProperties: false + properties: + requestId: + type: string + format: uuid + guitarName: + type: string + quantity: + type: integer + examples: + - name: "Gibson ES 335" + summary: "Example for Gibson ES 335" + payload: + requestId: ba4bf043-ee08-47c7-8b4f-75427d7213bf + guitarName: "Gibson ES 335" + quantity: 10 + - name: "Fender Stratocaster" + summary: "Example for Fender Stratocaster" + payload: + requestId: ba4bf043-ee08-47c7-8b4f-75427d7213be + guitarName: "Fender Stratocaster" + quantity: 5 +operations: + onGuitarRequestOut: + action: send + channel: + $ref: '#/channels/guitar-requests-out' + summary: Send command + messages: + - $ref: '#/channels/guitar-requests-out/messages/guitarRequest.message' + onGuitarRequestin: + action: receive + channel: + $ref: '#/channels/guitar-requests-in' + summary: Fetches command + messages: + - $ref: '#/channels/guitar-requests-in/messages/guitarRequest.message' + + +servers: + dev: + host: kafka://localhost:8092 + description: Kafka broker running in a Quarkus Dev Service + protocol: kafka diff --git a/src/test/java/info/touret/guitarheaven/test/application/APIContractTest.java b/src/test/java/info/touret/guitarheaven/test/application/APIContractTest.java new file mode 100644 index 0000000..86a2785 --- /dev/null +++ b/src/test/java/info/touret/guitarheaven/test/application/APIContractTest.java @@ -0,0 +1,41 @@ +package info.touret.guitarheaven.test.application; + +import com.fasterxml.jackson.databind.ObjectMapper; +import io.github.microcks.testcontainers.MicrocksContainer; +import io.github.microcks.testcontainers.model.TestRequest; +import io.github.microcks.testcontainers.model.TestResult; +import io.github.microcks.testcontainers.model.TestRunnerType; +import io.quarkus.test.junit.QuarkusTest; +import jakarta.inject.Inject; +import org.eclipse.microprofile.config.inject.ConfigProperty; +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +@QuarkusTest +public class APIContractTest { + private final static Logger LOGGER = LoggerFactory.getLogger(APIContractTest.class); + + @ConfigProperty(name = "quarkus.http.test-port") + int quarkusHttpPort; + + @ConfigProperty(name = "quarkus.microcks.default.http") + String microcksContainerUrl; + + @Inject + ObjectMapper mapper; + + @Test + public void testOpenAPIContract() throws Exception { + TestRequest testRequest = new TestRequest.Builder() + .serviceId("Guitar Heaven API with Examples:1.0.1") + .runnerType(TestRunnerType.OPEN_API_SCHEMA.name()) + .testEndpoint("http://host.testcontainers.internal:" + quarkusHttpPort) + .build(); + TestResult testResult = MicrocksContainer.testEndpoint(microcksContainerUrl, testRequest); + LOGGER.error(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(testResult)); + assertTrue(testResult.isSuccess()); + } +}