@ -32,7 +32,7 @@ import org.springframework.web.servlet.mvc.method.condition.RequestConditionFact
@@ -32,7 +32,7 @@ import org.springframework.web.servlet.mvc.method.condition.RequestConditionFact
import org.springframework.web.util.UrlPathHelper ;
/ * *
* Test fixture for { @link RequestMappingKey } tests .
* Test fixture for { @link RequestMappingInfo } tests .
*
* @author Arjen Poutsma
* @author Rossen Stoyanchev
@ -41,8 +41,8 @@ public class RequestKeyTests {
@@ -41,8 +41,8 @@ public class RequestKeyTests {
@Test
public void equals ( ) {
RequestMappingKey key1 = new RequestMappingKey ( singleton ( "/foo" ) , singleton ( GET ) ) ;
RequestMappingKey key2 = new RequestMappingKey ( singleton ( "/foo" ) , singleton ( GET ) ) ;
RequestMappingInfo key1 = new RequestMappingInfo ( singleton ( "/foo" ) , singleton ( GET ) ) ;
RequestMappingInfo key2 = new RequestMappingInfo ( singleton ( "/foo" ) , singleton ( GET ) ) ;
assertEquals ( key1 , key2 ) ;
assertEquals ( key1 . hashCode ( ) , key2 . hashCode ( ) ) ;
@ -50,8 +50,8 @@ public class RequestKeyTests {
@@ -50,8 +50,8 @@ public class RequestKeyTests {
@Test
public void equalsPrependSlash ( ) {
RequestMappingKey key1 = new RequestMappingKey ( singleton ( "/foo" ) , singleton ( GET ) ) ;
RequestMappingKey key2 = new RequestMappingKey ( singleton ( "foo" ) , singleton ( GET ) ) ;
RequestMappingInfo key1 = new RequestMappingInfo ( singleton ( "/foo" ) , singleton ( GET ) ) ;
RequestMappingInfo key2 = new RequestMappingInfo ( singleton ( "foo" ) , singleton ( GET ) ) ;
assertEquals ( key1 , key2 ) ;
assertEquals ( key1 . hashCode ( ) , key2 . hashCode ( ) ) ;
@ -61,9 +61,9 @@ public class RequestKeyTests {
@@ -61,9 +61,9 @@ public class RequestKeyTests {
public void combinePatterns ( ) {
AntPathMatcher pathMatcher = new AntPathMatcher ( ) ;
RequestMappingKey key1 = createKeyFromPatterns ( "/t1" , "/t2" ) ;
RequestMappingKey key2 = createKeyFromPatterns ( "/m1" , "/m2" ) ;
RequestMappingKey key3 = createKeyFromPatterns ( "/t1/m1" , "/t1/m2" , "/t2/m1" , "/t2/m2" ) ;
RequestMappingInfo key1 = createKeyFromPatterns ( "/t1" , "/t2" ) ;
RequestMappingInfo key2 = createKeyFromPatterns ( "/m1" , "/m2" ) ;
RequestMappingInfo key3 = createKeyFromPatterns ( "/t1/m1" , "/t1/m2" , "/t2/m1" , "/t2/m2" ) ;
assertEquals ( key3 . getPatterns ( ) , key1 . combine ( key2 , pathMatcher ) . getPatterns ( ) ) ;
key1 = createKeyFromPatterns ( "/t1" ) ;
@ -93,40 +93,40 @@ public class RequestKeyTests {
@@ -93,40 +93,40 @@ public class RequestKeyTests {
PathMatcher pathMatcher = new AntPathMatcher ( ) ;
MockHttpServletRequest request = new MockHttpServletRequest ( "GET" , "/foo" ) ;
RequestMappingKey key = new RequestMappingKey ( singleton ( "/foo" ) , null ) ;
RequestMappingKey match = key . getMatchingKey ( pathHelper . getLookupPathForRequest ( request ) , request , pathMatcher ) ;
RequestMappingInfo key = new RequestMappingInfo ( singleton ( "/foo" ) , null ) ;
RequestMappingInfo match = key . getMatchingRequestMapping ( pathHelper . getLookupPathForRequest ( request ) , request , pathMatcher ) ;
assertNotNull ( match ) ;
request = new MockHttpServletRequest ( "GET" , "/foo/bar" ) ;
key = new RequestMappingKey ( singleton ( "/foo/*" ) , null ) ;
match = key . getMatchingKey ( pathHelper . getLookupPathForRequest ( request ) , request , pathMatcher ) ;
key = new RequestMappingInfo ( singleton ( "/foo/*" ) , null ) ;
match = key . getMatchingRequestMapping ( pathHelper . getLookupPathForRequest ( request ) , request , pathMatcher ) ;
assertNotNull ( "Pattern match" , match ) ;
request = new MockHttpServletRequest ( "GET" , "/foo.html" ) ;
key = new RequestMappingKey ( singleton ( "/foo" ) , null ) ;
match = key . getMatchingKey ( pathHelper . getLookupPathForRequest ( request ) , request , pathMatcher ) ;
key = new RequestMappingInfo ( singleton ( "/foo" ) , null ) ;
match = key . getMatchingRequestMapping ( pathHelper . getLookupPathForRequest ( request ) , request , pathMatcher ) ;
assertNotNull ( "Implicit match by extension" , match ) ;
assertEquals ( "Contains matched pattern" , "/foo.*" , match . getPatterns ( ) . iterator ( ) . next ( ) ) ;
request = new MockHttpServletRequest ( "GET" , "/foo/" ) ;
key = new RequestMappingKey ( singleton ( "/foo" ) , null ) ;
match = key . getMatchingKey ( pathHelper . getLookupPathForRequest ( request ) , request , pathMatcher ) ;
key = new RequestMappingInfo ( singleton ( "/foo" ) , null ) ;
match = key . getMatchingRequestMapping ( pathHelper . getLookupPathForRequest ( request ) , request , pathMatcher ) ;
assertNotNull ( "Implicit match by trailing slash" , match ) ;
assertEquals ( "Contains matched pattern" , "/foo/" , match . getPatterns ( ) . iterator ( ) . next ( ) ) ;
request = new MockHttpServletRequest ( "GET" , "/foo.html" ) ;
key = new RequestMappingKey ( singleton ( "/foo.jpg" ) , null ) ;
match = key . getMatchingKey ( pathHelper . getLookupPathForRequest ( request ) , request , pathMatcher ) ;
key = new RequestMappingInfo ( singleton ( "/foo.jpg" ) , null ) ;
match = key . getMatchingRequestMapping ( pathHelper . getLookupPathForRequest ( request ) , request , pathMatcher ) ;
assertNull ( "Implicit match ignored if pattern has extension" , match ) ;
request = new MockHttpServletRequest ( "GET" , "/foo.html" ) ;
key = new RequestMappingKey ( singleton ( "/foo.jpg" ) , null ) ;
match = key . getMatchingKey ( pathHelper . getLookupPathForRequest ( request ) , request , pathMatcher ) ;
key = new RequestMappingInfo ( singleton ( "/foo.jpg" ) , null ) ;
match = key . getMatchingRequestMapping ( pathHelper . getLookupPathForRequest ( request ) , request , pathMatcher ) ;
assertNull ( "Implicit match ignored on pattern with trailing slash" , match ) ;
}
@ -137,18 +137,18 @@ public class RequestKeyTests {
@@ -137,18 +137,18 @@ public class RequestKeyTests {
MockHttpServletRequest request = new MockHttpServletRequest ( "GET" , "/foo" ) ;
String lookupPath = new UrlPathHelper ( ) . getLookupPathForRequest ( request ) ;
RequestMappingKey key = new RequestMappingKey ( singleton ( "/foo" ) , null ) ;
RequestMappingKey match = key . getMatchingKey ( lookupPath , request , pathMatcher ) ;
RequestMappingInfo key = new RequestMappingInfo ( singleton ( "/foo" ) , null ) ;
RequestMappingInfo match = key . getMatchingRequestMapping ( lookupPath , request , pathMatcher ) ;
assertNotNull ( "No method matches any method" , match ) ;
key = new RequestMappingKey ( singleton ( "/foo" ) , singleton ( GET ) ) ;
match = key . getMatchingKey ( lookupPath , request , pathMatcher ) ;
key = new RequestMappingInfo ( singleton ( "/foo" ) , singleton ( GET ) ) ;
match = key . getMatchingRequestMapping ( lookupPath , request , pathMatcher ) ;
assertNotNull ( "Exact match" , match ) ;
key = new RequestMappingKey ( singleton ( "/foo" ) , singleton ( POST ) ) ;
match = key . getMatchingKey ( lookupPath , request , pathMatcher ) ;
key = new RequestMappingInfo ( singleton ( "/foo" ) , singleton ( POST ) ) ;
match = key . getMatchingRequestMapping ( lookupPath , request , pathMatcher ) ;
assertNull ( "No match" , match ) ;
}
@ -159,15 +159,15 @@ public class RequestKeyTests {
@@ -159,15 +159,15 @@ public class RequestKeyTests {
MockHttpServletRequest request = new MockHttpServletRequest ( "GET" , "/foo" ) ;
String lookupPath = new UrlPathHelper ( ) . getLookupPathForRequest ( request ) ;
RequestMappingKey key = new RequestMappingKey ( asList ( "/foo*" , "/bar" ) , asList ( GET , POST ) ) ;
RequestMappingKey match = key . getMatchingKey ( lookupPath , request , pathMatcher ) ;
RequestMappingKey expected = new RequestMappingKey ( singleton ( "/foo*" ) , singleton ( GET ) ) ;
RequestMappingInfo key = new RequestMappingInfo ( asList ( "/foo*" , "/bar" ) , asList ( GET , POST ) ) ;
RequestMappingInfo match = key . getMatchingRequestMapping ( lookupPath , request , pathMatcher ) ;
RequestMappingInfo expected = new RequestMappingInfo ( singleton ( "/foo*" ) , singleton ( GET ) ) ;
assertEquals ( "Matching RequestKey contains matched patterns and methods only" , expected , match ) ;
key = new RequestMappingKey ( asList ( "/**" , "/foo*" , "/foo" ) , null ) ;
match = key . getMatchingKey ( lookupPath , request , pathMatcher ) ;
expected = new RequestMappingKey ( asList ( "/foo" , "/foo*" , "/**" ) , null ) ;
key = new RequestMappingInfo ( asList ( "/**" , "/foo*" , "/foo" ) , null ) ;
match = key . getMatchingRequestMapping ( lookupPath , request , pathMatcher ) ;
expected = new RequestMappingInfo ( asList ( "/foo" , "/foo*" , "/**" ) , null ) ;
assertEquals ( "Matched patterns are sorted with best match at the top" , expected , match ) ;
}
@ -179,13 +179,13 @@ public class RequestKeyTests {
@@ -179,13 +179,13 @@ public class RequestKeyTests {
request . setParameter ( "foo" , "bar" ) ;
String lookupPath = new UrlPathHelper ( ) . getLookupPathForRequest ( request ) ;
RequestMappingKey key = new RequestMappingKey ( asList ( "/foo" ) , null , RequestConditionFactory . parseParams ( "foo=bar" ) , null , null ) ;
RequestMappingKey match = key . getMatchingKey ( lookupPath , request , pathMatcher ) ;
RequestMappingInfo key = new RequestMappingInfo ( asList ( "/foo" ) , null , RequestConditionFactory . parseParams ( "foo=bar" ) , null ) ;
RequestMappingInfo match = key . getMatchingRequestMapping ( lookupPath , request , pathMatcher ) ;
assertNotNull ( match ) ;
key = new RequestMappingKey ( singleton ( "/foo" ) , null , RequestConditionFactory . parseParams ( "foo!=bar" ) , null , null ) ;
match = key . getMatchingKey ( lookupPath , request , pathMatcher ) ;
key = new RequestMappingInfo ( singleton ( "/foo" ) , null , RequestConditionFactory . parseParams ( "foo!=bar" ) , null ) ;
match = key . getMatchingRequestMapping ( lookupPath , request , pathMatcher ) ;
assertNull ( match ) ;
}
@ -197,39 +197,39 @@ public class RequestKeyTests {
@@ -197,39 +197,39 @@ public class RequestKeyTests {
request . addHeader ( "foo" , "bar" ) ;
String lookupPath = new UrlPathHelper ( ) . getLookupPathForRequest ( request ) ;
RequestMappingKey key = new RequestMappingKey ( singleton ( "/foo" ) , null , null , RequestConditionFactory . parseHeaders ( "foo=bar" ) , null ) ;
RequestMappingKey match = key . getMatchingKey ( lookupPath , request , pathMatcher ) ;
RequestMappingInfo key = new RequestMappingInfo ( singleton ( "/foo" ) , null , null , RequestConditionFactory . parseHeaders ( "foo=bar" ) ) ;
RequestMappingInfo match = key . getMatchingRequestMapping ( lookupPath , request , pathMatcher ) ;
assertNotNull ( match ) ;
key = new RequestMappingKey ( singleton ( "/foo" ) , null , null , RequestConditionFactory . parseHeaders ( "foo!=bar" ) , null ) ;
match = key . getMatchingKey ( lookupPath , request , pathMatcher ) ;
key = new RequestMappingInfo ( singleton ( "/foo" ) , null , null , RequestConditionFactory . parseHeaders ( "foo!=bar" ) ) ;
match = key . getMatchingRequestMapping ( lookupPath , request , pathMatcher ) ;
assertNull ( match ) ;
}
@Test
public void consumesCondition ( ) {
PathMatcher pathMatcher = new AntPathMatcher ( ) ;
MockHttpServletRequest request = new MockHttpServletRequest ( "GET" , "/foo" ) ;
request . setContentType ( "text/plain" ) ;
String lookupPath = new UrlPathHelper ( ) . getLookupPathForRequest ( request ) ;
RequestMappingKey key = new RequestMappingKey ( singleton ( "/foo" ) , null , null , null , RequestConditionFactory . parseConsumes (
"text/plain" ) ) ;
RequestMappingKey match = key . getMatchingKey ( lookupPath , request , pathMatcher ) ;
assertNotNull ( match ) ;
key = new RequestMappingKey ( singleton ( "/foo" ) , null , null , null , RequestConditionFactory . parseConsumes (
"application/xml" ) ) ;
match = key . getMatchingKey ( lookupPath , request , pathMatcher ) ;
assertNull ( match ) ;
}
private RequestMappingKey createKeyFromPatterns ( String . . . patterns ) {
return new RequestMappingKey ( asList ( patterns ) , null ) ;
// @Test
// public void consumesCondition() {
// PathMatcher pathMatcher = new AntPathMatcher();
// MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo");
// request.setContentType("text/plain");
// String lookupPath = new UrlPathHelper().getLookupPathForRequest(request);
//
// RequestMappingInfo key = new RequestMappingInfo(singleton("/foo"), null, null, null, RequestConditionFactory.parseConsumes(
// "text/plain"));
// RequestMappingInfo match = key.getMatchingKey(lookupPath, request, pathMatcher);
//
// assertNotNull(match);
//
// key = new RequestMappingInfo(singleton("/foo"), null, null, null, RequestConditionFactory.parseConsumes(
// "application/xml"));
// match = key.getMatchingKey(lookupPath, request, pathMatcher);
//
// assertNull(match);
// }
private RequestMappingInfo createKeyFromPatterns ( String . . . patterns ) {
return new RequestMappingInfo ( asList ( patterns ) , null ) ;
}
}