@Test public void compareToWithImpicitVsExplicitHttpMethodDeclaration() { RequestMappingInfo noMethods = paths().build(); RequestMappingInfo oneMethod = paths().methods(GET).build(); RequestMappingInfo oneMethodOneParam = paths().methods(GET).params("foo").build(); Comparator<RequestMappingInfo> comparator = (info, otherInfo) -> info.compareTo(otherInfo, new MockHttpServletRequest()); List<RequestMappingInfo> list = asList(noMethods, oneMethod, oneMethodOneParam); Collections.shuffle(list); Collections.sort(list, comparator); assertEquals(oneMethodOneParam, list.get(0)); assertEquals(oneMethod, list.get(1)); assertEquals(noMethods, list.get(2)); }
/** * Create a {@link RequestMappingInfo} from the supplied * {@link RequestMapping @RequestMapping} annotation, which is either * a directly declared annotation, a meta-annotation, or the synthesized * result of merging annotation attributes within an annotation hierarchy. */ protected RequestMappingInfo createRequestMappingInfo( RequestMapping requestMapping, @Nullable RequestCondition<?> customCondition) { RequestMappingInfo.Builder builder = RequestMappingInfo .paths(resolveEmbeddedValuesInPatterns(requestMapping.path())) .methods(requestMapping.method()) .params(requestMapping.params()) .headers(requestMapping.headers()) .consumes(requestMapping.consumes()) .produces(requestMapping.produces()) .mappingName(requestMapping.name()); if (customCondition != null) { builder.customCondition(customCondition); } return builder.options(this.config).build(); }
/** * Create a {@link RequestMappingInfo} from the supplied * {@link RequestMapping @RequestMapping} annotation, which is either * a directly declared annotation, a meta-annotation, or the synthesized * result of merging annotation attributes within an annotation hierarchy. */ protected RequestMappingInfo createRequestMappingInfo( RequestMapping requestMapping, @Nullable RequestCondition<?> customCondition) { RequestMappingInfo.Builder builder = RequestMappingInfo .paths(resolveEmbeddedValuesInPatterns(requestMapping.path())) .methods(requestMapping.method()) .params(requestMapping.params()) .headers(requestMapping.headers()) .consumes(requestMapping.consumes()) .produces(requestMapping.produces()) .mappingName(requestMapping.name()); if (customCondition != null) { builder.customCondition(customCondition); } return builder.options(this.config).build(); }
.paths(resolveEmbeddedValuesInPatterns(requestMapping.path())) .methods(requestMapping.method()) .params(requestMapping.params()) .headers(requestMapping.headers()) .consumes(requestMapping.consumes())
@Test public void equals() { RequestMappingInfo info1 = paths("/foo").methods(GET) .params("foo=bar", "customFoo=customBar").headers("foo=bar") .consumes("text/plain").produces("text/plain") .build(); .params("foo=bar", "customFoo=customBar").headers("foo=bar") .consumes("text/plain").produces("text/plain") .build(); .params("foo=bar", "customFoo=customBar").headers("foo=bar") .consumes("text/plain").produces("text/plain") .build(); .params("foo=bar", "customFoo=customBar").headers("foo=bar") .consumes("text/plain").produces("text/plain") .build(); .params("/NOOOOOO", "customFoo=customBar").headers("foo=bar") .consumes("text/plain").produces("text/plain") .build(); .params("foo=bar", "customFoo=customBar").headers("/NOOOOOO") .consumes("text/plain").produces("text/plain") .build(); .params("foo=bar", "customFoo=customBar").headers("foo=bar") .consumes("text/NOOOOOO").produces("text/plain") .build();
@Test public void matchParamsCondition() { MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo"); request.setParameter("foo", "bar"); RequestMappingInfo info = paths("/foo").params("foo=bar").build(); RequestMappingInfo match = info.getMatchingCondition(request); assertNotNull(match); info = paths("/foo").params("foo!=bar").build(); match = info.getMatchingCondition(request); assertNull(match); }
@Test public void matchCustomCondition() { MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo"); request.setParameter("foo", "bar"); RequestMappingInfo info = paths("/foo").params("foo=bar").build(); RequestMappingInfo match = info.getMatchingCondition(request); assertNotNull(match); info = paths("/foo").params("foo!=bar").params("foo!=bar").build(); match = info.getMatchingCondition(request); assertNull(match); }