Skip to content

Commit

Permalink
Add test to make sure ResponseEntity content type takes precedence
Browse files Browse the repository at this point in the history
Relates to: #24481
  • Loading branch information
geoand committed Mar 23, 2022
1 parent 7dcdbdb commit c68b8f2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public ResponseEntity<String> string() {
return ResponseEntity.ok("hello world");
}

@GetMapping(value = "/json", produces = "application/json")
@GetMapping(value = "/json")
public ResponseEntity<SomeClass> jsonPlusHeaders() {
return ResponseEntity.ok().header("custom-header", "somevalue").body(new SomeClass("dummy"));
}
Expand All @@ -30,4 +30,17 @@ public ResponseEntity<SomeClass> jsonPlusHeaders() {
public ResponseEntity<?> responseEntityWithoutType() {
return ResponseEntity.ok().body(new SomeClass("dummy"));
}

@GetMapping(value = "/custom-json")
public ResponseEntity<SomeClass> customJson() {
return ResponseEntity.ok().header("custom-header", "somevalue").header("content-type", "application/jsontest")
.body(new SomeClass("dummy"));
}

@GetMapping(value = "/content-type")
public ResponseEntity<SomeClass> contentType() {
return ResponseEntity.ok().header("custom-header", "somevalue")
.contentType(org.springframework.http.MediaType.valueOf("application/jsontest"))
.body(new SomeClass("dummy"));
}
}

0 comments on commit c68b8f2

Please sign in to comment.