From a30d0a6a99c55957813b6b59088d109dcabbb6b5 Mon Sep 17 00:00:00 2001 From: Josef Smrcka Date: Tue, 4 Jan 2022 14:14:44 +0100 Subject: [PATCH] Add coverage for HTTP `Content-Type` response header Verifies that the RESTEasy Classic / RESTEasy Reactive handles the `Content-Type` response header correctly and always sends properly formatted string. --- .../http/minimum/reactive/HelloResource.java | 10 +++++++++ .../minimum/reactive/HttpCustomHeadersIT.java | 22 ++++++++++++++++++- .../ts/http/minimum/HelloResource.java | 11 +++++++++- .../ts/http/minimum/HttpCustomHeadersIT.java | 22 ++++++++++++++++++- 4 files changed, 62 insertions(+), 3 deletions(-) diff --git a/http/http-minimum-reactive/src/main/java/io/quarkus/ts/http/minimum/reactive/HelloResource.java b/http/http-minimum-reactive/src/main/java/io/quarkus/ts/http/minimum/reactive/HelloResource.java index 5cb5f8407..0bc43d480 100644 --- a/http/http-minimum-reactive/src/main/java/io/quarkus/ts/http/minimum/reactive/HelloResource.java +++ b/http/http-minimum-reactive/src/main/java/io/quarkus/ts/http/minimum/reactive/HelloResource.java @@ -1,5 +1,6 @@ package io.quarkus.ts.http.minimum.reactive; +import javax.ws.rs.Consumes; import javax.ws.rs.DefaultValue; import javax.ws.rs.GET; import javax.ws.rs.Path; @@ -18,4 +19,13 @@ public class HelloResource { public Uni get(@QueryParam("name") @DefaultValue("World") String name) { return Uni.createFrom().item(new Hello(String.format(TEMPLATE, name))); } + + @GET + @Path("/json") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public Uni getJson() { + return Uni.createFrom().item(new Hello("hello")); + } + } diff --git a/http/http-minimum-reactive/src/test/java/io/quarkus/ts/http/minimum/reactive/HttpCustomHeadersIT.java b/http/http-minimum-reactive/src/test/java/io/quarkus/ts/http/minimum/reactive/HttpCustomHeadersIT.java index 4a84fd457..b295b79ff 100644 --- a/http/http-minimum-reactive/src/test/java/io/quarkus/ts/http/minimum/reactive/HttpCustomHeadersIT.java +++ b/http/http-minimum-reactive/src/test/java/io/quarkus/ts/http/minimum/reactive/HttpCustomHeadersIT.java @@ -3,16 +3,18 @@ import static io.restassured.RestAssured.given; import static org.hamcrest.CoreMatchers.is; +import javax.ws.rs.core.MediaType; + import org.apache.http.HttpStatus; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import io.quarkus.test.scenarios.QuarkusScenario; -@Tag("QUARKUS-1574") @QuarkusScenario public class HttpCustomHeadersIT { + @Tag("QUARKUS-1574") @Test public void caseInsensitiveAcceptHeader() { given() @@ -22,4 +24,22 @@ public void caseInsensitiveAcceptHeader() { .statusCode(HttpStatus.SC_OK) .body("content", is("Hello, World!")); } + + @Tag("QUARKUS-1557") + @Test + public void correctContentType() { + getContentType("ApPlIcAtIoN/JsOn"); + getContentType("application/json"); + getContentType("APPLICATION/JSON"); + } + + public void getContentType(String contentType) { + given() + .contentType(contentType) + .get("/api/hello/json") + .then() + .statusCode(HttpStatus.SC_OK) + .body("content", is("hello")) + .contentType(is(MediaType.APPLICATION_JSON)); + } } diff --git a/http/http-minimum/src/main/java/io/quarkus/ts/http/minimum/HelloResource.java b/http/http-minimum/src/main/java/io/quarkus/ts/http/minimum/HelloResource.java index 33c0d1c9d..b52ff6426 100644 --- a/http/http-minimum/src/main/java/io/quarkus/ts/http/minimum/HelloResource.java +++ b/http/http-minimum/src/main/java/io/quarkus/ts/http/minimum/HelloResource.java @@ -1,5 +1,6 @@ package io.quarkus.ts.http.minimum; +import javax.ws.rs.Consumes; import javax.ws.rs.DefaultValue; import javax.ws.rs.GET; import javax.ws.rs.Path; @@ -16,4 +17,12 @@ public class HelloResource { public Hello get(@QueryParam("name") @DefaultValue("World") String name) { return new Hello(String.format(TEMPLATE, name)); } -} \ No newline at end of file + + @GET + @Path("/json") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public Hello getJson() { + return new Hello("hello"); + } +} diff --git a/http/http-minimum/src/test/java/io/quarkus/ts/http/minimum/HttpCustomHeadersIT.java b/http/http-minimum/src/test/java/io/quarkus/ts/http/minimum/HttpCustomHeadersIT.java index 6feb1c4f4..c931128f3 100644 --- a/http/http-minimum/src/test/java/io/quarkus/ts/http/minimum/HttpCustomHeadersIT.java +++ b/http/http-minimum/src/test/java/io/quarkus/ts/http/minimum/HttpCustomHeadersIT.java @@ -3,16 +3,18 @@ import static io.restassured.RestAssured.given; import static org.hamcrest.CoreMatchers.is; +import javax.ws.rs.core.MediaType; + import org.apache.http.HttpStatus; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import io.quarkus.test.scenarios.QuarkusScenario; -@Tag("QUARKUS-1574") @QuarkusScenario public class HttpCustomHeadersIT { + @Tag("QUARKUS-1574") @Test public void caseInsensitiveAcceptHeader() { given() @@ -22,4 +24,22 @@ public void caseInsensitiveAcceptHeader() { .statusCode(HttpStatus.SC_OK) .body("content", is("Hello, World!")); } + + @Tag("QUARKUS-1557") + @Test + public void correctContentType() { + getContentType("ApPlIcAtIoN/JsOn"); + getContentType("application/json"); + getContentType("APPLICATION/JSON"); + } + + public void getContentType(String contentType) { + given() + .contentType(contentType) + .get("/api/hello/json") + .then() + .statusCode(HttpStatus.SC_OK) + .body("content", is("hello")) + .contentType(is(MediaType.APPLICATION_JSON)); + } }