Search in sources :

Example 86 with MockServerHttpRequest

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

the class RequestMappingInfoHandlerMappingTests method getHandlerTestInvalidContentType.

@Test
public void getHandlerTestInvalidContentType() {
    MockServerHttpRequest request = put("/person/1").header("content-type", "bogus").build();
    ServerWebExchange exchange = MockServerWebExchange.from(request);
    Mono<Object> mono = this.handlerMapping.getHandler(exchange);
    assertError(mono, UnsupportedMediaTypeStatusException.class, ex -> assertThat(ex.getMessage()).isEqualTo(("415 UNSUPPORTED_MEDIA_TYPE " + "\"Invalid mime type \"bogus\": does not contain '/'\"")));
}
Also used : MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) ServerWebExchange(org.springframework.web.server.ServerWebExchange) MockServerHttpRequest(org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest) Test(org.junit.jupiter.api.Test)

Example 87 with MockServerHttpRequest

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

the class RequestMappingInfoHandlerMappingTests method handleMatchMatrixVariablesDecoding.

@Test
public void handleMatchMatrixVariablesDecoding() {
    MockServerHttpRequest request = method(HttpMethod.GET, URI.create("/cars;mvar=a%2Fb")).build();
    ServerWebExchange exchange = MockServerWebExchange.from(request);
    handleMatch(exchange, "/{cars}");
    MultiValueMap<String, String> matrixVariables = getMatrixVariables(exchange, "cars");
    Map<String, String> uriVariables = getUriTemplateVariables(exchange);
    assertThat(matrixVariables).isNotNull();
    assertThat(matrixVariables.get("mvar")).isEqualTo(Collections.singletonList("a/b"));
    assertThat(uriVariables.get("cars")).isEqualTo("cars");
}
Also used : MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) ServerWebExchange(org.springframework.web.server.ServerWebExchange) MockServerHttpRequest(org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest) Test(org.junit.jupiter.api.Test)

Example 88 with MockServerHttpRequest

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

the class RequestParamMethodArgumentResolverTests method resolveSimpleTypeParam.

@Test
public void resolveSimpleTypeParam() {
    MockServerHttpRequest request = MockServerHttpRequest.get("/path?stringNotAnnot=plainValue").build();
    ServerWebExchange exchange = MockServerWebExchange.from(request);
    MethodParameter param = this.testMethod.annotNotPresent(RequestParam.class).arg(String.class);
    Object result = resolve(param, exchange);
    assertThat(result).isEqualTo("plainValue");
}
Also used : MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) ServerWebExchange(org.springframework.web.server.ServerWebExchange) RequestParam(org.springframework.web.bind.annotation.RequestParam) MockServerHttpRequest(org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest) MethodParameter(org.springframework.core.MethodParameter) Test(org.junit.jupiter.api.Test)

Example 89 with MockServerHttpRequest

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

the class RequestParamMethodArgumentResolverTests method resolveEmptyValueWithoutDefault.

@Test
public void resolveEmptyValueWithoutDefault() {
    MethodParameter param = this.testMethod.annotNotPresent(RequestParam.class).arg(String.class);
    MockServerHttpRequest request = MockServerHttpRequest.get("/path?stringNotAnnot=").build();
    assertThat(resolve(param, MockServerWebExchange.from(request))).isEqualTo("");
}
Also used : RequestParam(org.springframework.web.bind.annotation.RequestParam) MockServerHttpRequest(org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest) MethodParameter(org.springframework.core.MethodParameter) Test(org.junit.jupiter.api.Test)

Example 90 with MockServerHttpRequest

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

the class RequestParamMethodArgumentResolverTests method resolveStringArray.

@Test
public void resolveStringArray() {
    MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(String[].class);
    MockServerHttpRequest request = MockServerHttpRequest.get("/path?name=foo&name=bar").build();
    Object result = resolve(param, MockServerWebExchange.from(request));
    boolean condition = result instanceof String[];
    assertThat(condition).isTrue();
    assertThat((String[]) result).isEqualTo(new String[] { "foo", "bar" });
}
Also used : RequestParam(org.springframework.web.bind.annotation.RequestParam) MockServerHttpRequest(org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest) MethodParameter(org.springframework.core.MethodParameter) Test(org.junit.jupiter.api.Test)

Aggregations

MockServerHttpRequest (org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest)182 Test (org.junit.jupiter.api.Test)160 MockServerWebExchange (org.springframework.web.testfixture.server.MockServerWebExchange)101 Mono (reactor.core.publisher.Mono)52 DataBuffer (org.springframework.core.io.buffer.DataBuffer)51 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)50 Collections (java.util.Collections)48 StepVerifier (reactor.test.StepVerifier)46 HttpHeaders (org.springframework.http.HttpHeaders)39 Flux (reactor.core.publisher.Flux)37 MediaType (org.springframework.http.MediaType)34 ServerWebExchange (org.springframework.web.server.ServerWebExchange)34 MultiValueMap (org.springframework.util.MultiValueMap)33 HttpStatus (org.springframework.http.HttpStatus)31 StandardCharsets (java.nio.charset.StandardCharsets)29 MockServerHttpResponse (org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse)29 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)27 ClassPathResource (org.springframework.core.io.ClassPathResource)25 DefaultDataBuffer (org.springframework.core.io.buffer.DefaultDataBuffer)24 Optional (java.util.Optional)23