Search in sources :

Example 1 with HEAD

use of org.springframework.web.bind.annotation.RequestMethod.HEAD in project spring-framework by spring-projects.

the class RequestMappingInfoTests method compareToWithHttpHeadMapping.

// SPR-14383
@Test
public void compareToWithHttpHeadMapping() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setMethod("HEAD");
    request.addHeader("Accept", "application/json");
    RequestMappingInfo noMethods = paths().build();
    RequestMappingInfo getMethod = paths().methods(GET).produces("application/json").build();
    RequestMappingInfo headMethod = paths().methods(HEAD).build();
    Comparator<RequestMappingInfo> comparator = (info, otherInfo) -> info.compareTo(otherInfo, request);
    List<RequestMappingInfo> list = asList(noMethods, getMethod, headMethod);
    Collections.shuffle(list);
    Collections.sort(list, comparator);
    assertEquals(headMethod, list.get(0));
    assertEquals(getMethod, list.get(1));
    assertEquals(noMethods, list.get(2));
}
Also used : RequestMappingInfo.paths(org.springframework.web.servlet.mvc.method.RequestMappingInfo.paths) HEAD(org.springframework.web.bind.annotation.RequestMethod.HEAD) HttpHeaders(org.springframework.http.HttpHeaders) Assert.assertNotNull(org.junit.Assert.assertNotNull) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) Test(org.junit.Test) GET(org.springframework.web.bind.annotation.RequestMethod.GET) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) List(java.util.List) HttpServletRequest(javax.servlet.http.HttpServletRequest) Assert.assertNull(org.junit.Assert.assertNull) Arrays.asList(java.util.Arrays.asList) Assert.assertFalse(org.junit.Assert.assertFalse) Comparator(java.util.Comparator) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) Test(org.junit.Test)

Aggregations

Arrays.asList (java.util.Arrays.asList)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 List (java.util.List)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)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 Test (org.junit.Test)1 HttpHeaders (org.springframework.http.HttpHeaders)1 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)1 RequestMethod (org.springframework.web.bind.annotation.RequestMethod)1 GET (org.springframework.web.bind.annotation.RequestMethod.GET)1 HEAD (org.springframework.web.bind.annotation.RequestMethod.HEAD)1 RequestMappingInfo.paths (org.springframework.web.servlet.mvc.method.RequestMappingInfo.paths)1