Skip to content

Commit

Permalink
Add coverage for HEAD request
Browse files Browse the repository at this point in the history
This is cover age for quarkusio/quarkus#43440

(cherry picked from commit 2ebfe00)
  • Loading branch information
jedla97 committed Nov 28, 2024
1 parent 4d0b2b9 commit ec79077
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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();
}
Original file line number Diff line number Diff line change
@@ -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";
}
}
Original file line number Diff line number Diff line change
@@ -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";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ec79077

Please sign in to comment.