Search in sources :

Example 56 with ServerWebExchange

use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.

the class HttpEntityArgumentResolverTests method httpEntityWithSingleBody.

@Test
public void httpEntityWithSingleBody() throws Exception {
    ServerWebExchange exchange = postExchange("line1");
    ResolvableType type = httpEntityType(Single.class, String.class);
    HttpEntity<Single<String>> httpEntity = resolveValue(exchange, type);
    assertEquals(exchange.getRequest().getHeaders(), httpEntity.getHeaders());
    assertEquals("line1", httpEntity.getBody().toBlocking().value());
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange) Single(rx.Single) ResolvableType(org.springframework.core.ResolvableType) Test(org.junit.Test)

Example 57 with ServerWebExchange

use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.

the class HttpEntityArgumentResolverTests method httpEntityWithRxJava2SingleBody.

@Test
public void httpEntityWithRxJava2SingleBody() throws Exception {
    ServerWebExchange exchange = postExchange("line1");
    ResolvableType type = httpEntityType(io.reactivex.Single.class, String.class);
    HttpEntity<io.reactivex.Single<String>> httpEntity = resolveValue(exchange, type);
    assertEquals(exchange.getRequest().getHeaders(), httpEntity.getHeaders());
    assertEquals("line1", httpEntity.getBody().blockingGet());
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange) Single(rx.Single) ResolvableType(org.springframework.core.ResolvableType) Test(org.junit.Test)

Example 58 with ServerWebExchange

use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.

the class HttpEntityArgumentResolverTests method httpEntityWithStringBody.

@Test
public void httpEntityWithStringBody() throws Exception {
    ServerWebExchange exchange = postExchange("line1");
    ResolvableType type = httpEntityType(String.class);
    HttpEntity<String> httpEntity = resolveValue(exchange, type);
    assertEquals(exchange.getRequest().getHeaders(), httpEntity.getHeaders());
    assertEquals("line1", httpEntity.getBody());
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange) ResolvableType(org.springframework.core.ResolvableType) Test(org.junit.Test)

Example 59 with ServerWebExchange

use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.

the class HttpEntityArgumentResolverTests method httpEntityWithFluxBody.

@Test
public void httpEntityWithFluxBody() throws Exception {
    ServerWebExchange exchange = postExchange("line1\nline2\nline3\n");
    ResolvableType type = httpEntityType(Flux.class, String.class);
    HttpEntity<Flux<String>> httpEntity = resolveValue(exchange, type);
    assertEquals(exchange.getRequest().getHeaders(), httpEntity.getHeaders());
    StepVerifier.create(httpEntity.getBody()).expectNext("line1\n").expectNext("line2\n").expectNext("line3\n").expectComplete().verify();
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange) Flux(reactor.core.publisher.Flux) ResolvableType(org.springframework.core.ResolvableType) Test(org.junit.Test)

Example 60 with ServerWebExchange

use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.

the class InitBinderBindingContextTests method returnValueNotExpected.

@Test(expected = IllegalStateException.class)
public void returnValueNotExpected() throws Exception {
    ServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
    BindingContext context = createBindingContext("initBinderReturnValue", WebDataBinder.class);
    context.createDataBinder(exchange, null, "invalidName");
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) BindingContext(org.springframework.web.reactive.BindingContext) Test(org.junit.Test)

Aggregations

ServerWebExchange (org.springframework.web.server.ServerWebExchange)158 Test (org.junit.Test)138 MockServerWebExchange (org.springframework.mock.http.server.reactive.test.MockServerWebExchange)53 Mono (reactor.core.publisher.Mono)22 ServerHttpResponse (org.springframework.http.server.reactive.ServerHttpResponse)20 MediaType (org.springframework.http.MediaType)18 BindingContext (org.springframework.web.reactive.BindingContext)17 MethodParameter (org.springframework.core.MethodParameter)15 List (java.util.List)14 ResolvableType (org.springframework.core.ResolvableType)14 Map (java.util.Map)12 Collections (java.util.Collections)11 HttpStatus (org.springframework.http.HttpStatus)11 StepVerifier (reactor.test.StepVerifier)11 Assert.assertEquals (org.junit.Assert.assertEquals)10 MockServerHttpRequest (org.springframework.mock.http.server.reactive.test.MockServerHttpRequest)10 ResponseStatusException (org.springframework.web.server.ResponseStatusException)9 ServerWebInputException (org.springframework.web.server.ServerWebInputException)9 ReactiveAdapterRegistry (org.springframework.core.ReactiveAdapterRegistry)8 NotAcceptableStatusException (org.springframework.web.server.NotAcceptableStatusException)8