From 640943d6333008d9c295a190665a628e34bab822 Mon Sep 17 00:00:00 2001 From: Radoslav Husar Date: Tue, 9 Sep 2025 16:43:46 +0200 Subject: [PATCH] WFLY-19229 QS: The OpenAPI BasicRuntimeIT is ineffective and passes even on non-OpenAPI compliant runtime Signed-off-by: Radoslav Husar --- microprofile-openapi/pom.xml | 5 -- .../openapi/OpenAPIContextIT.java | 55 +++++++++++++++++++ 2 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 microprofile-openapi/src/test/java/org/wildfly/quickstart/microprofile/openapi/OpenAPIContextIT.java diff --git a/microprofile-openapi/pom.xml b/microprofile-openapi/pom.xml index c44e12d0ee..8b538e771e 100644 --- a/microprofile-openapi/pom.xml +++ b/microprofile-openapi/pom.xml @@ -159,11 +159,6 @@ org.apache.maven.plugins maven-failsafe-plugin - - - **/BasicRuntimeIT - - diff --git a/microprofile-openapi/src/test/java/org/wildfly/quickstart/microprofile/openapi/OpenAPIContextIT.java b/microprofile-openapi/src/test/java/org/wildfly/quickstart/microprofile/openapi/OpenAPIContextIT.java new file mode 100644 index 0000000000..4bbe416cd5 --- /dev/null +++ b/microprofile-openapi/src/test/java/org/wildfly/quickstart/microprofile/openapi/OpenAPIContextIT.java @@ -0,0 +1,55 @@ +/* + * Copyright The WildFly Authors + * SPDX-License-Identifier: Apache-2.0 + */ +package org.wildfly.quickstart.microprofile.openapi; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.time.Duration; + +import org.junit.Test; + +/** + * Tests that the /openapi context is available. + * This test would thus correctly fail (404) if run against a server without an OpenAPI subsystem. + * + * @author Radoslav Husar + */ +public class OpenAPIContextIT { + + private static final String DEFAULT_SERVER_HOST = "http://localhost:8080"; + + @Test + public void testOpenAPIContextIsAvailable() throws IOException, InterruptedException, URISyntaxException { + String serverHost = System.getenv("SERVER_HOST"); + if (serverHost == null) { + serverHost = System.getProperty("server.host"); + } + if (serverHost == null) { + serverHost = DEFAULT_SERVER_HOST; + } + final HttpRequest request = HttpRequest.newBuilder() + .uri(new URI(serverHost + "/openapi")) + .GET() + .build(); + final HttpClient client = HttpClient.newBuilder() + .followRedirects(HttpClient.Redirect.ALWAYS) + .connectTimeout(Duration.ofMinutes(1)) + .build(); + final HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); + assertEquals("/openapi context is not available", 200, response.statusCode()); + + // First line are just dashes, so lets check the second line with OpenAPI version key for the prefix + String[] bodyLines = response.body().split("\n"); + assertTrue(bodyLines[1].startsWith("openapi:")); + } + +}