use of org.springframework.test.web.reactive.server.WebTestClient in project spring-framework by spring-projects.
the class FilterTests method filterMappedBySuffix.
@Test
public void filterMappedBySuffix() {
WebTestClient client = MockMvcWebTestClient.bindToController(new PersonController()).filter(new RedirectFilter(), "*.html").build();
client.post().uri("/persons.html?name=Andy").exchange().expectStatus().isFound().expectHeader().location("/login");
}
use of org.springframework.test.web.reactive.server.WebTestClient in project spring-framework by spring-projects.
the class FilterTests method filterWithExactMapping.
@Test
public void filterWithExactMapping() {
WebTestClient client = MockMvcWebTestClient.bindToController(new PersonController()).filter(new RedirectFilter(), "/p", "/persons").build();
client.post().uri("/persons?name=Andy").exchange().expectStatus().isFound().expectHeader().location("/login");
}
use of org.springframework.test.web.reactive.server.WebTestClient in project spring-framework by spring-projects.
the class MultipartControllerTests method multipartRequestWrapped.
@Test
public void multipartRequestWrapped() throws Exception {
Map<String, String> json = Collections.singletonMap("name", "yeeeah");
MultipartBodyBuilder bodyBuilder = new MultipartBodyBuilder();
bodyBuilder.part("json", json, MediaType.APPLICATION_JSON);
WebTestClient client = MockMvcWebTestClient.bindToController(new MultipartController()).filter(new RequestWrappingFilter()).build();
EntityExchangeResult<Void> exchangeResult = client.post().uri("/multipartfile").bodyValue(bodyBuilder.build()).exchange().expectStatus().isFound().expectBody().isEmpty();
// Further assertions on the server response
MockMvcWebTestClient.resultActionsFor(exchangeResult).andExpect(model().attribute("jsonContent", json));
}
use of org.springframework.test.web.reactive.server.WebTestClient in project spring-framework by spring-projects.
the class ViewResolutionTests method xmlOnly.
@Test
void xmlOnly() {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setClassesToBeBound(Person.class);
WebTestClient testClient = MockMvcWebTestClient.bindToController(new PersonController()).singleView(new MarshallingView(marshaller)).build();
testClient.get().uri("/person/Corea").exchange().expectStatus().isOk().expectHeader().contentType(MediaType.APPLICATION_XML).expectBody().xpath("/person/name/text()").isEqualTo("Corea");
}
use of org.springframework.test.web.reactive.server.WebTestClient in project spring-framework by spring-projects.
the class ViewResolutionTests method defaultViewResolver.
@Test
void defaultViewResolver() throws Exception {
WebTestClient client = MockMvcWebTestClient.bindToController(new PersonController()).build();
EntityExchangeResult<Void> result = client.get().uri("/person/Corea").exchange().expectStatus().isOk().expectBody().isEmpty();
// Further assertions on the server response
MockMvcWebTestClient.resultActionsFor(result).andExpect(model().attribute("person", hasProperty("name", equalTo("Corea")))).andExpect(// InternalResourceViewResolver
forwardedUrl("person/show"));
}
Aggregations