Skip to content

Commit d0503ab

Browse files
committed
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
1 parent e0e3143 commit d0503ab

9 files changed

+34
-48
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ abstract class ContextLoaderUtils {
5757
private static final Log logger = LogFactory.getLog(ContextLoaderUtils.class);
5858

5959
private static final String DEFAULT_CONTEXT_LOADER_CLASS_NAME = "org.springframework.test.context.support.DelegatingSmartContextLoader";
60-
private static final String DEFAULT_WEB_CONTEXT_LOADER_CLASS_NAME = "org.springframework.test.context.support.WebDelegatingSmartContextLoader";
60+
private static final String DEFAULT_WEB_CONTEXT_LOADER_CLASS_NAME = "org.springframework.test.context.web.WebDelegatingSmartContextLoader";
6161

6262
private static final String WEB_APP_CONFIGURATION_CLASS_NAME = "org.springframework.test.context.web.WebAppConfiguration";
6363
private static final String WEB_MERGED_CONTEXT_CONFIGURATION_CLASS_NAME = "org.springframework.test.context.web.WebMergedContextConfiguration";

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
* @since 3.2
6464
* @see SmartContextLoader
6565
*/
66-
abstract class AbstractDelegatingSmartContextLoader implements SmartContextLoader {
66+
public abstract class AbstractDelegatingSmartContextLoader implements SmartContextLoader {
6767

6868
private static final Log logger = LogFactory.getLog(AbstractDelegatingSmartContextLoader.class);
6969

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
* @author Sam Brannen
3232
* @since 3.2
3333
*/
34-
abstract class AnnotationConfigContextLoaderUtils {
34+
public abstract class AnnotationConfigContextLoaderUtils {
3535

3636
private static final Log logger = LogFactory.getLog(AnnotationConfigContextLoaderUtils.class);
3737

@@ -86,7 +86,7 @@ private static boolean isDefaultConfigurationClassCandidate(Class<?> clazz) {
8686
* @return an array of default configuration classes, potentially empty but
8787
* never <code>null</code>
8888
*/
89-
static Class<?>[] detectDefaultConfigurationClasses(Class<?> declaringClass) {
89+
public static Class<?>[] detectDefaultConfigurationClasses(Class<?> declaringClass) {
9090
Assert.notNull(declaringClass, "Declaring class must not be null");
9191

9292
List<Class<?>> configClasses = new ArrayList<Class<?>>();
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.test.context.support;
17+
package org.springframework.test.context.web;
1818

1919
import javax.servlet.ServletContext;
2020

@@ -29,7 +29,7 @@
2929
import org.springframework.core.io.ResourceLoader;
3030
import org.springframework.mock.web.MockServletContext;
3131
import org.springframework.test.context.MergedContextConfiguration;
32-
import org.springframework.test.context.web.WebMergedContextConfiguration;
32+
import org.springframework.test.context.support.AbstractContextLoader;
3333
import org.springframework.web.context.WebApplicationContext;
3434
import org.springframework.web.context.support.GenericWebApplicationContext;
3535

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.test.context.support;
17+
package org.springframework.test.context.web;
1818

1919
import org.apache.commons.logging.Log;
2020
import org.apache.commons.logging.LogFactory;
2121
import org.springframework.context.annotation.AnnotatedBeanDefinitionReader;
2222
import org.springframework.test.context.ContextConfigurationAttributes;
23-
import org.springframework.test.context.web.WebMergedContextConfiguration;
23+
import org.springframework.test.context.support.AbstractContextLoader;
24+
import org.springframework.test.context.support.AnnotationConfigContextLoaderUtils;
2425
import org.springframework.util.ObjectUtils;
2526
import org.springframework.web.context.support.GenericWebApplicationContext;
2627

spring-test/src/main/java/org/springframework/test/context/support/XmlWebContextLoader.java renamed to spring-test/src/main/java/org/springframework/test/context/web/GenericXmlWebContextLoader.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,35 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.test.context.support;
17+
package org.springframework.test.context.web;
1818

1919
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
20-
import org.springframework.test.context.web.WebMergedContextConfiguration;
2120
import org.springframework.web.context.support.GenericWebApplicationContext;
2221

2322
/**
24-
* TODO [SPR-9864] Document XmlWebContextLoader.
23+
* TODO [SPR-9864] Document GenericXmlWebContextLoader.
2524
*
2625
* @author Sam Brannen
2726
* @since 3.2
2827
*/
29-
public class XmlWebContextLoader extends AbstractGenericWebContextLoader {
30-
31-
/**
32-
* Returns &quot;<code>-context.xml</code>&quot;.
33-
*/
34-
protected String getResourceSuffix() {
35-
return "-context.xml";
36-
}
28+
public class GenericXmlWebContextLoader extends AbstractGenericWebContextLoader {
3729

3830
/**
3931
* TODO [SPR-9864] Document overridden loadBeanDefinitions().
4032
*
41-
* @see org.springframework.test.context.support.AbstractGenericWebContextLoader#loadBeanDefinitions(org.springframework.web.context.support.GenericWebApplicationContext, org.springframework.test.context.web.WebMergedContextConfiguration)
33+
* @see org.springframework.test.context.web.AbstractGenericWebContextLoader#loadBeanDefinitions(org.springframework.web.context.support.GenericWebApplicationContext, org.springframework.test.context.web.WebMergedContextConfiguration)
4234
*/
4335
@Override
4436
protected void loadBeanDefinitions(GenericWebApplicationContext context,
4537
WebMergedContextConfiguration webMergedConfig) {
4638
new XmlBeanDefinitionReader(context).loadBeanDefinitions(webMergedConfig.getLocations());
4739
}
4840

41+
/**
42+
* Returns &quot;<code>-context.xml</code>&quot;.
43+
*/
44+
protected String getResourceSuffix() {
45+
return "-context.xml";
46+
}
47+
4948
}

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

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
import org.apache.commons.logging.Log;
2222
import org.apache.commons.logging.LogFactory;
23-
2423
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
2524
import org.springframework.context.ApplicationContext;
2625
import org.springframework.context.ConfigurableApplicationContext;
@@ -29,6 +28,7 @@
2928
import org.springframework.mock.web.MockServletContext;
3029
import org.springframework.test.context.TestContext;
3130
import org.springframework.test.context.TestExecutionListener;
31+
import org.springframework.test.context.support.AbstractTestExecutionListener;
3232
import org.springframework.web.context.WebApplicationContext;
3333
import org.springframework.web.context.request.RequestContextHolder;
3434
import org.springframework.web.context.request.ServletWebRequest;
@@ -39,21 +39,11 @@
3939
* @author Sam Brannen
4040
* @since 3.2
4141
*/
42-
public class ServletTestExecutionListener implements TestExecutionListener {
42+
public class ServletTestExecutionListener extends AbstractTestExecutionListener {
4343

4444
private static final Log logger = LogFactory.getLog(ServletTestExecutionListener.class);
4545

4646

47-
/**
48-
* The default implementation is <em>empty</em>. Can be overridden by
49-
* subclasses as necessary.
50-
*
51-
* @see TestExecutionListener#beforeTestClass(TestContext)
52-
*/
53-
public void beforeTestClass(TestContext testContext) throws Exception {
54-
/* no-op */
55-
}
56-
5747
/**
5848
* TODO [SPR-9864] Document overridden prepareTestInstance().
5949
*
@@ -84,21 +74,10 @@ public void afterTestMethod(TestContext testContext) throws Exception {
8474
RequestContextHolder.resetRequestAttributes();
8575
}
8676

87-
/**
88-
* The default implementation is <em>empty</em>. Can be overridden by
89-
* subclasses as necessary.
90-
*
91-
* @see TestExecutionListener#afterTestClass(TestContext)
92-
*/
93-
public void afterTestClass(TestContext testContext) throws Exception {
94-
/* no-op */
95-
}
96-
9777
/**
9878
* TODO [SPR-9864] Document setUpRequestContext().
9979
*
10080
* @param testContext
101-
* @param servletContext
10281
*/
10382
private void setUpRequestContextIfNecessary(TestContext testContext) {
10483

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,26 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.test.context.support;
17+
package org.springframework.test.context.web;
1818

1919
import org.springframework.test.context.SmartContextLoader;
20+
import org.springframework.test.context.support.AbstractDelegatingSmartContextLoader;
2021

2122
/**
2223
* {@code WebDelegatingSmartContextLoader} is a concrete implementation of
23-
* {@link AbstractDelegatingSmartContextLoader} that delegates to an
24-
* {@link XmlWebContextLoader} and an {@link AnnotationConfigWebContextLoader}.
24+
* {@link AbstractDelegatingSmartContextLoader} that delegates to a
25+
* {@link GenericXmlWebContextLoader} and an {@link AnnotationConfigWebContextLoader}.
2526
*
2627
* @author Sam Brannen
2728
* @since 3.2
2829
* @see SmartContextLoader
2930
* @see AbstractDelegatingSmartContextLoader
30-
* @see XmlWebContextLoader
31+
* @see GenericXmlWebContextLoader
3132
* @see AnnotationConfigWebContextLoader
3233
*/
3334
public class WebDelegatingSmartContextLoader extends AbstractDelegatingSmartContextLoader {
3435

35-
private final SmartContextLoader xmlLoader = new XmlWebContextLoader();
36+
private final SmartContextLoader xmlLoader = new GenericXmlWebContextLoader();
3637
private final SmartContextLoader annotationConfigLoader = new AnnotationConfigWebContextLoader();
3738

3839

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* Web support classes for the <em>Spring TestContext Framework</em>.
3+
*/
4+
5+
package org.springframework.test.context.web;
6+

0 commit comments

Comments
 (0)