EL container integration; support for contextual objects; removal of deprecated Spring 2.0 functionality; Java 5 code style

This commit is contained in:
Juergen Hoeller
2008-11-20 02:10:53 +00:00
parent 369821dd66
commit 347f34c68a
281 changed files with 6120 additions and 9903 deletions

View File

@@ -106,7 +106,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
private String contentType;
private final Map parameters = new LinkedHashMap(16);
private final Map<String, String[]> parameters = new LinkedHashMap<String, String[]>(16);
private String protocol = DEFAULT_PROTOCOL;
@@ -145,7 +145,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
private Cookie[] cookies;
/**
* The key is the lowercase header name; the value is a {@link org.springframework.mock.web.HeaderValueHolder} object.
* The key is the lowercase header name; the value is a {@link HeaderValueHolder} object.
*/
private final Hashtable headers = new Hashtable();
@@ -182,8 +182,8 @@ public class MockHttpServletRequest implements HttpServletRequest {
/**
* Create a new MockHttpServletRequest with a default
* {@link org.springframework.mock.web.MockServletContext}.
* @see org.springframework.mock.web.MockServletContext
* {@link MockServletContext}.
* @see MockServletContext
*/
public MockHttpServletRequest() {
this(null, "", "");
@@ -191,12 +191,12 @@ public class MockHttpServletRequest implements HttpServletRequest {
/**
* Create a new MockHttpServletRequest with a default
* {@link org.springframework.mock.web.MockServletContext}.
* {@link MockServletContext}.
* @param method the request method (may be <code>null</code>)
* @param requestURI the request URI (may be <code>null</code>)
* @see #setMethod
* @see #setRequestURI
* @see org.springframework.mock.web.MockServletContext
* @see MockServletContext
*/
public MockHttpServletRequest(String method, String requestURI) {
this(null, method, requestURI);
@@ -206,7 +206,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
* Create a new MockHttpServletRequest.
* @param servletContext the ServletContext that the request runs in
* (may be <code>null</code> to use a default MockServletContext)
* @see org.springframework.mock.web.MockServletContext
* @see MockServletContext
*/
public MockHttpServletRequest(ServletContext servletContext) {
this(servletContext, "", "");
@@ -220,7 +220,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
* @param requestURI the request URI (may be <code>null</code>)
* @see #setMethod
* @see #setRequestURI
* @see org.springframework.mock.web.MockServletContext
* @see MockServletContext
*/
public MockHttpServletRequest(ServletContext servletContext, String method, String requestURI) {
this.servletContext = (servletContext != null ? servletContext : new MockServletContext());
@@ -348,8 +348,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
*/
public void setParameters(Map params) {
Assert.notNull(params, "Parameter map must not be null");
for (Iterator it = params.keySet().iterator(); it.hasNext();) {
Object key = it.next();
for (Object key : params.keySet()) {
Assert.isInstanceOf(String.class, key,
"Parameter map key must be of type [" + String.class.getName() + "]");
Object value = params.get(key);
@@ -360,8 +359,9 @@ public class MockHttpServletRequest implements HttpServletRequest {
this.setParameter((String) key, (String[]) value);
}
else {
throw new IllegalArgumentException("Parameter map value must be single value " +
" or array of type [" + String.class.getName() + "]");
throw new IllegalArgumentException(
"Parameter map value must be single value " + " or array of type [" + String.class.getName() +
"]");
}
}
}
@@ -382,7 +382,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
*/
public void addParameter(String name, String[] values) {
Assert.notNull(name, "Parameter name must not be null");
String[] oldArr = (String[]) this.parameters.get(name);
String[] oldArr = this.parameters.get(name);
if (oldArr != null) {
String[] newArr = new String[oldArr.length + values.length];
System.arraycopy(oldArr, 0, newArr, 0, oldArr.length);
@@ -401,8 +401,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
*/
public void addParameters(Map params) {
Assert.notNull(params, "Parameter map must not be null");
for (Iterator it = params.keySet().iterator(); it.hasNext();) {
Object key = it.next();
for (Object key : params.keySet()) {
Assert.isInstanceOf(String.class, key,
"Parameter map key must be of type [" + String.class.getName() + "]");
Object value = params.get(key);
@@ -436,7 +435,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
public String getParameter(String name) {
Assert.notNull(name, "Parameter name must not be null");
String[] arr = (String[]) this.parameters.get(name);
String[] arr = this.parameters.get(name);
return (arr != null && arr.length > 0 ? arr[0] : null);
}
@@ -446,7 +445,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
public String[] getParameterValues(String name) {
Assert.notNull(name, "Parameter name must not be null");
return (String[]) this.parameters.get(name);
return this.parameters.get(name);
}
public Map getParameterMap() {
@@ -750,14 +749,6 @@ public class MockHttpServletRequest implements HttpServletRequest {
return this.remoteUser;
}
/**
* @deprecated in favor of addUserRole
* @see #addUserRole
*/
public void addRole(String role) {
addUserRole(role);
}
public void addUserRole(String role) {
this.userRoles.add(role);
}
@@ -855,4 +846,4 @@ public class MockHttpServletRequest implements HttpServletRequest {
return isRequestedSessionIdFromURL();
}
}
}

View File

@@ -698,43 +698,6 @@ public class DispatcherServletTests extends TestCase {
assertNull(myServlet.getServletConfig());
}
public void testThrowawayController() throws Exception {
SimpleWebApplicationContext.TestThrowawayController.counter = 0;
MockHttpServletRequest request = new MockHttpServletRequest(getServletContext(), "GET", "/throwaway.do");
request.addParameter("myInt", "5");
MockHttpServletResponse response = new MockHttpServletResponse();
simpleDispatcherServlet.service(request, response);
assertTrue("Correct response", "view5".equals(response.getForwardedUrl()));
Assert.assertEquals(1, SimpleWebApplicationContext.TestThrowawayController.counter);
request = new MockHttpServletRequest(getServletContext(), "GET", "/throwaway.do");
request.addParameter("myInt", "5");
response = new MockHttpServletResponse();
simpleDispatcherServlet.service(request, response);
assertTrue("Correct response", "view5".equals(response.getForwardedUrl()));
Assert.assertEquals(2, SimpleWebApplicationContext.TestThrowawayController.counter);
}
public void testThrowawayControllerWithBindingFailure() throws Exception {
SimpleWebApplicationContext.TestThrowawayController.counter = 0;
MockHttpServletRequest request = new MockHttpServletRequest(getServletContext(), "GET", "/throwaway.do");
request.addParameter("myInt", "5x");
MockHttpServletResponse response = new MockHttpServletResponse();
try {
simpleDispatcherServlet.service(request, response);
fail("Should have thrown ServletException");
}
catch (ServletException ex) {
// expected
assertTrue(ex.getRootCause() instanceof BindException);
Assert.assertEquals(1, SimpleWebApplicationContext.TestThrowawayController.counter);
}
}
public void testWebApplicationContextLookup() {
MockServletContext servletContext = new MockServletContext();
MockHttpServletRequest request = new MockHttpServletRequest(servletContext, "GET", "/invalid.do");

View File

@@ -35,7 +35,6 @@ import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver;
import org.springframework.web.servlet.mvc.Controller;
import org.springframework.web.servlet.mvc.LastModified;
import org.springframework.web.servlet.mvc.SimpleFormController;
import org.springframework.web.servlet.mvc.throwaway.ThrowawayController;
import org.springframework.web.servlet.support.RequestContextUtils;
import org.springframework.web.servlet.theme.AbstractThemeResolver;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
@@ -56,8 +55,6 @@ public class SimpleWebApplicationContext extends StaticWebApplicationContext {
registerSingleton("/locale.do", LocaleChecker.class);
registerPrototype("/throwaway.do", TestThrowawayController.class);
addMessage("test", Locale.ENGLISH, "test message");
addMessage("test", Locale.CANADA, "Canadian & test message");
addMessage("testArgs", Locale.ENGLISH, "test {0} message {1}");
@@ -118,24 +115,4 @@ public class SimpleWebApplicationContext extends StaticWebApplicationContext {
}
}
public static class TestThrowawayController implements ThrowawayController {
public static int counter = 0;
private int myInt;
public TestThrowawayController() {
counter++;
}
public void setMyInt(int myInt) {
this.myInt = myInt;
}
public ModelAndView execute() throws Exception {
return new ModelAndView("view" + this.myInt);
}
}
}
}