Skip to content

Commit

Permalink
Merge pull request #1568 from rsvoboda/record-response
Browse files Browse the repository at this point in the history
Test coverage for records returned in response from REST endpoint
  • Loading branch information
michalvavrik authored Dec 11, 2023
2 parents 352ea0e + f9b05cd commit 37b1f39
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,21 @@ public Response doSomething(@PathParam("something-with-dash") String param) {
public Response hello() {
return Response.ok("hello").header("Transfer-Encoding", "chunked").build();
}

public record Data(String data) {
}

@GET
@Path("short-record-response")
@Produces(MediaType.APPLICATION_JSON)
public Response shortRecordInResponseClass() {
return Response.ok().entity(new Data("ok")).build();
}

@GET
@Path("short-record")
@Produces(MediaType.APPLICATION_JSON)
public Data shortRecordReturnedDirectly() {
return new Data("ok");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import static org.hamcrest.Matchers.nullValue;
import static org.junit.jupiter.api.Assertions.assertEquals;

import jakarta.ws.rs.core.MediaType;

import org.apache.http.HttpStatus;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -60,6 +62,22 @@ public void transferEncodingAndContentLengthHeadersAreNotAllowedTogether() {
.headers("Content-Length", is(notNullValue()));
}

@Test
public void shortRecordInResponseClass() {
givenSpec().get("/api/hello/short-record-response").then()
.statusCode(HttpStatus.SC_OK)
.contentType(MediaType.APPLICATION_JSON)
.body("data", is("ok"));
}

@Test
public void shortRecordReturnedDirectly() {
givenSpec().get("/api/hello/short-record").then()
.statusCode(HttpStatus.SC_OK)
.contentType(MediaType.APPLICATION_JSON)
.body("data", is("ok"));
}

protected RequestSpecification givenSpec() {
return HTTP_CLIENT_SPEC;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,21 @@ public Response doSomething(@PathParam("something-with-dash") String param) {
public Response hello() {
return Response.ok("hello").header("Transfer-Encoding", "chunked").build();
}

public record Data(String data) {
}

@GET
@Path("short-record-response")
@Produces(MediaType.APPLICATION_JSON)
public Response shortRecordInResponseClass() {
return Response.ok().entity(new Data("ok")).build();
}

@GET
@Path("short-record")
@Produces(MediaType.APPLICATION_JSON)
public Data shortRecordReturnedDirectly() {
return new Data("ok");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;

import jakarta.ws.rs.core.MediaType;

import org.apache.http.HttpStatus;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -45,6 +47,22 @@ public void transferEncodingAndContentLengthHeadersAreNotAllowedTogether() {
.headers("Content-Length", is(notNullValue()));
}

@Test
public void shortRecordInResponseClass() {
givenSpec().get("/api/hello/short-record-response").then()
.statusCode(HttpStatus.SC_OK)
.contentType(MediaType.APPLICATION_JSON)
.body("data", is("ok"));
}

@Test
public void shortRecordReturnedDirectly() {
givenSpec().get("/api/hello/short-record").then()
.statusCode(HttpStatus.SC_OK)
.contentType(MediaType.APPLICATION_JSON)
.body("data", is("ok"));
}

protected RequestSpecification givenSpec() {
return HTTP_CLIENT_SPEC;
}
Expand Down
3 changes: 1 addition & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
<name>Quarkus QE TS: Parent</name>
<properties>
<maven.compiler.parameters>true</maven.compiler.parameters>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.release>17</maven.compiler.release>
<maven-checkstyle-plugin.version>3.3.1</maven-checkstyle-plugin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
Expand Down

0 comments on commit 37b1f39

Please sign in to comment.