Search in sources :

Example 6 with RequestMappingInfo

use of org.springframework.web.reactive.result.method.RequestMappingInfo in project spring-framework by spring-projects.

the class RequestMappingInfoTests method matchConsumesCondition.

@Test
public void matchConsumesCondition() {
    ServerWebExchange exchange = MockServerHttpRequest.post("/foo").contentType(MediaType.TEXT_PLAIN).toExchange();
    RequestMappingInfo info = paths("/foo").consumes("text/plain").build();
    RequestMappingInfo match = info.getMatchingCondition(exchange);
    assertNotNull(match);
    info = paths("/foo").consumes("application/xml").build();
    match = info.getMatchingCondition(exchange);
    assertNull(match);
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange) RequestMappingInfo(org.springframework.web.reactive.result.method.RequestMappingInfo) Test(org.junit.Test)

Example 7 with RequestMappingInfo

use of org.springframework.web.reactive.result.method.RequestMappingInfo in project spring-framework by spring-projects.

the class RequestMappingInfoTests method preFlightRequest.

@Test
@Ignore
public void preFlightRequest() throws Exception {
    MockServerWebExchange exchange = MockServerHttpRequest.options("/foo").header("Origin", "http://domain.com").header(HttpHeaders.ACCESS_CONTROL_REQUEST_HEADERS, "POST").toExchange();
    RequestMappingInfo info = paths("/foo").methods(RequestMethod.POST).build();
    RequestMappingInfo match = info.getMatchingCondition(exchange);
    assertNotNull(match);
    info = paths("/foo").methods(RequestMethod.OPTIONS).build();
    match = info.getMatchingCondition(exchange);
    assertNull("Pre-flight should match the ACCESS_CONTROL_REQUEST_METHOD", match);
}
Also used : RequestMappingInfo(org.springframework.web.reactive.result.method.RequestMappingInfo) MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with RequestMappingInfo

use of org.springframework.web.reactive.result.method.RequestMappingInfo in project spring-framework by spring-projects.

the class RequestMappingInfoTests method matchPatternsCondition.

@Test
public void matchPatternsCondition() {
    MockServerWebExchange exchange = MockServerHttpRequest.get("/foo").toExchange();
    RequestMappingInfo info = paths("/foo*", "/bar").build();
    RequestMappingInfo expected = paths("/foo*").build();
    assertEquals(expected, info.getMatchingCondition(exchange));
    info = paths("/**", "/foo*", "/foo").build();
    expected = paths("/foo", "/foo*", "/**").build();
    assertEquals(expected, info.getMatchingCondition(exchange));
}
Also used : RequestMappingInfo(org.springframework.web.reactive.result.method.RequestMappingInfo) MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange) Test(org.junit.Test)

Example 9 with RequestMappingInfo

use of org.springframework.web.reactive.result.method.RequestMappingInfo in project spring-framework by spring-projects.

the class RequestMappingInfoTests method matchParamsCondition.

@Test
public void matchParamsCondition() {
    ServerWebExchange exchange = MockServerHttpRequest.get("/foo?foo=bar").toExchange();
    RequestMappingInfo info = paths("/foo").params("foo=bar").build();
    RequestMappingInfo match = info.getMatchingCondition(exchange);
    assertNotNull(match);
    info = paths("/foo").params("foo!=bar").build();
    match = info.getMatchingCondition(exchange);
    assertNull(match);
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange) RequestMappingInfo(org.springframework.web.reactive.result.method.RequestMappingInfo) Test(org.junit.Test)

Example 10 with RequestMappingInfo

use of org.springframework.web.reactive.result.method.RequestMappingInfo in project spring-framework by spring-projects.

the class RequestMappingInfoTests method matchHeadersCondition.

@Test
public void matchHeadersCondition() {
    ServerWebExchange exchange = MockServerHttpRequest.get("/foo").header("foo", "bar").toExchange();
    RequestMappingInfo info = paths("/foo").headers("foo=bar").build();
    RequestMappingInfo match = info.getMatchingCondition(exchange);
    assertNotNull(match);
    info = paths("/foo").headers("foo!=bar").build();
    match = info.getMatchingCondition(exchange);
    assertNull(match);
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange) RequestMappingInfo(org.springframework.web.reactive.result.method.RequestMappingInfo) Test(org.junit.Test)

Aggregations

RequestMappingInfo (org.springframework.web.reactive.result.method.RequestMappingInfo)13 Test (org.junit.Test)12 MockServerWebExchange (org.springframework.mock.http.server.reactive.test.MockServerWebExchange)8 ServerWebExchange (org.springframework.web.server.ServerWebExchange)6 Ignore (org.junit.Ignore)2 RequestMethod (org.springframework.web.bind.annotation.RequestMethod)2 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertFalse (org.junit.Assert.assertFalse)1 Assert.assertNotEquals (org.junit.Assert.assertNotEquals)1 Assert.assertNotNull (org.junit.Assert.assertNotNull)1 Assert.assertNull (org.junit.Assert.assertNull)1 HttpHeaders (org.springframework.http.HttpHeaders)1 MediaType (org.springframework.http.MediaType)1 MockServerHttpRequest (org.springframework.mock.http.server.reactive.test.MockServerHttpRequest)1