Search in sources :

Example 66 with WebTestClient

use of org.springframework.test.web.reactive.server.WebTestClient in project spring-boot by spring-projects.

the class WelcomePageRouterFunctionFactoryTests method handlesRequestForStaticPageThatAcceptsAll.

@Test
void handlesRequestForStaticPageThatAcceptsAll() {
    WebTestClient client = withStaticIndex();
    client.get().uri("/").accept(MediaType.ALL).exchange().expectStatus().isOk().expectBody(String.class).isEqualTo("welcome-page-static");
}
Also used : WebTestClient(org.springframework.test.web.reactive.server.WebTestClient) Test(org.junit.jupiter.api.Test)

Example 67 with WebTestClient

use of org.springframework.test.web.reactive.server.WebTestClient in project spring-boot by spring-projects.

the class WelcomePageRouterFunctionFactoryTests method handlesRequestForTemplateThatAcceptsAll.

@Test
void handlesRequestForTemplateThatAcceptsAll() {
    WebTestClient client = withTemplateIndex();
    client.get().uri("/").accept(MediaType.ALL).exchange().expectStatus().isOk().expectBody(String.class).isEqualTo("welcome-page-template");
}
Also used : WebTestClient(org.springframework.test.web.reactive.server.WebTestClient) Test(org.junit.jupiter.api.Test)

Example 68 with WebTestClient

use of org.springframework.test.web.reactive.server.WebTestClient in project spring-boot by spring-projects.

the class WelcomePageRouterFunctionFactoryTests method handlesRequestWithNoAcceptHeader.

@Test
void handlesRequestWithNoAcceptHeader() {
    WebTestClient client = withStaticIndex();
    client.get().uri("/").exchange().expectStatus().isOk().expectBody(String.class).isEqualTo("welcome-page-static");
}
Also used : WebTestClient(org.springframework.test.web.reactive.server.WebTestClient) Test(org.junit.jupiter.api.Test)

Example 69 with WebTestClient

use of org.springframework.test.web.reactive.server.WebTestClient in project spring-boot by spring-projects.

the class WelcomePageRouterFunctionFactoryTests method handlesRequestForTemplateThatAcceptsTextHtml.

@Test
void handlesRequestForTemplateThatAcceptsTextHtml() {
    WebTestClient client = withTemplateIndex();
    client.get().uri("/").accept(MediaType.TEXT_HTML).exchange().expectStatus().isOk().expectBody(String.class).isEqualTo("welcome-page-template");
}
Also used : WebTestClient(org.springframework.test.web.reactive.server.WebTestClient) Test(org.junit.jupiter.api.Test)

Example 70 with WebTestClient

use of org.springframework.test.web.reactive.server.WebTestClient in project spring-boot by spring-projects.

the class WelcomePageRouterFunctionFactoryTests method handlesRequestWithEmptyAcceptHeader.

@Test
void handlesRequestWithEmptyAcceptHeader() {
    WebTestClient client = withStaticIndex();
    client.get().uri("/").header(HttpHeaders.ACCEPT, "").exchange().expectStatus().isOk().expectBody(String.class).isEqualTo("welcome-page-static");
}
Also used : WebTestClient(org.springframework.test.web.reactive.server.WebTestClient) 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