Raise exception on missing request parameters

Issue: SPR-10193
This commit is contained in:
Rossen Stoyanchev
2013-01-22 18:06:41 -05:00
parent 4d01d43c19
commit 3c09b07652
2 changed files with 44 additions and 0 deletions

View File

@@ -42,6 +42,7 @@ import org.springframework.util.MultiValueMap;
import org.springframework.web.HttpMediaTypeNotAcceptableException;
import org.springframework.web.HttpMediaTypeNotSupportedException;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.UnsatisfiedServletRequestParameterException;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@@ -202,6 +203,19 @@ public class RequestMappingInfoHandlerMappingTests {
}
}
@Test
public void testUnsatisfiedServletRequestParameterException() throws Exception {
try {
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/params");
this.handlerMapping.getHandler(request);
fail("UnsatisfiedServletRequestParameterException expected");
}
catch (UnsatisfiedServletRequestParameterException ex) {
assertArrayEquals("Invalid request parameter conditions",
new String[] { "foo=bar" }, ex.getParamConditions());
}
}
@Test
public void uriTemplateVariables() {
PatternsRequestCondition patterns = new PatternsRequestCondition("/{path1}/{path2}");
@@ -414,6 +428,11 @@ public class RequestMappingInfoHandlerMappingTests {
return "";
}
@RequestMapping(value = "/params", params="foo=bar")
public String param() {
return "";
}
@RequestMapping(value = "/content", produces="application/xml")
public String xmlContent() {
return "";