diff --git a/http/http-advanced-reactive/src/main/java/io/quarkus/ts/http/advanced/reactive/GreetingInterface.java b/http/http-advanced-reactive/src/main/java/io/quarkus/ts/http/advanced/reactive/GreetingInterface.java new file mode 100644 index 000000000..4ededef76 --- /dev/null +++ b/http/http-advanced-reactive/src/main/java/io/quarkus/ts/http/advanced/reactive/GreetingInterface.java @@ -0,0 +1,11 @@ +package io.quarkus.ts.http.advanced.reactive; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; + +public interface GreetingInterface { + + @GET + @Path("/interface-greeting") + String interfaceGreeting(); +} diff --git a/http/http-advanced-reactive/src/main/java/io/quarkus/ts/http/advanced/reactive/GreetingOptionAndHeadResource.java b/http/http-advanced-reactive/src/main/java/io/quarkus/ts/http/advanced/reactive/GreetingOptionAndHeadResource.java new file mode 100644 index 000000000..efaf3ed40 --- /dev/null +++ b/http/http-advanced-reactive/src/main/java/io/quarkus/ts/http/advanced/reactive/GreetingOptionAndHeadResource.java @@ -0,0 +1,20 @@ +package io.quarkus.ts.http.advanced.reactive; + +import jakarta.enterprise.inject.spi.CDI; +import jakarta.ws.rs.Path; + +@Path("/greeting") +public class GreetingOptionAndHeadResource implements GreetingInterface { + + @Path("/cdi-sub-resource") + public GreetingSubResources helloFromSubResource() { + return CDI.current() + .select(GreetingSubResources.class) + .get(); + } + + @Override + public String interfaceGreeting() { + return "Greeting from interface"; + } +} diff --git a/http/http-advanced-reactive/src/main/java/io/quarkus/ts/http/advanced/reactive/GreetingSubResources.java b/http/http-advanced-reactive/src/main/java/io/quarkus/ts/http/advanced/reactive/GreetingSubResources.java new file mode 100644 index 000000000..3b2f4c286 --- /dev/null +++ b/http/http-advanced-reactive/src/main/java/io/quarkus/ts/http/advanced/reactive/GreetingSubResources.java @@ -0,0 +1,20 @@ +package io.quarkus.ts.http.advanced.reactive; + +import jakarta.enterprise.context.RequestScoped; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.POST; + +@RequestScoped +public class GreetingSubResources { + + @GET + public String get() { + return "Greeting from sub-resource using GET"; + } + + @POST + public String post() { + return "Greeting from sub-resource using POST"; + } + +} diff --git a/http/http-advanced-reactive/src/test/java/io/quarkus/ts/http/advanced/reactive/BaseHttpAdvancedReactiveIT.java b/http/http-advanced-reactive/src/test/java/io/quarkus/ts/http/advanced/reactive/BaseHttpAdvancedReactiveIT.java index 8cb618574..efb108a15 100644 --- a/http/http-advanced-reactive/src/test/java/io/quarkus/ts/http/advanced/reactive/BaseHttpAdvancedReactiveIT.java +++ b/http/http-advanced-reactive/src/test/java/io/quarkus/ts/http/advanced/reactive/BaseHttpAdvancedReactiveIT.java @@ -25,6 +25,8 @@ import static org.apache.http.HttpStatus.SC_NOT_FOUND; import static org.apache.http.HttpStatus.SC_OK; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.allOf; +import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.in; @@ -102,6 +104,64 @@ public void abstractResourceWithPath() { .body(is("Hello from Quarkus REST")); } + @Test + @DisplayName("Test Quarkus REST using CDI getting the sub-resource") + void cdiSubResourceGetRequest() { + getApp().given() + .when() + .get(GREETING_ENDPOINT + "/cdi-sub-resource") + .then() + .statusCode(SC_OK) + .body(is("Greeting from sub-resource using GET")); + } + + @Test + @DisplayName("Test Quarkus REST using CDI getting the sub-resource") + void cdiSubResourcePostRequest() { + getApp().given() + .when() + .post(GREETING_ENDPOINT + "/cdi-sub-resource") + .then() + .statusCode(SC_OK) + .body(is("Greeting from sub-resource using POST")); + } + + @Test + @DisplayName("Test Quarkus REST interface resource with @Path") + void interfaceResourceWithPath() { + getApp().given() + .when() + .get(GREETING_ENDPOINT + "/interface-greeting") + .then() + .statusCode(SC_OK) + .body(is("Greeting from interface")); + } + + @Test + @Tag("https://github.com/quarkusio/quarkus/issues/43422") + @DisplayName("Test Quarkus REST abstract resource with @Path using OPTION and HEAD request") + @DisabledOnNative(reason = "https://github.com/quarkusio/quarkus/issues/42976") + void optionAndHeadRequestUsingAbstractResourceWithPath() { + testOptionRequest(GREETING_ENDPOINT); + testHeadRequest(GREETING_ENDPOINT); + } + + @Test + @Tag("https://github.com/quarkusio/quarkus/issues/43422") + @DisplayName("Test Quarkus REST interface resource with @Path using OPTION and HEAD request") + void optionAndHeadRequestUsingInterfaceResourceWithPath() { + testOptionRequest(GREETING_ENDPOINT + "/interface-greeting"); + testHeadRequest(GREETING_ENDPOINT + "/interface-greeting"); + } + + @Test + @Tag("https://github.com/quarkusio/quarkus/issues/43422") + @DisplayName("Test Quarkus REST using CDI getting the sub-resource for OPTION and HEAD request") + void cdiSubResourceOptionAndHeadRequest() { + testOptionRequest(GREETING_ENDPOINT + "/cdi-sub-resource"); + testHeadRequest(GREETING_ENDPOINT + "/cdi-sub-resource"); + } + @Test @DisplayName("GRPC Server test") public void testGrpc() { @@ -354,6 +414,24 @@ private void testResponseContentType(String acceptedContentType, String expected .then().header(CONTENT_TYPE, expectedContentType); } + private void testOptionRequest(String path) { + getApp().given() + .when() + .options(path) + .then() + .statusCode(SC_OK) + .header(HttpHeaders.ALLOW, allOf(containsString("HEAD"), + containsString("OPTIONS"), containsString("GET"))); + } + + private void testHeadRequest(String path) { + getApp().given() + .when() + .head(path) + .then() + .statusCode(SC_OK); + } + private ValidatableResponse req99BottlesOfBeer(int bottleNumber, int httpStatusCode) { return getApp().given() .get(ROOT_PATH + NinetyNineBottlesOfBeerResource.PATH + "/" + bottleNumber)