Search in sources :

Example 61 with ServerWebExchange

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

the class InitBinderBindingContextTests method createBinder.

@Test
public void createBinder() throws Exception {
    ServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
    BindingContext context = createBindingContext("initBinder", WebDataBinder.class);
    WebDataBinder dataBinder = context.createDataBinder(exchange, null, null);
    assertNotNull(dataBinder.getDisallowedFields());
    assertEquals("id", dataBinder.getDisallowedFields()[0]);
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) WebDataBinder(org.springframework.web.bind.WebDataBinder) BindingContext(org.springframework.web.reactive.BindingContext) Test(org.junit.Test)

Example 62 with ServerWebExchange

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

the class InitBinderBindingContextTests method createBinderWithAttrName.

@Test
public void createBinderWithAttrName() throws Exception {
    ServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
    BindingContext context = createBindingContext("initBinderWithAttributeName", WebDataBinder.class);
    WebDataBinder dataBinder = context.createDataBinder(exchange, null, "foo");
    assertNotNull(dataBinder.getDisallowedFields());
    assertEquals("id", dataBinder.getDisallowedFields()[0]);
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) WebDataBinder(org.springframework.web.bind.WebDataBinder) BindingContext(org.springframework.web.reactive.BindingContext) Test(org.junit.Test)

Example 63 with ServerWebExchange

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

the class RequestBodyArgumentResolverTests method resolveValue.

@SuppressWarnings("unchecked")
private <T> T resolveValue(MethodParameter param, String body) {
    ServerWebExchange exchange = MockServerHttpRequest.post("/path").body(body).toExchange();
    Mono<Object> result = this.resolver.readBody(param, true, new BindingContext(), exchange);
    Object value = result.block(Duration.ofSeconds(5));
    assertNotNull(value);
    assertTrue("Unexpected return value type: " + value, param.getParameterType().isAssignableFrom(value.getClass()));
    //no inspection unchecked
    return (T) value;
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) BindingContext(org.springframework.web.reactive.BindingContext)

Example 64 with ServerWebExchange

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

the class RequestHeaderMethodArgumentResolverTests method resolveNameFromSystemPropertyThroughPlaceholder.

@Test
public void resolveNameFromSystemPropertyThroughPlaceholder() throws Exception {
    String expected = "foo";
    ServerWebExchange exchange = MockServerHttpRequest.get("/").header("bar", expected).toExchange();
    System.setProperty("systemProperty", "bar");
    try {
        Mono<Object> mono = this.resolver.resolveArgument(this.paramResolvedNameWithPlaceholder, this.bindingContext, exchange);
        Object result = mono.block();
        assertTrue(result instanceof String);
        assertEquals(expected, result);
    } finally {
        System.clearProperty("systemProperty");
    }
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange) Test(org.junit.Test)

Example 65 with ServerWebExchange

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

the class RequestHeaderMethodArgumentResolverTests method resolveStringArgument.

@Test
public void resolveStringArgument() throws Exception {
    String expected = "foo";
    ServerWebExchange exchange = MockServerHttpRequest.get("/").header("name", expected).toExchange();
    Mono<Object> mono = this.resolver.resolveArgument(this.paramNamedDefaultValueStringHeader, this.bindingContext, exchange);
    Object result = mono.block();
    assertTrue(result instanceof String);
    assertEquals(expected, result);
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange) 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