Merge branch '3.2.x' into master
Conflicts: gradle.properties spring-beans/src/main/java/org/springframework/beans/factory/support/StaticListableBeanFactory.java spring-context-support/src/main/java/org/springframework/cache/ehcache/EhCacheManagerFactoryBean.java spring-core/src/main/java/org/springframework/core/convert/support/StringToEnumConverterFactory.java spring-core/src/main/java/org/springframework/core/env/ReadOnlySystemAttributesMap.java spring-jdbc/src/main/java/org/springframework/jdbc/datasource/LazyConnectionDataSourceProxy.java spring-jdbc/src/main/java/org/springframework/jdbc/support/lob/AbstractLobHandler.java spring-web/src/main/java/org/springframework/http/client/BufferingClientHttpRequestWrapper.java spring-web/src/main/java/org/springframework/http/client/SimpleBufferingClientHttpRequest.java spring-web/src/main/java/org/springframework/http/converter/BufferedImageHttpMessageConverter.java spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -30,12 +30,12 @@ import java.util.Date;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletException;
|
||||
@@ -97,8 +97,10 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
||||
|
||||
private static final String CHARSET_PREFIX = "charset=";
|
||||
|
||||
|
||||
private boolean active = true;
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// ServletRequest properties
|
||||
// ---------------------------------------------------------------------
|
||||
@@ -140,6 +142,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
||||
|
||||
private int localPort = DEFAULT_SERVER_PORT;
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// HttpServletRequest properties
|
||||
// ---------------------------------------------------------------------
|
||||
@@ -235,6 +238,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
||||
this.locales.add(Locale.ENGLISH);
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Lifecycle methods
|
||||
// ---------------------------------------------------------------------
|
||||
@@ -279,6 +283,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// ServletRequest interface
|
||||
// ---------------------------------------------------------------------
|
||||
@@ -290,7 +295,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
||||
|
||||
public Enumeration<String> getAttributeNames() {
|
||||
checkActive();
|
||||
return Collections.enumeration(this.attributes.keySet());
|
||||
return Collections.enumeration(new LinkedHashSet<String>(this.attributes.keySet()));
|
||||
}
|
||||
|
||||
public String getCharacterEncoding() {
|
||||
@@ -351,7 +356,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
||||
* parameter name, they will be replaced.
|
||||
*/
|
||||
public void setParameter(String name, String value) {
|
||||
setParameter(name, new String[] { value });
|
||||
setParameter(name, new String[] {value});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -373,7 +378,8 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
||||
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);
|
||||
@@ -382,8 +388,8 @@ 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() + "]");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -394,7 +400,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
||||
* 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});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -425,7 +431,8 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
||||
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);
|
||||
@@ -434,8 +441,8 @@ 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() + "]");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -456,8 +463,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
||||
}
|
||||
|
||||
public String getParameter(String name) {
|
||||
Assert.notNull(name, "Parameter name must not be null");
|
||||
String[] arr = this.parameters.get(name);
|
||||
String[] arr = (name != null ? this.parameters.get(name) : null);
|
||||
return (arr != null && arr.length > 0 ? arr[0] : null);
|
||||
}
|
||||
|
||||
@@ -466,8 +472,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
||||
}
|
||||
|
||||
public String[] getParameterValues(String name) {
|
||||
Assert.notNull(name, "Parameter name must not be null");
|
||||
return this.parameters.get(name);
|
||||
return (name != null ? this.parameters.get(name) : null);
|
||||
}
|
||||
|
||||
public Map<String, String[]> getParameterMap() {
|
||||
@@ -509,8 +514,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 {
|
||||
@@ -574,7 +579,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
||||
* @since 3.2
|
||||
*/
|
||||
public void setPreferredLocales(List<Locale> locales) {
|
||||
Assert.notEmpty(locales, "preferred locales list must not be empty");
|
||||
Assert.notEmpty(locales, "Locale list must not be empty");
|
||||
this.locales.clear();
|
||||
this.locales.addAll(locales);
|
||||
}
|
||||
@@ -635,6 +640,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
||||
return this.localPort;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// HttpServletRequest interface
|
||||
// ---------------------------------------------------------------------
|
||||
@@ -797,8 +803,8 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
||||
}
|
||||
|
||||
public boolean isUserInRole(String role) {
|
||||
return (this.userRoles.contains(role) || (this.servletContext instanceof MockServletContext && ((MockServletContext) this.servletContext).getDeclaredRoles().contains(
|
||||
role)));
|
||||
return (this.userRoles.contains(role) || (this.servletContext instanceof MockServletContext &&
|
||||
((MockServletContext) this.servletContext).getDeclaredRoles().contains(role)));
|
||||
}
|
||||
|
||||
public void setUserPrincipal(Principal userPrincipal) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,11 +24,11 @@ import java.io.PrintWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.io.Writer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@@ -56,6 +56,7 @@ public class MockHttpServletResponse implements HttpServletResponse {
|
||||
|
||||
private static final String LOCATION_HEADER = "Location";
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// ServletResponse properties
|
||||
//---------------------------------------------------------------------
|
||||
@@ -145,7 +146,7 @@ public class MockHttpServletResponse implements HttpServletResponse {
|
||||
private void updateContentTypeHeader() {
|
||||
if (this.contentType != null) {
|
||||
StringBuilder sb = new StringBuilder(this.contentType);
|
||||
if (this.contentType.toLowerCase().indexOf(CHARSET_PREFIX) == -1 && this.charset) {
|
||||
if (!this.contentType.toLowerCase().contains(CHARSET_PREFIX) && this.charset) {
|
||||
sb.append(";").append(CHARSET_PREFIX).append(this.characterEncoding);
|
||||
}
|
||||
doAddHeaderValue(CONTENT_TYPE_HEADER, sb.toString(), true);
|
||||
@@ -299,7 +300,7 @@ public class MockHttpServletResponse implements HttpServletResponse {
|
||||
* <p>As of Servlet 3.0, this method is also defined HttpServletResponse.
|
||||
* @return the {@code Set} of header name {@code Strings}, or an empty {@code Set} if none
|
||||
*/
|
||||
public Set<String> getHeaderNames() {
|
||||
public Collection<String> getHeaderNames() {
|
||||
return this.headers.keySet();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -22,6 +22,7 @@ import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpSession;
|
||||
@@ -50,6 +51,7 @@ public class MockHttpSession implements HttpSession {
|
||||
|
||||
public static final String SESSION_COOKIE_NAME = "JSESSION";
|
||||
|
||||
|
||||
private static int nextId = 1;
|
||||
|
||||
private final String id;
|
||||
@@ -141,7 +143,7 @@ public class MockHttpSession implements HttpSession {
|
||||
}
|
||||
|
||||
public Enumeration<String> getAttributeNames() {
|
||||
return Collections.enumeration(this.attributes.keySet());
|
||||
return Collections.enumeration(new LinkedHashSet<String>(this.attributes.keySet()));
|
||||
}
|
||||
|
||||
public String[] getValueNames() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,6 +21,7 @@ import java.io.UnsupportedEncodingException;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
import javax.el.ELContext;
|
||||
import javax.servlet.Servlet;
|
||||
@@ -249,7 +250,7 @@ public class MockPageContext extends PageContext {
|
||||
}
|
||||
|
||||
public Enumeration<String> getAttributeNames() {
|
||||
return Collections.enumeration(this.attributes.keySet());
|
||||
return Collections.enumeration(new LinkedHashSet<String>(this.attributes.keySet()));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -29,7 +29,6 @@ import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.activation.FileTypeMap;
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.Servlet;
|
||||
@@ -434,7 +433,7 @@ public class MockServletContext implements ServletContext {
|
||||
}
|
||||
|
||||
public Enumeration<String> getAttributeNames() {
|
||||
return Collections.enumeration(this.attributes.keySet());
|
||||
return Collections.enumeration(new LinkedHashSet<String>(this.attributes.keySet()));
|
||||
}
|
||||
|
||||
public void setAttribute(String name, Object value) {
|
||||
|
||||
@@ -125,4 +125,4 @@ public class MockClientDataRequest extends MockPortletRequest implements ClientD
|
||||
return this.method;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,4 +85,4 @@ public class MockEvent implements Event {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,4 +85,4 @@ public class MockEventRequest extends MockPortletRequest implements EventRequest
|
||||
return this.method;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -28,7 +28,6 @@ import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Vector;
|
||||
import javax.activation.FileTypeMap;
|
||||
import javax.portlet.PortletContext;
|
||||
import javax.portlet.PortletRequestDispatcher;
|
||||
@@ -210,7 +209,7 @@ public class MockPortletContext implements PortletContext {
|
||||
}
|
||||
|
||||
public Enumeration<String> getAttributeNames() {
|
||||
return new Vector<String>(this.attributes.keySet()).elements();
|
||||
return Collections.enumeration(new LinkedHashSet<String>(this.attributes.keySet()));
|
||||
}
|
||||
|
||||
public void setAttribute(String name, Object value) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,13 +21,12 @@ import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
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;
|
||||
@@ -332,7 +331,7 @@ public class MockPortletRequest implements PortletRequest {
|
||||
|
||||
public Enumeration<String> getAttributeNames() {
|
||||
checkActive();
|
||||
return new Vector<String>(this.attributes.keySet()).elements();
|
||||
return Collections.enumeration(new LinkedHashSet<String>(this.attributes.keySet()));
|
||||
}
|
||||
|
||||
public void setParameters(Map<String, String[]> parameters) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,10 +18,10 @@ package org.springframework.mock.web.portlet;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Vector;
|
||||
import javax.portlet.PortletContext;
|
||||
import javax.portlet.PortletSession;
|
||||
import javax.servlet.http.HttpSessionBindingEvent;
|
||||
@@ -51,9 +51,9 @@ public class MockPortletSession implements PortletSession {
|
||||
|
||||
private final PortletContext portletContext;
|
||||
|
||||
private final Map<String, Object> portletAttributes = new HashMap<String, Object>();
|
||||
private final Map<String, Object> portletAttributes = new LinkedHashMap<String, Object>();
|
||||
|
||||
private final Map<String, Object> applicationAttributes = new HashMap<String, Object>();
|
||||
private final Map<String, Object> applicationAttributes = new LinkedHashMap<String, Object>();
|
||||
|
||||
private boolean invalid = false;
|
||||
|
||||
@@ -92,15 +92,15 @@ public class MockPortletSession implements PortletSession {
|
||||
}
|
||||
|
||||
public Enumeration<String> getAttributeNames() {
|
||||
return new Vector<String>(this.portletAttributes.keySet()).elements();
|
||||
return Collections.enumeration(new LinkedHashSet<String>(this.portletAttributes.keySet()));
|
||||
}
|
||||
|
||||
public Enumeration<String> getAttributeNames(int scope) {
|
||||
if (scope == PortletSession.PORTLET_SCOPE) {
|
||||
return new Vector<String>(this.portletAttributes.keySet()).elements();
|
||||
return Collections.enumeration(new LinkedHashSet<String>(this.portletAttributes.keySet()));
|
||||
}
|
||||
else if (scope == PortletSession.APPLICATION_SCOPE) {
|
||||
return new Vector<String>(this.applicationAttributes.keySet()).elements();
|
||||
return Collections.enumeration(new LinkedHashSet<String>(this.applicationAttributes.keySet()));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -151,4 +151,4 @@ public class MockStateAwareResponse extends MockPortletResponse implements State
|
||||
return this.events.get(new QName(name));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -41,7 +41,8 @@ import org.springframework.util.StringUtils;
|
||||
/**
|
||||
* Utility methods for working with {@link ContextLoader ContextLoaders} and
|
||||
* {@link SmartContextLoader SmartContextLoaders} and resolving resource locations,
|
||||
* annotated classes, and active bean definition profiles.
|
||||
* annotated classes, active bean definition profiles, and application context
|
||||
* initializers.
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 3.1
|
||||
@@ -50,6 +51,7 @@ import org.springframework.util.StringUtils;
|
||||
* @see ContextConfiguration
|
||||
* @see ContextConfigurationAttributes
|
||||
* @see ActiveProfiles
|
||||
* @see ApplicationContextInitializer
|
||||
* @see MergedContextConfiguration
|
||||
*/
|
||||
abstract class ContextLoaderUtils {
|
||||
@@ -78,7 +80,7 @@ abstract class ContextLoaderUtils {
|
||||
* either {@value #DEFAULT_CONTEXT_LOADER_CLASS_NAME}
|
||||
* or {@value #DEFAULT_WEB_CONTEXT_LOADER_CLASS_NAME} will be used as the
|
||||
* default context loader class name. For details on the class resolution
|
||||
* process, see {@link #resolveContextLoaderClass()}.
|
||||
* process, see {@link #resolveContextLoaderClass}.
|
||||
*
|
||||
* @param testClass the test class for which the {@code ContextLoader}
|
||||
* should be resolved; must not be {@code null}
|
||||
@@ -89,8 +91,9 @@ abstract class ContextLoaderUtils {
|
||||
* {@code ContextLoader} class to use; may be {@code null} or <em>empty</em>
|
||||
* @return the resolved {@code ContextLoader} for the supplied
|
||||
* {@code testClass} (never {@code null})
|
||||
* @see #resolveContextLoaderClass()
|
||||
* @see #resolveContextLoaderClass
|
||||
*/
|
||||
@SuppressWarnings("javadoc")
|
||||
static ContextLoader resolveContextLoader(Class<?> testClass,
|
||||
List<ContextConfigurationAttributes> configAttributesList, String defaultContextLoaderClassName) {
|
||||
Assert.notNull(testClass, "Class must not be null");
|
||||
@@ -348,11 +351,11 @@ abstract class ContextLoaderUtils {
|
||||
* @param defaultContextLoaderClassName the name of the default
|
||||
* {@code ContextLoader} class to use (may be {@code null})
|
||||
* @return the merged context configuration
|
||||
* @see #resolveContextLoader()
|
||||
* @see #resolveContextConfigurationAttributes()
|
||||
* @see SmartContextLoader#processContextConfiguration()
|
||||
* @see ContextLoader#processLocations()
|
||||
* @see #resolveActiveProfiles()
|
||||
* @see #resolveContextLoader
|
||||
* @see #resolveContextConfigurationAttributes
|
||||
* @see SmartContextLoader#processContextConfiguration
|
||||
* @see ContextLoader#processLocations
|
||||
* @see #resolveActiveProfiles
|
||||
* @see MergedContextConfiguration
|
||||
*/
|
||||
static MergedContextConfiguration buildMergedContextConfiguration(Class<?> testClass,
|
||||
|
||||
@@ -448,4 +448,4 @@ public class TestContextManager {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,8 +185,8 @@ public abstract class AbstractContextLoader implements SmartContextLoader {
|
||||
*
|
||||
* <p>For example, if the supplied class is {@code com.example.MyTest},
|
||||
* the generated locations will contain a single string with a value of
|
||||
* "classpath:/com/example/MyTest{@code <suffix>}",
|
||||
* where {@code <suffix>} is the value of the
|
||||
* "classpath:/com/example/MyTest{@code <suffix>}",
|
||||
* where {@code <suffix>} is the value of the
|
||||
* {@link #getResourceSuffix() resource suffix} string.
|
||||
*
|
||||
* <p>As of Spring 3.1, the implementation of this method adheres to the
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -126,6 +126,7 @@ public class ServletTestExecutionListener extends AbstractTestExecutionListener
|
||||
RequestContextHolder.setRequestAttributes(servletWebRequest);
|
||||
|
||||
if (wac instanceof ConfigurableApplicationContext) {
|
||||
@SuppressWarnings("resource")
|
||||
ConfigurableApplicationContext configurableApplicationContext = (ConfigurableApplicationContext) wac;
|
||||
ConfigurableListableBeanFactory bf = configurableApplicationContext.getBeanFactory();
|
||||
bf.registerResolvableDependency(MockHttpServletResponse.class, response);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,13 +23,13 @@ import java.util.List;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.core.io.support.EncodedResource;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.DataAccessResourceFailureException;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.SqlParameterValue;
|
||||
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -42,6 +42,7 @@ import org.springframework.util.StringUtils;
|
||||
* @author Thomas Risberg
|
||||
* @author Sam Brannen
|
||||
* @author Juergen Hoeller
|
||||
* @author Phillip Webb
|
||||
* @since 2.5.4
|
||||
*/
|
||||
public class JdbcTestUtils {
|
||||
@@ -60,7 +61,7 @@ public class JdbcTestUtils {
|
||||
* @return the number of rows in the table
|
||||
*/
|
||||
public static int countRowsInTable(JdbcTemplate jdbcTemplate, String tableName) {
|
||||
return jdbcTemplate.queryForInt("SELECT COUNT(0) FROM " + tableName);
|
||||
return jdbcTemplate.queryForObject("SELECT COUNT(0) FROM " + tableName, Integer.class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,7 +83,7 @@ public class JdbcTestUtils {
|
||||
if (StringUtils.hasText(whereClause)) {
|
||||
sql += " WHERE " + whereClause;
|
||||
}
|
||||
return jdbcTemplate.queryForInt(sql);
|
||||
return jdbcTemplate.queryForObject(sql, Integer.class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -103,6 +104,39 @@ public class JdbcTestUtils {
|
||||
return totalRowCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete rows from the given table, using the provided {@code WHERE} clause.
|
||||
* <p>If the provided {@code WHERE} clause contains text, it will be prefixed
|
||||
* with {@code " WHERE "} and then appended to the generated {@code DELETE}
|
||||
* statement. For example, if the provided table name is {@code "person"} and
|
||||
* the provided where clause is {@code "name = 'Bob' and age > 25"}, the
|
||||
* resulting SQL statement to execute will be
|
||||
* {@code "DELETE FROM person WHERE name = 'Bob' and age > 25"}.
|
||||
* <p>As an alternative to hard-coded values, the {@code "?"} placeholder can
|
||||
* be used within the {@code WHERE} clause, binding to the given arguments.
|
||||
* @param jdbcTemplate the JdbcTemplate with which to perform JDBC operations
|
||||
* @param tableName the name of the table to delete rows from
|
||||
* @param whereClause the {@code WHERE} clause to append to the query
|
||||
* @param args arguments to bind to the query (leaving it to the PreparedStatement
|
||||
* to guess the corresponding SQL type); may also contain {@link SqlParameterValue}
|
||||
* objects which indicate not only the argument value but also the SQL type and
|
||||
* optionally the scale.
|
||||
* @return the number of rows deleted from the table
|
||||
*/
|
||||
public static int deleteFromTableWhere(JdbcTemplate jdbcTemplate, String tableName,
|
||||
String whereClause, Object... args) {
|
||||
String sql = "DELETE FROM " + tableName;
|
||||
if (StringUtils.hasText(whereClause)) {
|
||||
sql += " WHERE " + whereClause;
|
||||
}
|
||||
int rowCount = (args != null && args.length > 0 ? jdbcTemplate.update(sql, args)
|
||||
: jdbcTemplate.update(sql));
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Deleted " + rowCount + " rows from table " + tableName);
|
||||
}
|
||||
return rowCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Drop the specified tables.
|
||||
* @param jdbcTemplate the JdbcTemplate with which to perform JDBC operations
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -326,6 +326,7 @@ public abstract class AbstractJpaTests extends AbstractAnnotationAwareTransactio
|
||||
|
||||
private final LoadTimeWeaver ltw;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public LoadTimeWeaverInjectingBeanPostProcessor(LoadTimeWeaver ltw) {
|
||||
this.ltw = ltw;
|
||||
}
|
||||
@@ -346,6 +347,7 @@ public abstract class AbstractJpaTests extends AbstractAnnotationAwareTransactio
|
||||
|
||||
private final ClassLoader shadowingClassLoader;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public ShadowingLoadTimeWeaver(ClassLoader shadowingClassLoader) {
|
||||
this.shadowingClassLoader = shadowingClassLoader;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user