Search in sources :

Example 1 with RequestMappingInfo

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

the class RequestMappingInfoTests method equals.

@Test
public void equals() {
    RequestMappingInfo info1 = paths("/foo").methods(RequestMethod.GET).params("foo=bar").headers("foo=bar").consumes("text/plain").produces("text/plain").customCondition(new ParamsRequestCondition("customFoo=customBar")).build();
    RequestMappingInfo info2 = paths("/foo").methods(RequestMethod.GET).params("foo=bar").headers("foo=bar").consumes("text/plain").produces("text/plain").customCondition(new ParamsRequestCondition("customFoo=customBar")).build();
    assertEquals(info1, info2);
    assertEquals(info1.hashCode(), info2.hashCode());
    info2 = paths("/foo", "/NOOOOOO").methods(RequestMethod.GET).params("foo=bar").headers("foo=bar").consumes("text/plain").produces("text/plain").customCondition(new ParamsRequestCondition("customFoo=customBar")).build();
    assertFalse(info1.equals(info2));
    assertNotEquals(info1.hashCode(), info2.hashCode());
    info2 = paths("/foo").methods(RequestMethod.GET, RequestMethod.POST).params("foo=bar").headers("foo=bar").consumes("text/plain").produces("text/plain").customCondition(new ParamsRequestCondition("customFoo=customBar")).build();
    assertFalse(info1.equals(info2));
    assertNotEquals(info1.hashCode(), info2.hashCode());
    info2 = paths("/foo").methods(RequestMethod.GET).params("/NOOOOOO").headers("foo=bar").consumes("text/plain").produces("text/plain").customCondition(new ParamsRequestCondition("customFoo=customBar")).build();
    assertFalse(info1.equals(info2));
    assertNotEquals(info1.hashCode(), info2.hashCode());
    info2 = paths("/foo").methods(RequestMethod.GET).params("foo=bar").headers("/NOOOOOO").consumes("text/plain").produces("text/plain").customCondition(new ParamsRequestCondition("customFoo=customBar")).build();
    assertFalse(info1.equals(info2));
    assertNotEquals(info1.hashCode(), info2.hashCode());
    info2 = paths("/foo").methods(RequestMethod.GET).params("foo=bar").headers("foo=bar").consumes("text/NOOOOOO").produces("text/plain").customCondition(new ParamsRequestCondition("customFoo=customBar")).build();
    assertFalse(info1.equals(info2));
    assertNotEquals(info1.hashCode(), info2.hashCode());
    info2 = paths("/foo").methods(RequestMethod.GET).params("foo=bar").headers("foo=bar").consumes("text/plain").produces("text/NOOOOOO").customCondition(new ParamsRequestCondition("customFoo=customBar")).build();
    assertFalse(info1.equals(info2));
    assertNotEquals(info1.hashCode(), info2.hashCode());
    info2 = paths("/foo").methods(RequestMethod.GET).params("foo=bar").headers("foo=bar").consumes("text/plain").produces("text/plain").customCondition(new ParamsRequestCondition("customFoo=NOOOOOO")).build();
    assertFalse(info1.equals(info2));
    assertNotEquals(info1.hashCode(), info2.hashCode());
}
Also used : RequestMappingInfo(org.springframework.web.reactive.result.method.RequestMappingInfo) Test(org.junit.Test)

Example 2 with RequestMappingInfo

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

the class RequestMappingInfoTests method matchCustomCondition.

@Test
public void matchCustomCondition() {
    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").customCondition(new ParamsRequestCondition("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 3 with RequestMappingInfo

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

the class RequestMappingInfoTests method compareTwoHttpMethodsOneParam.

@Test
public void compareTwoHttpMethodsOneParam() {
    RequestMappingInfo none = paths().build();
    RequestMappingInfo oneMethod = paths().methods(RequestMethod.GET).build();
    RequestMappingInfo oneMethodOneParam = paths().methods(RequestMethod.GET).params("foo").build();
    ServerWebExchange exchange = MockServerHttpRequest.get("/foo").toExchange();
    Comparator<RequestMappingInfo> comparator = (info, otherInfo) -> info.compareTo(otherInfo, exchange);
    List<RequestMappingInfo> list = asList(none, oneMethod, oneMethodOneParam);
    Collections.shuffle(list);
    list.sort(comparator);
    assertEquals(oneMethodOneParam, list.get(0));
    assertEquals(oneMethod, list.get(1));
    assertEquals(none, list.get(2));
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) Assert.assertNotNull(org.junit.Assert.assertNotNull) MediaType(org.springframework.http.MediaType) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) Test(org.junit.Test) RequestMappingInfo.paths(org.springframework.web.reactive.result.method.RequestMappingInfo.paths) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) ServerWebExchange(org.springframework.web.server.ServerWebExchange) List(java.util.List) MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange) MockServerHttpRequest(org.springframework.mock.http.server.reactive.test.MockServerHttpRequest) Assert.assertNull(org.junit.Assert.assertNull) Ignore(org.junit.Ignore) Arrays.asList(java.util.Arrays.asList) Assert.assertFalse(org.junit.Assert.assertFalse) Comparator(java.util.Comparator) Collections(java.util.Collections) RequestMappingInfo(org.springframework.web.reactive.result.method.RequestMappingInfo) Assert.assertEquals(org.junit.Assert.assertEquals) 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 4 with RequestMappingInfo

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

the class RequestMappingInfoTests method matchProducesCondition.

@Test
public void matchProducesCondition() {
    ServerWebExchange exchange = MockServerHttpRequest.get("/foo").accept(MediaType.TEXT_PLAIN).toExchange();
    RequestMappingInfo info = paths("/foo").produces("text/plain").build();
    RequestMappingInfo match = info.getMatchingCondition(exchange);
    assertNotNull(match);
    info = paths("/foo").produces("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 5 with RequestMappingInfo

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

the class RequestMappingInfoTests method createEmpty.

// TODO: CORS pre-flight (see @Ignored)
@Test
public void createEmpty() {
    RequestMappingInfo info = paths().build();
    assertEquals(0, info.getPatternsCondition().getPatterns().size());
    assertEquals(0, info.getMethodsCondition().getMethods().size());
    assertEquals(true, info.getConsumesCondition().isEmpty());
    assertEquals(true, info.getProducesCondition().isEmpty());
    assertNotNull(info.getParamsCondition());
    assertNotNull(info.getHeadersCondition());
    assertNull(info.getCustomCondition());
}
Also used : 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