From 19ce4e08829cdd7dd142a6ed9cdc2497306f619c Mon Sep 17 00:00:00 2001 From: Pablo Gonzalez Granados Date: Wed, 2 Jun 2021 17:39:48 +0200 Subject: [PATCH] Legacy non-application endpoint redirection use case (#216) quarkus.http.redirect-to-non-application-root-path deprecated property was removed It is possible to achieve the previous behavior by explicitly setting endpoints to be absolute instead of relative. For instance, the Health endpoint can be forced to be available at /health instead of /q/health by setting quarkus.smallrye-health.root-path=/health --- .../src/main/resources/application.properties | 1 - .../endpoint/CommonNonAppEndpoint.java | 2 +- .../LegacyNonApplicationEndpointIT.java | 10 +++++++ .../LegacyNonApplicationEndpointTest.java | 29 +++++++++++++++++++ .../NonAppEndpointNonRootPathTest.java | 1 - .../endpoint/NonAppEndpointTest.java | 1 - ...NonAppEndpointTestNonBaseRootPathTest.java | 1 - .../RelativePathNonAppEndpointTest.java | 1 - 8 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 020-quarkus-http-non-application-endpoints/src/test/java/io/quarkus/qe/non_application/endpoint/LegacyNonApplicationEndpointIT.java create mode 100644 020-quarkus-http-non-application-endpoints/src/test/java/io/quarkus/qe/non_application/endpoint/LegacyNonApplicationEndpointTest.java diff --git a/020-quarkus-http-non-application-endpoints/src/main/resources/application.properties b/020-quarkus-http-non-application-endpoints/src/main/resources/application.properties index 03bf2251..c46ab04f 100644 --- a/020-quarkus-http-non-application-endpoints/src/main/resources/application.properties +++ b/020-quarkus-http-non-application-endpoints/src/main/resources/application.properties @@ -2,7 +2,6 @@ quarkus.container-image.name=demo quarkus.application.name=non-application endpoints quarkus.http.root-path=/api quarkus.http.non-application-root-path=/q -quarkus.http.redirect-to-non-application-root-path=true quarkus.swagger-ui.always-include=true quarkus.health.openapi.included=true \ No newline at end of file diff --git a/020-quarkus-http-non-application-endpoints/src/test/java/io/quarkus/qe/non_application/endpoint/CommonNonAppEndpoint.java b/020-quarkus-http-non-application-endpoints/src/test/java/io/quarkus/qe/non_application/endpoint/CommonNonAppEndpoint.java index e83e47e2..d214bb85 100644 --- a/020-quarkus-http-non-application-endpoints/src/test/java/io/quarkus/qe/non_application/endpoint/CommonNonAppEndpoint.java +++ b/020-quarkus-http-non-application-endpoints/src/test/java/io/quarkus/qe/non_application/endpoint/CommonNonAppEndpoint.java @@ -15,7 +15,7 @@ public abstract class CommonNonAppEndpoint { protected static final String ROOT_BASE_PATH = "/api/"; protected static final String QUARKUS_PROFILE = "quarkus.profile"; protected static final String NATIVE = "native"; - protected static final boolean IS_NATIVE = System.getProperty(QUARKUS_PROFILE, "").equals(NATIVE); + public static final boolean IS_NATIVE = System.getProperty(QUARKUS_PROFILE, "").equals(NATIVE); private RequestSpecification request; private RequestSpecBuilder spec; diff --git a/020-quarkus-http-non-application-endpoints/src/test/java/io/quarkus/qe/non_application/endpoint/LegacyNonApplicationEndpointIT.java b/020-quarkus-http-non-application-endpoints/src/test/java/io/quarkus/qe/non_application/endpoint/LegacyNonApplicationEndpointIT.java new file mode 100644 index 00000000..5bd921b8 --- /dev/null +++ b/020-quarkus-http-non-application-endpoints/src/test/java/io/quarkus/qe/non_application/endpoint/LegacyNonApplicationEndpointIT.java @@ -0,0 +1,10 @@ +package io.quarkus.qe.non_application.endpoint; + +import static io.quarkus.qe.non_application.endpoint.CommonNonAppEndpoint.NATIVE; +import static io.quarkus.qe.non_application.endpoint.CommonNonAppEndpoint.QUARKUS_PROFILE; + +import org.junit.jupiter.api.condition.EnabledIfSystemProperty; + +@EnabledIfSystemProperty(named = QUARKUS_PROFILE, matches = NATIVE) +public class LegacyNonApplicationEndpointIT extends LegacyNonApplicationEndpointTest { +} diff --git a/020-quarkus-http-non-application-endpoints/src/test/java/io/quarkus/qe/non_application/endpoint/LegacyNonApplicationEndpointTest.java b/020-quarkus-http-non-application-endpoints/src/test/java/io/quarkus/qe/non_application/endpoint/LegacyNonApplicationEndpointTest.java new file mode 100644 index 00000000..a1dd49d8 --- /dev/null +++ b/020-quarkus-http-non-application-endpoints/src/test/java/io/quarkus/qe/non_application/endpoint/LegacyNonApplicationEndpointTest.java @@ -0,0 +1,29 @@ +package io.quarkus.qe.non_application.endpoint; + +import static io.quarkus.qe.non_application.endpoint.CommonNonAppEndpoint.IS_NATIVE; +import static io.restassured.RestAssured.when; + +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.qe.http.non_application.endpoint.HelloResource; +import io.quarkus.test.QuarkusProdModeTest; + +public class LegacyNonApplicationEndpointTest { + + @RegisterExtension + static final QuarkusProdModeTest nonApplicationEndpointScenario = new QuarkusProdModeTest() + .setBuildNative(IS_NATIVE) + .overrideConfigKey("quarkus.http.root-path", "/api") + .overrideConfigKey("quarkus.smallrye-health.root-path", "/health") + .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) + .addClass(HelloResource.class)) + .setRun(true); + + @Test + protected void nonAppEndpointScenario() { + when().get("/health").then().statusCode(200); + } +} diff --git a/020-quarkus-http-non-application-endpoints/src/test/java/io/quarkus/qe/non_application/endpoint/NonAppEndpointNonRootPathTest.java b/020-quarkus-http-non-application-endpoints/src/test/java/io/quarkus/qe/non_application/endpoint/NonAppEndpointNonRootPathTest.java index 6425adea..8cb6b22a 100644 --- a/020-quarkus-http-non-application-endpoints/src/test/java/io/quarkus/qe/non_application/endpoint/NonAppEndpointNonRootPathTest.java +++ b/020-quarkus-http-non-application-endpoints/src/test/java/io/quarkus/qe/non_application/endpoint/NonAppEndpointNonRootPathTest.java @@ -17,7 +17,6 @@ public class NonAppEndpointNonRootPathTest extends CommonNonAppEndpoint { .setBuildNative(IS_NATIVE) .overrideConfigKey("quarkus.http.root-path", "/api") .overrideConfigKey("quarkus.http.non-application-root-path", BASE_PATH) - .overrideConfigKey("quarkus.http.redirect-to-non-application-root-path", "false") .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) .addClass(HelloResource.class)) .setRun(true); diff --git a/020-quarkus-http-non-application-endpoints/src/test/java/io/quarkus/qe/non_application/endpoint/NonAppEndpointTest.java b/020-quarkus-http-non-application-endpoints/src/test/java/io/quarkus/qe/non_application/endpoint/NonAppEndpointTest.java index 671a71df..ba5a4ca0 100644 --- a/020-quarkus-http-non-application-endpoints/src/test/java/io/quarkus/qe/non_application/endpoint/NonAppEndpointTest.java +++ b/020-quarkus-http-non-application-endpoints/src/test/java/io/quarkus/qe/non_application/endpoint/NonAppEndpointTest.java @@ -18,7 +18,6 @@ public class NonAppEndpointTest extends CommonNonAppEndpoint { .setBuildNative(IS_NATIVE) .overrideConfigKey("quarkus.http.root-path", "/api") .overrideConfigKey("quarkus.http.non-application-root-path", BASE_PATH) - .overrideConfigKey("quarkus.http.redirect-to-non-application-root-path", "false") .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) .addClass(HelloResource.class)) .setRun(true); diff --git a/020-quarkus-http-non-application-endpoints/src/test/java/io/quarkus/qe/non_application/endpoint/NonAppEndpointTestNonBaseRootPathTest.java b/020-quarkus-http-non-application-endpoints/src/test/java/io/quarkus/qe/non_application/endpoint/NonAppEndpointTestNonBaseRootPathTest.java index 1385fb59..227fecc4 100644 --- a/020-quarkus-http-non-application-endpoints/src/test/java/io/quarkus/qe/non_application/endpoint/NonAppEndpointTestNonBaseRootPathTest.java +++ b/020-quarkus-http-non-application-endpoints/src/test/java/io/quarkus/qe/non_application/endpoint/NonAppEndpointTestNonBaseRootPathTest.java @@ -18,7 +18,6 @@ public class NonAppEndpointTestNonBaseRootPathTest extends CommonNonAppEndpoint .setBuildNative(IS_NATIVE) .overrideConfigKey("quarkus.http.root-path", "/") .overrideConfigKey("quarkus.http.non-application-root-path", BASE_PATH) - .overrideConfigKey("quarkus.http.redirect-to-non-application-root-path", "false") .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) .addClasses(HelloResource.class)) .setRun(true); diff --git a/020-quarkus-http-non-application-endpoints/src/test/java/io/quarkus/qe/non_application/endpoint/RelativePathNonAppEndpointTest.java b/020-quarkus-http-non-application-endpoints/src/test/java/io/quarkus/qe/non_application/endpoint/RelativePathNonAppEndpointTest.java index c8d248a1..656a3b8d 100644 --- a/020-quarkus-http-non-application-endpoints/src/test/java/io/quarkus/qe/non_application/endpoint/RelativePathNonAppEndpointTest.java +++ b/020-quarkus-http-non-application-endpoints/src/test/java/io/quarkus/qe/non_application/endpoint/RelativePathNonAppEndpointTest.java @@ -18,7 +18,6 @@ public class RelativePathNonAppEndpointTest extends CommonNonAppEndpoint { .setBuildNative(IS_NATIVE) .overrideConfigKey("quarkus.http.root-path", "/api") .overrideConfigKey("quarkus.http.non-application-root-path", BASE_PATH) - .overrideConfigKey("quarkus.http.redirect-to-non-application-root-path", "false") .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) .addClass(HelloResource.class)) .setRun(true);