Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Can't reproduce for now
  • Loading branch information
sdeleuze committed Nov 7, 2023
1 parent a0f3aa5 commit db2c4c4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,24 @@ void controllerValidationWorks(WebTestClient client) {
.isBadRequest();
}

@Test
void controllerValidationWorksWithInheritedClass(WebTestClient client) {
client.post()
.uri("/inherited-hello")
.contentType(MediaType.APPLICATION_JSON)
.bodyValue("{\"name\": \"world\"}")
.exchange()
.expectStatus()
.isOk()
.expectBody()
.consumeWith((result) -> assertThat(new String(result.getResponseBodyContent())).isEqualTo("Inherited Hello world"));
client.post()
.uri("/inherited-hello")
.contentType(MediaType.APPLICATION_JSON)
.bodyValue("{\"name\": \"\"}")
.exchange()
.expectStatus()
.isBadRequest();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public String hello(@Validated @RequestBody Dto dto) {
return "Hello " + dto.getName();
}

@PostMapping(value = "inherited-hello", consumes = MediaType.APPLICATION_JSON_VALUE)
public String inheritedHello(@Validated @RequestBody InheritedDto dto) {
return "Inherited Hello " + dto.getName();
}

static class Dto {

@NotBlank
Expand All @@ -31,4 +36,7 @@ public void setName(String name) {

}

static class InheritedDto extends Dto {
}

}

0 comments on commit db2c4c4

Please sign in to comment.