Search in sources :

Example 11 with MockServerHttpRequest

use of org.springframework.mock.http.server.reactive.test.MockServerHttpRequest in project spring-framework by spring-projects.

the class CorsUtilsTests method isCorsRequest.

@Test
public void isCorsRequest() {
    MockServerHttpRequest request = get("/").header(HttpHeaders.ORIGIN, "http://domain.com").build();
    assertTrue(CorsUtils.isCorsRequest(request));
}
Also used : MockServerHttpRequest(org.springframework.mock.http.server.reactive.test.MockServerHttpRequest) Test(org.junit.Test)

Example 12 with MockServerHttpRequest

use of org.springframework.mock.http.server.reactive.test.MockServerHttpRequest in project spring-framework by spring-projects.

the class CorsUtilsTests method isPreFlightRequest.

@Test
public void isPreFlightRequest() {
    MockServerHttpRequest request = options("/").header(HttpHeaders.ORIGIN, "http://domain.com").header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET").build();
    assertTrue(CorsUtils.isPreFlightRequest(request));
}
Also used : MockServerHttpRequest(org.springframework.mock.http.server.reactive.test.MockServerHttpRequest) Test(org.junit.Test)

Example 13 with MockServerHttpRequest

use of org.springframework.mock.http.server.reactive.test.MockServerHttpRequest in project spring-framework by spring-projects.

the class CorsUtilsTests method isNotCorsRequest.

@Test
public void isNotCorsRequest() {
    MockServerHttpRequest request = get("/").build();
    assertFalse(CorsUtils.isCorsRequest(request));
}
Also used : MockServerHttpRequest(org.springframework.mock.http.server.reactive.test.MockServerHttpRequest) Test(org.junit.Test)

Example 14 with MockServerHttpRequest

use of org.springframework.mock.http.server.reactive.test.MockServerHttpRequest in project spring-framework by spring-projects.

the class WebHttpHandlerBuilderTests method orderedWebExceptionHandlerBeans.

// SPR-15074
@Test
public void orderedWebExceptionHandlerBeans() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    context.register(OrderedExceptionHandlerBeanConfig.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("ExceptionHandlerB", 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 15 with MockServerHttpRequest

use of org.springframework.mock.http.server.reactive.test.MockServerHttpRequest in project spring-framework by spring-projects.

the class WebHttpHandlerBuilderTests method configWithoutFilters.

@Test
public void configWithoutFilters() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    context.register(NoFilterConfig.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("handled", 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)

Aggregations

MockServerHttpRequest (org.springframework.mock.http.server.reactive.test.MockServerHttpRequest)34 Test (org.junit.Test)33 Mono (reactor.core.publisher.Mono)14 MockServerHttpResponse (org.springframework.mock.http.server.reactive.test.MockServerHttpResponse)12 StepVerifier (reactor.test.StepVerifier)11 HttpHandler (org.springframework.http.server.reactive.HttpHandler)9 Flux (reactor.core.publisher.Flux)8 Assert (org.junit.Assert)7 DataBuffer (org.springframework.core.io.buffer.DataBuffer)7 DefaultDataBuffer (org.springframework.core.io.buffer.DefaultDataBuffer)7 DefaultDataBufferFactory (org.springframework.core.io.buffer.DefaultDataBufferFactory)7 Mockito (org.mockito.Mockito)6 HttpHeaders (org.springframework.http.HttpHeaders)6 HttpStatus (org.springframework.http.HttpStatus)6 ReactiveHttpInputMessage (org.springframework.http.ReactiveHttpInputMessage)6 ResponseStatusException (org.springframework.web.server.ResponseStatusException)6 ServerWebExchange (org.springframework.web.server.ServerWebExchange)6 Collections (java.util.Collections)5 MediaType (org.springframework.http.MediaType)5 Jackson2JsonDecoder (org.springframework.http.codec.json.Jackson2JsonDecoder)5