Relocate web artifacts in the TCF to web package

This commit relocates recently introduced web artifacts in the
TestContext framework to the ~.test.context.web package and renames some
classes for consistency with the existing code base.

 - introduced package-info.java in the web package.

 - ServletTestExecutionListener now extends
   AbstractTestExecutionListener instead of implementing
   TestExecutionListener.

 - relocated AbstractGenericWebContextLoader,
   AnnotationConfigWebContextLoader, XmlWebContextLoader, and
   WebDelegatingSmartContextLoader to the web package.

 - renamed XmlWebContextLoader to GenericXmlWebContextLoader for
   consistency with GenericXmlContextLoader.

 - changed the visibility of AbstractDelegatingSmartContextLoader and
   AnnotationConfigContextLoaderUtils to public.

Issue: SPR-10067
This commit is contained in:
Sam Brannen 2012-12-03 23:29:10 +01:00
parent e0e3143dd5
commit d0503ab733
9 changed files with 37 additions and 51 deletions

View File

@ -57,7 +57,7 @@ abstract class ContextLoaderUtils {
private static final Log logger = LogFactory.getLog(ContextLoaderUtils.class);
private static final String DEFAULT_CONTEXT_LOADER_CLASS_NAME = "org.springframework.test.context.support.DelegatingSmartContextLoader";
private static final String DEFAULT_WEB_CONTEXT_LOADER_CLASS_NAME = "org.springframework.test.context.support.WebDelegatingSmartContextLoader";
private static final String DEFAULT_WEB_CONTEXT_LOADER_CLASS_NAME = "org.springframework.test.context.web.WebDelegatingSmartContextLoader";
private static final String WEB_APP_CONFIGURATION_CLASS_NAME = "org.springframework.test.context.web.WebAppConfiguration";
private static final String WEB_MERGED_CONTEXT_CONFIGURATION_CLASS_NAME = "org.springframework.test.context.web.WebMergedContextConfiguration";

View File

@ -63,7 +63,7 @@ import org.springframework.util.ObjectUtils;
* @since 3.2
* @see SmartContextLoader
*/
abstract class AbstractDelegatingSmartContextLoader implements SmartContextLoader {
public abstract class AbstractDelegatingSmartContextLoader implements SmartContextLoader {
private static final Log logger = LogFactory.getLog(AbstractDelegatingSmartContextLoader.class);

View File

@ -31,7 +31,7 @@ import org.springframework.util.Assert;
* @author Sam Brannen
* @since 3.2
*/
abstract class AnnotationConfigContextLoaderUtils {
public abstract class AnnotationConfigContextLoaderUtils {
private static final Log logger = LogFactory.getLog(AnnotationConfigContextLoaderUtils.class);
@ -86,7 +86,7 @@ abstract class AnnotationConfigContextLoaderUtils {
* @return an array of default configuration classes, potentially empty but
* never <code>null</code>
*/
static Class<?>[] detectDefaultConfigurationClasses(Class<?> declaringClass) {
public static Class<?>[] detectDefaultConfigurationClasses(Class<?> declaringClass) {
Assert.notNull(declaringClass, "Declaring class must not be null");
List<Class<?>> configClasses = new ArrayList<Class<?>>();

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.test.context.support;
package org.springframework.test.context.web;
import javax.servlet.ServletContext;
@ -29,7 +29,7 @@ import org.springframework.core.io.FileSystemResourceLoader;
import org.springframework.core.io.ResourceLoader;
import org.springframework.mock.web.MockServletContext;
import org.springframework.test.context.MergedContextConfiguration;
import org.springframework.test.context.web.WebMergedContextConfiguration;
import org.springframework.test.context.support.AbstractContextLoader;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.GenericWebApplicationContext;

View File

@ -14,13 +14,14 @@
* limitations under the License.
*/
package org.springframework.test.context.support;
package org.springframework.test.context.web;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.annotation.AnnotatedBeanDefinitionReader;
import org.springframework.test.context.ContextConfigurationAttributes;
import org.springframework.test.context.web.WebMergedContextConfiguration;
import org.springframework.test.context.support.AbstractContextLoader;
import org.springframework.test.context.support.AnnotationConfigContextLoaderUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.web.context.support.GenericWebApplicationContext;

View File

@ -14,19 +14,29 @@
* limitations under the License.
*/
package org.springframework.test.context.support;
package org.springframework.test.context.web;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.test.context.web.WebMergedContextConfiguration;
import org.springframework.web.context.support.GenericWebApplicationContext;
/**
* TODO [SPR-9864] Document XmlWebContextLoader.
* TODO [SPR-9864] Document GenericXmlWebContextLoader.
*
* @author Sam Brannen
* @since 3.2
*/
public class XmlWebContextLoader extends AbstractGenericWebContextLoader {
public class GenericXmlWebContextLoader extends AbstractGenericWebContextLoader {
/**
* TODO [SPR-9864] Document overridden loadBeanDefinitions().
*
* @see org.springframework.test.context.web.AbstractGenericWebContextLoader#loadBeanDefinitions(org.springframework.web.context.support.GenericWebApplicationContext, org.springframework.test.context.web.WebMergedContextConfiguration)
*/
@Override
protected void loadBeanDefinitions(GenericWebApplicationContext context,
WebMergedContextConfiguration webMergedConfig) {
new XmlBeanDefinitionReader(context).loadBeanDefinitions(webMergedConfig.getLocations());
}
/**
* Returns &quot;<code>-context.xml</code>&quot;.
@ -35,15 +45,4 @@ public class XmlWebContextLoader extends AbstractGenericWebContextLoader {
return "-context.xml";
}
/**
* TODO [SPR-9864] Document overridden loadBeanDefinitions().
*
* @see org.springframework.test.context.support.AbstractGenericWebContextLoader#loadBeanDefinitions(org.springframework.web.context.support.GenericWebApplicationContext, org.springframework.test.context.web.WebMergedContextConfiguration)
*/
@Override
protected void loadBeanDefinitions(GenericWebApplicationContext context,
WebMergedContextConfiguration webMergedConfig) {
new XmlBeanDefinitionReader(context).loadBeanDefinitions(webMergedConfig.getLocations());
}
}

View File

@ -20,7 +20,6 @@ import javax.servlet.ServletContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
@ -29,6 +28,7 @@ import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.mock.web.MockServletContext;
import org.springframework.test.context.TestContext;
import org.springframework.test.context.TestExecutionListener;
import org.springframework.test.context.support.AbstractTestExecutionListener;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletWebRequest;
@ -39,21 +39,11 @@ import org.springframework.web.context.request.ServletWebRequest;
* @author Sam Brannen
* @since 3.2
*/
public class ServletTestExecutionListener implements TestExecutionListener {
public class ServletTestExecutionListener extends AbstractTestExecutionListener {
private static final Log logger = LogFactory.getLog(ServletTestExecutionListener.class);
/**
* The default implementation is <em>empty</em>. Can be overridden by
* subclasses as necessary.
*
* @see TestExecutionListener#beforeTestClass(TestContext)
*/
public void beforeTestClass(TestContext testContext) throws Exception {
/* no-op */
}
/**
* TODO [SPR-9864] Document overridden prepareTestInstance().
*
@ -84,21 +74,10 @@ public class ServletTestExecutionListener implements TestExecutionListener {
RequestContextHolder.resetRequestAttributes();
}
/**
* The default implementation is <em>empty</em>. Can be overridden by
* subclasses as necessary.
*
* @see TestExecutionListener#afterTestClass(TestContext)
*/
public void afterTestClass(TestContext testContext) throws Exception {
/* no-op */
}
/**
* TODO [SPR-9864] Document setUpRequestContext().
*
* @param testContext
* @param servletContext
*/
private void setUpRequestContextIfNecessary(TestContext testContext) {

View File

@ -14,25 +14,26 @@
* limitations under the License.
*/
package org.springframework.test.context.support;
package org.springframework.test.context.web;
import org.springframework.test.context.SmartContextLoader;
import org.springframework.test.context.support.AbstractDelegatingSmartContextLoader;
/**
* {@code WebDelegatingSmartContextLoader} is a concrete implementation of
* {@link AbstractDelegatingSmartContextLoader} that delegates to an
* {@link XmlWebContextLoader} and an {@link AnnotationConfigWebContextLoader}.
* {@link AbstractDelegatingSmartContextLoader} that delegates to a
* {@link GenericXmlWebContextLoader} and an {@link AnnotationConfigWebContextLoader}.
*
* @author Sam Brannen
* @since 3.2
* @see SmartContextLoader
* @see AbstractDelegatingSmartContextLoader
* @see XmlWebContextLoader
* @see GenericXmlWebContextLoader
* @see AnnotationConfigWebContextLoader
*/
public class WebDelegatingSmartContextLoader extends AbstractDelegatingSmartContextLoader {
private final SmartContextLoader xmlLoader = new XmlWebContextLoader();
private final SmartContextLoader xmlLoader = new GenericXmlWebContextLoader();
private final SmartContextLoader annotationConfigLoader = new AnnotationConfigWebContextLoader();

View File

@ -0,0 +1,6 @@
/**
* Web support classes for the <em>Spring TestContext Framework</em>.
*/
package org.springframework.test.context.web;