Skip to content

Commit

Permalink
Test coverage for backport 3.8.6-41411
Browse files Browse the repository at this point in the history
  • Loading branch information
jcarranzan authored and jedla97 committed Sep 2, 2024
1 parent 01635f7 commit 40854a4
Show file tree
Hide file tree
Showing 12 changed files with 162 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.quarkus.ts.http.advanced.reactive;

public class CustomHeaderResponse {
private final String content;

public CustomHeaderResponse(String content) {
this.content = content;
}

public String getContent() {
return content;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.quarkus.ts.http.advanced.reactive;

import java.io.IOException;
import java.io.OutputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;

import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.MultivaluedMap;
import jakarta.ws.rs.ext.MessageBodyWriter;
import jakarta.ws.rs.ext.Provider;

@Provider
public class HeadersMessageBodyWriter implements MessageBodyWriter<CustomHeaderResponse> {

@Override
public boolean isWriteable(Class aClass, Type type, Annotation[] annotations, MediaType mediaType) {
return CustomHeaderResponse.class.isAssignableFrom(aClass) && MediaType.TEXT_PLAIN_TYPE.isCompatible(mediaType);
}

@Override
public void writeTo(CustomHeaderResponse customHeaderResponse, Class<?> aClass, Type type, Annotation[] annotations,
MediaType mediaType, MultivaluedMap<String, Object> multivaluedMap, OutputStream outputStream)
throws IOException, WebApplicationException {
final String content = "Headers response: " + customHeaderResponse.getContent();
outputStream.write(content.getBytes());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;

import io.smallrye.mutiny.Uni;
Expand All @@ -28,4 +30,11 @@ public Uni<Response> headersOverride() {
return Uni.createFrom().item(response);
}

@GET
@Path("/no-accept")
@Produces(MediaType.TEXT_PLAIN)
public Uni<String> okHeaders() {
return Uni.createFrom().item("ok headers");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,12 @@ public void httpServer() {
@Test
@DisplayName("GRPC Server test")
public void testGrpc() {
getApp().given().when().get("/api/grpc/trinity").then().statusCode(SC_OK).body(is("Hello trinity"));
getApp().given()
.when()
.get("/api/grpc/trinity")
.then()
.statusCode(SC_OK)
.body(is("Hello trinity"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ public void testGrpcAsClient() throws ExecutionException, InterruptedException {

@Test
public void testGrpcViaRest() {
app.given().when().get("/api/grpc/trinity").then().statusCode(HttpStatus.SC_OK).body(is("Hello trinity"));
app.given()
.when()
.get("/api/grpc/trinity")
.then()
.statusCode(HttpStatus.SC_OK)
.body(is("Hello trinity"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

import java.util.List;

import io.restassured.http.Header;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

Expand All @@ -22,6 +24,8 @@
public class HeadersIT {

@QuarkusApplication(classes = { PathSpecificHeadersResource.class,
HeadersMessageBodyWriter.class,
CustomHeaderResponse.class,
HeadersResource.class }, properties = "headers.properties")
static RestService app = new RestService();

Expand Down Expand Up @@ -100,6 +104,20 @@ private ValidatableResponse whenGet(String path) {
.body(is("ok"));
}

@Disabled("https://github.com/quarkusio/quarkus/issues/42854")
@Test
@Tag("https://github.com/quarkusio/quarkus/pull/41411")
void testWithNoAcceptHeader() {
Header header = new Header("Accept", null);
given()
.when()
.header(header)
.get("/headers/no-accept")
.then()
.statusCode(200)
.body(is("Headers response: ok headers"));
}

/**
* Cache-Control header may be present multiple times in the response, e.g. in an OpenShift deployment. That is why we need
* to look for a specific value among all headers of the same name, and not just match the last one of them, which is what
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.quarkus.ts.http.advanced;

public class CustomHeaderResponse {

private final String content;

public CustomHeaderResponse(String content) {
this.content = content;
}

public String getContent() {
return content;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.quarkus.ts.http.advanced;

import java.io.IOException;
import java.io.OutputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;

import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.MultivaluedMap;
import jakarta.ws.rs.ext.MessageBodyWriter;
import jakarta.ws.rs.ext.Provider;

@Provider
public class HeadersMessageBodyWriter implements MessageBodyWriter<CustomHeaderResponse> {

@Override
public boolean isWriteable(Class aClass, Type type, Annotation[] annotations, MediaType mediaType) {
return CustomHeaderResponse.class.isAssignableFrom(aClass) && MediaType.TEXT_PLAIN_TYPE.isCompatible(mediaType);
}

@Override
public void writeTo(CustomHeaderResponse customHeaderResponse, Class<?> aClass, Type type, Annotation[] annotations,
MediaType mediaType, MultivaluedMap<String, Object> multivaluedMap, OutputStream outputStream)
throws IOException, WebApplicationException {
final String content = "Headers response: " + customHeaderResponse.getContent();
outputStream.write(content.getBytes());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;

@Path("/headers")
Expand All @@ -13,6 +15,13 @@ public String headers() {
return "ok";
}

@GET
@Path("/no-accept")
@Produces(MediaType.TEXT_PLAIN)
public CustomHeaderResponse noAcceptheaders() {
return new CustomHeaderResponse("ok");
}

@GET
@Path("/pragma")
public String pragmaHeaderMustBeSet() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,13 @@ public void clientHostAddress(TestInfo testInfo) {
@Test
@DisplayName("GRPC Server test")
public void testGrpc() {
getApp().given().when().get("/api/grpc/trinity").then().statusCode(HttpStatus.SC_OK).body(is("Hello trinity"));
getApp()
.given()
.when()
.get("/api/grpc/trinity")
.then()
.statusCode(HttpStatus.SC_OK)
.body(is("Hello trinity"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ public void testGrpcAsClient() {

@Test
public void testGrpcViaRest() {
app.given().when().get("/api/grpc/trinity").then().statusCode(HttpStatus.SC_OK).body(is("Hello trinity"));
app.given()
.when()
.get("/api/grpc/trinity")
.then()
.statusCode(HttpStatus.SC_OK)
.body(is("Hello trinity"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
import io.quarkus.test.bootstrap.RestService;
import io.quarkus.test.scenarios.QuarkusScenario;
import io.quarkus.test.services.QuarkusApplication;
import io.restassured.http.Header;
import io.restassured.response.ValidatableResponse;

@QuarkusScenario
public class HeadersIT {

@QuarkusApplication(classes = { PathSpecificHeadersResource.class,
HeadersMessageBodyWriter.class,
CustomHeaderResponse.class,
HeadersResource.class }, properties = "headers.properties")
static RestService app = new RestService();

Expand Down Expand Up @@ -93,6 +96,19 @@ void testPathSpecificHeaderRulesOrder() {
cacheControlMatches(response, "max-age=1");
}

@Test
@Tag("https://github.com/quarkusio/quarkus/pull/41411")
void testWithNoAcceptHeader() {
Header header = new Header("Accept", null);
given()
.when()
.header(header)
.get("/headers/no-accept")
.then()
.statusCode(200)
.body(is("Headers response: ok"));
}

private ValidatableResponse whenGet(String path) {
return given()
.get(path)
Expand Down

0 comments on commit 40854a4

Please sign in to comment.