use of org.springframework.mock.http.server.reactive.test.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);
return response;
}
use of org.springframework.mock.http.server.reactive.test.MockServerHttpResponse in project spring-framework by spring-projects.
the class WebHttpHandlerBuilderTests method orderedWebFilterBeans.
// SPR-15074
@Test
public void orderedWebFilterBeans() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.register(OrderedWebFilterBeanConfig.class);
context.refresh();
HttpHandler httpHandler = WebHttpHandlerBuilder.applicationContext(context).build();
MockServerHttpRequest request = MockServerHttpRequest.get("/").build();
MockServerHttpResponse response = new MockServerHttpResponse();
httpHandler.handle(request, response).blockMillis(5000);
assertEquals("FilterB::FilterA", response.getBodyAsString().blockMillis(5000));
}
use of org.springframework.mock.http.server.reactive.test.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()).filters(Collections.singletonList(new ExceptionFilter())).exceptionHandlers(Collections.singletonList(exceptionHandler)).build().handle(request, response).block();
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
assertNotNull(exceptionHandler.ex);
assertEquals("boo", exceptionHandler.ex.getMessage());
}
use of org.springframework.mock.http.server.reactive.test.MockServerHttpResponse in project spring-framework by spring-projects.
the class DefaultWebSessionManagerTests method setUp.
@Before
public void setUp() throws Exception {
this.manager = new DefaultWebSessionManager();
this.idResolver = new TestWebSessionIdResolver();
this.manager.setSessionIdResolver(this.idResolver);
MockServerHttpRequest request = MockServerHttpRequest.get("/path").build();
MockServerHttpResponse response = new MockServerHttpResponse();
this.exchange = new DefaultServerWebExchange(request, response, this.manager);
}
use of org.springframework.mock.http.server.reactive.test.MockServerHttpResponse in project spring-framework by spring-projects.
the class BodyInsertersTests method ofPublisher.
@Test
public void ofPublisher() throws Exception {
Flux<String> body = Flux.just("foo");
BodyInserter<Flux<String>, ReactiveHttpOutputMessage> inserter = BodyInserters.fromPublisher(body, String.class);
MockServerHttpResponse response = new MockServerHttpResponse();
Mono<Void> result = inserter.insert(response, this.context);
StepVerifier.create(result).expectComplete().verify();
ByteBuffer byteBuffer = ByteBuffer.wrap("foo".getBytes(UTF_8));
DataBuffer buffer = new DefaultDataBufferFactory().wrap(byteBuffer);
StepVerifier.create(response.getBody()).expectNext(buffer).expectComplete().verify();
}
Aggregations