Search in sources :

Example 1 with HEAD

use of cn.taketoday.http.HttpMethod.HEAD in project today-infrastructure by TAKETODAY.

the class RequestMappingInfoTests method compareToWithHttpHeadMapping.

@Test
// SPR-14383
void compareToWithHttpHeadMapping() {
    MockHttpServletRequest request = initRequest("GET", "/", false);
    request.setMethod("HEAD");
    request.addHeader("Accept", "application/json");
    RequestMappingInfo noMethods = RequestMappingInfo.paths().build();
    RequestMappingInfo getMethod = RequestMappingInfo.paths().methods(GET).produces("application/json").build();
    RequestMappingInfo headMethod = RequestMappingInfo.paths().methods(HEAD).build();
    Comparator<RequestMappingInfo> comparator = (info, otherInfo) -> info.compareTo(otherInfo, new ServletRequestContext(null, request, null));
    List<RequestMappingInfo> list = asList(noMethods, getMethod, headMethod);
    Collections.shuffle(list);
    list.sort(comparator);
    assertThat(list.get(0)).isEqualTo(headMethod);
    assertThat(list.get(1)).isEqualTo(getMethod);
    assertThat(list.get(2)).isEqualTo(noMethods);
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) MockHttpServletRequest(cn.taketoday.web.mock.MockHttpServletRequest) Test(org.junit.jupiter.api.Test) HttpMethod(cn.taketoday.http.HttpMethod) ServletRequestContext(cn.taketoday.web.servlet.ServletRequestContext) List(java.util.List) HttpHeaders(cn.taketoday.http.HttpHeaders) Stream(java.util.stream.Stream) GET(cn.taketoday.http.HttpMethod.GET) Arrays.asList(java.util.Arrays.asList) PathPatternsParameterizedTest(cn.taketoday.web.view.PathPatternsParameterizedTest) HEAD(cn.taketoday.http.HttpMethod.HEAD) PathPatternParser(cn.taketoday.web.util.pattern.PathPatternParser) Comparator(java.util.Comparator) MediaType(cn.taketoday.http.MediaType) Collections(java.util.Collections) MockHttpServletRequest(cn.taketoday.web.mock.MockHttpServletRequest) ServletRequestContext(cn.taketoday.web.servlet.ServletRequestContext) Test(org.junit.jupiter.api.Test) PathPatternsParameterizedTest(cn.taketoday.web.view.PathPatternsParameterizedTest)

Example 2 with HEAD

use of cn.taketoday.http.HttpMethod.HEAD in project today-framework by TAKETODAY.

the class RequestMappingInfoTests method compareToWithHttpHeadMapping.

@Test
// SPR-14383
void compareToWithHttpHeadMapping() {
    MockHttpServletRequest request = initRequest("GET", "/", false);
    request.setMethod("HEAD");
    request.addHeader("Accept", "application/json");
    RequestMappingInfo noMethods = RequestMappingInfo.paths().build();
    RequestMappingInfo getMethod = RequestMappingInfo.paths().methods(GET).produces("application/json").build();
    RequestMappingInfo headMethod = RequestMappingInfo.paths().methods(HEAD).build();
    Comparator<RequestMappingInfo> comparator = (info, otherInfo) -> info.compareTo(otherInfo, new ServletRequestContext(null, request, null));
    List<RequestMappingInfo> list = asList(noMethods, getMethod, headMethod);
    Collections.shuffle(list);
    list.sort(comparator);
    assertThat(list.get(0)).isEqualTo(headMethod);
    assertThat(list.get(1)).isEqualTo(getMethod);
    assertThat(list.get(2)).isEqualTo(noMethods);
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.jupiter.api.Test) HttpMethod(cn.taketoday.http.HttpMethod) ServletRequestContext(cn.taketoday.web.servlet.ServletRequestContext) List(java.util.List) HttpHeaders(cn.taketoday.http.HttpHeaders) Stream(java.util.stream.Stream) MockHttpServletRequest(cn.taketoday.web.testfixture.servlet.MockHttpServletRequest) GET(cn.taketoday.http.HttpMethod.GET) Arrays.asList(java.util.Arrays.asList) PathPatternsParameterizedTest(cn.taketoday.web.view.PathPatternsParameterizedTest) HEAD(cn.taketoday.http.HttpMethod.HEAD) PathPatternParser(cn.taketoday.web.util.pattern.PathPatternParser) Comparator(java.util.Comparator) MediaType(cn.taketoday.http.MediaType) Collections(java.util.Collections) MockHttpServletRequest(cn.taketoday.web.testfixture.servlet.MockHttpServletRequest) ServletRequestContext(cn.taketoday.web.servlet.ServletRequestContext) Test(org.junit.jupiter.api.Test) PathPatternsParameterizedTest(cn.taketoday.web.view.PathPatternsParameterizedTest)

Aggregations

HttpHeaders (cn.taketoday.http.HttpHeaders)2 HttpMethod (cn.taketoday.http.HttpMethod)2 GET (cn.taketoday.http.HttpMethod.GET)2 HEAD (cn.taketoday.http.HttpMethod.HEAD)2 MediaType (cn.taketoday.http.MediaType)2 ServletRequestContext (cn.taketoday.web.servlet.ServletRequestContext)2 PathPatternParser (cn.taketoday.web.util.pattern.PathPatternParser)2 PathPatternsParameterizedTest (cn.taketoday.web.view.PathPatternsParameterizedTest)2 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)2 Arrays.asList (java.util.Arrays.asList)2 Collections (java.util.Collections)2 Comparator (java.util.Comparator)2 List (java.util.List)2 Stream (java.util.stream.Stream)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Test (org.junit.jupiter.api.Test)2 MockHttpServletRequest (cn.taketoday.web.mock.MockHttpServletRequest)1 MockHttpServletRequest (cn.taketoday.web.testfixture.servlet.MockHttpServletRequest)1