Skip to content

Commit

Permalink
Add coverage for HTTP Content-Type response header
Browse files Browse the repository at this point in the history
Verifies that the RESTEasy Classic / RESTEasy Reactive handles the
`Content-Type` response header correctly and always sends properly
formatted string.
  • Loading branch information
jsmrcka authored and fedinskiy committed Jan 6, 2022
1 parent cc4f2f3 commit a30d0a6
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -18,4 +19,13 @@ public class HelloResource {
public Uni<Hello> 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<Hello> getJson() {
return Uni.createFrom().item(new Hello("hello"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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));
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -16,4 +17,12 @@ public class HelloResource {
public Hello get(@QueryParam("name") @DefaultValue("World") String name) {
return new Hello(String.format(TEMPLATE, name));
}
}

@GET
@Path("/json")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Hello getJson() {
return new Hello("hello");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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));
}
}

0 comments on commit a30d0a6

Please sign in to comment.