From c68b8f256462f9619bd2d1dd778ed98332d852cb Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Wed, 23 Mar 2022 07:21:50 +0200 Subject: [PATCH] Add test to make sure ResponseEntity content type takes precedence Relates to: #24481 --- .../spring/web/test/BasicMappingTest.java | 18 ++++++++++++++++++ .../web/test/ResponseEntityController.java | 15 ++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/extensions/spring-web/resteasy-reactive/tests/src/test/java/io/quarkus/spring/web/test/BasicMappingTest.java b/extensions/spring-web/resteasy-reactive/tests/src/test/java/io/quarkus/spring/web/test/BasicMappingTest.java index 33d78e98fcd9b..7f6d45b08b477 100644 --- a/extensions/spring-web/resteasy-reactive/tests/src/test/java/io/quarkus/spring/web/test/BasicMappingTest.java +++ b/extensions/spring-web/resteasy-reactive/tests/src/test/java/io/quarkus/spring/web/test/BasicMappingTest.java @@ -197,6 +197,24 @@ public void verifyJsonContentResponseEntityWithoutType() { .body("message", is("dummy")); } + @Test + public void verifyJsonContentResponseEntityWithCustomJsonHeader() { + when().get(ResponseEntityController.CONTROLLER_PATH + "/custom-json") + .then() + .statusCode(200) + .contentType("application/jsontest") + .header("custom-header", "somevalue"); + } + + @Test + public void verifyJsonContentResponseEntityWithContentType() { + when().get(ResponseEntityController.CONTROLLER_PATH + "/content-type") + .then() + .statusCode(200) + .contentType("application/jsontest") + .header("custom-header", "somevalue"); + } + @Test public void verifyEmptyContentResponseStatus() { when().get(ResponseStatusController.CONTROLLER_PATH + "/noContent") diff --git a/extensions/spring-web/resteasy-reactive/tests/src/test/java/io/quarkus/spring/web/test/ResponseEntityController.java b/extensions/spring-web/resteasy-reactive/tests/src/test/java/io/quarkus/spring/web/test/ResponseEntityController.java index 31bd989f05245..806beeb1464d7 100644 --- a/extensions/spring-web/resteasy-reactive/tests/src/test/java/io/quarkus/spring/web/test/ResponseEntityController.java +++ b/extensions/spring-web/resteasy-reactive/tests/src/test/java/io/quarkus/spring/web/test/ResponseEntityController.java @@ -21,7 +21,7 @@ public ResponseEntity string() { return ResponseEntity.ok("hello world"); } - @GetMapping(value = "/json", produces = "application/json") + @GetMapping(value = "/json") public ResponseEntity jsonPlusHeaders() { return ResponseEntity.ok().header("custom-header", "somevalue").body(new SomeClass("dummy")); } @@ -30,4 +30,17 @@ public ResponseEntity jsonPlusHeaders() { public ResponseEntity responseEntityWithoutType() { return ResponseEntity.ok().body(new SomeClass("dummy")); } + + @GetMapping(value = "/custom-json") + public ResponseEntity customJson() { + return ResponseEntity.ok().header("custom-header", "somevalue").header("content-type", "application/jsontest") + .body(new SomeClass("dummy")); + } + + @GetMapping(value = "/content-type") + public ResponseEntity contentType() { + return ResponseEntity.ok().header("custom-header", "somevalue") + .contentType(org.springframework.http.MediaType.valueOf("application/jsontest")) + .body(new SomeClass("dummy")); + } }