Search in sources :

Example 76 with MockServerWebExchange

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

the class RequestHeaderMethodArgumentResolverTests method resolveDefaultValue.

@Test
public void resolveDefaultValue() {
    MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
    Mono<Object> mono = this.resolver.resolveArgument(this.paramNamedDefaultValueStringHeader, this.bindingContext, exchange);
    Object result = mono.block();
    boolean condition = result instanceof String;
    assertThat(condition).isTrue();
    assertThat(result).isEqualTo("bar");
}
Also used : MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) Test(org.junit.jupiter.api.Test)

Example 77 with MockServerWebExchange

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

the class CookieValueMethodArgumentResolverTests method resolveCookieStringArgument.

@Test
public void resolveCookieStringArgument() {
    HttpCookie cookie = new HttpCookie("name", "foo");
    MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").cookie(cookie));
    Mono<Object> mono = this.resolver.resolveArgument(this.cookieStringParameter, this.bindingContext, exchange);
    assertThat(mono.block()).as("Invalid result").isEqualTo(cookie.getValue());
}
Also used : MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) HttpCookie(org.springframework.http.HttpCookie) Test(org.junit.jupiter.api.Test)

Example 78 with MockServerWebExchange

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

the class InitBinderBindingContextTests method createBinderWithAttrName.

@Test
public void createBinderWithAttrName() throws Exception {
    MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
    BindingContext context = createBindingContext("initBinderWithAttributeName", WebDataBinder.class);
    WebDataBinder dataBinder = context.createDataBinder(exchange, null, "foo");
    assertThat(dataBinder.getDisallowedFields()).isNotNull();
    assertThat(dataBinder.getDisallowedFields()[0]).isEqualTo("id");
}
Also used : WebDataBinder(org.springframework.web.bind.WebDataBinder) MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) BindingContext(org.springframework.web.reactive.BindingContext) Test(org.junit.jupiter.api.Test)

Example 79 with MockServerWebExchange

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

the class InitBinderBindingContextTests method returnValueNotExpected.

@Test
public void returnValueNotExpected() throws Exception {
    MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
    BindingContext context = createBindingContext("initBinderReturnValue", WebDataBinder.class);
    assertThatIllegalStateException().isThrownBy(() -> context.createDataBinder(exchange, null, "invalidName"));
}
Also used : MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) BindingContext(org.springframework.web.reactive.BindingContext) Test(org.junit.jupiter.api.Test)

Example 80 with MockServerWebExchange

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

the class InitBinderBindingContextTests method createBinder.

@Test
public void createBinder() throws Exception {
    MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
    BindingContext context = createBindingContext("initBinder", WebDataBinder.class);
    WebDataBinder dataBinder = context.createDataBinder(exchange, null, null);
    assertThat(dataBinder.getDisallowedFields()).isNotNull();
    assertThat(dataBinder.getDisallowedFields()[0]).isEqualTo("id");
}
Also used : WebDataBinder(org.springframework.web.bind.WebDataBinder) MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) BindingContext(org.springframework.web.reactive.BindingContext) Test(org.junit.jupiter.api.Test)

Aggregations

MockServerWebExchange (org.springframework.web.testfixture.server.MockServerWebExchange)224 Test (org.junit.jupiter.api.Test)216 MockServerHttpRequest (org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest)61 ClassPathResource (org.springframework.core.io.ClassPathResource)26 HttpHeaders (org.springframework.http.HttpHeaders)25 Resource (org.springframework.core.io.Resource)24 HandlerResult (org.springframework.web.reactive.HandlerResult)23 MethodParameter (org.springframework.core.MethodParameter)22 MockServerHttpResponse (org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse)22 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)19 MediaType (org.springframework.http.MediaType)19 Mono (reactor.core.publisher.Mono)18 BeforeEach (org.junit.jupiter.api.BeforeEach)17 HttpMethod (org.springframework.http.HttpMethod)15 StepVerifier (reactor.test.StepVerifier)13 Arrays (java.util.Arrays)12 Collections (java.util.Collections)12 List (java.util.List)12 HttpStatus (org.springframework.http.HttpStatus)12 IOException (java.io.IOException)10