I have my SpringBootTest setup like this
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class ControllerTest {
@Autowired
private WebTestClient webTestClient;
@Test
public void postTest() {
// Setup data
Form form = new Form();
form.setName("Test1");
form.setDescription("Description1");
// Run method
webTestClient.post()
.uri("/api/v1/data")
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)
.syncBody(form)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("data.id").isNotEmpty()
.jsonPath("data.name").isEqualTo(form.getName())
.jsonPath("data.description").isEqualTo(form.getDescription())
.jsonPath("data.status").isEqualTo("A");
}
}
I cannot work out a way of making the WebTestClient
log out all of the HTTP requests and responses.
I would like to leave the WebTestClient
as @Autowired
. There is probably some sort of application config or configuration class I could create to do this but unfortunately I have not found out how.