SPR-8819 Fix issue in setting best matching pattern.

This commit is contained in:
Rossen Stoyanchev
2011-11-08 20:00:42 +00:00
parent b9a3d4577a
commit c3f0f31243
2 changed files with 17 additions and 6 deletions

View File

@@ -204,12 +204,22 @@ public class RequestMappingInfoHandlerMappingTests {
@Test
public void bestMatchingPatternAttribute() {
PatternsRequestCondition patterns = new PatternsRequestCondition("/1/2", "/{path1}/2");
PatternsRequestCondition patterns = new PatternsRequestCondition("/{path1}/2", "/**");
RequestMappingInfo key = new RequestMappingInfo(patterns, null, null, null, null, null, null);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/1/2");
String lookupPath = new UrlPathHelper().getLookupPathForRequest(request);
this.mapping.handleMatch(key, lookupPath, request);
this.mapping.handleMatch(key, "/1/2", request);
assertEquals("/{path1}/2", request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE));
}
@Test
public void bestMatchingPatternAttributeNoPatternsDefined() {
PatternsRequestCondition patterns = new PatternsRequestCondition();
RequestMappingInfo key = new RequestMappingInfo(patterns, null, null, null, null, null, null);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/1/2");
this.mapping.handleMatch(key, "/1/2", request);
assertEquals("/1/2", request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE));
}