Search in sources :

Example 51 with MockServerHttpRequest

use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.

the class AcceptHeaderLocaleContextResolverTests method resolveInvalidAcceptLanguageHeaderWithDefault.

@Test
public void resolveInvalidAcceptLanguageHeaderWithDefault() {
    this.resolver.setDefaultLocale(US);
    MockServerHttpRequest request = MockServerHttpRequest.get("/").header(HttpHeaders.ACCEPT_LANGUAGE, "en_US").build();
    MockServerWebExchange exchange = MockServerWebExchange.from(request);
    assertThat(this.resolver.resolveLocaleContext(exchange).getLocale()).isEqualTo(US);
}
Also used : MockServerHttpRequest(org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest) MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) Test(org.junit.jupiter.api.Test)

Example 52 with MockServerHttpRequest

use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.

the class AcceptHeaderLocaleContextResolverTests method resolveInvalidAcceptLanguageHeader.

@Test
public void resolveInvalidAcceptLanguageHeader() {
    MockServerHttpRequest request = MockServerHttpRequest.get("/").header(HttpHeaders.ACCEPT_LANGUAGE, "en_US").build();
    MockServerWebExchange exchange = MockServerWebExchange.from(request);
    assertThat(this.resolver.resolveLocaleContext(exchange).getLocale()).isNull();
}
Also used : MockServerHttpRequest(org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest) MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) Test(org.junit.jupiter.api.Test)

Example 53 with MockServerHttpRequest

use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.

the class AcceptHeaderLocaleContextResolverTests method resolveMissingAcceptLanguageHeader.

@Test
public void resolveMissingAcceptLanguageHeader() {
    MockServerHttpRequest request = MockServerHttpRequest.get("/").build();
    MockServerWebExchange exchange = MockServerWebExchange.from(request);
    assertThat(this.resolver.resolveLocaleContext(exchange).getLocale()).isNull();
}
Also used : MockServerHttpRequest(org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest) MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) Test(org.junit.jupiter.api.Test)

Example 54 with MockServerHttpRequest

use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.

the class CookieWebSessionIdResolverTests method setSessionId.

@Test
public void setSessionId() {
    MockServerHttpRequest request = MockServerHttpRequest.get("https://example.org/path").build();
    MockServerWebExchange exchange = MockServerWebExchange.from(request);
    this.resolver.setSessionId(exchange, "123");
    MultiValueMap<String, ResponseCookie> cookies = exchange.getResponse().getCookies();
    assertThat(cookies.size()).isEqualTo(1);
    ResponseCookie cookie = cookies.getFirst(this.resolver.getCookieName());
    assertThat(cookie).isNotNull();
    assertThat(cookie.toString()).isEqualTo("SESSION=123; Path=/; Secure; HttpOnly; SameSite=Lax");
}
Also used : MockServerHttpRequest(org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest) MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) ResponseCookie(org.springframework.http.ResponseCookie) Test(org.junit.jupiter.api.Test)

Example 55 with MockServerHttpRequest

use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.

the class DefaultWebSessionManagerTests method setUp.

@BeforeEach
void setUp() throws Exception {
    given(this.createSession.save()).willReturn(Mono.empty());
    given(this.createSession.getId()).willReturn("create-session-id");
    given(this.updateSession.getId()).willReturn("update-session-id");
    given(this.sessionStore.createWebSession()).willReturn(Mono.just(this.createSession));
    given(this.sessionStore.retrieveSession(this.updateSession.getId())).willReturn(Mono.just(this.updateSession));
    this.sessionManager = new DefaultWebSessionManager();
    this.sessionManager.setSessionIdResolver(this.sessionIdResolver);
    this.sessionManager.setSessionStore(this.sessionStore);
    MockServerHttpRequest request = MockServerHttpRequest.get("/path").build();
    MockServerHttpResponse response = new MockServerHttpResponse();
    this.exchange = new DefaultServerWebExchange(request, response, this.sessionManager, ServerCodecConfigurer.create(), new AcceptHeaderLocaleContextResolver());
}
Also used : AcceptHeaderLocaleContextResolver(org.springframework.web.server.i18n.AcceptHeaderLocaleContextResolver) DefaultServerWebExchange(org.springframework.web.server.adapter.DefaultServerWebExchange) MockServerHttpRequest(org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest) MockServerHttpResponse(org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

MockServerHttpRequest (org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest)182 Test (org.junit.jupiter.api.Test)160 MockServerWebExchange (org.springframework.web.testfixture.server.MockServerWebExchange)101 Mono (reactor.core.publisher.Mono)52 DataBuffer (org.springframework.core.io.buffer.DataBuffer)51 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)50 Collections (java.util.Collections)48 StepVerifier (reactor.test.StepVerifier)46 HttpHeaders (org.springframework.http.HttpHeaders)39 Flux (reactor.core.publisher.Flux)37 MediaType (org.springframework.http.MediaType)34 ServerWebExchange (org.springframework.web.server.ServerWebExchange)34 MultiValueMap (org.springframework.util.MultiValueMap)33 HttpStatus (org.springframework.http.HttpStatus)31 StandardCharsets (java.nio.charset.StandardCharsets)29 MockServerHttpResponse (org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse)29 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)27 ClassPathResource (org.springframework.core.io.ClassPathResource)25 DefaultDataBuffer (org.springframework.core.io.buffer.DefaultDataBuffer)24 Optional (java.util.Optional)23