use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse in project spring-framework by spring-projects.
the class WebHttpHandlerBuilderTests method httpHandlerDecorator.
@Test
void httpHandlerDecorator() {
BiFunction<ServerHttpRequest, String, ServerHttpRequest> mutator = (req, value) -> req.mutate().headers(headers -> headers.add("My-Header", value)).build();
AtomicBoolean success = new AtomicBoolean();
HttpHandler httpHandler = WebHttpHandlerBuilder.webHandler(exchange -> {
HttpHeaders headers = exchange.getRequest().getHeaders();
assertThat(headers.get("My-Header")).containsExactlyInAnyOrder("1", "2", "3");
success.set(true);
return Mono.empty();
}).httpHandlerDecorator(handler -> (req, res) -> handler.handle(mutator.apply(req, "1"), res)).httpHandlerDecorator(handler -> (req, res) -> handler.handle(mutator.apply(req, "2"), res)).httpHandlerDecorator(handler -> (req, res) -> handler.handle(mutator.apply(req, "3"), res)).build();
httpHandler.handle(MockServerHttpRequest.get("/").build(), new MockServerHttpResponse()).block();
assertThat(success.get()).isTrue();
}
use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse in project spring-framework by spring-projects.
the class WebHttpHandlerBuilderTests method orderedWebFilterBeans.
// SPR-15074
@Test
void orderedWebFilterBeans() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.register(OrderedWebFilterBeanConfig.class);
context.refresh();
HttpHandler httpHandler = WebHttpHandlerBuilder.applicationContext(context).build();
boolean condition = httpHandler instanceof HttpWebHandlerAdapter;
assertThat(condition).isTrue();
assertThat(((HttpWebHandlerAdapter) httpHandler).getApplicationContext()).isSameAs(context);
MockServerHttpRequest request = MockServerHttpRequest.get("/").build();
MockServerHttpResponse response = new MockServerHttpResponse();
httpHandler.handle(request, response).block(ofMillis(5000));
assertThat(response.getBodyAsString().block(ofMillis(5000))).isEqualTo("FilterB::FilterA");
}
use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse in project spring-framework by spring-projects.
the class FilteringWebHandlerTests method handleErrorFromFilter.
@Test
public void handleErrorFromFilter() throws Exception {
MockServerHttpRequest request = MockServerHttpRequest.get("/").build();
MockServerHttpResponse response = new MockServerHttpResponse();
TestExceptionHandler exceptionHandler = new TestExceptionHandler();
WebHttpHandlerBuilder.webHandler(new StubWebHandler()).filter(new ExceptionFilter()).exceptionHandler(exceptionHandler).build().handle(request, response).block();
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
assertThat(exceptionHandler.ex).isNotNull();
assertThat(exceptionHandler.ex.getMessage()).isEqualTo("boo");
}
use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse 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());
}
use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse in project spring-framework by spring-projects.
the class ContextPathCompositeHandlerTests method testHandle.
private ServerHttpResponse testHandle(String pathToHandle, Map<String, HttpHandler> handlerMap) {
ServerHttpRequest request = MockServerHttpRequest.get(pathToHandle).build();
ServerHttpResponse response = new MockServerHttpResponse();
new ContextPathCompositeHandler(handlerMap).handle(request, response).block(Duration.ofSeconds(5));
return response;
}
Aggregations