From f873e652ce3905f28e7197cf59272542e9baa686 Mon Sep 17 00:00:00 2001 From: Jakub Jedlicka Date: Wed, 8 Nov 2023 14:00:44 +0100 Subject: [PATCH] Add test coverage for https://github.com/quarkusio/quarkus/issues/35582 --- .../advanced/reactive/CookiesResource.java | 15 +++++++++++++ .../ts/http/advanced/reactive/CookiesIT.java | 22 ++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/http/http-advanced-reactive/src/main/java/io/quarkus/ts/http/advanced/reactive/CookiesResource.java b/http/http-advanced-reactive/src/main/java/io/quarkus/ts/http/advanced/reactive/CookiesResource.java index 5d3d03644..b9a17e53c 100644 --- a/http/http-advanced-reactive/src/main/java/io/quarkus/ts/http/advanced/reactive/CookiesResource.java +++ b/http/http-advanced-reactive/src/main/java/io/quarkus/ts/http/advanced/reactive/CookiesResource.java @@ -1,5 +1,7 @@ package io.quarkus.ts.http.advanced.reactive; +import java.util.Map; + import jakarta.ws.rs.Consumes; import jakarta.ws.rs.CookieParam; import jakarta.ws.rs.FormParam; @@ -56,6 +58,19 @@ public Response getSameSiteAttributeFromFormParam(@FormParam(TEST_COOKIE) String return responseBuilder.cookie(newCookie).build(); } + @GET + @Path("newcookie-serialization") + public Map getRequestCookies(HttpHeaders httpHeaders) { + NewCookie cookie = new NewCookie.Builder(TEST_COOKIE).value("test-cookie-value").build(); + return Map.of(cookie.getName(), cookie); + } + + @GET + @Path("cookie-serialization") + public Map test(HttpHeaders httpHeaders) { + return httpHeaders.getCookies(); + } + public static String toRawCookie(String sameSite) { if (sameSite == null || sameSite.isEmpty()) { return String.format("%s=\"test-cookie-value\";Version=\"1\";", TEST_COOKIE); diff --git a/http/http-advanced-reactive/src/test/java/io/quarkus/ts/http/advanced/reactive/CookiesIT.java b/http/http-advanced-reactive/src/test/java/io/quarkus/ts/http/advanced/reactive/CookiesIT.java index fadc9ea1c..3c4e001cb 100644 --- a/http/http-advanced-reactive/src/test/java/io/quarkus/ts/http/advanced/reactive/CookiesIT.java +++ b/http/http-advanced-reactive/src/test/java/io/quarkus/ts/http/advanced/reactive/CookiesIT.java @@ -1,9 +1,9 @@ package io.quarkus.ts.http.advanced.reactive; import static io.quarkus.ts.http.advanced.reactive.CookiesResource.TEST_COOKIE; -import static io.restassured.RestAssured.get; import static io.restassured.RestAssured.given; import static io.restassured.matcher.RestAssuredMatchers.detailedCookie; +import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.is; import org.junit.jupiter.api.Test; @@ -52,6 +52,26 @@ void testSameSiteAttributeAddedByVertxHttpExt() { .cookie("vertx", detailedCookie().sameSite(sameSite).secured(true)); } + @Test + void testNewCookiesSerialization() { + given() + .get("/cookie/newcookie-serialization") + .then() + .statusCode(200) + .body(containsString(String.format("\"name\":\"%s\"", TEST_COOKIE)), + containsString("\"value\":\"test-cookie-value\"")); + } + + @Test + void testCookiesSerialization() { + given().cookie(String.format("%s=\"test-cookie-value\";", TEST_COOKIE)) + .get("/cookie/cookie-serialization") + .then() + .statusCode(200) + .body(containsString(String.format("\"name\":\"%s\"", TEST_COOKIE)), + containsString("\"value\":\"test-cookie-value\"")); + } + private static void assertSameSiteAttribute(String sameSite) { ValidatableResponse response;