SPR-7354 - Added equivalent of JAX-RS @Consumes to Spring MVC

This commit is contained in:
Arjen Poutsma
2011-04-08 12:06:53 +00:00
parent 0cdb237576
commit 44b4f59c5e
4 changed files with 49 additions and 26 deletions

View File

@@ -147,7 +147,7 @@ public class RequestKeyTests {
}
@Test
public void testMatchingKeyContent() {
public void matchingKeyContent() {
UrlPathHelper urlPathHelper = new UrlPathHelper();
PathMatcher pathMatcher = new AntPathMatcher();
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo");
@@ -167,7 +167,7 @@ public class RequestKeyTests {
}
@Test
public void testParamConditions() {
public void paramsCondition() {
UrlPathHelper urlPathHelper = new UrlPathHelper();
PathMatcher pathMatcher = new AntPathMatcher();
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo");
@@ -185,7 +185,7 @@ public class RequestKeyTests {
}
@Test
public void testHeaderConditions() {
public void headersCondition() {
UrlPathHelper urlPathHelper = new UrlPathHelper();
PathMatcher pathMatcher = new AntPathMatcher();
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo");
@@ -203,7 +203,27 @@ public class RequestKeyTests {
}
@Test
public void testCreateFromServletRequest() {
public void consumesCondition() {
UrlPathHelper urlPathHelper = new UrlPathHelper();
PathMatcher pathMatcher = new AntPathMatcher();
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo");
request.setContentType("text/plain");
RequestKey key = new RequestKey(singleton("/foo"), null, null, null, RequestConditionFactory.parseConsumes(
"text/plain"));
RequestKey match = key.getMatchingKey(request, pathMatcher, urlPathHelper);
assertNotNull(match);
key = new RequestKey(singleton("/foo"), null, null, null, RequestConditionFactory.parseConsumes(
"application/xml"));
match = key.getMatchingKey(request, pathMatcher, urlPathHelper);
assertNull(match);
}
@Test
public void createFromServletRequest() {
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo");
RequestKey key = RequestKey.createFromServletRequest(request, new UrlPathHelper());
assertEquals(new RequestKey(singleton("/foo"), singleton(RequestMethod.GET), null, null, null), key);