use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.
the class DispatcherHandlerTests method preFlightRequest.
@Test
void preFlightRequest() {
WebHandler webHandler = mock(WebHandler.class);
HandlerMapping handlerMapping = mock(HandlerMapping.class);
given((handlerMapping).getHandler(any())).willReturn(Mono.just(webHandler));
StaticApplicationContext context = new StaticApplicationContext();
context.registerBean("handlerMapping", HandlerMapping.class, () -> handlerMapping);
context.registerBean(HandlerAdapter.class, SimpleHandlerAdapter::new);
context.registerBean(HandlerResultHandler.class, StringHandlerResultHandler::new);
context.refresh();
MockServerHttpRequest request = MockServerHttpRequest.options("/").header(HttpHeaders.ORIGIN, "https://domain.com").header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET").build();
MockServerWebExchange exchange = MockServerWebExchange.from(request);
new DispatcherHandler(context).handle(exchange).block(Duration.ofSeconds(0));
verifyNoInteractions(webHandler);
}
use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.
the class AcceptHeaderLocaleContextResolverTests method resolveMissingAcceptLanguageHeaderWithDefault.
@Test
public void resolveMissingAcceptLanguageHeaderWithDefault() {
this.resolver.setDefaultLocale(US);
MockServerHttpRequest request = MockServerHttpRequest.get("/").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 defaultLocale.
@Test
public void defaultLocale() {
this.resolver.setDefaultLocale(JAPANESE);
MockServerHttpRequest request = MockServerHttpRequest.get("/").build();
MockServerWebExchange exchange = MockServerWebExchange.from(request);
assertThat(this.resolver.resolveLocaleContext(exchange).getLocale()).isEqualTo(JAPANESE);
request = MockServerHttpRequest.get("/").acceptLanguageAsLocales(US).build();
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 resolveEmptyAcceptLanguageHeader.
@Test
public void resolveEmptyAcceptLanguageHeader() {
MockServerHttpRequest request = MockServerHttpRequest.get("/").header(HttpHeaders.ACCEPT_LANGUAGE, "").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 resolveEmptyAcceptLanguageHeaderWithDefault.
@Test
public void resolveEmptyAcceptLanguageHeaderWithDefault() {
this.resolver.setDefaultLocale(US);
MockServerHttpRequest request = MockServerHttpRequest.get("/").header(HttpHeaders.ACCEPT_LANGUAGE, "").build();
MockServerWebExchange exchange = MockServerWebExchange.from(request);
assertThat(this.resolver.resolveLocaleContext(exchange).getLocale()).isEqualTo(US);
}
Aggregations