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);
}
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();
}
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();
}
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");
}
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);
}
Aggregations