Search in sources :

Example 6 with MockServerHttpResponse

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;
}
Also used : MockServerHttpRequest(org.springframework.mock.http.server.reactive.test.MockServerHttpRequest) MockServerHttpResponse(org.springframework.mock.http.server.reactive.test.MockServerHttpResponse) MockServerHttpResponse(org.springframework.mock.http.server.reactive.test.MockServerHttpResponse)

Example 7 with MockServerHttpResponse

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));
}
Also used : HttpHandler(org.springframework.http.server.reactive.HttpHandler) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) MockServerHttpRequest(org.springframework.mock.http.server.reactive.test.MockServerHttpRequest) MockServerHttpResponse(org.springframework.mock.http.server.reactive.test.MockServerHttpResponse) Test(org.junit.Test)

Example 8 with MockServerHttpResponse

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());
}
Also used : MockServerHttpRequest(org.springframework.mock.http.server.reactive.test.MockServerHttpRequest) MockServerHttpResponse(org.springframework.mock.http.server.reactive.test.MockServerHttpResponse) Test(org.junit.Test)

Example 9 with MockServerHttpResponse

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);
}
Also used : DefaultServerWebExchange(org.springframework.web.server.adapter.DefaultServerWebExchange) MockServerHttpRequest(org.springframework.mock.http.server.reactive.test.MockServerHttpRequest) MockServerHttpResponse(org.springframework.mock.http.server.reactive.test.MockServerHttpResponse) Before(org.junit.Before)

Example 10 with MockServerHttpResponse

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();
}
Also used : ReactiveHttpOutputMessage(org.springframework.http.ReactiveHttpOutputMessage) DefaultDataBufferFactory(org.springframework.core.io.buffer.DefaultDataBufferFactory) Flux(reactor.core.publisher.Flux) MockServerHttpResponse(org.springframework.mock.http.server.reactive.test.MockServerHttpResponse) ByteBuffer(java.nio.ByteBuffer) DefaultDataBuffer(org.springframework.core.io.buffer.DefaultDataBuffer) DataBuffer(org.springframework.core.io.buffer.DataBuffer) Test(org.junit.Test)

Aggregations

MockServerHttpResponse (org.springframework.mock.http.server.reactive.test.MockServerHttpResponse)42 Test (org.junit.Test)37 MockServerHttpRequest (org.springframework.mock.http.server.reactive.test.MockServerHttpRequest)14 HttpHandler (org.springframework.http.server.reactive.HttpHandler)9 HttpHeaders (org.springframework.http.HttpHeaders)8 HttpStatus (org.springframework.http.HttpStatus)8 ServerWebExchange (org.springframework.web.server.ServerWebExchange)8 Mono (reactor.core.publisher.Mono)8 StepVerifier (reactor.test.StepVerifier)8 MediaType (org.springframework.http.MediaType)7 Assert (org.junit.Assert)6 Mockito (org.mockito.Mockito)6 ReactiveHttpOutputMessage (org.springframework.http.ReactiveHttpOutputMessage)6 ResponseStatusException (org.springframework.web.server.ResponseStatusException)6 HashMap (java.util.HashMap)5 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)4 MockServerWebExchange (org.springframework.mock.http.server.reactive.test.MockServerWebExchange)4 Flux (reactor.core.publisher.Flux)4 Before (org.junit.Before)3 DataBuffer (org.springframework.core.io.buffer.DataBuffer)3