Add validation module: Bean Validation on Spring Boot 4.2.0 with Hibernate Validator 9.1.6, built-in and custom constraints, groups, method validation, ProblemDetail errors, message i18n, JPA integration and tests, with real transcripts
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b4RzcCS5JCAgcxLz7T
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package com.ankurm.validation;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.webmvc.test.autoconfigure.AutoConfigureMockMvc;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.assertj.MockMvcTester;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/** The same default request as in 09-http-defaults, through MockMvc: no servlet error dispatch. */
|
||||
@SpringBootTest(properties = "app.problem-advice=false")
|
||||
@AutoConfigureMockMvc
|
||||
class MockMvcEmptyBodyTest {
|
||||
|
||||
@Autowired
|
||||
MockMvcTester mvc;
|
||||
|
||||
@Test
|
||||
void bodyIsEmptyInMockMvc() throws Exception {
|
||||
var result = mvc.post().uri("/contacts").contentType(MediaType.APPLICATION_JSON)
|
||||
.content(WebDefaultsTest.SPAM).exchange();
|
||||
String body = result.getResponse().getContentAsString();
|
||||
Transcript t = new Transcript("18-mockmvc-vs-server");
|
||||
t.head("MockMvc, no advice, POST /contacts with the short spam message");
|
||||
t.line("status: " + result.getResponse().getStatus());
|
||||
t.line("body length: " + body.length());
|
||||
t.line("resolved exception: " + result.getMvcResult().getResolvedException().getClass().getSimpleName());
|
||||
t.write();
|
||||
assertThat(body).isEmpty();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user