Search in sources :

Example 86 with WebTestClient

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");
}
Also used : WebTestClient(org.springframework.test.web.reactive.server.WebTestClient) MockMvcWebTestClient(org.springframework.test.web.servlet.client.MockMvcWebTestClient) Test(org.junit.jupiter.api.Test)

Example 87 with WebTestClient

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");
}
Also used : WebTestClient(org.springframework.test.web.reactive.server.WebTestClient) MockMvcWebTestClient(org.springframework.test.web.servlet.client.MockMvcWebTestClient) Test(org.junit.jupiter.api.Test)

Example 88 with WebTestClient

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));
}
Also used : MultipartBodyBuilder(org.springframework.http.client.MultipartBodyBuilder) WebTestClient(org.springframework.test.web.reactive.server.WebTestClient) MockMvcWebTestClient(org.springframework.test.web.servlet.client.MockMvcWebTestClient) Test(org.junit.jupiter.api.Test)

Example 89 with WebTestClient

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");
}
Also used : WebTestClient(org.springframework.test.web.reactive.server.WebTestClient) MockMvcWebTestClient(org.springframework.test.web.servlet.client.MockMvcWebTestClient) MarshallingView(org.springframework.web.servlet.view.xml.MarshallingView) Jaxb2Marshaller(org.springframework.oxm.jaxb.Jaxb2Marshaller) Test(org.junit.jupiter.api.Test)

Example 90 with WebTestClient

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"));
}
Also used : WebTestClient(org.springframework.test.web.reactive.server.WebTestClient) MockMvcWebTestClient(org.springframework.test.web.servlet.client.MockMvcWebTestClient) Test(org.junit.jupiter.api.Test)

Aggregations

WebTestClient (org.springframework.test.web.reactive.server.WebTestClient)165 Test (org.junit.jupiter.api.Test)159 SecurityWebFilterChain (org.springframework.security.web.server.SecurityWebFilterChain)44 WebTestClientBuilder (org.springframework.security.test.web.reactive.server.WebTestClientBuilder)34 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)31 Authentication (org.springframework.security.core.Authentication)28 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)27 WebDriver (org.openqa.selenium.WebDriver)26 Mono (reactor.core.publisher.Mono)25 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)23 ServerSecurityContextRepository (org.springframework.security.web.server.context.ServerSecurityContextRepository)22 ReactiveAuthenticationManager (org.springframework.security.authentication.ReactiveAuthenticationManager)21 WebFilterChainProxy (org.springframework.security.web.server.WebFilterChainProxy)21 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)20 BDDMockito.given (org.mockito.BDDMockito.given)20 Mockito.verify (org.mockito.Mockito.verify)20 GetMapping (org.springframework.web.bind.annotation.GetMapping)19 WebFilter (org.springframework.web.server.WebFilter)18 SecurityContext (org.springframework.security.core.context.SecurityContext)17 RestController (org.springframework.web.bind.annotation.RestController)17