Search in sources :

Example 96 with MockServerWebExchange

use of org.springframework.web.testfixture.server.MockServerWebExchange 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 97 with MockServerWebExchange

use of org.springframework.web.testfixture.server.MockServerWebExchange 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 98 with MockServerWebExchange

use of org.springframework.web.testfixture.server.MockServerWebExchange 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 99 with MockServerWebExchange

use of org.springframework.web.testfixture.server.MockServerWebExchange 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 100 with MockServerWebExchange

use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.

the class DefaultServerWebExchangeCheckNotModifiedTests method checkModifiedETagAndNotModifiedTimestamp.

@Test
void checkModifiedETagAndNotModifiedTimestamp() throws Exception {
    String currentETag = "\"Foo\"";
    String oldEtag = "\"Bar\"";
    long time = currentDate.toEpochMilli();
    MockServerHttpRequest request = get("/").ifNoneMatch(oldEtag).ifModifiedSince(time).build();
    MockServerWebExchange exchange = MockServerWebExchange.from(request);
    assertThat(exchange.checkNotModified(currentETag, currentDate)).isFalse();
    assertThat(exchange.getResponse().getStatusCode()).isNull();
    assertThat(exchange.getResponse().getHeaders().getETag()).isEqualTo(currentETag);
    assertThat(exchange.getResponse().getHeaders().getLastModified()).isEqualTo(time);
}
Also used : MockServerHttpRequest(org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest) MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) Test(org.junit.jupiter.api.Test)

Aggregations

MockServerWebExchange (org.springframework.web.testfixture.server.MockServerWebExchange)224 Test (org.junit.jupiter.api.Test)216 MockServerHttpRequest (org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest)61 ClassPathResource (org.springframework.core.io.ClassPathResource)26 HttpHeaders (org.springframework.http.HttpHeaders)25 Resource (org.springframework.core.io.Resource)24 HandlerResult (org.springframework.web.reactive.HandlerResult)23 MethodParameter (org.springframework.core.MethodParameter)22 MockServerHttpResponse (org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse)22 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)19 MediaType (org.springframework.http.MediaType)19 Mono (reactor.core.publisher.Mono)18 BeforeEach (org.junit.jupiter.api.BeforeEach)17 HttpMethod (org.springframework.http.HttpMethod)15 StepVerifier (reactor.test.StepVerifier)13 Arrays (java.util.Arrays)12 Collections (java.util.Collections)12 List (java.util.List)12 HttpStatus (org.springframework.http.HttpStatus)12 IOException (java.io.IOException)10