Update Javadoc for mocks regarding Servlet 3.0
Commit deba32cad9 upgraded the Servlet API mocks to Servlet 3.0;
however, not all of the Javadoc was updated accordingly.
This commit updates the remaining Javadoc with regard to Servlet 3.0 as
the baseline for mocks in the spring-test module.
In addition, this commit syncs up the mocks used for internal testing in
the spring-web module with the most current versions from spring-test.
Issue: SPR-11049
			
			
This commit is contained in:
		
							parent
							
								
									d371886988
								
							
						
					
					
						commit
						2e6c998168
					
				|  | @ -40,8 +40,9 @@ import org.springframework.web.util.WebUtils; | |||
| /** | ||||
|  * Mock implementation of the {@link javax.servlet.http.HttpServletResponse} interface. | ||||
|  * | ||||
|  * <p>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. | ||||
|  * <p>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 | ||||
|  |  | |||
|  | @ -35,7 +35,7 @@ import org.springframework.util.Assert; | |||
| /** | ||||
|  * Mock implementation of the {@link javax.servlet.http.HttpSession} interface. | ||||
|  * | ||||
|  * <p>Compatible with Servlet 2.5 as well as Servlet 3.0. | ||||
|  * <p>As of Spring 4.0, this set of mocks is designed on a Servlet 3.0 baseline. | ||||
|  * | ||||
|  * <p>Used for testing the web framework; also useful for testing application | ||||
|  * controllers. | ||||
|  |  | |||
|  | @ -35,6 +35,8 @@ import org.springframework.web.multipart.MultipartHttpServletRequest; | |||
|  * Mock implementation of the | ||||
|  * {@link org.springframework.web.multipart.MultipartHttpServletRequest} interface. | ||||
|  * | ||||
|  * <p>As of Spring 4.0, this set of mocks is designed on a Servlet 3.0 baseline. | ||||
|  * | ||||
|  * <p>Useful for testing application controllers that access multipart uploads. | ||||
|  * The {@link MockMultipartFile} can be used to populate these mock requests | ||||
|  * with files. | ||||
|  |  | |||
|  | @ -56,7 +56,9 @@ import org.springframework.web.util.WebUtils; | |||
| /** | ||||
|  * Mock implementation of the {@link javax.servlet.ServletContext} interface. | ||||
|  * | ||||
|  * <p>Compatible with Servlet 3.0. Can be configured to expose a specific version | ||||
|  * <p>As of Spring 4.0, this set of mocks is designed on a Servlet 3.0 baseline. | ||||
|  * | ||||
|  * <p>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. | ||||
|  |  | |||
|  | @ -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. | ||||
|  * <p>Useful for testing web contexts and controllers. | ||||
|  * | ||||
|  * <p>More convenient to use than dynamic mock objects | ||||
|  * (<a href="http://www.easymock.org">EasyMock</a>) or | ||||
|  * existing Servlet API mock objects | ||||
|  * (<a href="http://www.mockobjects.com">MockObjects</a>). | ||||
|  * | ||||
|  */ | ||||
| 
 | ||||
| package org.springframework.mock.web; | ||||
| 
 | ||||
|  |  | |||
|  | @ -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. | ||||
|  * | ||||
|  * <p>As of Spring 4.0, this set of mocks is entirely based on Servlet 3.0. | ||||
|  * <p>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<String> getAttributeNames() { | ||||
| 		checkActive(); | ||||
| 		return Collections.enumeration(this.attributes.keySet()); | ||||
| 		return Collections.enumeration(new LinkedHashSet<String>(this.attributes.keySet())); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
|  | @ -946,9 +948,17 @@ public class MockHttpServletRequest implements HttpServletRequest { | |||
| 
 | ||||
| 	@Override | ||||
| 	public StringBuffer getRequestURL() { | ||||
| 		StringBuffer url = new StringBuffer(this.scheme); | ||||
| 		url.append("://").append(this.serverName).append(':').append(this.serverPort); | ||||
| 		StringBuffer url = new StringBuffer(this.scheme).append("://").append(this.serverName); | ||||
| 
 | ||||
| 		if (this.serverPort > 0 | ||||
| 				&& (("http".equalsIgnoreCase(scheme) && this.serverPort != 80) || ("https".equalsIgnoreCase(scheme) && this.serverPort != 443))) { | ||||
| 			url.append(':').append(this.serverPort); | ||||
| 		} | ||||
| 
 | ||||
| 		if (StringUtils.hasText(getRequestURI())) { | ||||
| 			url.append(getRequestURI()); | ||||
| 		} | ||||
| 
 | ||||
| 		return url; | ||||
| 	} | ||||
| 
 | ||||
|  |  | |||
|  | @ -40,8 +40,9 @@ import org.springframework.web.util.WebUtils; | |||
| /** | ||||
|  * Mock implementation of the {@link javax.servlet.http.HttpServletResponse} interface. | ||||
|  * | ||||
|  * <p>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. | ||||
|  * <p>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,14 +534,18 @@ public class MockHttpServletResponse implements HttpServletResponse { | |||
| 
 | ||||
| 	@Override | ||||
| 	public void setStatus(int status) { | ||||
| 		if(!this.isCommitted()) { | ||||
| 			this.status = status; | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setStatus(int status, String errorMessage) { | ||||
| 		if(!this.isCommitted()) { | ||||
| 			this.status = status; | ||||
| 			this.errorMessage = errorMessage; | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public int getStatus() { | ||||
|  |  | |||
|  | @ -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. | ||||
|  * | ||||
|  * <p>Compatible with Servlet 2.5 as well as Servlet 3.0. | ||||
|  * <p>As of Spring 4.0, this set of mocks is designed on a Servlet 3.0 baseline. | ||||
|  * | ||||
|  * <p>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<String> getAttributeNames() { | ||||
| 		return Collections.enumeration(this.attributes.keySet()); | ||||
| 		assertIsValid(); | ||||
| 		return Collections.enumeration(new LinkedHashSet<String>(this.attributes.keySet())); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public String[] getValueNames() { | ||||
| 		assertIsValid(); | ||||
| 		return this.attributes.keySet().toArray(new String[this.attributes.size()]); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setAttribute(String name, Object value) { | ||||
| 		assertIsValid(); | ||||
| 		Assert.notNull(name, "Attribute name must not be null"); | ||||
| 		if (value != null) { | ||||
| 			this.attributes.put(name, value); | ||||
|  | @ -180,6 +188,7 @@ public class MockHttpSession implements HttpSession { | |||
| 
 | ||||
| 	@Override | ||||
| 	public void removeAttribute(String name) { | ||||
| 		assertIsValid(); | ||||
| 		Assert.notNull(name, "Attribute name must not be null"); | ||||
| 		Object value = this.attributes.remove(name); | ||||
| 		if (value instanceof HttpSessionBindingListener) { | ||||
|  | @ -214,11 +223,7 @@ public class MockHttpSession implements HttpSession { | |||
| 	 */ | ||||
| 	@Override | ||||
| 	public void invalidate() { | ||||
| 		if (this.invalid) { | ||||
| 			throw new IllegalStateException("The session has already been invalidated"); | ||||
| 		} | ||||
| 
 | ||||
| 		// else | ||||
| 		assertIsValid(); | ||||
| 		this.invalid = true; | ||||
| 		clearAttributes(); | ||||
| 	} | ||||
|  | @ -227,12 +232,25 @@ public class MockHttpSession implements HttpSession { | |||
| 		return this.invalid; | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Convenience method for asserting that this session has not been | ||||
| 	 * {@linkplain #invalidate() invalidated}. | ||||
| 	 *  | ||||
| 	 * @throws IllegalStateException if this session has been invalidated | ||||
| 	 */ | ||||
| 	private void assertIsValid() { | ||||
| 		if (isInvalid()) { | ||||
| 			throw new IllegalStateException("The session has already been invalidated"); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	public void setNew(boolean value) { | ||||
| 		this.isNew = value; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public boolean isNew() { | ||||
| 		assertIsValid(); | ||||
| 		return this.isNew; | ||||
| 	} | ||||
| 
 | ||||
|  |  | |||
|  | @ -35,6 +35,8 @@ import org.springframework.web.multipart.MultipartHttpServletRequest; | |||
|  * Mock implementation of the | ||||
|  * {@link org.springframework.web.multipart.MultipartHttpServletRequest} interface. | ||||
|  * | ||||
|  * <p>As of Spring 4.0, this set of mocks is designed on a Servlet 3.0 baseline. | ||||
|  * | ||||
|  * <p>Useful for testing application controllers that access multipart uploads. | ||||
|  * The {@link MockMultipartFile} can be used to populate these mock requests | ||||
|  * with files. | ||||
|  |  | |||
|  | @ -56,7 +56,9 @@ import org.springframework.web.util.WebUtils; | |||
| /** | ||||
|  * Mock implementation of the {@link javax.servlet.ServletContext} interface. | ||||
|  * | ||||
|  * <p>Compatible with Servlet 3.0. Can be configured to expose a specific version | ||||
|  * <p>As of Spring 4.0, this set of mocks is designed on a Servlet 3.0 baseline. | ||||
|  * | ||||
|  * <p>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. | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue