Browse Source

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
pull/196/head
Sam Brannen 13 years ago
parent
commit
d0503ab733
  1. 2
      spring-test/src/main/java/org/springframework/test/context/ContextLoaderUtils.java
  2. 2
      spring-test/src/main/java/org/springframework/test/context/support/AbstractDelegatingSmartContextLoader.java
  3. 4
      spring-test/src/main/java/org/springframework/test/context/support/AnnotationConfigContextLoaderUtils.java
  4. 4
      spring-test/src/main/java/org/springframework/test/context/web/AbstractGenericWebContextLoader.java
  5. 5
      spring-test/src/main/java/org/springframework/test/context/web/AnnotationConfigWebContextLoader.java
  6. 23
      spring-test/src/main/java/org/springframework/test/context/web/GenericXmlWebContextLoader.java
  7. 25
      spring-test/src/main/java/org/springframework/test/context/web/ServletTestExecutionListener.java
  8. 11
      spring-test/src/main/java/org/springframework/test/context/web/WebDelegatingSmartContextLoader.java
  9. 6
      spring-test/src/main/java/org/springframework/test/context/web/package-info.java

2
spring-test/src/main/java/org/springframework/test/context/ContextLoaderUtils.java

@ -57,7 +57,7 @@ abstract class ContextLoaderUtils { @@ -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";

2
spring-test/src/main/java/org/springframework/test/context/support/AbstractDelegatingSmartContextLoader.java

@ -63,7 +63,7 @@ import org.springframework.util.ObjectUtils; @@ -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);

4
spring-test/src/main/java/org/springframework/test/context/support/AnnotationConfigContextLoaderUtils.java

@ -31,7 +31,7 @@ import org.springframework.util.Assert; @@ -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 { @@ -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<?>>();

4
spring-test/src/main/java/org/springframework/test/context/support/AbstractGenericWebContextLoader.java → spring-test/src/main/java/org/springframework/test/context/web/AbstractGenericWebContextLoader.java

@ -14,7 +14,7 @@ @@ -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; @@ -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;

5
spring-test/src/main/java/org/springframework/test/context/support/AnnotationConfigWebContextLoader.java → spring-test/src/main/java/org/springframework/test/context/web/AnnotationConfigWebContextLoader.java

@ -14,13 +14,14 @@ @@ -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;

23
spring-test/src/main/java/org/springframework/test/context/support/XmlWebContextLoader.java → spring-test/src/main/java/org/springframework/test/context/web/GenericXmlWebContextLoader.java

@ -14,31 +14,23 @@ @@ -14,31 +14,23 @@
* 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 {
/**
* Returns &quot;<code>-context.xml</code>&quot;.
*/
protected String getResourceSuffix() {
return "-context.xml";
}
public class GenericXmlWebContextLoader extends AbstractGenericWebContextLoader {
/**
* 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)
* @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,
@ -46,4 +38,11 @@ public class XmlWebContextLoader extends AbstractGenericWebContextLoader { @@ -46,4 +38,11 @@ public class XmlWebContextLoader extends AbstractGenericWebContextLoader {
new XmlBeanDefinitionReader(context).loadBeanDefinitions(webMergedConfig.getLocations());
}
/**
* Returns &quot;<code>-context.xml</code>&quot;.
*/
protected String getResourceSuffix() {
return "-context.xml";
}
}

25
spring-test/src/main/java/org/springframework/test/context/web/ServletTestExecutionListener.java

@ -20,7 +20,6 @@ import javax.servlet.ServletContext; @@ -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; @@ -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; @@ -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 { @@ -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) {

11
spring-test/src/main/java/org/springframework/test/context/support/WebDelegatingSmartContextLoader.java → spring-test/src/main/java/org/springframework/test/context/web/WebDelegatingSmartContextLoader.java

@ -14,25 +14,26 @@ @@ -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();

6
spring-test/src/main/java/org/springframework/test/context/web/package-info.java

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