Suppressing warnings, polishing JavaDoc, etc.
This commit is contained in:
parent
e7c2713fd4
commit
6926e0f563
|
|
@ -27,19 +27,21 @@ import javax.servlet.jsp.el.VariableResolver;
|
|||
import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;
|
||||
|
||||
/**
|
||||
* Mock implementation of the JSP 2.0 {@link javax.servlet.jsp.el.ExpressionEvaluator}
|
||||
* interface, delegating to the Jakarta JSTL ExpressionEvaluatorManager.
|
||||
*
|
||||
* <p>Used for testing the web framework; only necessary for testing
|
||||
* applications when testing custom JSP tags.
|
||||
*
|
||||
* <p>Note that the Jakarta JSTL implementation (jstl.jar, standard.jar)
|
||||
* has to be available on the class path to use this expression evaluator.
|
||||
*
|
||||
* Mock implementation of the JSP 2.0
|
||||
* {@link javax.servlet.jsp.el.ExpressionEvaluator} interface, delegating to the
|
||||
* Jakarta JSTL ExpressionEvaluatorManager.
|
||||
* <p>
|
||||
* Used for testing the web framework; only necessary for testing applications
|
||||
* when testing custom JSP tags.
|
||||
* <p>
|
||||
* Note that the Jakarta JSTL implementation (jstl.jar, standard.jar) has to be
|
||||
* available on the class path to use this expression evaluator.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 1.1.5
|
||||
* @see org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class MockExpressionEvaluator extends ExpressionEvaluator {
|
||||
|
||||
private final PageContext pageContext;
|
||||
|
|
@ -47,26 +49,28 @@ public class MockExpressionEvaluator extends ExpressionEvaluator {
|
|||
|
||||
/**
|
||||
* Create a new MockExpressionEvaluator for the given PageContext.
|
||||
*
|
||||
* @param pageContext the JSP PageContext to run in
|
||||
*/
|
||||
public MockExpressionEvaluator(PageContext pageContext) {
|
||||
this.pageContext = pageContext;
|
||||
}
|
||||
|
||||
public Expression parseExpression(
|
||||
final String expression, final Class expectedType, final FunctionMapper functionMapper)
|
||||
throws ELException {
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Expression parseExpression(final String expression, final Class expectedType,
|
||||
final FunctionMapper functionMapper) throws ELException {
|
||||
|
||||
return new Expression() {
|
||||
|
||||
public Object evaluate(VariableResolver variableResolver) throws ELException {
|
||||
return doEvaluate(expression, expectedType, functionMapper);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public Object evaluate(
|
||||
String expression, Class expectedType, VariableResolver variableResolver, FunctionMapper functionMapper)
|
||||
throws ELException {
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Object evaluate(String expression, Class expectedType, VariableResolver variableResolver,
|
||||
FunctionMapper functionMapper) throws ELException {
|
||||
|
||||
if (variableResolver != null) {
|
||||
throw new IllegalArgumentException("Custom VariableResolver not supported");
|
||||
|
|
@ -74,8 +78,8 @@ public class MockExpressionEvaluator extends ExpressionEvaluator {
|
|||
return doEvaluate(expression, expectedType, functionMapper);
|
||||
}
|
||||
|
||||
protected Object doEvaluate(
|
||||
String expression, Class expectedType, FunctionMapper functionMapper)
|
||||
@SuppressWarnings("rawtypes")
|
||||
protected Object doEvaluate(String expression, Class expectedType, FunctionMapper functionMapper)
|
||||
throws ELException {
|
||||
|
||||
if (functionMapper != null) {
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ import java.util.Locale;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Vector;
|
||||
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletInputStream;
|
||||
|
|
@ -48,10 +49,10 @@ import org.springframework.util.LinkedCaseInsensitiveMap;
|
|||
/**
|
||||
* Mock implementation of the {@link javax.servlet.http.HttpServletRequest}
|
||||
* interface. Supports the Servlet 2.5 API level.
|
||||
*
|
||||
* <p>Used for testing the web framework; also useful for testing
|
||||
* application controllers.
|
||||
*
|
||||
* <p>
|
||||
* Used for testing the web framework; also useful for testing application
|
||||
* controllers.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @author Rod Johnson
|
||||
* @author Rick Evans
|
||||
|
|
@ -90,13 +91,11 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
|||
*/
|
||||
public static final String DEFAULT_REMOTE_HOST = "localhost";
|
||||
|
||||
|
||||
private boolean active = true;
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------
|
||||
// ServletRequest properties
|
||||
//---------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
private final Map<String, Object> attributes = new LinkedHashMap<String, Object>();
|
||||
|
||||
|
|
@ -135,10 +134,9 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
|||
|
||||
private int localPort = DEFAULT_SERVER_PORT;
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------
|
||||
// HttpServletRequest properties
|
||||
//---------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
private String authType;
|
||||
|
||||
|
|
@ -175,13 +173,14 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
|||
private boolean requestedSessionIdFromURL = false;
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------
|
||||
// Constructors
|
||||
//---------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Create a new MockHttpServletRequest with a default
|
||||
* {@link MockServletContext}.
|
||||
*
|
||||
* @see MockServletContext
|
||||
*/
|
||||
public MockHttpServletRequest() {
|
||||
|
|
@ -191,6 +190,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
|||
/**
|
||||
* Create a new MockHttpServletRequest with a default
|
||||
* {@link MockServletContext}.
|
||||
*
|
||||
* @param method the request method (may be <code>null</code>)
|
||||
* @param requestURI the request URI (may be <code>null</code>)
|
||||
* @see #setMethod
|
||||
|
|
@ -203,8 +203,9 @@ 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)
|
||||
*
|
||||
* @param servletContext the ServletContext that the request runs in (may be
|
||||
* <code>null</code> to use a default MockServletContext)
|
||||
* @see MockServletContext
|
||||
*/
|
||||
public MockHttpServletRequest(ServletContext servletContext) {
|
||||
|
|
@ -213,8 +214,9 @@ 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)
|
||||
*
|
||||
* @param servletContext the ServletContext that the request runs in (may be
|
||||
* <code>null</code> to use a default MockServletContext)
|
||||
* @param method the request method (may be <code>null</code>)
|
||||
* @param requestURI the request URI (may be <code>null</code>)
|
||||
* @see #setMethod
|
||||
|
|
@ -228,14 +230,13 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
|||
this.locales.add(Locale.ENGLISH);
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------
|
||||
// Lifecycle methods
|
||||
//---------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Return the ServletContext that this request is associated with.
|
||||
* (Not available in the standard HttpServletRequest interface for some reason.)
|
||||
* Return the ServletContext that this request is associated with. (Not
|
||||
* available in the standard HttpServletRequest interface for some reason.)
|
||||
*/
|
||||
public ServletContext getServletContext() {
|
||||
return this.servletContext;
|
||||
|
|
@ -273,10 +274,9 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------
|
||||
// ServletRequest interface
|
||||
//---------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
public Object getAttribute(String name) {
|
||||
checkActive();
|
||||
|
|
@ -323,16 +323,18 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
|||
|
||||
/**
|
||||
* Set a single value for the specified HTTP parameter.
|
||||
* <p>If there are already one or more values registered for the given
|
||||
* <p>
|
||||
* If there are already one or more values registered for the given
|
||||
* parameter name, they will be replaced.
|
||||
*/
|
||||
public void setParameter(String name, String value) {
|
||||
setParameter(name, new String[] {value});
|
||||
setParameter(name, new String[] { value });
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an array of values for the specified HTTP parameter.
|
||||
* <p>If there are already one or more values registered for the given
|
||||
* <p>
|
||||
* If there are already one or more values registered for the given
|
||||
* parameter name, they will be replaced.
|
||||
*/
|
||||
public void setParameter(String name, String[] values) {
|
||||
|
|
@ -341,15 +343,15 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
|||
}
|
||||
|
||||
/**
|
||||
* Sets all provided parameters <emphasis>replacing</emphasis> any
|
||||
* existing values for the provided parameter names. To add without
|
||||
* replacing existing values, use {@link #addParameters(java.util.Map)}.
|
||||
* Sets all provided parameters <emphasis>replacing</emphasis> any existing
|
||||
* values for the provided parameter names. To add without replacing
|
||||
* existing values, use {@link #addParameters(java.util.Map)}.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void setParameters(Map params) {
|
||||
Assert.notNull(params, "Parameter map must not be null");
|
||||
for (Object key : params.keySet()) {
|
||||
Assert.isInstanceOf(String.class, key,
|
||||
"Parameter map key must be of type [" + String.class.getName() + "]");
|
||||
Assert.isInstanceOf(String.class, key, "Parameter map key must be of type [" + String.class.getName() + "]");
|
||||
Object value = params.get(key);
|
||||
if (value instanceof String) {
|
||||
this.setParameter((String) key, (String) value);
|
||||
|
|
@ -358,25 +360,26 @@ 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() + "]");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a single value for the specified HTTP parameter.
|
||||
* <p>If there are already one or more values registered for the given
|
||||
* <p>
|
||||
* If there are already one or more values registered for the given
|
||||
* parameter name, the given value will be added to the end of the list.
|
||||
*/
|
||||
public void addParameter(String name, String value) {
|
||||
addParameter(name, new String[] {value});
|
||||
addParameter(name, new String[] { value });
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an array of values for the specified HTTP parameter.
|
||||
* <p>If there are already one or more values registered for the given
|
||||
* <p>
|
||||
* If there are already one or more values registered for the given
|
||||
* parameter name, the given values will be added to the end of the list.
|
||||
*/
|
||||
public void addParameter(String name, String[] values) {
|
||||
|
|
@ -394,15 +397,15 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
|||
}
|
||||
|
||||
/**
|
||||
* Adds all provided parameters <emphasis>without</emphasis> replacing
|
||||
* any existing values. To replace existing values, use
|
||||
* Adds all provided parameters <emphasis>without</emphasis> replacing any
|
||||
* existing values. To replace existing values, use
|
||||
* {@link #setParameters(java.util.Map)}.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void addParameters(Map params) {
|
||||
Assert.notNull(params, "Parameter map must not be null");
|
||||
for (Object key : params.keySet()) {
|
||||
Assert.isInstanceOf(String.class, key,
|
||||
"Parameter map key must be of type [" + String.class.getName() + "]");
|
||||
Assert.isInstanceOf(String.class, key, "Parameter map key must be of type [" + String.class.getName() + "]");
|
||||
Object value = params.get(key);
|
||||
if (value instanceof String) {
|
||||
this.addParameter((String) key, (String) value);
|
||||
|
|
@ -411,14 +414,15 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
|||
this.addParameter((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() + "]");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove already registered values for the specified HTTP parameter, if any.
|
||||
* Remove already registered values for the specified HTTP parameter, if
|
||||
* any.
|
||||
*/
|
||||
public void removeParameter(String name) {
|
||||
Assert.notNull(name, "Parameter name must not be null");
|
||||
|
|
@ -486,8 +490,8 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
|||
public BufferedReader getReader() throws UnsupportedEncodingException {
|
||||
if (this.content != null) {
|
||||
InputStream sourceStream = new ByteArrayInputStream(this.content);
|
||||
Reader sourceReader = (this.characterEncoding != null) ?
|
||||
new InputStreamReader(sourceStream, this.characterEncoding) : new InputStreamReader(sourceStream);
|
||||
Reader sourceReader = (this.characterEncoding != null) ? new InputStreamReader(sourceStream,
|
||||
this.characterEncoding) : new InputStreamReader(sourceStream);
|
||||
return new BufferedReader(sourceReader);
|
||||
}
|
||||
else {
|
||||
|
|
@ -599,10 +603,9 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
|||
return this.localPort;
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------
|
||||
// HttpServletRequest interface
|
||||
//---------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
public void setAuthType(String authType) {
|
||||
this.authType = authType;
|
||||
|
|
@ -622,21 +625,25 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
|||
|
||||
/**
|
||||
* Add a header entry for the given name.
|
||||
* <p>If there was no entry for that header name before,
|
||||
* the value will be used as-is. In case of an existing entry,
|
||||
* a String array will be created, adding the given value (more
|
||||
* specifically, its toString representation) as further element.
|
||||
* <p>Multiple values can only be stored as list of Strings,
|
||||
* following the Servlet spec (see <code>getHeaders</code> accessor).
|
||||
* As alternative to repeated <code>addHeader</code> calls for
|
||||
* individual elements, you can use a single call with an entire
|
||||
* array or Collection of values as parameter.
|
||||
* <p>
|
||||
* If there was no entry for that header name before, the value will be used
|
||||
* as-is. In case of an existing entry, a String array will be created,
|
||||
* adding the given value (more specifically, its toString representation)
|
||||
* as further element.
|
||||
* <p>
|
||||
* Multiple values can only be stored as list of Strings, following the
|
||||
* Servlet spec (see <code>getHeaders</code> accessor). As alternative to
|
||||
* repeated <code>addHeader</code> calls for individual elements, you can
|
||||
* use a single call with an entire array or Collection of values as
|
||||
* parameter.
|
||||
*
|
||||
* @see #getHeaderNames
|
||||
* @see #getHeader
|
||||
* @see #getHeaders
|
||||
* @see #getDateHeader
|
||||
* @see #getIntHeader
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void addHeader(String name, Object value) {
|
||||
HeaderValueHolder header = HeaderValueHolder.getByName(this.headers, name);
|
||||
Assert.notNull(value, "Header value must not be null");
|
||||
|
|
@ -665,8 +672,8 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
|||
return ((Number) value).longValue();
|
||||
}
|
||||
else if (value != null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Value for header '" + name + "' is neither a Date nor a Number: " + value);
|
||||
throw new IllegalArgumentException("Value for header '" + name + "' is neither a Date nor a Number: "
|
||||
+ value);
|
||||
}
|
||||
else {
|
||||
return -1L;
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import java.util.Iterator;
|
|||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Vector;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import javax.servlet.http.HttpSessionBindingEvent;
|
||||
|
|
@ -34,22 +35,22 @@ import org.springframework.util.Assert;
|
|||
/**
|
||||
* Mock implementation of the {@link javax.servlet.http.HttpSession} interface.
|
||||
* Supports the Servlet 2.4 API level.
|
||||
*
|
||||
* <p>Used for testing the web framework; also useful for testing
|
||||
* application controllers.
|
||||
*
|
||||
* <p>
|
||||
* Used for testing the web framework; also useful for testing application
|
||||
* controllers.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @author Rod Johnson
|
||||
* @author Mark Fisher
|
||||
* @since 1.0.2
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class MockHttpSession implements HttpSession {
|
||||
|
||||
public static final String SESSION_COOKIE_NAME = "JSESSION";
|
||||
|
||||
private static int nextId = 1;
|
||||
|
||||
|
||||
private final String id;
|
||||
|
||||
private final long creationTime = System.currentTimeMillis();
|
||||
|
|
@ -69,6 +70,7 @@ public class MockHttpSession implements HttpSession {
|
|||
|
||||
/**
|
||||
* Create a new MockHttpSession with a default {@link MockServletContext}.
|
||||
*
|
||||
* @see MockServletContext
|
||||
*/
|
||||
public MockHttpSession() {
|
||||
|
|
@ -77,6 +79,7 @@ public class MockHttpSession implements HttpSession {
|
|||
|
||||
/**
|
||||
* Create a new MockHttpSession.
|
||||
*
|
||||
* @param servletContext the ServletContext that the session runs in
|
||||
*/
|
||||
public MockHttpSession(ServletContext servletContext) {
|
||||
|
|
@ -85,6 +88,7 @@ public class MockHttpSession implements HttpSession {
|
|||
|
||||
/**
|
||||
* Create a new MockHttpSession.
|
||||
*
|
||||
* @param servletContext the ServletContext that the session runs in
|
||||
* @param id a unique identifier for this session
|
||||
*/
|
||||
|
|
@ -93,7 +97,6 @@ public class MockHttpSession implements HttpSession {
|
|||
this.id = (id != null ? id : Integer.toString(nextId++));
|
||||
}
|
||||
|
||||
|
||||
public long getCreationTime() {
|
||||
return this.creationTime;
|
||||
}
|
||||
|
|
@ -205,10 +208,10 @@ public class MockHttpSession implements HttpSession {
|
|||
return this.isNew;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Serialize the attributes of this session into an object that can
|
||||
* be turned into a byte array with standard Java serialization.
|
||||
* Serialize the attributes of this session into an object that can be
|
||||
* turned into a byte array with standard Java serialization.
|
||||
*
|
||||
* @return a representation of this session's serialized state
|
||||
*/
|
||||
public Serializable serializeState() {
|
||||
|
|
@ -233,8 +236,9 @@ public class MockHttpSession implements HttpSession {
|
|||
}
|
||||
|
||||
/**
|
||||
* Deserialize the attributes of this session from a state object
|
||||
* created by {@link #serializeState()}.
|
||||
* Deserialize the attributes of this session from a state object created by
|
||||
* {@link #serializeState()}.
|
||||
*
|
||||
* @param state a representation of this session's serialized state
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import java.util.Enumeration;
|
|||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Vector;
|
||||
|
||||
import javax.el.ELContext;
|
||||
import javax.servlet.Servlet;
|
||||
import javax.servlet.ServletConfig;
|
||||
|
|
@ -40,17 +41,18 @@ import org.springframework.util.Assert;
|
|||
|
||||
/**
|
||||
* Mock implementation of the {@link javax.servlet.jsp.PageContext} interface.
|
||||
*
|
||||
* <p>Used for testing the web framework; only necessary for testing
|
||||
* applications when testing custom JSP tags.
|
||||
*
|
||||
* <p>Note: Expects initialization via the constructor rather than via the
|
||||
* <code>PageContext.initialize</code> method. Does not support writing to
|
||||
* a JspWriter, request dispatching, and <code>handlePageException</code> calls.
|
||||
*
|
||||
* <p>
|
||||
* Used for testing the web framework; only necessary for testing applications
|
||||
* when testing custom JSP tags.
|
||||
* <p>
|
||||
* Note: Expects initialization via the constructor rather than via the
|
||||
* <code>PageContext.initialize</code> method. Does not support writing to a
|
||||
* JspWriter, request dispatching, and <code>handlePageException</code> calls.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 1.0.2
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class MockPageContext extends PageContext {
|
||||
|
||||
private final ServletContext servletContext;
|
||||
|
|
@ -78,8 +80,9 @@ public class MockPageContext extends PageContext {
|
|||
/**
|
||||
* Create new MockPageContext with a default {@link MockHttpServletRequest},
|
||||
* {@link MockHttpServletResponse}, {@link MockServletConfig}.
|
||||
* @param servletContext the ServletContext that the JSP page runs in
|
||||
* (only necessary when actually accessing the ServletContext)
|
||||
*
|
||||
* @param servletContext the ServletContext that the JSP page runs in (only
|
||||
* necessary when actually accessing the ServletContext)
|
||||
*/
|
||||
public MockPageContext(ServletContext servletContext) {
|
||||
this(servletContext, null, null, null);
|
||||
|
|
@ -88,9 +91,10 @@ public class MockPageContext extends PageContext {
|
|||
/**
|
||||
* Create new MockPageContext with a MockHttpServletResponse,
|
||||
* MockServletConfig.
|
||||
*
|
||||
* @param servletContext the ServletContext that the JSP page runs in
|
||||
* @param request the current HttpServletRequest
|
||||
* (only necessary when actually accessing the request)
|
||||
* @param request the current HttpServletRequest (only necessary when
|
||||
* actually accessing the request)
|
||||
*/
|
||||
public MockPageContext(ServletContext servletContext, HttpServletRequest request) {
|
||||
this(servletContext, request, null, null);
|
||||
|
|
@ -98,10 +102,11 @@ public class MockPageContext extends PageContext {
|
|||
|
||||
/**
|
||||
* Create new MockPageContext with a MockServletConfig.
|
||||
*
|
||||
* @param servletContext the ServletContext that the JSP page runs in
|
||||
* @param request the current HttpServletRequest
|
||||
* @param response the current HttpServletResponse
|
||||
* (only necessary when actually writing to the response)
|
||||
* @param response the current HttpServletResponse (only necessary when
|
||||
* actually writing to the response)
|
||||
*/
|
||||
public MockPageContext(ServletContext servletContext, HttpServletRequest request, HttpServletResponse response) {
|
||||
this(servletContext, request, response, null);
|
||||
|
|
@ -109,13 +114,15 @@ public class MockPageContext extends PageContext {
|
|||
|
||||
/**
|
||||
* Create new MockServletConfig.
|
||||
*
|
||||
* @param servletContext the ServletContext that the JSP page runs in
|
||||
* @param request the current HttpServletRequest
|
||||
* @param response the current HttpServletResponse
|
||||
* @param servletConfig the ServletConfig (hardly ever accessed from within a tag)
|
||||
* @param servletConfig the ServletConfig (hardly ever accessed from within
|
||||
* a tag)
|
||||
*/
|
||||
public MockPageContext(ServletContext servletContext, HttpServletRequest request,
|
||||
HttpServletResponse response, ServletConfig servletConfig) {
|
||||
public MockPageContext(ServletContext servletContext, HttpServletRequest request, HttpServletResponse response,
|
||||
ServletConfig servletConfig) {
|
||||
|
||||
this.servletContext = (servletContext != null ? servletContext : new MockServletContext());
|
||||
this.request = (request != null ? request : new MockHttpServletRequest(servletContext));
|
||||
|
|
@ -123,10 +130,8 @@ public class MockPageContext extends PageContext {
|
|||
this.servletConfig = (servletConfig != null ? servletConfig : new MockServletConfig(servletContext));
|
||||
}
|
||||
|
||||
|
||||
public void initialize(
|
||||
Servlet servlet, ServletRequest request, ServletResponse response,
|
||||
String errorPageURL, boolean needsSession, int bufferSize, boolean autoFlush) {
|
||||
public void initialize(Servlet servlet, ServletRequest request, ServletResponse response, String errorPageURL,
|
||||
boolean needsSession, int bufferSize, boolean autoFlush) {
|
||||
|
||||
throw new UnsupportedOperationException("Use appropriate constructor");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import java.util.Locale;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Vector;
|
||||
|
||||
import javax.portlet.PortalContext;
|
||||
import javax.portlet.PortletContext;
|
||||
import javax.portlet.PortletMode;
|
||||
|
|
@ -41,7 +42,7 @@ import org.springframework.util.CollectionUtils;
|
|||
|
||||
/**
|
||||
* Mock implementation of the {@link javax.portlet.PortletRequest} interface.
|
||||
*
|
||||
*
|
||||
* @author John A. Lewis
|
||||
* @author Juergen Hoeller
|
||||
* @since 2.0
|
||||
|
|
@ -102,6 +103,7 @@ public class MockPortletRequest implements PortletRequest {
|
|||
/**
|
||||
* Create a new MockPortletRequest with a default {@link MockPortalContext}
|
||||
* and a default {@link MockPortletContext}.
|
||||
*
|
||||
* @see MockPortalContext
|
||||
* @see MockPortletContext
|
||||
*/
|
||||
|
|
@ -111,6 +113,7 @@ public class MockPortletRequest implements PortletRequest {
|
|||
|
||||
/**
|
||||
* Create a new MockPortletRequest with a default {@link MockPortalContext}.
|
||||
*
|
||||
* @param portletContext the PortletContext that the request runs in
|
||||
* @see MockPortalContext
|
||||
*/
|
||||
|
|
@ -120,6 +123,7 @@ public class MockPortletRequest implements PortletRequest {
|
|||
|
||||
/**
|
||||
* Create a new MockPortletRequest.
|
||||
*
|
||||
* @param portalContext the PortalContext that the request runs in
|
||||
* @param portletContext the PortletContext that the request runs in
|
||||
*/
|
||||
|
|
@ -131,10 +135,9 @@ public class MockPortletRequest implements PortletRequest {
|
|||
this.attributes.put(LIFECYCLE_PHASE, getLifecyclePhase());
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------
|
||||
// Lifecycle methods
|
||||
//---------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Return the Portlet 2.0 lifecycle id for the current phase.
|
||||
|
|
@ -167,10 +170,9 @@ public class MockPortletRequest implements PortletRequest {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------
|
||||
// PortletRequest methods
|
||||
//---------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
public boolean isWindowStateAllowed(WindowState windowState) {
|
||||
return CollectionUtils.contains(this.portalContext.getSupportedWindowStates(), windowState);
|
||||
|
|
@ -234,8 +236,9 @@ public class MockPortletRequest implements PortletRequest {
|
|||
|
||||
/**
|
||||
* Set a single value for the specified property.
|
||||
* <p>If there are already one or more values registered for the given
|
||||
* property key, they will be replaced.
|
||||
* <p>
|
||||
* If there are already one or more values registered for the given property
|
||||
* key, they will be replaced.
|
||||
*/
|
||||
public void setProperty(String key, String value) {
|
||||
Assert.notNull(key, "Property key must not be null");
|
||||
|
|
@ -246,8 +249,9 @@ public class MockPortletRequest implements PortletRequest {
|
|||
|
||||
/**
|
||||
* Add a single value for the specified property.
|
||||
* <p>If there are already one or more values registered for the given
|
||||
* property key, the given value will be added to the end of the list.
|
||||
* <p>
|
||||
* If there are already one or more values registered for the given property
|
||||
* key, the given value will be added to the end of the list.
|
||||
*/
|
||||
public void addProperty(String key, String value) {
|
||||
Assert.notNull(key, "Property key must not be null");
|
||||
|
|
@ -264,7 +268,7 @@ public class MockPortletRequest implements PortletRequest {
|
|||
|
||||
public String getProperty(String key) {
|
||||
Assert.notNull(key, "Property key must not be null");
|
||||
List list = this.properties.get(key);
|
||||
List<String> list = this.properties.get(key);
|
||||
return (list != null && list.size() > 0 ? (String) list.get(0) : null);
|
||||
}
|
||||
|
||||
|
|
@ -340,7 +344,7 @@ public class MockPortletRequest implements PortletRequest {
|
|||
public void setParameter(String key, String value) {
|
||||
Assert.notNull(key, "Parameter key must be null");
|
||||
Assert.notNull(value, "Parameter value must not be null");
|
||||
this.parameters.put(key, new String[] {value});
|
||||
this.parameters.put(key, new String[] { value });
|
||||
}
|
||||
|
||||
public void setParameter(String key, String[] values) {
|
||||
|
|
@ -350,7 +354,7 @@ public class MockPortletRequest implements PortletRequest {
|
|||
}
|
||||
|
||||
public void addParameter(String name, String value) {
|
||||
addParameter(name, new String[] {value});
|
||||
addParameter(name, new String[] { value });
|
||||
}
|
||||
|
||||
public void addParameter(String name, String[] values) {
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ import org.springframework.util.Assert;
|
|||
* ({@link org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests})
|
||||
*/
|
||||
@Deprecated
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public abstract class AbstractDependencyInjectionSpringContextTests extends AbstractSingleSpringContextTests {
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@ import org.springframework.dao.DataAccessException;
|
|||
import org.springframework.dao.DataAccessResourceFailureException;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.test.jdbc.JdbcTestUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Subclass of AbstractTransactionalSpringContextTests that adds some convenience
|
||||
|
|
@ -49,6 +48,7 @@ import org.springframework.util.StringUtils;
|
|||
* ({@link org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests})
|
||||
*/
|
||||
@Deprecated
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public abstract class AbstractTransactionalDataSourceSpringContextTests
|
||||
extends AbstractTransactionalSpringContextTests {
|
||||
|
||||
|
|
|
|||
|
|
@ -84,6 +84,7 @@ package org.springframework.test;
|
|||
* @deprecated favor use of JUnit 4's {@code @Test(expected=...)} support
|
||||
*/
|
||||
@Deprecated
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public abstract class AssertThrows {
|
||||
|
||||
private final Class expectedException;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
|
||||
/**
|
||||
*
|
||||
* <p>Support classes for ApplicationContext-based and transactional
|
||||
* tests run with JUnit 3.8 and the <em>Spring TestContext Framework</em>.</p>
|
||||
*
|
||||
*/
|
||||
|
||||
package org.springframework.test.context.junit38;
|
||||
|
||||
|
|
|
|||
|
|
@ -462,6 +462,7 @@ public class SpringJUnit4ClassRunner extends BlockJUnit4ClassRunner {
|
|||
* @see RunBeforeTestMethodCallbacks
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
protected Statement withBefores(FrameworkMethod frameworkMethod, Object testInstance, Statement statement) {
|
||||
Statement junitBefores = super.withBefores(frameworkMethod, testInstance, statement);
|
||||
return new RunBeforeTestMethodCallbacks(junitBefores, testInstance, frameworkMethod.getMethod(),
|
||||
|
|
@ -477,6 +478,7 @@ public class SpringJUnit4ClassRunner extends BlockJUnit4ClassRunner {
|
|||
* @see RunAfterTestMethodCallbacks
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
protected Statement withAfters(FrameworkMethod frameworkMethod, Object testInstance, Statement statement) {
|
||||
Statement junitAfters = super.withAfters(frameworkMethod, testInstance, statement);
|
||||
return new RunAfterTestMethodCallbacks(junitAfters, testInstance, frameworkMethod.getMethod(),
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
|
||||
/**
|
||||
*
|
||||
* <p>Support classes for the <em>Spring TestContext Framework</em>.</p>
|
||||
*
|
||||
*/
|
||||
|
||||
package org.springframework.test.context.support;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
|
||||
/**
|
||||
*
|
||||
* <p>Support classes for ApplicationContext-based and transactional
|
||||
* tests run with TestNG and the <em>Spring TestContext Framework</em>.</p>
|
||||
*
|
||||
*/
|
||||
|
||||
package org.springframework.test.context.testng;
|
||||
|
||||
|
|
|
|||
|
|
@ -52,8 +52,8 @@ import org.springframework.util.StringUtils;
|
|||
* <p>
|
||||
* <code>TestExecutionListener</code> which provides support for executing
|
||||
* tests within transactions by using
|
||||
* {@link org.springframework.transaction.annotation.Transactional @Transactional}
|
||||
* and {@link NotTransactional @NotTransactional} annotations.
|
||||
* {@link org.springframework.transaction.annotation.Transactional @Transactional}
|
||||
* and {@link NotTransactional @NotTransactional} annotations.
|
||||
* </p>
|
||||
* <p>
|
||||
* Changes to the database during a test run with @Transactional will be
|
||||
|
|
@ -66,9 +66,9 @@ import org.springframework.util.StringUtils;
|
|||
* </p>
|
||||
* <p>
|
||||
* Transactional commit and rollback behavior can be configured via the
|
||||
* class-level {@link TransactionConfiguration @TransactionConfiguration} and
|
||||
* method-level {@link Rollback @Rollback} annotations.
|
||||
* {@link TransactionConfiguration @TransactionConfiguration} also provides
|
||||
* class-level {@link TransactionConfiguration @TransactionConfiguration} and
|
||||
* method-level {@link Rollback @Rollback} annotations.
|
||||
* {@link TransactionConfiguration @TransactionConfiguration} also provides
|
||||
* configuration of the bean name of the {@link PlatformTransactionManager} that
|
||||
* is to be used to drive transactions.
|
||||
* </p>
|
||||
|
|
@ -77,8 +77,8 @@ import org.springframework.util.StringUtils;
|
|||
* certain <em>set up</em> or <em>tear down</em> code outside of a
|
||||
* transaction. <code>TransactionalTestExecutionListener</code> provides such
|
||||
* support for methods annotated with
|
||||
* {@link BeforeTransaction @BeforeTransaction} and
|
||||
* {@link AfterTransaction @AfterTransaction}.
|
||||
* {@link BeforeTransaction @BeforeTransaction} and
|
||||
* {@link AfterTransaction @AfterTransaction}.
|
||||
* </p>
|
||||
*
|
||||
* @author Sam Brannen
|
||||
|
|
@ -91,6 +91,7 @@ import org.springframework.util.StringUtils;
|
|||
* @see BeforeTransaction
|
||||
* @see AfterTransaction
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class TransactionalTestExecutionListener extends AbstractTestExecutionListener {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(TransactionalTestExecutionListener.class);
|
||||
|
|
@ -107,10 +108,10 @@ public class TransactionalTestExecutionListener extends AbstractTestExecutionLis
|
|||
/**
|
||||
* If the test method of the supplied {@link TestContext test context} is
|
||||
* configured to run within a transaction, this method will run
|
||||
* {@link BeforeTransaction @BeforeTransaction methods} and start a new
|
||||
* {@link BeforeTransaction @BeforeTransaction methods} and start a new
|
||||
* transaction.
|
||||
* <p>Note that if a {@link BeforeTransaction @BeforeTransaction method} fails,
|
||||
* remaining {@link BeforeTransaction @BeforeTransaction methods} will not
|
||||
* <p>Note that if a {@link BeforeTransaction @BeforeTransaction method} fails,
|
||||
* remaining {@link BeforeTransaction @BeforeTransaction methods} will not
|
||||
* be invoked, and a transaction will not be started.
|
||||
* @see org.springframework.transaction.annotation.Transactional
|
||||
* @see org.springframework.test.annotation.NotTransactional
|
||||
|
|
@ -167,8 +168,8 @@ public class TransactionalTestExecutionListener extends AbstractTestExecutionLis
|
|||
/**
|
||||
* If a transaction is currently active for the test method of the supplied
|
||||
* {@link TestContext test context}, this method will end the transaction
|
||||
* and run {@link AfterTransaction @AfterTransaction methods}.
|
||||
* <p>{@link AfterTransaction @AfterTransaction methods} are guaranteed to be
|
||||
* and run {@link AfterTransaction @AfterTransaction methods}.
|
||||
* <p>{@link AfterTransaction @AfterTransaction methods} are guaranteed to be
|
||||
* invoked even if an error occurs while ending the transaction.
|
||||
*/
|
||||
@Override
|
||||
|
|
@ -189,7 +190,7 @@ public class TransactionalTestExecutionListener extends AbstractTestExecutionLis
|
|||
}
|
||||
|
||||
/**
|
||||
* Run all {@link BeforeTransaction @BeforeTransaction methods} for the
|
||||
* Run all {@link BeforeTransaction @BeforeTransaction methods} for the
|
||||
* specified {@link TestContext test context}. If one of the methods fails,
|
||||
* however, the caught exception will be rethrown in a wrapped
|
||||
* {@link RuntimeException}, and the remaining methods will <strong>not</strong>
|
||||
|
|
@ -216,7 +217,7 @@ public class TransactionalTestExecutionListener extends AbstractTestExecutionLis
|
|||
}
|
||||
|
||||
/**
|
||||
* Run all {@link AfterTransaction @AfterTransaction methods} for the
|
||||
* Run all {@link AfterTransaction @AfterTransaction methods} for the
|
||||
* specified {@link TestContext test context}. If one of the methods fails,
|
||||
* the caught exception will be logged as an error, and the remaining
|
||||
* methods will be given a chance to execute. After all methods have
|
||||
|
|
@ -449,7 +450,7 @@ public class TransactionalTestExecutionListener extends AbstractTestExecutionLis
|
|||
/**
|
||||
* Retrieves the {@link TransactionConfigurationAttributes} for the
|
||||
* specified {@link Class class} which may optionally declare or inherit a
|
||||
* {@link TransactionConfiguration @TransactionConfiguration}. If a
|
||||
* {@link TransactionConfiguration @TransactionConfiguration}. If a
|
||||
* {@link TransactionConfiguration} annotation is not present for the
|
||||
* supplied class, the <em>default values</em> for attributes defined in
|
||||
* {@link TransactionConfiguration} will be used instead.
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
|
||||
/**
|
||||
*
|
||||
* <p>Transactional support classes for the <em>Spring TestContext
|
||||
* Framework</em>.</p>
|
||||
*
|
||||
*/
|
||||
|
||||
package org.springframework.test.context.transaction;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
|
||||
/**
|
||||
*
|
||||
* Support classes for tests based on JDBC.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.springframework.test.jdbc;
|
||||
|
||||
|
|
|
|||
|
|
@ -161,6 +161,7 @@ public abstract class AbstractJpaTests extends AbstractAnnotationAwareTransactio
|
|||
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public void runBare() throws Throwable {
|
||||
if (!shouldUseShadowLoader()) {
|
||||
super.runBare();
|
||||
|
|
@ -308,6 +309,7 @@ public abstract class AbstractJpaTests extends AbstractAnnotationAwareTransactio
|
|||
|
||||
private final LoadTimeWeaver ltw;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public LoadTimeWeaverInjectingBeanPostProcessor(LoadTimeWeaver ltw) {
|
||||
this.ltw = ltw;
|
||||
}
|
||||
|
|
@ -328,6 +330,7 @@ public abstract class AbstractJpaTests extends AbstractAnnotationAwareTransactio
|
|||
|
||||
private final ClassLoader shadowingClassLoader;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public ShadowingLoadTimeWeaver(ClassLoader shadowingClassLoader) {
|
||||
this.shadowingClassLoader = shadowingClassLoader;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
|
||||
/**
|
||||
*
|
||||
* Helper classes for unit tests with reflective needs.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.springframework.test.util;
|
||||
|
||||
|
|
|
|||
|
|
@ -72,6 +72,7 @@ public abstract class AbstractModelAndViewTests extends TestCase {
|
|||
* <code>null</code>)
|
||||
* @param expectedList the expected list
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
protected void assertCompareListModelAttribute(ModelAndView mav, String modelName, List expectedList) {
|
||||
try {
|
||||
ModelAndViewAssert.assertCompareListModelAttribute(mav, modelName, expectedList);
|
||||
|
|
@ -139,6 +140,7 @@ public abstract class AbstractModelAndViewTests extends TestCase {
|
|||
* not specifying the comparator, both lists will be sorted not using
|
||||
* any comparator.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
protected void assertSortAndCompareListModelAttribute(
|
||||
ModelAndView mav, String modelName, List expectedList, Comparator comparator) {
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -27,13 +27,13 @@ import org.springframework.util.ObjectUtils;
|
|||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
/**
|
||||
* A collection of assertions intended to simplify testing scenarios
|
||||
* dealing with Spring Web MVC
|
||||
* {@link org.springframework.web.servlet.ModelAndView ModelAndView} objects.
|
||||
*
|
||||
* <p>Intended for use with JUnit 4 and TestNG.
|
||||
* All <code>assert*()</code> methods throw {@link AssertionError}s.
|
||||
*
|
||||
* A collection of assertions intended to simplify testing scenarios dealing
|
||||
* with Spring Web MVC {@link org.springframework.web.servlet.ModelAndView
|
||||
* ModelAndView} objects.
|
||||
* <p>
|
||||
* Intended for use with JUnit 4 and TestNG. All <code>assert*()</code> methods
|
||||
* throw {@link AssertionError}s.
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @author Alef Arendsen
|
||||
* @author Bram Smeets
|
||||
|
|
@ -44,8 +44,9 @@ public abstract class ModelAndViewAssert {
|
|||
|
||||
/**
|
||||
* Checks whether the model value under the given <code>modelName</code>
|
||||
* exists and checks it type, based on the <code>expectedType</code>. If
|
||||
* the model entry exists and the type matches, the model value is returned.
|
||||
* exists and checks it type, based on the <code>expectedType</code>. If the
|
||||
* model entry exists and the type matches, the model value is returned.
|
||||
*
|
||||
* @param mav ModelAndView to test against (never <code>null</code>)
|
||||
* @param modelName name of the object to add to the model (never
|
||||
* <code>null</code>)
|
||||
|
|
@ -58,29 +59,32 @@ public abstract class ModelAndViewAssert {
|
|||
assertCondition(mav.getModel() != null, "Model is null");
|
||||
Object obj = mav.getModel().get(modelName);
|
||||
assertCondition(obj != null, "Model attribute with name '" + modelName + "' is null");
|
||||
assertCondition(expectedType.isAssignableFrom(obj.getClass()), "Model attribute is not of expected type '" +
|
||||
expectedType.getName() + "' but rather of type '" + obj.getClass().getName() + "'");
|
||||
assertCondition(expectedType.isAssignableFrom(obj.getClass()), "Model attribute is not of expected type '"
|
||||
+ expectedType.getName() + "' but rather of type '" + obj.getClass().getName() + "'");
|
||||
return (T) obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare each individual entry in a list, without first sorting the lists.
|
||||
*
|
||||
* @param mav ModelAndView to test against (never <code>null</code>)
|
||||
* @param modelName name of the object to add to the model (never
|
||||
* <code>null</code>)
|
||||
* @param expectedList the expected list
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static void assertCompareListModelAttribute(ModelAndView mav, String modelName, List expectedList) {
|
||||
assertCondition(mav != null, "ModelAndView is null");
|
||||
List modelList = assertAndReturnModelAttributeOfType(mav, modelName, List.class);
|
||||
assertCondition(expectedList.size() == modelList.size(), "Size of model list is '" + modelList.size() +
|
||||
"' while size of expected list is '" + expectedList.size() + "'");
|
||||
assertCondition(expectedList.equals(modelList), "List in model under name '" + modelName +
|
||||
"' is not equal to the expected list.");
|
||||
assertCondition(expectedList.size() == modelList.size(), "Size of model list is '" + modelList.size()
|
||||
+ "' while size of expected list is '" + expectedList.size() + "'");
|
||||
assertCondition(expectedList.equals(modelList), "List in model under name '" + modelName
|
||||
+ "' is not equal to the expected list.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert whether or not a model attribute is available.
|
||||
*
|
||||
* @param mav ModelAndView to test against (never <code>null</code>)
|
||||
* @param modelName name of the object to add to the model (never
|
||||
* <code>null</code>)
|
||||
|
|
@ -88,13 +92,14 @@ public abstract class ModelAndViewAssert {
|
|||
public static void assertModelAttributeAvailable(ModelAndView mav, String modelName) {
|
||||
assertCondition(mav != null, "ModelAndView is null");
|
||||
assertCondition(mav.getModel() != null, "Model is null");
|
||||
assertCondition(mav.getModel().containsKey(modelName), "Model attribute with name '" + modelName +
|
||||
"' is not available");
|
||||
assertCondition(mav.getModel().containsKey(modelName), "Model attribute with name '" + modelName
|
||||
+ "' is not available");
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare a given <code>expectedValue</code> to the value from the model
|
||||
* bound under the given <code>modelName</code>.
|
||||
*
|
||||
* @param mav ModelAndView to test against (never <code>null</code>)
|
||||
* @param modelName name of the object to add to the model (never
|
||||
* <code>null</code>)
|
||||
|
|
@ -103,13 +108,14 @@ public abstract class ModelAndViewAssert {
|
|||
public static void assertModelAttributeValue(ModelAndView mav, String modelName, Object expectedValue) {
|
||||
assertCondition(mav != null, "ModelAndView is null");
|
||||
Object modelValue = assertAndReturnModelAttributeOfType(mav, modelName, Object.class);
|
||||
assertCondition(modelValue.equals(expectedValue), "Model value with name '" + modelName +
|
||||
"' is not the same as the expected value which was '" + expectedValue + "'");
|
||||
assertCondition(modelValue.equals(expectedValue), "Model value with name '" + modelName
|
||||
+ "' is not the same as the expected value which was '" + expectedValue + "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* Inspect the <code>expectedModel</code> to see if all elements in the
|
||||
* model appear and are equal.
|
||||
*
|
||||
* @param mav ModelAndView to test against (never <code>null</code>)
|
||||
* @param expectedModel the expected model
|
||||
*/
|
||||
|
|
@ -128,8 +134,8 @@ public abstract class ModelAndViewAssert {
|
|||
Object assertionValue = expectedModel.get(modelName);
|
||||
Object mavValue = mav.getModel().get(modelName);
|
||||
if (!assertionValue.equals(mavValue)) {
|
||||
sb.append("Value under name '").append(modelName).append("' differs, should have been '")
|
||||
.append(assertionValue).append("' but was '").append(mavValue).append("'\n");
|
||||
sb.append("Value under name '").append(modelName).append("' differs, should have been '").append(
|
||||
assertionValue).append("' but was '").append(mavValue).append("'\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -142,23 +148,24 @@ public abstract class ModelAndViewAssert {
|
|||
/**
|
||||
* Compare each individual entry in a list after having sorted both lists
|
||||
* (optionally using a comparator).
|
||||
*
|
||||
* @param mav ModelAndView to test against (never <code>null</code>)
|
||||
* @param modelName name of the object to add to the model
|
||||
* (never <code>null</code>)
|
||||
* @param modelName name of the object to add to the model (never
|
||||
* <code>null</code>)
|
||||
* @param expectedList the expected list
|
||||
* @param comparator the comparator to use (may be <code>null</code>).
|
||||
* If not specifying the comparator, both lists will be sorted not using
|
||||
* any comparator.
|
||||
* @param comparator the comparator to use (may be <code>null</code>). If
|
||||
* not specifying the comparator, both lists will be sorted not using any
|
||||
* comparator.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void assertSortAndCompareListModelAttribute(
|
||||
ModelAndView mav, String modelName, List expectedList, Comparator comparator) {
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public static void assertSortAndCompareListModelAttribute(ModelAndView mav, String modelName, List expectedList,
|
||||
Comparator comparator) {
|
||||
|
||||
assertCondition(mav != null, "ModelAndView is null");
|
||||
List modelList = assertAndReturnModelAttributeOfType(mav, modelName, List.class);
|
||||
|
||||
assertCondition(expectedList.size() == modelList.size(), "Size of model list is '" + modelList.size() +
|
||||
"' while size of expected list is '" + expectedList.size() + "'");
|
||||
assertCondition(expectedList.size() == modelList.size(), "Size of model list is '" + modelList.size()
|
||||
+ "' while size of expected list is '" + expectedList.size() + "'");
|
||||
|
||||
if (comparator != null) {
|
||||
Collections.sort(modelList, comparator);
|
||||
|
|
@ -169,26 +176,27 @@ public abstract class ModelAndViewAssert {
|
|||
Collections.sort(expectedList);
|
||||
}
|
||||
|
||||
assertCondition(expectedList.equals(modelList), "List in model under name '" + modelName +
|
||||
"' is not equal to the expected list.");
|
||||
assertCondition(expectedList.equals(modelList), "List in model under name '" + modelName
|
||||
+ "' is not equal to the expected list.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if the view name in the ModelAndView matches the given
|
||||
* <code>expectedName</code>.
|
||||
*
|
||||
* @param mav ModelAndView to test against (never <code>null</code>)
|
||||
* @param expectedName the name of the model value
|
||||
*/
|
||||
public static void assertViewName(ModelAndView mav, String expectedName) {
|
||||
assertCondition(mav != null, "ModelAndView is null");
|
||||
assertCondition(ObjectUtils.nullSafeEquals(expectedName, mav.getViewName()),
|
||||
"View name is not equal to '" + expectedName + "' but was '" + mav.getViewName() + "'");
|
||||
assertCondition(ObjectUtils.nullSafeEquals(expectedName, mav.getViewName()), "View name is not equal to '"
|
||||
+ expectedName + "' but was '" + mav.getViewName() + "'");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fails by throwing an <code>AssertionError</code> with the supplied
|
||||
* <code>message</code>.
|
||||
*
|
||||
* @param message the exception message to use
|
||||
* @see #assertCondition(boolean,String)
|
||||
*/
|
||||
|
|
@ -198,8 +206,9 @@ public abstract class ModelAndViewAssert {
|
|||
|
||||
/**
|
||||
* Assert the provided boolean <code>condition</code>, throwing
|
||||
* <code>AssertionError</code> with the supplied <code>message</code> if
|
||||
* the test result is <code>false</code>.
|
||||
* <code>AssertionError</code> with the supplied <code>message</code> if the
|
||||
* test result is <code>false</code>.
|
||||
*
|
||||
* @param condition a boolean expression
|
||||
* @param message the exception message to use if the assertion fails
|
||||
* @see #fail(String)
|
||||
|
|
@ -210,8 +219,8 @@ public abstract class ModelAndViewAssert {
|
|||
}
|
||||
}
|
||||
|
||||
private static void appendNonMatchingSetsErrorMessage(
|
||||
Set<String> assertionSet, Set<String> incorrectSet, StringBuilder sb) {
|
||||
private static void appendNonMatchingSetsErrorMessage(Set<String> assertionSet, Set<String> incorrectSet,
|
||||
StringBuilder sb) {
|
||||
|
||||
Set<String> tempSet = new HashSet<String>();
|
||||
tempSet.addAll(incorrectSet);
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
|
||||
/**
|
||||
*
|
||||
* Helper classes for unit tests based on Spring's web support.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.springframework.test.web;
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import org.springframework.core.enums.ShortCodedLabeledEnum;
|
|||
/**
|
||||
* @author Rob Harrop
|
||||
*/
|
||||
@SuppressWarnings({ "serial", "deprecation" })
|
||||
public class Colour extends ShortCodedLabeledEnum {
|
||||
|
||||
public static final Colour RED = new Colour(0, "RED");
|
||||
|
|
@ -28,6 +29,7 @@ public class Colour extends ShortCodedLabeledEnum {
|
|||
public static final Colour GREEN = new Colour(2, "GREEN");
|
||||
public static final Colour PURPLE = new Colour(3, "PURPLE");
|
||||
|
||||
|
||||
private Colour(int code, String label) {
|
||||
super(code, label);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import java.util.TreeSet;
|
|||
* @author Juergen Hoeller
|
||||
* @since 11.11.2003
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class IndexedTestBean {
|
||||
|
||||
private TestBean[] array;
|
||||
|
|
@ -57,6 +58,7 @@ public class IndexedTestBean {
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void populate() {
|
||||
TestBean tb0 = new TestBean("name0", 0);
|
||||
TestBean tb1 = new TestBean("name1", 0);
|
||||
|
|
@ -68,7 +70,7 @@ public class IndexedTestBean {
|
|||
TestBean tb7 = new TestBean("name7", 0);
|
||||
TestBean tbX = new TestBean("nameX", 0);
|
||||
TestBean tbY = new TestBean("nameY", 0);
|
||||
this.array = new TestBean[] {tb0, tb1};
|
||||
this.array = new TestBean[] { tb0, tb1 };
|
||||
this.list = new ArrayList();
|
||||
this.list.add(tb2);
|
||||
this.list.add(tb3);
|
||||
|
|
@ -85,7 +87,6 @@ public class IndexedTestBean {
|
|||
this.map.put("key4", list);
|
||||
}
|
||||
|
||||
|
||||
public TestBean[] getArray() {
|
||||
return array;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,11 +35,12 @@ import org.springframework.util.ObjectUtils;
|
|||
|
||||
/**
|
||||
* Simple test bean used for testing bean factories, the AOP framework etc.
|
||||
*
|
||||
*
|
||||
* @author Rod Johnson
|
||||
* @author Juergen Hoeller
|
||||
* @since 15 April 2001
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOther, Comparable {
|
||||
|
||||
private String beanName;
|
||||
|
|
@ -107,7 +108,7 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
|
|||
}
|
||||
|
||||
public TestBean(ITestBean spouse) {
|
||||
this.spouses = new ITestBean[] {spouse};
|
||||
this.spouses = new ITestBean[] { spouse };
|
||||
}
|
||||
|
||||
public TestBean(String name, int age) {
|
||||
|
|
@ -116,7 +117,7 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
|
|||
}
|
||||
|
||||
public TestBean(ITestBean spouse, Properties someProperties) {
|
||||
this.spouses = new ITestBean[] {spouse};
|
||||
this.spouses = new ITestBean[] { spouse };
|
||||
this.someProperties = someProperties;
|
||||
}
|
||||
|
||||
|
|
@ -136,7 +137,6 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
|
|||
this.someProperties = someProperties;
|
||||
}
|
||||
|
||||
|
||||
public void setBeanName(String beanName) {
|
||||
this.beanName = beanName;
|
||||
}
|
||||
|
|
@ -201,7 +201,7 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
|
|||
}
|
||||
|
||||
public void setSpouse(ITestBean spouse) {
|
||||
this.spouses = new ITestBean[] {spouse};
|
||||
this.spouses = new ITestBean[] { spouse };
|
||||
}
|
||||
|
||||
public ITestBean[] getSpouses() {
|
||||
|
|
@ -366,7 +366,6 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
|
|||
this.pets = pets;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see ITestBean#exceptional(Throwable)
|
||||
*/
|
||||
|
|
@ -379,6 +378,7 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
|
|||
public void unreliableFileOperation() throws IOException {
|
||||
throw new IOException();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ITestBean#returnsThis()
|
||||
*/
|
||||
|
|
@ -396,7 +396,6 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
|
|||
return age++;
|
||||
}
|
||||
|
||||
|
||||
public void destroy() {
|
||||
this.destroyed = true;
|
||||
}
|
||||
|
|
@ -405,7 +404,6 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
|
|||
return destroyed;
|
||||
}
|
||||
|
||||
|
||||
public boolean equals(Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ public class MockHttpServletRequestTests extends TestCase {
|
|||
String headerName = "Header1";
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.addHeader(headerName, "value1");
|
||||
Enumeration requestHeaders = request.getHeaderNames();
|
||||
Enumeration<String> requestHeaders = request.getHeaderNames();
|
||||
assertNotNull(requestHeaders);
|
||||
assertEquals("HTTP header casing not being preserved", headerName, requestHeaders.nextElement());
|
||||
}
|
||||
|
|
@ -41,7 +41,7 @@ public class MockHttpServletRequestTests extends TestCase {
|
|||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.setParameter("key1", "value1");
|
||||
request.setParameter("key2", "value2");
|
||||
Map params = new HashMap(2);
|
||||
Map<String, Object> params = new HashMap<String, Object>(2);
|
||||
params.put("key1", "newValue1");
|
||||
params.put("key3", new String[] { "value3A", "value3B" });
|
||||
request.setParameters(params);
|
||||
|
|
@ -59,7 +59,7 @@ public class MockHttpServletRequestTests extends TestCase {
|
|||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.setParameter("key1", "value1");
|
||||
request.setParameter("key2", "value2");
|
||||
Map params = new HashMap(2);
|
||||
Map<String, Object> params = new HashMap<String, Object>(2);
|
||||
params.put("key1", "newValue1");
|
||||
params.put("key3", new String[] { "value3A", "value3B" });
|
||||
request.addParameters(params);
|
||||
|
|
@ -77,7 +77,7 @@ public class MockHttpServletRequestTests extends TestCase {
|
|||
public void testRemoveAllParameters() {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.setParameter("key1", "value1");
|
||||
Map params = new HashMap(2);
|
||||
Map<String, Object> params = new HashMap<String, Object>(2);
|
||||
params.put("key2", "value2");
|
||||
params.put("key3", new String[] { "value3A", "value3B" });
|
||||
request.addParameters(params);
|
||||
|
|
|
|||
|
|
@ -34,8 +34,8 @@ public class MockHttpServletResponseTests extends TestCase {
|
|||
public void testSetContentTypeWithNoEncoding() {
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
response.setContentType("test/plain");
|
||||
assertEquals("Character encoding should be the default",
|
||||
WebUtils.DEFAULT_CHARACTER_ENCODING, response.getCharacterEncoding());
|
||||
assertEquals("Character encoding should be the default", WebUtils.DEFAULT_CHARACTER_ENCODING,
|
||||
response.getCharacterEncoding());
|
||||
}
|
||||
|
||||
public void testSetContentTypeWithUTF8() {
|
||||
|
|
@ -49,7 +49,7 @@ public class MockHttpServletResponseTests extends TestCase {
|
|||
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
response.addHeader(headerName, "value1");
|
||||
Set responseHeaders = response.getHeaderNames();
|
||||
Set<String> responseHeaders = response.getHeaderNames();
|
||||
assertNotNull(responseHeaders);
|
||||
assertEquals(1, responseHeaders.size());
|
||||
assertEquals("HTTP header casing not being preserved", headerName, responseHeaders.iterator().next());
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2007 the original author or authors.
|
||||
* Copyright 2007-2011 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.
|
||||
|
|
@ -24,10 +24,11 @@ import org.springframework.context.ApplicationContext;
|
|||
* Abstract JUnit 3.8 based unit test which verifies new functionality requested
|
||||
* in <a href="http://opensource.atlassian.com/projects/spring/browse/SPR-3550"
|
||||
* target="_blank">SPR-3350</a>.
|
||||
*
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 2.5
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public abstract class AbstractSpr3350SingleSpringContextTests extends AbstractDependencyInjectionSpringContextTests {
|
||||
|
||||
private Pet cat;
|
||||
|
|
@ -48,8 +49,9 @@ public abstract class AbstractSpr3350SingleSpringContextTests extends AbstractDe
|
|||
/**
|
||||
* Forcing concrete subclasses to provide a config path appropriate to the
|
||||
* configured
|
||||
* {@link #createBeanDefinitionReader(org.springframework.context.support.GenericApplicationContext) BeanDefinitionReader}.
|
||||
*
|
||||
* {@link #createBeanDefinitionReader(org.springframework.context.support.GenericApplicationContext)
|
||||
* BeanDefinitionReader}.
|
||||
*
|
||||
* @see org.springframework.test.AbstractSingleSpringContextTests#getConfigPath()
|
||||
*/
|
||||
protected abstract String getConfigPath();
|
||||
|
|
@ -62,12 +64,11 @@ public abstract class AbstractSpr3350SingleSpringContextTests extends AbstractDe
|
|||
* {@link AbstractSingleSpringContextTests} always uses an
|
||||
* {@link XmlBeanDefinitionReader} internally when creating the
|
||||
* {@link ApplicationContext} inside
|
||||
* {@link #createApplicationContext(String[])}. It would be nice to have
|
||||
* the bean definition reader creation in a separate method so that
|
||||
* subclasses can choose that individually without having to copy-n-paste
|
||||
* code from createApplicationContext() to do the context creation and
|
||||
* refresh. Consider JavaConfig where an Annotation based reader can be
|
||||
* plugged in.
|
||||
* {@link #createApplicationContext(String[])}. It would be nice to have the
|
||||
* bean definition reader creation in a separate method so that subclasses
|
||||
* can choose that individually without having to copy-n-paste code from
|
||||
* createApplicationContext() to do the context creation and refresh.
|
||||
* Consider JavaConfig where an Annotation based reader can be plugged in.
|
||||
* </p>
|
||||
*/
|
||||
public final void testApplicationContextNotAutoCreated() {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2007 the original author or authors.
|
||||
* Copyright 2007-2011 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.
|
||||
|
|
@ -20,11 +20,12 @@ package org.springframework.test;
|
|||
* JUnit 3.8 based unit test which verifies new functionality requested in <a
|
||||
* href="http://opensource.atlassian.com/projects/spring/browse/SPR-3264"
|
||||
* target="_blank">SPR-3264</a>.
|
||||
*
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 2.5
|
||||
* @see Spr3264SingleSpringContextTests
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class Spr3264DependencyInjectionSpringContextTests extends AbstractDependencyInjectionSpringContextTests {
|
||||
|
||||
public Spr3264DependencyInjectionSpringContextTests() {
|
||||
|
|
@ -50,7 +51,7 @@ public class Spr3264DependencyInjectionSpringContextTests extends AbstractDepend
|
|||
// Re-assert issues covered by Spr3264SingleSpringContextTests as a
|
||||
// safety net.
|
||||
assertNull("The ApplicationContext should NOT be automatically created if no 'locations' are defined.",
|
||||
this.applicationContext);
|
||||
this.applicationContext);
|
||||
assertEquals("Verifying the ApplicationContext load count.", 0, super.getLoadCount());
|
||||
|
||||
// Assert changes to AbstractDependencyInjectionSpringContextTests:
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2007 the original author or authors.
|
||||
* Copyright 2007-2011 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.
|
||||
|
|
@ -20,11 +20,12 @@ package org.springframework.test;
|
|||
* JUnit 3.8 based unit test which verifies new functionality requested in <a
|
||||
* href="http://opensource.atlassian.com/projects/spring/browse/SPR-3264"
|
||||
* target="_blank">SPR-3264</a>.
|
||||
*
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 2.5
|
||||
* @see Spr3264DependencyInjectionSpringContextTests
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class Spr3264SingleSpringContextTests extends AbstractSingleSpringContextTests {
|
||||
|
||||
public Spr3264SingleSpringContextTests() {
|
||||
|
|
@ -47,7 +48,7 @@ public class Spr3264SingleSpringContextTests extends AbstractSingleSpringContext
|
|||
*/
|
||||
public void testApplicationContextNotAutoCreated() {
|
||||
assertNull("The ApplicationContext should NOT be automatically created if no 'locations' are defined.",
|
||||
super.applicationContext);
|
||||
super.applicationContext);
|
||||
assertEquals("Verifying the ApplicationContext load count.", 0, super.getLoadCount());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ import junit.framework.TestResult;
|
|||
* Verifies proper handling of {@link IfProfileValue @IfProfileValue} and
|
||||
* {@link ProfileValueSourceConfiguration @ProfileValueSourceConfiguration} in
|
||||
* conjunction with {@link AbstractAnnotationAwareTransactionalTests}.
|
||||
*
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 2.5
|
||||
*/
|
||||
|
|
@ -46,11 +46,11 @@ public class ProfileValueAnnotationAwareTransactionalTests extends TestCase {
|
|||
testCase.setName(testName);
|
||||
TestResult testResult = testCase.run();
|
||||
assertEquals("Verifying number of invocations for test method [" + testName + "].", expectedInvocationCount,
|
||||
testCase.invocationCount);
|
||||
testCase.invocationCount);
|
||||
assertEquals("Verifying number of errors for test method [" + testName + "].", expectedErrorCount,
|
||||
testResult.errorCount());
|
||||
testResult.errorCount());
|
||||
assertEquals("Verifying number of failures for test method [" + testName + "].", expectedFailureCount,
|
||||
testResult.failureCount());
|
||||
testResult.failureCount());
|
||||
}
|
||||
|
||||
private void runTests(Class<? extends DefaultProfileValueSourceTestCase> testCaseType) throws Exception {
|
||||
|
|
@ -64,21 +64,23 @@ public class ProfileValueAnnotationAwareTransactionalTests extends TestCase {
|
|||
|
||||
public void testDefaultProfileValueSource() throws Exception {
|
||||
assertEquals("Verifying the type of the configured ProfileValueSource.", SystemProfileValueSource.class,
|
||||
new DefaultProfileValueSourceTestCase().getProfileValueSource().getClass());
|
||||
new DefaultProfileValueSourceTestCase().getProfileValueSource().getClass());
|
||||
runTests(DefaultProfileValueSourceTestCase.class);
|
||||
}
|
||||
|
||||
public void testHardCodedProfileValueSource() throws Exception {
|
||||
assertEquals("Verifying the type of the configured ProfileValueSource.", HardCodedProfileValueSource.class,
|
||||
new HardCodedProfileValueSourceTestCase().getProfileValueSource().getClass());
|
||||
new HardCodedProfileValueSourceTestCase().getProfileValueSource().getClass());
|
||||
runTests(HardCodedProfileValueSourceTestCase.class);
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
protected static class DefaultProfileValueSourceTestCase extends AbstractAnnotationAwareTransactionalTests {
|
||||
|
||||
int invocationCount = 0;
|
||||
|
||||
|
||||
public DefaultProfileValueSourceTestCase() {
|
||||
}
|
||||
|
||||
|
|
@ -130,12 +132,10 @@ public class ProfileValueAnnotationAwareTransactionalTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@ProfileValueSourceConfiguration(HardCodedProfileValueSource.class)
|
||||
protected static class HardCodedProfileValueSourceTestCase extends DefaultProfileValueSourceTestCase {
|
||||
}
|
||||
|
||||
|
||||
public static class HardCodedProfileValueSource implements ProfileValueSource {
|
||||
|
||||
public String get(String key) {
|
||||
|
|
|
|||
|
|
@ -23,8 +23,6 @@ import java.lang.reflect.Method;
|
|||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ProfileValueUtils}.
|
||||
|
|
@ -32,7 +30,6 @@ import org.junit.runners.JUnit4;
|
|||
* @author Sam Brannen
|
||||
* @since 3.0
|
||||
*/
|
||||
@RunWith(JUnit4.class)
|
||||
public class ProfileValueUtilsTests {
|
||||
|
||||
private static final String NON_ANNOTATED_METHOD = "nonAnnotatedMethod";
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ import javax.sql.DataSource;
|
|||
|
||||
import org.junit.internal.runners.JUnit38ClassRunner;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.Employee;
|
||||
import org.springframework.beans.Pet;
|
||||
import org.springframework.beans.factory.BeanNameAware;
|
||||
|
|
@ -42,10 +41,11 @@ import org.springframework.test.jdbc.SimpleJdbcTestUtils;
|
|||
/**
|
||||
* Combined unit test for {@link AbstractJUnit38SpringContextTests} and
|
||||
* {@link AbstractTransactionalJUnit38SpringContextTests}.
|
||||
*
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 2.5
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@RunWith(JUnit38ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
public class ConcreteTransactionalJUnit38SpringContextTests extends AbstractTransactionalJUnit38SpringContextTests
|
||||
|
|
@ -142,13 +142,13 @@ public class ConcreteTransactionalJUnit38SpringContextTests extends AbstractTran
|
|||
@NotTransactional
|
||||
public void testApplicationContextSet() {
|
||||
assertNotNull("The application context should have been set due to ApplicationContextAware semantics.",
|
||||
super.applicationContext);
|
||||
super.applicationContext);
|
||||
}
|
||||
|
||||
@NotTransactional
|
||||
public void testBeanInitialized() {
|
||||
assertTrue("This test bean should have been initialized due to InitializingBean semantics.",
|
||||
this.beanInitialized);
|
||||
this.beanInitialized);
|
||||
}
|
||||
|
||||
@NotTransactional
|
||||
|
|
@ -184,7 +184,7 @@ public class ConcreteTransactionalJUnit38SpringContextTests extends AbstractTran
|
|||
public void beforeTransaction() {
|
||||
this.inTransaction = true;
|
||||
assertEquals("Verifying the number of rows in the person table before a transactional test method.", 1,
|
||||
countRowsInPersonTable(super.simpleJdbcTemplate));
|
||||
countRowsInPersonTable(super.simpleJdbcTemplate));
|
||||
assertEquals("Adding yoda", 1, addPerson(super.simpleJdbcTemplate, YODA));
|
||||
}
|
||||
|
||||
|
|
@ -198,7 +198,7 @@ public class ConcreteTransactionalJUnit38SpringContextTests extends AbstractTran
|
|||
assertEquals("Adding jane", 1, addPerson(super.simpleJdbcTemplate, JANE));
|
||||
assertEquals("Adding sue", 1, addPerson(super.simpleJdbcTemplate, SUE));
|
||||
assertEquals("Verifying the number of rows in the person table within transactionalMethod2().", 4,
|
||||
countRowsInPersonTable(super.simpleJdbcTemplate));
|
||||
countRowsInPersonTable(super.simpleJdbcTemplate));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -211,7 +211,7 @@ public class ConcreteTransactionalJUnit38SpringContextTests extends AbstractTran
|
|||
public void afterTransaction() {
|
||||
assertEquals("Deleting yoda", 1, deletePerson(super.simpleJdbcTemplate, YODA));
|
||||
assertEquals("Verifying the number of rows in the person table after a transactional test method.", 1,
|
||||
countRowsInPersonTable(super.simpleJdbcTemplate));
|
||||
countRowsInPersonTable(super.simpleJdbcTemplate));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -23,10 +23,10 @@ import org.springframework.test.context.ContextConfiguration;
|
|||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* Abstract base class for verifying support of Spring's
|
||||
* {@link Transactional @Transactional} and
|
||||
* {@link NotTransactional @NotTransactional} annotations.
|
||||
*
|
||||
* Abstract base class for verifying support of Spring's {@link Transactional
|
||||
* @Transactional} and {@link NotTransactional @NotTransactional}
|
||||
* annotations.
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 2.5
|
||||
* @see ClassLevelTransactionalSpringRunnerTests
|
||||
|
|
@ -34,7 +34,8 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
* @see Transactional
|
||||
* @see NotTransactional
|
||||
*/
|
||||
@ContextConfiguration(locations = {"transactionalTests-context.xml"})
|
||||
@SuppressWarnings("deprecation")
|
||||
@ContextConfiguration("transactionalTests-context.xml")
|
||||
public abstract class AbstractTransactionalSpringRunnerTests {
|
||||
|
||||
protected static final String BOB = "bob";
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ import org.junit.AfterClass;
|
|||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
||||
import org.springframework.test.annotation.NotTransactional;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
|
@ -40,11 +39,11 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
/**
|
||||
* <p>
|
||||
* JUnit 4 based unit test which verifies support of Spring's
|
||||
* {@link Transactional @Transactional},
|
||||
* {@link NotTransactional @NotTransactional},
|
||||
* {@link TestExecutionListeners @TestExecutionListeners}, and
|
||||
* {@link ContextConfiguration @ContextConfiguration} annotations in conjunction
|
||||
* with the {@link SpringJUnit4ClassRunner} and the following
|
||||
* {@link Transactional @Transactional}, {@link NotTransactional
|
||||
* @NotTransactional}, {@link TestExecutionListeners
|
||||
* @TestExecutionListeners}, and {@link ContextConfiguration
|
||||
* @ContextConfiguration} annotations in conjunction with the
|
||||
* {@link SpringJUnit4ClassRunner} and the following
|
||||
* {@link TestExecutionListener TestExecutionListeners}:
|
||||
* </p>
|
||||
* <ul>
|
||||
|
|
@ -56,11 +55,12 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
* This class specifically tests usage of <code>@Transactional</code>
|
||||
* defined at the <strong>class level</strong>.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 2.5
|
||||
* @see MethodLevelTransactionalSpringRunnerTests
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
@Transactional
|
||||
|
|
@ -72,7 +72,7 @@ public class ClassLevelTransactionalSpringRunnerTests extends AbstractTransactio
|
|||
@AfterClass
|
||||
public static void verifyFinalTestData() {
|
||||
assertEquals("Verifying the final number of rows in the person table after all tests.", 4,
|
||||
countRowsInPersonTable(simpleJdbcTemplate));
|
||||
countRowsInPersonTable(simpleJdbcTemplate));
|
||||
}
|
||||
|
||||
@Before
|
||||
|
|
@ -80,10 +80,9 @@ public class ClassLevelTransactionalSpringRunnerTests extends AbstractTransactio
|
|||
clearPersonTable(simpleJdbcTemplate);
|
||||
assertEquals("Adding bob", 1, addPerson(simpleJdbcTemplate, BOB));
|
||||
assertEquals("Verifying the initial number of rows in the person table.", 1,
|
||||
countRowsInPersonTable(simpleJdbcTemplate));
|
||||
countRowsInPersonTable(simpleJdbcTemplate));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void modifyTestDataWithinTransaction() {
|
||||
assertInTransaction(true);
|
||||
|
|
@ -91,7 +90,7 @@ public class ClassLevelTransactionalSpringRunnerTests extends AbstractTransactio
|
|||
assertEquals("Adding jane", 1, addPerson(simpleJdbcTemplate, JANE));
|
||||
assertEquals("Adding sue", 1, addPerson(simpleJdbcTemplate, SUE));
|
||||
assertEquals("Verifying the number of rows in the person table within a transaction.", 2,
|
||||
countRowsInPersonTable(simpleJdbcTemplate));
|
||||
countRowsInPersonTable(simpleJdbcTemplate));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -102,7 +101,7 @@ public class ClassLevelTransactionalSpringRunnerTests extends AbstractTransactio
|
|||
assertEquals("Adding leia", 1, addPerson(simpleJdbcTemplate, LEIA));
|
||||
assertEquals("Adding yoda", 1, addPerson(simpleJdbcTemplate, YODA));
|
||||
assertEquals("Verifying the number of rows in the person table without a transaction.", 4,
|
||||
countRowsInPersonTable(simpleJdbcTemplate));
|
||||
countRowsInPersonTable(simpleJdbcTemplate));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@ import javax.sql.DataSource;
|
|||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.Employee;
|
||||
import org.springframework.beans.Pet;
|
||||
import org.springframework.beans.factory.BeanNameAware;
|
||||
|
|
@ -46,10 +45,11 @@ import org.springframework.test.jdbc.SimpleJdbcTestUtils;
|
|||
/**
|
||||
* Combined unit test for {@link AbstractJUnit4SpringContextTests} and
|
||||
* {@link AbstractTransactionalJUnit4SpringContextTests}.
|
||||
*
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 2.5
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@ContextConfiguration
|
||||
public class ConcreteTransactionalJUnit4SpringContextTests extends AbstractTransactionalJUnit4SpringContextTests
|
||||
implements BeanNameAware, InitializingBean {
|
||||
|
|
@ -61,7 +61,6 @@ public class ConcreteTransactionalJUnit4SpringContextTests extends AbstractTrans
|
|||
protected static final String LEIA = "leia";
|
||||
protected static final String YODA = "yoda";
|
||||
|
||||
|
||||
private boolean beanInitialized = false;
|
||||
|
||||
private String beanName = "replace me with [" + getClass().getName() + "]";
|
||||
|
|
@ -105,7 +104,6 @@ public class ConcreteTransactionalJUnit4SpringContextTests extends AbstractTrans
|
|||
return simpleJdbcTemplate.update("DELETE FROM person WHERE name=?", name);
|
||||
}
|
||||
|
||||
|
||||
@Resource
|
||||
public void setDataSource(DataSource dataSource) {
|
||||
super.setDataSource(dataSource);
|
||||
|
|
@ -129,13 +127,12 @@ public class ConcreteTransactionalJUnit4SpringContextTests extends AbstractTrans
|
|||
this.beanInitialized = true;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@NotTransactional
|
||||
public final void verifyApplicationContext() {
|
||||
assertInTransaction(false);
|
||||
assertNotNull("The application context should have been set due to ApplicationContextAware semantics.",
|
||||
super.applicationContext);
|
||||
super.applicationContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -143,7 +140,7 @@ public class ConcreteTransactionalJUnit4SpringContextTests extends AbstractTrans
|
|||
public final void verifyBeanInitialized() {
|
||||
assertInTransaction(false);
|
||||
assertTrue("This test bean should have been initialized due to InitializingBean semantics.",
|
||||
this.beanInitialized);
|
||||
this.beanInitialized);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -185,18 +182,17 @@ public class ConcreteTransactionalJUnit4SpringContextTests extends AbstractTrans
|
|||
assertEquals("The bar method should have been wired via @Resource.", "Bar", this.bar);
|
||||
}
|
||||
|
||||
|
||||
@BeforeTransaction
|
||||
public void beforeTransaction() {
|
||||
assertEquals("Verifying the number of rows in the person table before a transactional test method.", 1,
|
||||
countRowsInPersonTable(super.simpleJdbcTemplate));
|
||||
countRowsInPersonTable(super.simpleJdbcTemplate));
|
||||
assertEquals("Adding yoda", 1, addPerson(super.simpleJdbcTemplate, YODA));
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
assertEquals("Verifying the number of rows in the person table before a test method.",
|
||||
(inTransaction() ? 2 : 1), countRowsInPersonTable(super.simpleJdbcTemplate));
|
||||
(inTransaction() ? 2 : 1), countRowsInPersonTable(super.simpleJdbcTemplate));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -205,20 +201,20 @@ public class ConcreteTransactionalJUnit4SpringContextTests extends AbstractTrans
|
|||
assertEquals("Adding jane", 1, addPerson(super.simpleJdbcTemplate, JANE));
|
||||
assertEquals("Adding sue", 1, addPerson(super.simpleJdbcTemplate, SUE));
|
||||
assertEquals("Verifying the number of rows in the person table in modifyTestDataWithinTransaction().", 4,
|
||||
countRowsInPersonTable(super.simpleJdbcTemplate));
|
||||
countRowsInPersonTable(super.simpleJdbcTemplate));
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
assertEquals("Verifying the number of rows in the person table after a test method.",
|
||||
(inTransaction() ? 4 : 1), countRowsInPersonTable(super.simpleJdbcTemplate));
|
||||
(inTransaction() ? 4 : 1), countRowsInPersonTable(super.simpleJdbcTemplate));
|
||||
}
|
||||
|
||||
@AfterTransaction
|
||||
public void afterTransaction() {
|
||||
assertEquals("Deleting yoda", 1, deletePerson(super.simpleJdbcTemplate, YODA));
|
||||
assertEquals("Verifying the number of rows in the person table after a transactional test method.", 1,
|
||||
countRowsInPersonTable(super.simpleJdbcTemplate));
|
||||
countRowsInPersonTable(super.simpleJdbcTemplate));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -16,15 +16,16 @@
|
|||
|
||||
package org.springframework.test.context.junit4;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.springframework.test.transaction.TransactionTestUtils.assertInTransaction;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.TestExecutionListener;
|
||||
|
|
@ -32,17 +33,15 @@ import org.springframework.test.context.TestExecutionListeners;
|
|||
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
|
||||
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;
|
||||
import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
|
||||
import org.springframework.test.context.transaction.TransactionConfiguration;
|
||||
import static org.springframework.test.transaction.TransactionTestUtils.*;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* JUnit 4 based unit test which verifies support of Spring's
|
||||
* {@link Transactional @Transactional},
|
||||
* {@link TestExecutionListeners @TestExecutionListeners}, and
|
||||
* {@link ContextConfiguration @ContextConfiguration} annotations in conjunction
|
||||
* with the {@link SpringJUnit4ClassRunner} and the following
|
||||
* {@link Transactional @Transactional}, {@link TestExecutionListeners
|
||||
* @TestExecutionListeners}, and {@link ContextConfiguration
|
||||
* @ContextConfiguration} annotations in conjunction with the
|
||||
* {@link SpringJUnit4ClassRunner} and the following
|
||||
* {@link TestExecutionListener TestExecutionListeners}:
|
||||
* </p>
|
||||
* <ul>
|
||||
|
|
@ -56,15 +55,15 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
* {@link ClassLevelTransactionalSpringRunnerTests}, this class omits usage of
|
||||
* <code>@NotTransactional</code>.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 2.5
|
||||
* @see ClassLevelTransactionalSpringRunnerTests
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
@TestExecutionListeners({DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class,
|
||||
TransactionalTestExecutionListener.class})
|
||||
@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class,
|
||||
TransactionalTestExecutionListener.class })
|
||||
public class MethodLevelTransactionalSpringRunnerTests extends AbstractTransactionalSpringRunnerTests {
|
||||
|
||||
protected static SimpleJdbcTemplate simpleJdbcTemplate;
|
||||
|
|
@ -73,7 +72,7 @@ public class MethodLevelTransactionalSpringRunnerTests extends AbstractTransacti
|
|||
@AfterClass
|
||||
public static void verifyFinalTestData() {
|
||||
assertEquals("Verifying the final number of rows in the person table after all tests.", 4,
|
||||
countRowsInPersonTable(simpleJdbcTemplate));
|
||||
countRowsInPersonTable(simpleJdbcTemplate));
|
||||
}
|
||||
|
||||
@Before
|
||||
|
|
@ -81,7 +80,7 @@ public class MethodLevelTransactionalSpringRunnerTests extends AbstractTransacti
|
|||
clearPersonTable(simpleJdbcTemplate);
|
||||
assertEquals("Adding bob", 1, addPerson(simpleJdbcTemplate, BOB));
|
||||
assertEquals("Verifying the initial number of rows in the person table.", 1,
|
||||
countRowsInPersonTable(simpleJdbcTemplate));
|
||||
countRowsInPersonTable(simpleJdbcTemplate));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -92,7 +91,7 @@ public class MethodLevelTransactionalSpringRunnerTests extends AbstractTransacti
|
|||
assertEquals("Adding jane", 1, addPerson(simpleJdbcTemplate, JANE));
|
||||
assertEquals("Adding sue", 1, addPerson(simpleJdbcTemplate, SUE));
|
||||
assertEquals("Verifying the number of rows in the person table within a transaction.", 2,
|
||||
countRowsInPersonTable(simpleJdbcTemplate));
|
||||
countRowsInPersonTable(simpleJdbcTemplate));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -102,7 +101,7 @@ public class MethodLevelTransactionalSpringRunnerTests extends AbstractTransacti
|
|||
assertEquals("Adding leia", 1, addPerson(simpleJdbcTemplate, LEIA));
|
||||
assertEquals("Adding yoda", 1, addPerson(simpleJdbcTemplate, YODA));
|
||||
assertEquals("Verifying the number of rows in the person table without a transaction.", 4,
|
||||
countRowsInPersonTable(simpleJdbcTemplate));
|
||||
countRowsInPersonTable(simpleJdbcTemplate));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ import static org.springframework.test.transaction.TransactionTestUtils.assertIn
|
|||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.test.annotation.NotTransactional;
|
||||
import org.springframework.test.annotation.Repeat;
|
||||
import org.springframework.test.annotation.Timed;
|
||||
|
|
@ -29,16 +28,17 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
|
||||
/**
|
||||
* JUnit 4 based unit test which verifies support of Spring's
|
||||
* {@link Transactional @Transactional} and
|
||||
* {@link NotTransactional @NotTransactional} annotations in conjunction with
|
||||
* {@link Timed @Timed} and JUnit 4's {@link Test#timeout() timeout} attribute.
|
||||
*
|
||||
* {@link Transactional @Transactional} and {@link NotTransactional
|
||||
* @NotTransactional} annotations in conjunction with {@link Timed
|
||||
* @Timed} and JUnit 4's {@link Test#timeout() timeout} attribute.
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 2.5
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = {"transactionalTests-context.xml"})
|
||||
@ContextConfiguration("transactionalTests-context.xml")
|
||||
@Transactional
|
||||
@SuppressWarnings("deprecation")
|
||||
public class TimedTransactionalSpringRunnerTests {
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ import org.testng.annotations.Test;
|
|||
* @author Sam Brannen
|
||||
* @since 2.5
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@ContextConfiguration
|
||||
public class ConcreteTransactionalTestNGSpringContextTests extends AbstractTransactionalTestNGSpringContextTests
|
||||
implements BeanNameAware, InitializingBean {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2011 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.
|
||||
|
|
@ -16,59 +16,62 @@
|
|||
|
||||
package org.springframework.test.jdbc;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link JdbcTestUtils}.
|
||||
*
|
||||
*
|
||||
* @author Thomas Risberg
|
||||
* @since 2.5.4
|
||||
*/
|
||||
public class JdbcTestUtilsTests extends TestCase {
|
||||
public class JdbcTestUtilsTests {
|
||||
|
||||
public void testContainsDelimiters() {
|
||||
assertTrue("test with ';' is wrong", !JdbcTestUtils.containsSqlScriptDelimiters("select 1\n select ';'", ';'));
|
||||
assertTrue("test with delimiter ; is wrong", JdbcTestUtils.containsSqlScriptDelimiters("select 1; select 2", ';'));
|
||||
assertTrue("test with '\\n' is wrong", !JdbcTestUtils.containsSqlScriptDelimiters("select 1; select '\\n\n';", '\n'));
|
||||
assertTrue("test with delimiter \\n is wrong", JdbcTestUtils.containsSqlScriptDelimiters("select 1\n select 2", '\n'));
|
||||
@Test
|
||||
public void containsDelimiters() {
|
||||
assertTrue("test with ';' is wrong", !JdbcTestUtils.containsSqlScriptDelimiters("select 1\n select ';'", ';'));
|
||||
assertTrue("test with delimiter ; is wrong",
|
||||
JdbcTestUtils.containsSqlScriptDelimiters("select 1; select 2", ';'));
|
||||
assertTrue("test with '\\n' is wrong",
|
||||
!JdbcTestUtils.containsSqlScriptDelimiters("select 1; select '\\n\n';", '\n'));
|
||||
assertTrue("test with delimiter \\n is wrong",
|
||||
JdbcTestUtils.containsSqlScriptDelimiters("select 1\n select 2", '\n'));
|
||||
}
|
||||
|
||||
public void testSplitSqlScriptDelimitedWithSemicolon() {
|
||||
String statement1 = "insert into customer (id, name) \n" +
|
||||
"values (1, 'Rod ; Johnson'), (2, 'Adrian \n Collier')";
|
||||
String statement2 = "insert into orders(id, order_date, customer_id) \n" +
|
||||
"values (1, '2008-01-02', 2)";
|
||||
String statement3 = "insert into orders(id, order_date, customer_id) " +
|
||||
"values (1, '2008-01-02', 2)";
|
||||
@Test
|
||||
public void splitSqlScriptDelimitedWithSemicolon() {
|
||||
String statement1 = "insert into customer (id, name) \n"
|
||||
+ "values (1, 'Rod ; Johnson'), (2, 'Adrian \n Collier')";
|
||||
String statement2 = "insert into orders(id, order_date, customer_id) \n" + "values (1, '2008-01-02', 2)";
|
||||
String statement3 = "insert into orders(id, order_date, customer_id) " + "values (1, '2008-01-02', 2)";
|
||||
char delim = ';';
|
||||
String script = statement1 + delim + statement2 + delim + statement3;
|
||||
List statements = new ArrayList();
|
||||
List<String> statements = new ArrayList<String>();
|
||||
JdbcTestUtils.splitSqlScript(script, delim, statements);
|
||||
assertEquals("wrong number of statements", 3, statements.size());
|
||||
assertEquals("statement 1 not split correctly", statement1, statements.get(0));
|
||||
assertEquals("statement 2 not split correctly", statement2, statements.get(1));
|
||||
assertEquals("statement 3 not split correctly", statement3, statements.get(2));
|
||||
|
||||
}
|
||||
|
||||
public void testSplitSqlScriptDelimitedWithNewLine() {
|
||||
String statement1 = "insert into customer (id, name) " +
|
||||
"values (1, 'Rod ; Johnson'), (2, 'Adrian ; Collier')";
|
||||
String statement2 = "insert into orders(id, order_date, customer_id) " +
|
||||
"values (1, '2008-01-02', 2)";
|
||||
String statement3 = "insert into orders(id, order_date, customer_id) " +
|
||||
"values (1, '2008-01-02', 2)";
|
||||
@Test
|
||||
public void splitSqlScriptDelimitedWithNewLine() {
|
||||
String statement1 = "insert into customer (id, name) " + "values (1, 'Rod ; Johnson'), (2, 'Adrian ; Collier')";
|
||||
String statement2 = "insert into orders(id, order_date, customer_id) " + "values (1, '2008-01-02', 2)";
|
||||
String statement3 = "insert into orders(id, order_date, customer_id) " + "values (1, '2008-01-02', 2)";
|
||||
char delim = '\n';
|
||||
String script = statement1 + delim + statement2 + delim + statement3;
|
||||
List statements = new ArrayList();
|
||||
List<String> statements = new ArrayList<String>();
|
||||
JdbcTestUtils.splitSqlScript(script, delim, statements);
|
||||
assertEquals("wrong number of statements", 3, statements.size());
|
||||
assertEquals("statement 1 not split correctly", statement1, statements.get(0));
|
||||
assertEquals("statement 2 not split correctly", statement2, statements.get(1));
|
||||
assertEquals("statement 3 not split correctly", statement3, statements.get(2));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2011 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.
|
||||
|
|
@ -23,10 +23,11 @@ import org.springframework.test.util.subpackage.Person;
|
|||
|
||||
/**
|
||||
* JUnit 3.8 based unit tests for {@link ReflectionTestUtils}.
|
||||
*
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class ReflectionTestUtilsTests extends TestCase {
|
||||
|
||||
protected static final Float PI = new Float((float) 22 / 7);
|
||||
|
|
@ -48,11 +49,11 @@ public class ReflectionTestUtilsTests extends TestCase {
|
|||
assertEquals("Verifying that the person's name (protected field) was set.", "Tom", person.getName());
|
||||
assertEquals("Verifying that the person's age (private field) was set.", 42, person.getAge());
|
||||
assertEquals("Verifying that the person's eye color (package private field) was set.", "blue",
|
||||
person.getEyeColor());
|
||||
person.getEyeColor());
|
||||
assertEquals("Verifying that the person's 'likes pets' flag (package private boolean field) was set.", true,
|
||||
person.likesPets());
|
||||
person.likesPets());
|
||||
assertEquals("Verifying that the person's 'favorite number' (package field) was set.", PI,
|
||||
person.getFavoriteNumber());
|
||||
person.getFavoriteNumber());
|
||||
|
||||
assertEquals(new Long(99), ReflectionTestUtils.getField(person, "id"));
|
||||
assertEquals("Tom", ReflectionTestUtils.getField(person, "name"));
|
||||
|
|
@ -74,7 +75,7 @@ public class ReflectionTestUtilsTests extends TestCase {
|
|||
// Null - primitives
|
||||
|
||||
new AssertThrows(IllegalArgumentException.class,
|
||||
"Calling setField() with NULL for a primitive type should throw an IllegalArgumentException.") {
|
||||
"Calling setField() with NULL for a primitive type should throw an IllegalArgumentException.") {
|
||||
|
||||
public void test() throws Exception {
|
||||
ReflectionTestUtils.setField(person, "id", null, long.class);
|
||||
|
|
@ -82,7 +83,7 @@ public class ReflectionTestUtilsTests extends TestCase {
|
|||
}.runTest();
|
||||
|
||||
new AssertThrows(IllegalArgumentException.class,
|
||||
"Calling setField() with NULL for a primitive type should throw an IllegalArgumentException.") {
|
||||
"Calling setField() with NULL for a primitive type should throw an IllegalArgumentException.") {
|
||||
|
||||
public void test() throws Exception {
|
||||
ReflectionTestUtils.setField(person, "age", null, int.class);
|
||||
|
|
@ -90,7 +91,7 @@ public class ReflectionTestUtilsTests extends TestCase {
|
|||
}.runTest();
|
||||
|
||||
new AssertThrows(IllegalArgumentException.class,
|
||||
"Calling setField() with NULL for a primitive type should throw an IllegalArgumentException.") {
|
||||
"Calling setField() with NULL for a primitive type should throw an IllegalArgumentException.") {
|
||||
|
||||
public void test() throws Exception {
|
||||
ReflectionTestUtils.setField(person, "likesPets", null, boolean.class);
|
||||
|
|
@ -114,11 +115,11 @@ public class ReflectionTestUtilsTests extends TestCase {
|
|||
assertEquals("Verifying that the person's name (private method) was set.", "Tom", person.getName());
|
||||
assertEquals("Verifying that the person's age (protected method) was set.", 42, person.getAge());
|
||||
assertEquals("Verifying that the person's eye color (package private method) was set.", "blue",
|
||||
person.getEyeColor());
|
||||
person.getEyeColor());
|
||||
assertEquals("Verifying that the person's 'likes pets' flag (protected method for a boolean) was set.", true,
|
||||
person.likesPets());
|
||||
person.likesPets());
|
||||
assertEquals("Verifying that the person's 'favorite number' (protected method for a Number) was set.", PI,
|
||||
person.getFavoriteNumber());
|
||||
person.getFavoriteNumber());
|
||||
|
||||
assertEquals(new Long(99), ReflectionTestUtils.invokeGetterMethod(person, "id"));
|
||||
assertEquals("Tom", ReflectionTestUtils.invokeGetterMethod(person, "name"));
|
||||
|
|
@ -140,11 +141,11 @@ public class ReflectionTestUtilsTests extends TestCase {
|
|||
assertEquals("Verifying that the person's name (private method) was set.", "Jerry", person.getName());
|
||||
assertEquals("Verifying that the person's age (protected method) was set.", 33, person.getAge());
|
||||
assertEquals("Verifying that the person's eye color (package private method) was set.", "green",
|
||||
person.getEyeColor());
|
||||
person.getEyeColor());
|
||||
assertEquals("Verifying that the person's 'likes pets' flag (protected method for a boolean) was set.", false,
|
||||
person.likesPets());
|
||||
person.likesPets());
|
||||
assertEquals("Verifying that the person's 'favorite number' (protected method for a Number) was set.",
|
||||
new Integer(42), person.getFavoriteNumber());
|
||||
new Integer(42), person.getFavoriteNumber());
|
||||
|
||||
assertEquals(new Long(1), ReflectionTestUtils.invokeGetterMethod(person, "getId"));
|
||||
assertEquals("Jerry", ReflectionTestUtils.invokeGetterMethod(person, "getName"));
|
||||
|
|
@ -162,12 +163,12 @@ public class ReflectionTestUtilsTests extends TestCase {
|
|||
assertNull("Verifying that the person's name (private method) was set.", person.getName());
|
||||
assertNull("Verifying that the person's eye color (package private method) was set.", person.getEyeColor());
|
||||
assertNull("Verifying that the person's 'favorite number' (protected method for a Number) was set.",
|
||||
person.getFavoriteNumber());
|
||||
person.getFavoriteNumber());
|
||||
|
||||
// Null - primitives
|
||||
|
||||
new AssertThrows(RuntimeException.class,
|
||||
"Calling invokeSetterMethod() with NULL for a primitive type should throw an IllegalArgumentException.") {
|
||||
"Calling invokeSetterMethod() with NULL for a primitive type should throw an IllegalArgumentException.") {
|
||||
|
||||
public void test() throws Exception {
|
||||
ReflectionTestUtils.invokeSetterMethod(person, "id", null, long.class);
|
||||
|
|
@ -175,7 +176,7 @@ public class ReflectionTestUtilsTests extends TestCase {
|
|||
}.runTest();
|
||||
|
||||
new AssertThrows(RuntimeException.class,
|
||||
"Calling invokeSetterMethod() with NULL for a primitive type should throw an IllegalArgumentException.") {
|
||||
"Calling invokeSetterMethod() with NULL for a primitive type should throw an IllegalArgumentException.") {
|
||||
|
||||
public void test() throws Exception {
|
||||
ReflectionTestUtils.invokeSetterMethod(person, "age", null, int.class);
|
||||
|
|
@ -183,7 +184,7 @@ public class ReflectionTestUtilsTests extends TestCase {
|
|||
}.runTest();
|
||||
|
||||
new AssertThrows(RuntimeException.class,
|
||||
"Calling invokeSetterMethod() with NULL for a primitive type should throw an IllegalArgumentException.") {
|
||||
"Calling invokeSetterMethod() with NULL for a primitive type should throw an IllegalArgumentException.") {
|
||||
|
||||
public void test() throws Exception {
|
||||
ReflectionTestUtils.invokeSetterMethod(person, "likesPets", null, boolean.class);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2007 the original author or authors.
|
||||
* Copyright 2007-2011 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.
|
||||
|
|
@ -21,7 +21,7 @@ import org.springframework.core.style.ToStringCreator;
|
|||
/**
|
||||
* Concrete subclass of {@link PersistentEntity} representing a <em>person</em>
|
||||
* entity; intended for use in unit tests.
|
||||
*
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 2.5
|
||||
*/
|
||||
|
|
@ -42,6 +42,7 @@ public class Person extends PersistentEntity {
|
|||
return this.name;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private final void setName(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,11 @@
|
|||
|
||||
package org.springframework.web.multipart;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
|
|
@ -25,8 +30,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.mock.web.MockMultipartFile;
|
||||
import org.springframework.mock.web.MockMultipartHttpServletRequest;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
|
@ -35,9 +39,10 @@ import org.springframework.util.ObjectUtils;
|
|||
/**
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class MockMultipartHttpServletRequestTests extends TestCase {
|
||||
public class MockMultipartHttpServletRequestTests {
|
||||
|
||||
public void testMockMultipartHttpServletRequestWithByteArray() throws IOException {
|
||||
@Test
|
||||
public void mockMultipartHttpServletRequestWithByteArray() throws IOException {
|
||||
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
|
||||
assertFalse(request.getFileNames().hasNext());
|
||||
assertNull(request.getFile("file1"));
|
||||
|
|
@ -49,16 +54,18 @@ public class MockMultipartHttpServletRequestTests extends TestCase {
|
|||
doTestMultipartHttpServletRequest(request);
|
||||
}
|
||||
|
||||
public void testMockMultipartHttpServletRequestWithInputStream() throws IOException {
|
||||
@Test
|
||||
public void mockMultipartHttpServletRequestWithInputStream() throws IOException {
|
||||
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
|
||||
request.addFile(new MockMultipartFile("file1", new ByteArrayInputStream("myContent1".getBytes())));
|
||||
request.addFile(new MockMultipartFile("file2", "myOrigFilename", "text/plain", new ByteArrayInputStream("myContent2".getBytes())));
|
||||
request.addFile(new MockMultipartFile("file2", "myOrigFilename", "text/plain", new ByteArrayInputStream(
|
||||
"myContent2".getBytes())));
|
||||
doTestMultipartHttpServletRequest(request);
|
||||
}
|
||||
|
||||
private void doTestMultipartHttpServletRequest(MultipartHttpServletRequest request) throws IOException {
|
||||
Set fileNames = new HashSet();
|
||||
Iterator fileIter = request.getFileNames();
|
||||
Set<String> fileNames = new HashSet<String>();
|
||||
Iterator<String> fileIter = request.getFileNames();
|
||||
while (fileIter.hasNext()) {
|
||||
fileNames.add(fileIter.next());
|
||||
}
|
||||
|
|
@ -67,8 +74,8 @@ public class MockMultipartHttpServletRequestTests extends TestCase {
|
|||
assertTrue(fileNames.contains("file2"));
|
||||
MultipartFile file1 = request.getFile("file1");
|
||||
MultipartFile file2 = request.getFile("file2");
|
||||
Map fileMap = request.getFileMap();
|
||||
List fileMapKeys = new LinkedList(fileMap.keySet());
|
||||
Map<String, MultipartFile> fileMap = request.getFileMap();
|
||||
List<String> fileMapKeys = new LinkedList<String>(fileMap.keySet());
|
||||
assertEquals(2, fileMapKeys.size());
|
||||
assertEquals(file1, fileMap.get("file1"));
|
||||
assertEquals(file2, fileMap.get("file2"));
|
||||
|
|
@ -77,12 +84,14 @@ public class MockMultipartHttpServletRequestTests extends TestCase {
|
|||
assertEquals("", file1.getOriginalFilename());
|
||||
assertNull(file1.getContentType());
|
||||
assertTrue(ObjectUtils.nullSafeEquals("myContent1".getBytes(), file1.getBytes()));
|
||||
assertTrue(ObjectUtils.nullSafeEquals("myContent1".getBytes(), FileCopyUtils.copyToByteArray(file1.getInputStream())));
|
||||
assertTrue(ObjectUtils.nullSafeEquals("myContent1".getBytes(),
|
||||
FileCopyUtils.copyToByteArray(file1.getInputStream())));
|
||||
assertEquals("file2", file2.getName());
|
||||
assertEquals("myOrigFilename", file2.getOriginalFilename());
|
||||
assertEquals("text/plain", file2.getContentType());
|
||||
assertTrue(ObjectUtils.nullSafeEquals("myContent2".getBytes(), file2.getBytes()));
|
||||
assertTrue(ObjectUtils.nullSafeEquals("myContent2".getBytes(), FileCopyUtils.copyToByteArray(file2.getInputStream())));
|
||||
assertTrue(ObjectUtils.nullSafeEquals("myContent2".getBytes(),
|
||||
FileCopyUtils.copyToByteArray(file2.getInputStream())));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue