diff --git a/spring-test/src/main/java/org/springframework/mock/web/MockHttpServletResponse.java b/spring-test/src/main/java/org/springframework/mock/web/MockHttpServletResponse.java index 12a7e8a965..347ad8291e 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/MockHttpServletResponse.java +++ b/spring-test/src/main/java/org/springframework/mock/web/MockHttpServletResponse.java @@ -40,8 +40,9 @@ import org.springframework.web.util.WebUtils; /** * Mock implementation of the {@link javax.servlet.http.HttpServletResponse} interface. * - *
As of Spring 4.0, this set of mocks is designed on a Servlet 3.0 baseline. Beyond that, - * this MockHttpServletResponse is also compatible with Servlet 3.1's setContentLengthLong. + *
As of Spring 4.0, this set of mocks is designed on a Servlet 3.0 baseline. + * Beyond that, {@code MockHttpServletResponse} is also compatible with Servlet + * 3.1's {@code setContentLengthLong()} method. * * @author Juergen Hoeller * @author Rod Johnson diff --git a/spring-test/src/main/java/org/springframework/mock/web/MockHttpSession.java b/spring-test/src/main/java/org/springframework/mock/web/MockHttpSession.java index 513f64ad56..d59c5e70f3 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/MockHttpSession.java +++ b/spring-test/src/main/java/org/springframework/mock/web/MockHttpSession.java @@ -35,7 +35,7 @@ import org.springframework.util.Assert; /** * Mock implementation of the {@link javax.servlet.http.HttpSession} interface. * - *
Compatible with Servlet 2.5 as well as Servlet 3.0. + *
As of Spring 4.0, this set of mocks is designed on a Servlet 3.0 baseline. * *
Used for testing the web framework; also useful for testing application * controllers. diff --git a/spring-test/src/main/java/org/springframework/mock/web/MockMultipartHttpServletRequest.java b/spring-test/src/main/java/org/springframework/mock/web/MockMultipartHttpServletRequest.java index 01abe7665f..ac0cb75e64 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/MockMultipartHttpServletRequest.java +++ b/spring-test/src/main/java/org/springframework/mock/web/MockMultipartHttpServletRequest.java @@ -35,6 +35,8 @@ import org.springframework.web.multipart.MultipartHttpServletRequest; * Mock implementation of the * {@link org.springframework.web.multipart.MultipartHttpServletRequest} interface. * + *
As of Spring 4.0, this set of mocks is designed on a Servlet 3.0 baseline. + * *
Useful for testing application controllers that access multipart uploads. * The {@link MockMultipartFile} can be used to populate these mock requests * with files. diff --git a/spring-test/src/main/java/org/springframework/mock/web/MockServletContext.java b/spring-test/src/main/java/org/springframework/mock/web/MockServletContext.java index 1ab7a63e5c..23f5010d7c 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/MockServletContext.java +++ b/spring-test/src/main/java/org/springframework/mock/web/MockServletContext.java @@ -56,7 +56,9 @@ import org.springframework.web.util.WebUtils; /** * Mock implementation of the {@link javax.servlet.ServletContext} interface. * - *
Compatible with Servlet 3.0. Can be configured to expose a specific version + *
As of Spring 4.0, this set of mocks is designed on a Servlet 3.0 baseline. + * + *
Compatible with Servlet 3.0 but can be configured to expose a specific version * through {@link #setMajorVersion}/{@link #setMinorVersion}; default is 3.0. * Note that Servlet 3.0 support is limited: servlet, filter and listener * registration methods are not supported; neither is JSP configuration. diff --git a/spring-test/src/main/java/org/springframework/mock/web/package-info.java b/spring-test/src/main/java/org/springframework/mock/web/package-info.java index be8cb8601c..ce02d00c83 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/package-info.java +++ b/spring-test/src/main/java/org/springframework/mock/web/package-info.java @@ -1,15 +1,14 @@ - /** + * A comprehensive set of Servlet API 3.0 mock objects, targeted at usage with + * Spring's web MVC framework. * - * A comprehensive set of Servlet API 2.5 mock objects, - * targeted at usage with Spring's web MVC framework. - * Useful for testing web contexts and controllers. + *
Useful for testing web contexts and controllers. * *
More convenient to use than dynamic mock objects * (EasyMock) or * existing Servlet API mock objects * (MockObjects). - * */ + package org.springframework.mock.web; diff --git a/spring-web/src/test/java/org/springframework/mock/web/test/MockHttpServletRequest.java b/spring-web/src/test/java/org/springframework/mock/web/test/MockHttpServletRequest.java index 203b5143b6..7e87dfb891 100644 --- a/spring-web/src/test/java/org/springframework/mock/web/test/MockHttpServletRequest.java +++ b/spring-web/src/test/java/org/springframework/mock/web/test/MockHttpServletRequest.java @@ -36,6 +36,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Set; + import javax.servlet.AsyncContext; import javax.servlet.DispatcherType; import javax.servlet.RequestDispatcher; @@ -52,11 +53,12 @@ import javax.servlet.http.Part; import org.springframework.util.Assert; import org.springframework.util.LinkedCaseInsensitiveMap; +import org.springframework.util.StringUtils; /** * Mock implementation of the {@link javax.servlet.http.HttpServletRequest} interface. * - *
As of Spring 4.0, this set of mocks is entirely based on Servlet 3.0. + *
As of Spring 4.0, this set of mocks is designed on a Servlet 3.0 baseline.
*
* @author Juergen Hoeller
* @author Rod Johnson
@@ -313,7 +315,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
@Override
public Enumeration As of Spring 4.0, this set of mocks is designed on a Servlet 3.0 baseline. Beyond that,
- * this MockHttpServletResponse is also compatible with Servlet 3.1's setContentLengthLong.
+ * As of Spring 4.0, this set of mocks is designed on a Servlet 3.0 baseline.
+ * Beyond that, {@code MockHttpServletResponse} is also compatible with Servlet
+ * 3.1's {@code setContentLengthLong()} method.
*
* @author Juergen Hoeller
* @author Rod Johnson
@@ -533,13 +534,17 @@ public class MockHttpServletResponse implements HttpServletResponse {
@Override
public void setStatus(int status) {
- this.status = status;
+ if(!this.isCommitted()) {
+ this.status = status;
+ }
}
@Override
public void setStatus(int status, String errorMessage) {
- this.status = status;
- this.errorMessage = errorMessage;
+ if(!this.isCommitted()) {
+ this.status = status;
+ this.errorMessage = errorMessage;
+ }
}
@Override
diff --git a/spring-web/src/test/java/org/springframework/mock/web/test/MockHttpSession.java b/spring-web/src/test/java/org/springframework/mock/web/test/MockHttpSession.java
index 12301763b6..43357bd314 100644
--- a/spring-web/src/test/java/org/springframework/mock/web/test/MockHttpSession.java
+++ b/spring-web/src/test/java/org/springframework/mock/web/test/MockHttpSession.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@ import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
import java.util.Map;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;
@@ -34,7 +35,7 @@ import org.springframework.util.Assert;
/**
* Mock implementation of the {@link javax.servlet.http.HttpSession} interface.
*
- * Compatible with Servlet 2.5 as well as Servlet 3.0.
+ * As of Spring 4.0, this set of mocks is designed on a Servlet 3.0 baseline.
*
* Used for testing the web framework; also useful for testing application
* controllers.
@@ -50,6 +51,7 @@ public class MockHttpSession implements HttpSession {
public static final String SESSION_COOKIE_NAME = "JSESSION";
+
private static int nextId = 1;
private final String id;
@@ -100,6 +102,7 @@ public class MockHttpSession implements HttpSession {
@Override
public long getCreationTime() {
+ assertIsValid();
return this.creationTime;
}
@@ -115,6 +118,7 @@ public class MockHttpSession implements HttpSession {
@Override
public long getLastAccessedTime() {
+ assertIsValid();
return this.lastAccessedTime;
}
@@ -140,6 +144,7 @@ public class MockHttpSession implements HttpSession {
@Override
public Object getAttribute(String name) {
+ assertIsValid();
Assert.notNull(name, "Attribute name must not be null");
return this.attributes.get(name);
}
@@ -151,16 +156,19 @@ public class MockHttpSession implements HttpSession {
@Override
public Enumeration As of Spring 4.0, this set of mocks is designed on a Servlet 3.0 baseline.
+ *
* Useful for testing application controllers that access multipart uploads.
* The {@link MockMultipartFile} can be used to populate these mock requests
* with files.
diff --git a/spring-web/src/test/java/org/springframework/mock/web/test/MockServletContext.java b/spring-web/src/test/java/org/springframework/mock/web/test/MockServletContext.java
index 0878f4d246..57e6f024ef 100644
--- a/spring-web/src/test/java/org/springframework/mock/web/test/MockServletContext.java
+++ b/spring-web/src/test/java/org/springframework/mock/web/test/MockServletContext.java
@@ -56,7 +56,9 @@ import org.springframework.web.util.WebUtils;
/**
* Mock implementation of the {@link javax.servlet.ServletContext} interface.
*
- * Compatible with Servlet 3.0. Can be configured to expose a specific version
+ * As of Spring 4.0, this set of mocks is designed on a Servlet 3.0 baseline.
+ *
+ * Compatible with Servlet 3.0 but can be configured to expose a specific version
* through {@link #setMajorVersion}/{@link #setMinorVersion}; default is 3.0.
* Note that Servlet 3.0 support is limited: servlet, filter and listener
* registration methods are not supported; neither is JSP configuration.