@Test
public void invalidInput() {
// create
Task titleBlankTask = new Task();
try {
restTemplate.postForLocation(resourceUrl, titleBlankTask);
fail("Create should fail while title is blank");
} catch (HttpStatusCodeException e) {
assertThat(e.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
Map messages = jsonMapper.fromJson(e.getResponseBodyAsString(), Map.class);
assertThat(messages).hasSize(1);
assertThat(messages.get("title")).isIn("may not be empty", "不能为空");
}
// update
titleBlankTask.setId(1L);
try {
restTemplate.put(resourceUrl + "/1", titleBlankTask);
fail("Update should fail while title is blank");
} catch (HttpStatusCodeException e) {
assertThat(e.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);