Search in sources :

Example 1 with SimpleHandlerAdapter

use of org.springframework.web.reactive.result.SimpleHandlerAdapter 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);
}
Also used : StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) MockServerHttpRequest(org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest) WebHandler(org.springframework.web.server.WebHandler) MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) SimpleHandlerAdapter(org.springframework.web.reactive.result.SimpleHandlerAdapter) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)1 StaticApplicationContext (org.springframework.context.support.StaticApplicationContext)1 SimpleHandlerAdapter (org.springframework.web.reactive.result.SimpleHandlerAdapter)1 WebHandler (org.springframework.web.server.WebHandler)1 MockServerHttpRequest (org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest)1 MockServerWebExchange (org.springframework.web.testfixture.server.MockServerWebExchange)1