Search in sources :

Example 41 with ServerWebExchange

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

the class RequestMethodsRequestConditionTests method testMatch.

private void testMatch(RequestMethodsRequestCondition condition, RequestMethod method) throws Exception {
    ServerWebExchange exchange = getExchange(method.name());
    RequestMethodsRequestCondition actual = condition.getMatchingCondition(exchange);
    assertNotNull(actual);
    assertEquals(Collections.singleton(method), actual.getContent());
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange)

Example 42 with ServerWebExchange

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

the class RequestMethodsRequestConditionTests method testNoMatch.

private void testNoMatch(RequestMethodsRequestCondition condition, RequestMethod method) throws Exception {
    ServerWebExchange exchange = getExchange(method.name());
    assertNull(condition.getMatchingCondition(exchange));
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange)

Example 43 with ServerWebExchange

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

the class RequestMethodsRequestConditionTests method getMatchingConditionWithEmptyConditions.

@Test
public void getMatchingConditionWithEmptyConditions() throws Exception {
    RequestMethodsRequestCondition condition = new RequestMethodsRequestCondition();
    for (RequestMethod method : RequestMethod.values()) {
        if (!OPTIONS.equals(method)) {
            ServerWebExchange exchange = getExchange(method.name());
            assertNotNull(condition.getMatchingCondition(exchange));
        }
    }
    testNoMatch(condition, OPTIONS);
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) Test(org.junit.Test)

Example 44 with ServerWebExchange

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

the class RequestMappingInfoHandlerMappingTests method handleMatchMatrixVariablesDecoding.

@Test
public void handleMatchMatrixVariablesDecoding() throws Exception {
    HttpRequestPathHelper urlPathHelper = new HttpRequestPathHelper();
    urlPathHelper.setUrlDecode(false);
    this.handlerMapping.setPathHelper(urlPathHelper);
    ServerWebExchange exchange = get("/").toExchange();
    handleMatch(exchange, "/path{filter}", "/path;mvar=a%2fb");
    MultiValueMap<String, String> matrixVariables = getMatrixVariables(exchange, "filter");
    Map<String, String> uriVariables = getUriTemplateVariables(exchange);
    assertNotNull(matrixVariables);
    assertEquals(Collections.singletonList("a/b"), matrixVariables.get("mvar"));
    assertEquals(";mvar=a/b", uriVariables.get("filter"));
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) HttpRequestPathHelper(org.springframework.web.server.support.HttpRequestPathHelper) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 45 with ServerWebExchange

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

the class RequestMappingInfoHandlerMappingTests method getHandlerTestInvalidContentType.

@Test
public void getHandlerTestInvalidContentType() throws Exception {
    ServerWebExchange exchange = MockServerHttpRequest.put("/person/1").header("content-type", "bogus").toExchange();
    Mono<Object> mono = this.handlerMapping.getHandler(exchange);
    assertError(mono, UnsupportedMediaTypeStatusException.class, ex -> assertEquals("Request failure [status: 415, " + "reason: \"Invalid mime type \"bogus\": does not contain '/'\"]", ex.getMessage()));
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) 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