use of org.springframework.test.web.reactive.server.WebTestClient in project spring-framework by spring-projects.
the class ViewResolutionTests method jsonOnly.
@Test
void jsonOnly() {
WebTestClient testClient = MockMvcWebTestClient.bindToController(new PersonController()).singleView(new MappingJackson2JsonView()).build();
testClient.get().uri("/person/Corea").exchange().expectStatus().isOk().expectHeader().contentTypeCompatibleWith(MediaType.APPLICATION_JSON).expectBody().jsonPath("$.person.name", "Corea");
}
use of org.springframework.test.web.reactive.server.WebTestClient in project spring-framework by spring-projects.
the class ViewResolutionTests method contentNegotiation.
@Test
void contentNegotiation() throws Exception {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setClassesToBeBound(Person.class);
List<View> viewList = new ArrayList<>();
viewList.add(new MappingJackson2JsonView());
viewList.add(new MarshallingView(marshaller));
ContentNegotiationManager manager = new ContentNegotiationManager(new HeaderContentNegotiationStrategy(), new FixedContentNegotiationStrategy(MediaType.TEXT_HTML));
ContentNegotiatingViewResolver cnViewResolver = new ContentNegotiatingViewResolver();
cnViewResolver.setDefaultViews(viewList);
cnViewResolver.setContentNegotiationManager(manager);
cnViewResolver.afterPropertiesSet();
WebTestClient testClient = MockMvcWebTestClient.bindToController(new PersonController()).viewResolvers(cnViewResolver, new InternalResourceViewResolver()).build();
EntityExchangeResult<Void> result = testClient.get().uri("/person/Corea").exchange().expectStatus().isOk().expectBody().isEmpty();
// Further assertions on the server response
MockMvcWebTestClient.resultActionsFor(result).andExpect(model().size(1)).andExpect(model().attributeExists("person")).andExpect(forwardedUrl("person/show"));
testClient.get().uri("/person/Corea").accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk().expectHeader().contentTypeCompatibleWith(MediaType.APPLICATION_JSON).expectBody().jsonPath("$.person.name", "Corea");
testClient.get().uri("/person/Corea").accept(MediaType.APPLICATION_XML).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-integration by spring-projects.
the class IntegrationGraphControllerTests method testIntegrationGraphGet.
@Test
public void testIntegrationGraphGet() {
WebTestClient webTestClient = WebTestClient.bindToApplicationContext(this.wac).build();
webTestClient.get().uri("/testIntegration").accept(MediaType.APPLICATION_JSON_UTF8).exchange().expectStatus().isOk().expectHeader().contentType(MediaType.APPLICATION_JSON_UTF8).expectBody().jsonPath("$.nodes..name").isArray().jsonPath("$.contentDescriptor.name").isEqualTo("testApplication").jsonPath("$.links").exists();
}
use of org.springframework.test.web.reactive.server.WebTestClient in project spring-boot by spring-projects.
the class AbstractEndpointRequestIntegrationTests method toEndpointShouldMatch.
@Test
void toEndpointShouldMatch() {
getContextRunner().run((context) -> {
WebTestClient webTestClient = getWebTestClient(context);
webTestClient.get().uri("/actuator/e1").exchange().expectStatus().isOk();
});
}
use of org.springframework.test.web.reactive.server.WebTestClient in project spring-boot by spring-projects.
the class MvcEndpointRequestIntegrationTests method toAnyEndpointWhenServletPathSetShouldMatch.
@Test
void toAnyEndpointWhenServletPathSetShouldMatch() {
getContextRunner().withPropertyValues("spring.mvc.servlet.path=/admin", "spring.security.user.password=password").run((context) -> {
WebTestClient webTestClient = getWebTestClient(context);
webTestClient.get().uri("/admin/actuator/e2").exchange().expectStatus().isUnauthorized();
webTestClient.get().uri("/admin/actuator/e2").header("Authorization", getBasicAuth()).exchange().expectStatus().isOk();
});
}
Aggregations