Improve documentation of annotated class support in the TCF
Updated all Javadoc in the Spring TestContext Framework (TCF) to explain and refer to 'annotated classes' instead of 'configuration classes'. Specifically, @ContextConfiguration now explicitly defines what is meant by 'annotated classes', and various other classes now refer to this definition. Otherwise, the term 'configuration class' has simply been replaced with 'annotated class'. Also deleted cross references to deprecated JUnit 3.8 classes and formatted Javadoc in general for greater readability. Issue: SPR-9401
This commit is contained in:
parent
59e3223c84
commit
36e7cb2d31
|
|
@ -1,8 +1,6 @@
|
|||
|
||||
/**
|
||||
*
|
||||
* Support classes for annotation-driven tests.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.springframework.test.annotation;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 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.
|
||||
|
|
@ -65,15 +65,15 @@ public @interface ActiveProfiles {
|
|||
* Whether or not bean definition profiles from superclasses should be
|
||||
* <em>inherited</em>.
|
||||
*
|
||||
* <p>The default value is <code>true</code>, which means that an annotated
|
||||
* class will <em>inherit</em> bean definition profiles defined by an
|
||||
* annotated superclass. Specifically, the bean definition profiles for an
|
||||
* annotated class will be appended to the list of bean definition profiles
|
||||
* defined by an annotated superclass. Thus, subclasses have the option of
|
||||
* <p>The default value is <code>true</code>, which means that a test
|
||||
* class will <em>inherit</em> bean definition profiles defined by a
|
||||
* test superclass. Specifically, the bean definition profiles for a test
|
||||
* class will be appended to the list of bean definition profiles
|
||||
* defined by a test superclass. Thus, subclasses have the option of
|
||||
* <em>extending</em> the list of bean definition profiles.
|
||||
*
|
||||
* <p>If <code>inheritProfiles</code> is set to <code>false</code>, the bean
|
||||
* definition profiles for the annotated class will <em>shadow</em> and
|
||||
* definition profiles for the test class will <em>shadow</em> and
|
||||
* effectively replace any bean definition profiles defined by a superclass.
|
||||
*
|
||||
* <p>In the following example, the {@code ApplicationContext} for
|
||||
|
|
@ -98,7 +98,8 @@ public @interface ActiveProfiles {
|
|||
*
|
||||
* <p>Note: {@code @ActiveProfiles} can be used when loading an
|
||||
* {@code ApplicationContext} from path-based resource locations or
|
||||
* configuration classes.
|
||||
* annotated classes.
|
||||
*
|
||||
* @see ContextConfiguration#locations
|
||||
* @see ContextConfiguration#classes
|
||||
* @see ContextConfiguration#inheritLocations
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 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.
|
||||
|
|
@ -25,16 +25,15 @@ import org.springframework.core.style.ToStringCreator;
|
|||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Cache for Spring {@link ApplicationContext ApplicationContexts}
|
||||
* in a test environment.
|
||||
* Cache for Spring {@link ApplicationContext ApplicationContexts} in a test environment.
|
||||
*
|
||||
* <p>Maintains a cache of {@link ApplicationContext contexts} keyed by
|
||||
* {@link MergedContextConfiguration} instances. This has significant performance
|
||||
* benefits if initializing the context would take time. While initializing a
|
||||
* Spring context itself is very quick, some beans in a context, such as a
|
||||
* {@link org.springframework.orm.hibernate3.LocalSessionFactoryBean LocalSessionFactoryBean}
|
||||
* for working with Hibernate, may take some time to initialize. Hence it often
|
||||
* makes sense to perform that initialization once.
|
||||
* {@code LocalSessionFactoryBean} for working with Hibernate, may take some time
|
||||
* to initialize. Hence it often makes sense to perform that initialization only
|
||||
* once per test suite.
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @author Juergen Hoeller
|
||||
|
|
@ -70,6 +69,7 @@ class ContextCache {
|
|||
|
||||
/**
|
||||
* Return whether there is a cached context for the given key.
|
||||
*
|
||||
* @param key the context key (never <code>null</code>)
|
||||
*/
|
||||
boolean contains(MergedContextConfiguration key) {
|
||||
|
|
@ -79,8 +79,10 @@ class ContextCache {
|
|||
|
||||
/**
|
||||
* Obtain a cached ApplicationContext for the given key.
|
||||
*
|
||||
* <p>The {@link #getHitCount() hit} and {@link #getMissCount() miss}
|
||||
* counts will be updated accordingly.
|
||||
*
|
||||
* @param key the context key (never <code>null</code>)
|
||||
* @return the corresponding ApplicationContext instance,
|
||||
* or <code>null</code> if not found in the cache.
|
||||
|
|
@ -133,6 +135,7 @@ class ContextCache {
|
|||
|
||||
/**
|
||||
* Explicitly add an ApplicationContext instance to the cache under the given key.
|
||||
*
|
||||
* @param key the context key (never <code>null</code>)
|
||||
* @param context the ApplicationContext instance (never <code>null</code>)
|
||||
*/
|
||||
|
|
@ -144,9 +147,10 @@ class ContextCache {
|
|||
|
||||
/**
|
||||
* Remove the context with the given key.
|
||||
*
|
||||
* @param key the context key (never <code>null</code>)
|
||||
* @return the corresponding ApplicationContext instance,
|
||||
* or <code>null</code> if not found in the cache.
|
||||
* @return the corresponding ApplicationContext instance, or <code>null</code>
|
||||
* if not found in the cache.
|
||||
* @see #setDirty
|
||||
*/
|
||||
ApplicationContext remove(MergedContextConfiguration key) {
|
||||
|
|
@ -156,11 +160,13 @@ class ContextCache {
|
|||
/**
|
||||
* Mark the context with the given key as dirty, effectively
|
||||
* {@link #remove removing} the context from the cache and explicitly
|
||||
* {@link ConfigurableApplicationContext#close() closing} it if
|
||||
* it is an instance of {@link ConfigurableApplicationContext}.
|
||||
* {@link ConfigurableApplicationContext#close() closing} it if it is an
|
||||
* instance of {@link ConfigurableApplicationContext}.
|
||||
*
|
||||
* <p>Generally speaking, you would only call this method if you change the
|
||||
* state of a singleton bean, potentially affecting future interaction with
|
||||
* the context.
|
||||
*
|
||||
* @param key the context key (never <code>null</code>)
|
||||
* @see #remove
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 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,20 +23,43 @@ import java.lang.annotation.Retention;
|
|||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* {@code ContextConfiguration} defines class-level metadata that is
|
||||
* used to determine how to load and configure an
|
||||
* {@link org.springframework.context.ApplicationContext ApplicationContext}
|
||||
* for test classes.
|
||||
*
|
||||
*
|
||||
* <h3>Supported Resource Types</h3>
|
||||
*
|
||||
* <p>Prior to Spring 3.1, only path-based resource locations were supported.
|
||||
* As of Spring 3.1, {@link #loader context loaders} may choose to support
|
||||
* either path-based or class-based resources (but not both). Consequently
|
||||
* {@code @ContextConfiguration} can be used to declare either path-based
|
||||
* resource locations (via the {@link #locations} or {@link #value}
|
||||
* attribute) <i>or</i> configuration classes (via the {@link #classes}
|
||||
* attribute) <i>or</i> annotated classes (via the {@link #classes}
|
||||
* attribute).
|
||||
*
|
||||
*
|
||||
* <h3>Annotated Classes</h3>
|
||||
*
|
||||
* <p>The term <em>annotated class</em> can refer to any of the following.
|
||||
*
|
||||
* <ul>
|
||||
* <li>A class annotated with {@link Configuration @Configuration}</li>
|
||||
* <li>A component (i.e., a class annotated with
|
||||
* {@link org.springframework.stereotype.Component @Component},
|
||||
* {@link org.springframework.stereotype.Service @Service},
|
||||
* {@link org.springframework.stereotype.Repository @Repository}, etc.)</li>
|
||||
* <li>A JSR-330 compliant class that is annotated with {@code javax.inject} annotations</li>
|
||||
* <li>Any other class that contains {@link Bean @Bean}-methods</li>
|
||||
* </ul>
|
||||
*
|
||||
* Consult the JavaDoc for {@link Configuration @Configuration} and {@link Bean @Bean}
|
||||
* for further information regarding the configuration and semantics of
|
||||
* <em>annotated classes</em>.
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 2.5
|
||||
* @see ContextLoader
|
||||
|
|
@ -92,19 +115,19 @@ public @interface ContextConfiguration {
|
|||
String[] locations() default {};
|
||||
|
||||
/**
|
||||
* The {@link org.springframework.context.annotation.Configuration
|
||||
* configuration classes} to use for loading an
|
||||
* The <em>annotated classes</em> to use for loading an
|
||||
* {@link org.springframework.context.ApplicationContext ApplicationContext}.
|
||||
*
|
||||
* <p>Check out the Javadoc for
|
||||
* {@link org.springframework.test.context.support.AnnotationConfigContextLoader#detectDefaultConfigurationClasses
|
||||
* AnnotationConfigContextLoader.detectDefaultConfigurationClasses()} for details
|
||||
* on how default configuration classes will be detected if none are specified.
|
||||
* See the documentation for {@link #loader} for further details regarding
|
||||
* default loaders.
|
||||
* on how default configuration classes will be detected if no
|
||||
* <em>annotated classes</em> are specified. See the documentation for
|
||||
* {@link #loader} for further details regarding default loaders.
|
||||
*
|
||||
* <p>This attribute may <strong>not</strong> be used in conjunction with
|
||||
* {@link #locations} or {@link #value}.
|
||||
*
|
||||
* @since 3.1
|
||||
* @see org.springframework.context.annotation.Configuration
|
||||
* @see org.springframework.test.context.support.AnnotationConfigContextLoader
|
||||
|
|
@ -112,23 +135,21 @@ public @interface ContextConfiguration {
|
|||
Class<?>[] classes() default {};
|
||||
|
||||
/**
|
||||
* Whether or not {@link #locations resource locations} or
|
||||
* {@link #classes configuration classes} from superclasses should be
|
||||
* <em>inherited</em>.
|
||||
*
|
||||
* Whether or not {@link #locations resource locations} or <em>annotated
|
||||
* classes</em> from test superclasses should be <em>inherited</em>.
|
||||
*
|
||||
* <p>The default value is <code>true</code>. This means that an annotated
|
||||
* class will <em>inherit</em> the resource locations or configuration
|
||||
* classes defined by annotated superclasses. Specifically, the resource
|
||||
* locations or configuration classes for an annotated class will be
|
||||
* appended to the list of resource locations or configuration classes
|
||||
* defined by annotated superclasses. Thus, subclasses have the option of
|
||||
* <em>extending</em> the list of resource locations or configuration
|
||||
* classes.
|
||||
* class will <em>inherit</em> the resource locations or annotated classes
|
||||
* defined by test superclasses. Specifically, the resource locations or
|
||||
* annotated classes for a given test class will be appended to the list of
|
||||
* resource locations or annotated classes defined by test superclasses.
|
||||
* Thus, subclasses have the option of <em>extending</em> the list of resource
|
||||
* locations or annotated classes.
|
||||
*
|
||||
* <p>If <code>inheritLocations</code> is set to <code>false</code>, the
|
||||
* resource locations or configuration classes for the annotated class
|
||||
* resource locations or annotated classes for the annotated class
|
||||
* will <em>shadow</em> and effectively replace any resource locations
|
||||
* or configuration classes defined by superclasses.
|
||||
* or annotated classes defined by superclasses.
|
||||
*
|
||||
* <p>In the following example that uses path-based resource locations, the
|
||||
* {@link org.springframework.context.ApplicationContext ApplicationContext}
|
||||
|
|
@ -149,7 +170,7 @@ public @interface ContextConfiguration {
|
|||
* }
|
||||
* </pre>
|
||||
*
|
||||
* <p>Similarly, in the following example that uses configuration
|
||||
* <p>Similarly, in the following example that uses annotated
|
||||
* classes, the
|
||||
* {@link org.springframework.context.ApplicationContext ApplicationContext}
|
||||
* for {@code ExtendedTest} will be loaded from the
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ public class ContextConfigurationAttributes {
|
|||
*
|
||||
* @param declaringClass the test class that declared {@code @ContextConfiguration}
|
||||
* @param locations the resource locations declared via {@code @ContextConfiguration}
|
||||
* @param classes the configuration classes declared via {@code @ContextConfiguration}
|
||||
* @param classes the annotated classes declared via {@code @ContextConfiguration}
|
||||
* @param inheritLocations the <code>inheritLocations</code> flag declared via {@code @ContextConfiguration}
|
||||
* @param contextLoaderClass the {@code ContextLoader} class declared via {@code @ContextConfiguration}
|
||||
* @throws IllegalArgumentException if the {@code declaringClass} or {@code contextLoaderClass} is
|
||||
|
|
@ -128,6 +128,7 @@ public class ContextConfigurationAttributes {
|
|||
/**
|
||||
* Get the {@link Class class} that declared the
|
||||
* {@link ContextConfiguration @ContextConfiguration} annotation.
|
||||
*
|
||||
* @return the declaring class; never <code>null</code>
|
||||
*/
|
||||
public Class<?> getDeclaringClass() {
|
||||
|
|
@ -137,9 +138,11 @@ public class ContextConfigurationAttributes {
|
|||
/**
|
||||
* Get the resource locations that were declared via
|
||||
* {@link ContextConfiguration @ContextConfiguration}.
|
||||
*
|
||||
* <p>Note: this is a mutable property. The returned value may therefore
|
||||
* represent a <em>processed</em> value that does not match the original value
|
||||
* declared via {@link ContextConfiguration @ContextConfiguration}.
|
||||
*
|
||||
* @return the resource locations; potentially <code>null</code> or <em>empty</em>
|
||||
* @see ContextConfiguration#value
|
||||
* @see ContextConfiguration#locations
|
||||
|
|
@ -152,6 +155,7 @@ public class ContextConfigurationAttributes {
|
|||
/**
|
||||
* Set the <em>processed</em> resource locations, effectively overriding the
|
||||
* original value declared via {@link ContextConfiguration @ContextConfiguration}.
|
||||
*
|
||||
* @see #getLocations()
|
||||
*/
|
||||
public void setLocations(String[] locations) {
|
||||
|
|
@ -159,12 +163,14 @@ public class ContextConfigurationAttributes {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the configuration classes that were declared via
|
||||
* Get the annotated classes that were declared via
|
||||
* {@link ContextConfiguration @ContextConfiguration}.
|
||||
*
|
||||
* <p>Note: this is a mutable property. The returned value may therefore
|
||||
* represent a <em>processed</em> value that does not match the original value
|
||||
* declared via {@link ContextConfiguration @ContextConfiguration}.
|
||||
* @return the configuration classes; potentially <code>null</code> or <em>empty</em>
|
||||
*
|
||||
* @return the annotated classes; potentially <code>null</code> or <em>empty</em>
|
||||
* @see ContextConfiguration#classes
|
||||
* @see #setClasses(Class[])
|
||||
*/
|
||||
|
|
@ -173,8 +179,9 @@ public class ContextConfigurationAttributes {
|
|||
}
|
||||
|
||||
/**
|
||||
* Set the <em>processed</em> configuration classes, effectively overriding the
|
||||
* Set the <em>processed</em> annotated classes, effectively overriding the
|
||||
* original value declared via {@link ContextConfiguration @ContextConfiguration}.
|
||||
*
|
||||
* @see #getClasses()
|
||||
*/
|
||||
public void setClasses(Class<?>[] classes) {
|
||||
|
|
@ -184,6 +191,7 @@ public class ContextConfigurationAttributes {
|
|||
/**
|
||||
* Determine if this {@code ContextConfigurationAttributes} instance has
|
||||
* path-based resource locations.
|
||||
*
|
||||
* @return <code>true</code> if the {@link #getLocations() locations} array is not empty
|
||||
* @see #hasResources()
|
||||
* @see #hasClasses()
|
||||
|
|
@ -195,6 +203,7 @@ public class ContextConfigurationAttributes {
|
|||
/**
|
||||
* Determine if this {@code ContextConfigurationAttributes} instance has
|
||||
* class-based resources.
|
||||
*
|
||||
* @return <code>true</code> if the {@link #getClasses() classes} array is not empty
|
||||
* @see #hasResources()
|
||||
* @see #hasLocations()
|
||||
|
|
@ -206,6 +215,7 @@ public class ContextConfigurationAttributes {
|
|||
/**
|
||||
* Determine if this {@code ContextConfigurationAttributes} instance has
|
||||
* either path-based resource locations or class-based resources.
|
||||
*
|
||||
* @return <code>true</code> if either the {@link #getLocations() locations}
|
||||
* or the {@link #getClasses() classes} array is not empty
|
||||
* @see #hasLocations()
|
||||
|
|
@ -218,6 +228,7 @@ public class ContextConfigurationAttributes {
|
|||
/**
|
||||
* Get the <code>inheritLocations</code> flag that was declared via
|
||||
* {@link ContextConfiguration @ContextConfiguration}.
|
||||
*
|
||||
* @return the <code>inheritLocations</code> flag
|
||||
* @see ContextConfiguration#inheritLocations
|
||||
*/
|
||||
|
|
@ -228,6 +239,7 @@ public class ContextConfigurationAttributes {
|
|||
/**
|
||||
* Get the <code>ContextLoader</code> class that was declared via
|
||||
* {@link ContextConfiguration @ContextConfiguration}.
|
||||
*
|
||||
* @return the <code>ContextLoader</code> class
|
||||
* @see ContextConfiguration#loader
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 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,8 +23,8 @@ import org.springframework.context.ApplicationContext;
|
|||
* for an integration test managed by the Spring TestContext Framework.
|
||||
*
|
||||
* <p><b>Note</b>: as of Spring 3.1, implement {@link SmartContextLoader} instead
|
||||
* of this interface in order to provide support for configuration classes and
|
||||
* active bean definition profiles.
|
||||
* of this interface in order to provide support for annotated classes and active
|
||||
* bean definition profiles.
|
||||
*
|
||||
* <p>Clients of a ContextLoader should call
|
||||
* {@link #processLocations(Class,String...) processLocations()} prior to
|
||||
|
|
@ -52,8 +52,10 @@ public interface ContextLoader {
|
|||
|
||||
/**
|
||||
* Processes application context resource locations for a specified class.
|
||||
*
|
||||
* <p>Concrete implementations may choose to modify the supplied locations,
|
||||
* generate new locations, or simply return the supplied locations unchanged.
|
||||
*
|
||||
* @param clazz the class with which the locations are associated: used to
|
||||
* determine how to process the supplied locations
|
||||
* @param locations the unmodified locations to use for loading the
|
||||
|
|
@ -66,8 +68,10 @@ public interface ContextLoader {
|
|||
* Loads a new {@link ApplicationContext context} based on the supplied
|
||||
* <code>locations</code>, configures the context, and finally returns
|
||||
* the context in fully <em>refreshed</em> state.
|
||||
*
|
||||
* <p>Configuration locations are generally considered to be classpath
|
||||
* resources by default.
|
||||
*
|
||||
* <p>Concrete implementations should register annotation configuration
|
||||
* processors with bean factories of {@link ApplicationContext application
|
||||
* contexts} loaded by this ContextLoader. Beans will therefore automatically
|
||||
|
|
@ -75,11 +79,13 @@ public interface ContextLoader {
|
|||
* {@link org.springframework.beans.factory.annotation.Autowired @Autowired},
|
||||
* {@link javax.annotation.Resource @Resource}, and
|
||||
* {@link javax.inject.Inject @Inject}.
|
||||
*
|
||||
* <p>Any ApplicationContext loaded by a ContextLoader <strong>must</strong>
|
||||
* register a JVM shutdown hook for itself. Unless the context gets closed
|
||||
* early, all context instances will be automatically closed on JVM
|
||||
* shutdown. This allows for freeing external resources held by beans within
|
||||
* the context, e.g. temporary files.
|
||||
*
|
||||
* @param locations the resource locations to use to load the application context
|
||||
* @return a new application context
|
||||
* @throws Exception if context loading failed
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 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.
|
||||
|
|
@ -35,7 +35,7 @@ import org.springframework.util.StringUtils;
|
|||
/**
|
||||
* Utility methods for working with {@link ContextLoader ContextLoaders} and
|
||||
* {@link SmartContextLoader SmartContextLoaders} and resolving resource locations,
|
||||
* configuration classes, and active bean definition profiles.
|
||||
* annotated classes, and active bean definition profiles.
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 3.1
|
||||
|
|
@ -61,11 +61,13 @@ abstract class ContextLoaderUtils {
|
|||
* Resolve the {@link ContextLoader} {@link Class class} to use for the
|
||||
* supplied {@link Class testClass} and then instantiate and return that
|
||||
* {@code ContextLoader}.
|
||||
*
|
||||
* <p>If the supplied <code>defaultContextLoaderClassName</code> is
|
||||
* <code>null</code> or <em>empty</em>, the <em>standard</em>
|
||||
* default context loader class name {@value #DEFAULT_CONTEXT_LOADER_CLASS_NAME}
|
||||
* will be used. For details on the class resolution process, see
|
||||
* {@link #resolveContextLoaderClass()}.
|
||||
*
|
||||
* @param testClass the test class for which the {@code ContextLoader}
|
||||
* should be resolved (must not be <code>null</code>)
|
||||
* @param defaultContextLoaderClassName the name of the default
|
||||
|
|
@ -90,6 +92,7 @@ abstract class ContextLoaderUtils {
|
|||
/**
|
||||
* Resolve the {@link ContextLoader} {@link Class} to use for the supplied
|
||||
* {@link Class testClass}.
|
||||
*
|
||||
* <ol>
|
||||
* <li>If the {@link ContextConfiguration#loader() loader} attribute of
|
||||
* {@link ContextConfiguration @ContextConfiguration} is configured
|
||||
|
|
@ -101,6 +104,7 @@ abstract class ContextLoaderUtils {
|
|||
* the class hierarchy, an attempt will be made to load and return the class
|
||||
* with the supplied <code>defaultContextLoaderClassName</code>.</li>
|
||||
* </ol>
|
||||
*
|
||||
* @param testClass the class for which to resolve the {@code ContextLoader}
|
||||
* class; must not be <code>null</code>
|
||||
* @param defaultContextLoaderClassName the name of the default
|
||||
|
|
@ -163,13 +167,15 @@ abstract class ContextLoaderUtils {
|
|||
/**
|
||||
* Resolve the list of {@link ContextConfigurationAttributes configuration
|
||||
* attributes} for the supplied {@link Class class} and its superclasses.
|
||||
*
|
||||
* <p>Note that the {@link ContextConfiguration#inheritLocations
|
||||
* inheritLocations} flag of {@link ContextConfiguration
|
||||
* @ContextConfiguration} will be taken into consideration.
|
||||
* Specifically, if the <code>inheritLocations</code> flag is set to
|
||||
* <code>true</code>, configuration attributes defined in the annotated
|
||||
* <code>true</code>, configuration attributes defined in the test
|
||||
* class will be appended to the configuration attributes defined in
|
||||
* superclasses.
|
||||
*
|
||||
* @param clazz the class for which to resolve the configuration attributes (must
|
||||
* not be <code>null</code>)
|
||||
* @return the list of configuration attributes for the specified class,
|
||||
|
|
@ -214,11 +220,13 @@ abstract class ContextLoaderUtils {
|
|||
|
||||
/**
|
||||
* Resolve <em>active bean definition profiles</em> for the supplied {@link Class}.
|
||||
*
|
||||
* <p>Note that the {@link ActiveProfiles#inheritProfiles inheritProfiles}
|
||||
* flag of {@link ActiveProfiles @ActiveProfiles} will be taken into
|
||||
* consideration. Specifically, if the <code>inheritProfiles</code> flag is
|
||||
* set to <code>true</code>, profiles defined in the annotated class will be
|
||||
* set to <code>true</code>, profiles defined in the test class will be
|
||||
* merged with those defined in superclasses.
|
||||
*
|
||||
* @param clazz the class for which to resolve the active profiles (must
|
||||
* not be <code>null</code>)
|
||||
* @return the set of active profiles for the specified class, including
|
||||
|
|
@ -280,6 +288,7 @@ abstract class ContextLoaderUtils {
|
|||
* Build the {@link MergedContextConfiguration merged context configuration}
|
||||
* for the supplied {@link Class testClass} and
|
||||
* <code>defaultContextLoaderClassName</code>.
|
||||
*
|
||||
* @param testClass the test class for which the {@code MergedContextConfiguration}
|
||||
* should be built (must not be <code>null</code>)
|
||||
* @param defaultContextLoaderClassName the name of the default
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 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,8 +30,8 @@ import org.springframework.util.StringUtils;
|
|||
* context configuration declared on a test class and all of its superclasses
|
||||
* via {@link ContextConfiguration @ContextConfiguration} and
|
||||
* {@link ActiveProfiles @ActiveProfiles}.
|
||||
*
|
||||
* <p>Merged resource locations, configuration classes, and active profiles
|
||||
*
|
||||
* <p>Merged resource locations, annotated classes, and active profiles
|
||||
* represent all declared values in the test class hierarchy taking into
|
||||
* consideration the semantics of the
|
||||
* {@link ContextConfiguration#inheritLocations inheritLocations} and
|
||||
|
|
@ -98,15 +98,17 @@ public class MergedContextConfiguration implements Serializable {
|
|||
|
||||
/**
|
||||
* Create a new {@code MergedContextConfiguration} instance for the
|
||||
* supplied {@link Class test class}, resource locations, configuration
|
||||
* classes, active profiles, and {@link ContextLoader}.
|
||||
* supplied test class, resource locations, annotated classes, active
|
||||
* profiles, and {@code ContextLoader}.
|
||||
*
|
||||
* <p>If a <code>null</code> value is supplied for <code>locations</code>,
|
||||
* <code>classes</code>, or <code>activeProfiles</code> an empty array will
|
||||
* be stored instead. Furthermore, active profiles will be sorted, and duplicate
|
||||
* profiles will be removed.
|
||||
* profiles will be removed.
|
||||
*
|
||||
* @param testClass the test class for which the configuration was merged
|
||||
* @param locations the merged resource locations
|
||||
* @param classes the merged configuration classes
|
||||
* @param classes the merged annotated classes
|
||||
* @param activeProfiles the merged active bean definition profiles
|
||||
* @param contextLoader the resolved <code>ContextLoader</code>
|
||||
*/
|
||||
|
|
@ -120,40 +122,35 @@ public class MergedContextConfiguration implements Serializable {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the {@link Class test class} associated with this
|
||||
* {@code MergedContextConfiguration}.
|
||||
* Get the {@link Class test class} associated with this {@code MergedContextConfiguration}.
|
||||
*/
|
||||
public Class<?> getTestClass() {
|
||||
return testClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the merged resource locations for the
|
||||
* {@link #getTestClass() test class}.
|
||||
* Get the merged resource locations for the {@link #getTestClass() test class}.
|
||||
*/
|
||||
public String[] getLocations() {
|
||||
return locations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the merged configuration classes for the
|
||||
* {@link #getTestClass() test class}.
|
||||
* Get the merged annotated classes for the {@link #getTestClass() test class}.
|
||||
*/
|
||||
public Class<?>[] getClasses() {
|
||||
return classes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the merged active bean definition profiles for the
|
||||
* {@link #getTestClass() test class}.
|
||||
* Get the merged active bean definition profiles for the {@link #getTestClass() test class}.
|
||||
*/
|
||||
public String[] getActiveProfiles() {
|
||||
return activeProfiles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the resolved {@link ContextLoader} for the
|
||||
* {@link #getTestClass() test class}.
|
||||
* Get the resolved {@link ContextLoader} for the {@link #getTestClass() test class}.
|
||||
*/
|
||||
public ContextLoader getContextLoader() {
|
||||
return contextLoader;
|
||||
|
|
@ -178,7 +175,7 @@ public class MergedContextConfiguration implements Serializable {
|
|||
/**
|
||||
* Determine if the supplied object is equal to this {@code MergedContextConfiguration}
|
||||
* instance by comparing both object's {@link #getLocations() locations},
|
||||
* {@link #getClasses() configuration classes}, {@link #getActiveProfiles()
|
||||
* {@link #getClasses() annotated classes}, {@link #getActiveProfiles()
|
||||
* active profiles}, and the fully qualified names of their
|
||||
* {@link #getContextLoader() ContextLoaders}.
|
||||
*/
|
||||
|
|
@ -212,7 +209,7 @@ public class MergedContextConfiguration implements Serializable {
|
|||
|
||||
/**
|
||||
* Provide a String representation of the {@link #getTestClass() test class},
|
||||
* {@link #getLocations() locations}, {@link #getClasses() configuration classes},
|
||||
* {@link #getLocations() locations}, {@link #getClasses() annotated classes},
|
||||
* {@link #getActiveProfiles() active profiles}, and the name of the
|
||||
* {@link #getContextLoader() ContextLoader}.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -24,11 +24,15 @@ import org.springframework.context.ApplicationContext;
|
|||
*
|
||||
* <p>The {@code SmartContextLoader} SPI supersedes the {@link ContextLoader} SPI
|
||||
* introduced in Spring 2.5: a {@code SmartContextLoader} can choose to process
|
||||
* either resource locations or configuration classes. Furthermore, a
|
||||
* either resource locations or annotated classes. Furthermore, a
|
||||
* {@code SmartContextLoader} can set active bean definition profiles in the
|
||||
* context that it loads (see {@link MergedContextConfiguration#getActiveProfiles()}
|
||||
* and {@link #loadContext(MergedContextConfiguration)}).
|
||||
*
|
||||
* <p>See the Javadoc for
|
||||
* {@link org.springframework.test.context.ContextConfiguration @ContextConfiguration}
|
||||
* for a definition of <em>annotated class</em>.
|
||||
*
|
||||
* <p>Clients of a {@code SmartContextLoader} should call
|
||||
* {@link #processContextConfiguration(ContextConfigurationAttributes)
|
||||
* processContextConfiguration()} prior to calling
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2012 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.
|
||||
|
|
@ -60,11 +60,10 @@ import org.springframework.test.context.support.DirtiesContextTestExecutionListe
|
|||
* @see TestContext
|
||||
* @see TestContextManager
|
||||
* @see AbstractTransactionalJUnit4SpringContextTests
|
||||
* @see org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests
|
||||
* @see org.springframework.test.context.testng.AbstractTestNGSpringContextTests
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@TestExecutionListeners( { DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class })
|
||||
@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class })
|
||||
public abstract class AbstractJUnit4SpringContextTests implements ApplicationContextAware {
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 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.
|
||||
|
|
@ -74,7 +74,6 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
* @see org.springframework.test.context.transaction.BeforeTransaction
|
||||
* @see org.springframework.test.context.transaction.AfterTransaction
|
||||
* @see org.springframework.test.jdbc.SimpleJdbcTestUtils
|
||||
* @see org.springframework.test.context.junit38.AbstractTransactionalJUnit38SpringContextTests
|
||||
* @see org.springframework.test.context.testng.AbstractTransactionalTestNGSpringContextTests
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
|
|
|
|||
|
|
@ -1,16 +1,15 @@
|
|||
/**
|
||||
* <p>This package contains the <em>Spring TestContext Framework</em>
|
||||
* which provides annotation-driven unit and integration testing support
|
||||
* that is agnostic of the actual testing framework in use. The same
|
||||
* techniques and annotation-based configuration used in, for example, a
|
||||
* JUnit 3.8 environment can also be applied to tests written with JUnit
|
||||
* 4.5+, TestNG, etc.</p>
|
||||
* <p>This package contains the <em>Spring TestContext Framework</em> which
|
||||
* provides annotation-driven unit and integration testing support that is
|
||||
* agnostic of the actual testing framework in use. The same techniques and
|
||||
* annotation-based configuration used in, for example, a JUnit 4.5+ environment
|
||||
* can also be applied to tests written with TestNG, etc.
|
||||
*
|
||||
* <p>In addition to providing generic and extensible testing
|
||||
* infrastructure, the Spring TestContext Framework provides out-of-the-box
|
||||
* support for Spring-specific integration testing functionality such as
|
||||
* context management and caching, dependency injection of test fixtures,
|
||||
* and transactional test management with default rollback semantics.</p>
|
||||
* <p>In addition to providing generic and extensible testing infrastructure,
|
||||
* the Spring TestContext Framework provides out-of-the-box support for
|
||||
* Spring-specific integration testing functionality such as context management
|
||||
* and caching, dependency injection of test fixtures, and transactional test
|
||||
* management with default rollback semantics.
|
||||
*/
|
||||
|
||||
package org.springframework.test.context;
|
||||
|
|
|
|||
|
|
@ -68,8 +68,10 @@ public abstract class AbstractContextLoader implements SmartContextLoader {
|
|||
* processed locations are then
|
||||
* {@link ContextConfigurationAttributes#setLocations(String[]) set} in
|
||||
* the supplied configuration attributes.
|
||||
*
|
||||
* <p>Can be overridden in subclasses — for example, to process
|
||||
* configuration classes instead of resource locations.
|
||||
* annotated classes instead of resource locations.
|
||||
*
|
||||
* @since 3.1
|
||||
* @see #processLocations(Class, String...)
|
||||
*/
|
||||
|
|
@ -90,6 +92,7 @@ public abstract class AbstractContextLoader implements SmartContextLoader {
|
|||
* {@link #getResourceSuffix() resource suffix}; otherwise, the supplied
|
||||
* <code>locations</code> will be {@link #modifyLocations modified} if
|
||||
* necessary and returned.
|
||||
*
|
||||
* @param clazz the class with which the locations are associated: to be
|
||||
* used when generating default locations
|
||||
* @param locations the unmodified locations to use for loading the
|
||||
|
|
@ -110,18 +113,22 @@ public abstract class AbstractContextLoader implements SmartContextLoader {
|
|||
/**
|
||||
* Generate the default classpath resource locations array based on the
|
||||
* supplied class.
|
||||
*
|
||||
* <p>For example, if the supplied class is <code>com.example.MyTest</code>,
|
||||
* the generated locations will contain a single string with a value of
|
||||
* "classpath:/com/example/MyTest<code><suffix></code>",
|
||||
* where <code><suffix></code> is the value of the
|
||||
* {@link #getResourceSuffix() resource suffix} string.
|
||||
*
|
||||
* <p>As of Spring 3.1, the implementation of this method adheres to the
|
||||
* contract defined in the {@link SmartContextLoader} SPI. Specifically,
|
||||
* this method will <em>preemptively</em> verify that the generated default
|
||||
* location actually exists. If it does not exist, this method will log a
|
||||
* warning and return an empty array.
|
||||
*
|
||||
* <p>Subclasses can override this method to implement a different
|
||||
* <em>default location generation</em> strategy.
|
||||
*
|
||||
* @param clazz the class for which the default locations are to be generated
|
||||
* @return an array of default application context resource locations
|
||||
* @since 2.5
|
||||
|
|
@ -153,6 +160,7 @@ public abstract class AbstractContextLoader implements SmartContextLoader {
|
|||
|
||||
/**
|
||||
* Generate a modified version of the supplied locations array and return it.
|
||||
*
|
||||
* <p>A plain path — for example, "context.xml" — will
|
||||
* be treated as a classpath resource that is relative to the package in which
|
||||
* the specified class is defined. A path starting with a slash is treated
|
||||
|
|
@ -162,8 +170,10 @@ public abstract class AbstractContextLoader implements SmartContextLoader {
|
|||
* {@link ResourceUtils#CLASSPATH_URL_PREFIX classpath:},
|
||||
* {@link ResourceUtils#FILE_URL_PREFIX file:}, <code>http:</code>,
|
||||
* etc.) will be added to the results unchanged.
|
||||
*
|
||||
* <p>Subclasses can override this method to implement a different
|
||||
* <em>location modification</em> strategy.
|
||||
*
|
||||
* @param clazz the class with which the locations are associated
|
||||
* @param locations the resource locations to be modified
|
||||
* @return an array of modified application context resource locations
|
||||
|
|
@ -191,6 +201,7 @@ public abstract class AbstractContextLoader implements SmartContextLoader {
|
|||
* Determine whether or not <em>default</em> resource locations should be
|
||||
* generated if the <code>locations</code> provided to
|
||||
* {@link #processLocations(Class, String...)} are <code>null</code> or empty.
|
||||
*
|
||||
* <p>As of Spring 3.1, the semantics of this method have been overloaded
|
||||
* to include detection of either default resource locations or default
|
||||
* configuration classes. Consequently, this method can also be used to
|
||||
|
|
@ -199,7 +210,9 @@ public abstract class AbstractContextLoader implements SmartContextLoader {
|
|||
* {@link ContextConfigurationAttributes configuration attributes} supplied
|
||||
* to {@link #processContextConfiguration(ContextConfigurationAttributes)}
|
||||
* are <code>null</code> or empty.
|
||||
*
|
||||
* <p>Can be overridden by subclasses to change the default behavior.
|
||||
*
|
||||
* @return always <code>true</code> by default
|
||||
* @since 2.5
|
||||
*/
|
||||
|
|
@ -208,9 +221,11 @@ public abstract class AbstractContextLoader implements SmartContextLoader {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the suffix to append to {@link ApplicationContext} resource
|
||||
* locations when generating default locations.
|
||||
* Get the suffix to append to {@link ApplicationContext} resource locations
|
||||
* when generating default locations.
|
||||
*
|
||||
* <p>Must be implemented by subclasses.
|
||||
*
|
||||
* @return the resource suffix; should not be <code>null</code> or empty
|
||||
* @since 2.5
|
||||
* @see #generateDefaultLocations(Class)
|
||||
|
|
|
|||
|
|
@ -40,8 +40,7 @@ import org.springframework.util.StringUtils;
|
|||
* SPI, the context will be loaded from the {@link MergedContextConfiguration}
|
||||
* provided to {@link #loadContext(MergedContextConfiguration)}. In such cases, a
|
||||
* <code>SmartContextLoader</code> will decide whether to load the context from
|
||||
* <em>locations</em> or
|
||||
* {@link org.springframework.context.annotation.Configuration configuration classes}.</li>
|
||||
* <em>locations</em> or <em>annotated classes</em>.</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>Concrete subclasses must provide an appropriate implementation of
|
||||
|
|
@ -62,7 +61,9 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader
|
|||
|
||||
/**
|
||||
* Load a Spring ApplicationContext from the supplied {@link MergedContextConfiguration}.
|
||||
*
|
||||
* <p>Implementation details:
|
||||
*
|
||||
* <ul>
|
||||
* <li>Creates a {@link GenericApplicationContext} instance.</li>
|
||||
* <li>Sets the <em>active bean definition profiles</em> from the supplied
|
||||
|
|
@ -73,7 +74,7 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader
|
|||
* <li>Calls {@link #customizeBeanFactory(DefaultListableBeanFactory)} to allow for customizing the
|
||||
* context's <code>DefaultListableBeanFactory</code>.</li>
|
||||
* <li>Delegates to {@link #loadBeanDefinitions(GenericApplicationContext, MergedContextConfiguration)}
|
||||
* to populate the context from the configuration locations or classes in the supplied
|
||||
* to populate the context from the locations or classes in the supplied
|
||||
* <code>MergedContextConfiguration</code>.</li>
|
||||
* <li>Delegates to {@link AnnotationConfigUtils} for
|
||||
* {@link AnnotationConfigUtils#registerAnnotationConfigProcessors registering}
|
||||
|
|
@ -83,6 +84,7 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader
|
|||
* <li>{@link ConfigurableApplicationContext#refresh Refreshes} the
|
||||
* context and registers a JVM shutdown hook for it.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @return a new application context
|
||||
* @see org.springframework.test.context.SmartContextLoader#loadContext(MergedContextConfiguration)
|
||||
* @see GenericApplicationContext
|
||||
|
|
@ -107,7 +109,9 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader
|
|||
|
||||
/**
|
||||
* Load a Spring ApplicationContext from the supplied <code>locations</code>.
|
||||
*
|
||||
* <p>Implementation details:
|
||||
*
|
||||
* <ul>
|
||||
* <li>Creates a {@link GenericApplicationContext} instance.</li>
|
||||
* <li>Calls {@link #prepareContext(GenericApplicationContext)} to allow for customizing the context
|
||||
|
|
@ -116,7 +120,7 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader
|
|||
* context's <code>DefaultListableBeanFactory</code>.</li>
|
||||
* <li>Delegates to {@link #createBeanDefinitionReader(GenericApplicationContext)} to create a
|
||||
* {@link BeanDefinitionReader} which is then used to populate the context
|
||||
* from the specified config locations.</li>
|
||||
* from the specified locations.</li>
|
||||
* <li>Delegates to {@link AnnotationConfigUtils} for
|
||||
* {@link AnnotationConfigUtils#registerAnnotationConfigProcessors registering}
|
||||
* annotation configuration processors.</li>
|
||||
|
|
@ -125,9 +129,11 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader
|
|||
* <li>{@link ConfigurableApplicationContext#refresh Refreshes} the
|
||||
* context and registers a JVM shutdown hook for it.</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p><b>Note</b>: this method does not provide a means to set active bean definition
|
||||
* profiles for the loaded context. See {@link #loadContext(MergedContextConfiguration)}
|
||||
* for an alternative.
|
||||
*
|
||||
* @return a new application context
|
||||
* @see org.springframework.test.context.ContextLoader#loadContext
|
||||
* @see GenericApplicationContext
|
||||
|
|
@ -153,8 +159,10 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader
|
|||
/**
|
||||
* Prepare the {@link GenericApplicationContext} created by this <code>ContextLoader</code>.
|
||||
* Called <i>before</i> bean definitions are read.
|
||||
*
|
||||
* <p>The default implementation is empty. Can be overridden in subclasses to
|
||||
* customize <code>GenericApplicationContext</code>'s standard settings.
|
||||
*
|
||||
* @param context the context that should be prepared
|
||||
* @see #loadContext(MergedContextConfiguration)
|
||||
* @see #loadContext(String...)
|
||||
|
|
@ -169,8 +177,10 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader
|
|||
/**
|
||||
* Customize the internal bean factory of the ApplicationContext created by
|
||||
* this <code>ContextLoader</code>.
|
||||
*
|
||||
* <p>The default implementation is empty but can be overridden in subclasses
|
||||
* to customize <code>DefaultListableBeanFactory</code>'s standard settings.
|
||||
*
|
||||
* @param beanFactory the bean factory created by this <code>ContextLoader</code>
|
||||
* @see #loadContext(MergedContextConfiguration)
|
||||
* @see #loadContext(String...)
|
||||
|
|
@ -185,17 +195,19 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader
|
|||
|
||||
/**
|
||||
* Load bean definitions into the supplied {@link GenericApplicationContext context}
|
||||
* from the configuration locations or classes in the supplied
|
||||
* <code>MergedContextConfiguration</code>.</li>
|
||||
* from the locations or classes in the supplied <code>MergedContextConfiguration</code>.
|
||||
*
|
||||
* <p>The default implementation delegates to the {@link BeanDefinitionReader}
|
||||
* returned by {@link #createBeanDefinitionReader(GenericApplicationContext)} to
|
||||
* {@link BeanDefinitionReader#loadBeanDefinitions(String) load} the
|
||||
* bean definitions.
|
||||
*
|
||||
* <p>Subclasses must provide an appropriate implementation of
|
||||
* {@link #createBeanDefinitionReader(GenericApplicationContext)}. Alternatively subclasses may
|
||||
* provide a <em>no-op</em> implementation of {@code createBeanDefinitionReader()}
|
||||
* {@link #createBeanDefinitionReader(GenericApplicationContext)}. Alternatively subclasses
|
||||
* may provide a <em>no-op</em> implementation of {@code createBeanDefinitionReader()}
|
||||
* and override this method to provide a custom strategy for loading or
|
||||
* registering bean definitions.
|
||||
*
|
||||
* @param context the context into which the bean definitions should be loaded
|
||||
* @param mergedConfig the merged context configuration
|
||||
* @see #loadContext(MergedContextConfiguration)
|
||||
|
|
@ -208,6 +220,7 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader
|
|||
/**
|
||||
* Factory method for creating a new {@link BeanDefinitionReader} for loading
|
||||
* bean definitions into the supplied {@link GenericApplicationContext context}.
|
||||
*
|
||||
* @param context the context for which the <code>BeanDefinitionReader</code>
|
||||
* should be created
|
||||
* @return a <code>BeanDefinitionReader</code> for the supplied context
|
||||
|
|
@ -222,8 +235,10 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader
|
|||
* Customize the {@link GenericApplicationContext} created by this
|
||||
* <code>ContextLoader</code> <i>after</i> bean definitions have been
|
||||
* loaded into the context but <i>before</i> the context is refreshed.
|
||||
*
|
||||
* <p>The default implementation is empty but can be overridden in subclasses
|
||||
* to customize the application context.
|
||||
*
|
||||
* @param context the newly created application context
|
||||
* @see #loadContext(MergedContextConfiguration)
|
||||
* @see #loadContext(String...)
|
||||
|
|
|
|||
|
|
@ -33,11 +33,13 @@ import org.springframework.util.ObjectUtils;
|
|||
|
||||
/**
|
||||
* Concrete implementation of {@link AbstractGenericContextLoader} that loads
|
||||
* bean definitions from
|
||||
* {@link org.springframework.context.annotation.Configuration configuration classes}.
|
||||
*
|
||||
* <p>Note: <code>AnnotationConfigContextLoader</code> supports
|
||||
* {@link org.springframework.context.annotation.Configuration configuration classes}
|
||||
* bean definitions from annotated classes.
|
||||
*
|
||||
* <p>See the Javadoc for
|
||||
* {@link org.springframework.test.context.ContextConfiguration @ContextConfiguration}
|
||||
* for a definition of <em>annotated class</em>.
|
||||
*
|
||||
* <p>Note: <code>AnnotationConfigContextLoader</code> supports <em>annotated classes</em>
|
||||
* rather than the String-based resource locations defined by the legacy
|
||||
* {@link org.springframework.test.context.ContextLoader ContextLoader} API. Thus,
|
||||
* although <code>AnnotationConfigContextLoader</code> extends
|
||||
|
|
@ -62,8 +64,9 @@ public class AnnotationConfigContextLoader extends AbstractGenericContextLoader
|
|||
// --- SmartContextLoader -----------------------------------------------
|
||||
|
||||
/**
|
||||
* Process configuration classes in the supplied {@link ContextConfigurationAttributes}.
|
||||
* <p>If the configuration classes are <code>null</code> or empty and
|
||||
* Process <em>annotated classes</em> in the supplied {@link ContextConfigurationAttributes}.
|
||||
*
|
||||
* <p>If the <em>annotated classes</em> are <code>null</code> or empty and
|
||||
* {@link #isGenerateDefaultLocations()} returns <code>true</code>, this
|
||||
* <code>SmartContextLoader</code> will attempt to {@link
|
||||
* #detectDefaultConfigurationClasses detect default configuration classes}.
|
||||
|
|
@ -71,6 +74,7 @@ public class AnnotationConfigContextLoader extends AbstractGenericContextLoader
|
|||
* {@link ContextConfigurationAttributes#setClasses(Class[]) set} in the
|
||||
* supplied configuration attributes. Otherwise, properties in the supplied
|
||||
* configuration attributes will not be modified.
|
||||
*
|
||||
* @param configAttributes the context configuration attributes to process
|
||||
* @see org.springframework.test.context.SmartContextLoader#processContextConfiguration(ContextConfigurationAttributes)
|
||||
* @see #isGenerateDefaultLocations()
|
||||
|
|
@ -94,7 +98,9 @@ public class AnnotationConfigContextLoader extends AbstractGenericContextLoader
|
|||
/**
|
||||
* Determine if the supplied {@link Class} meets the criteria for being
|
||||
* considered a <em>default configuration class</em> candidate.
|
||||
*
|
||||
* <p>Specifically, such candidates:
|
||||
*
|
||||
* <ul>
|
||||
* <li>must not be <code>null</code></li>
|
||||
* <li>must not be <code>private</code></li>
|
||||
|
|
@ -102,6 +108,7 @@ public class AnnotationConfigContextLoader extends AbstractGenericContextLoader
|
|||
* <li>must be <code>static</code></li>
|
||||
* <li>must be annotated with {@code @Configuration}</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param clazz the class to check
|
||||
* @return <code>true</code> if the supplied class meets the candidate criteria
|
||||
*/
|
||||
|
|
@ -111,16 +118,18 @@ public class AnnotationConfigContextLoader extends AbstractGenericContextLoader
|
|||
|
||||
/**
|
||||
* Detect the default configuration classes for the supplied test class.
|
||||
*
|
||||
* <p>The returned class array will contain all static inner classes of
|
||||
* the supplied class that meet the requirements for {@code @Configuration}
|
||||
* class implementations as specified in the documentation for
|
||||
* {@link Configuration @Configuration}.
|
||||
*
|
||||
* <p>The implementation of this method adheres to the contract defined in the
|
||||
* {@link org.springframework.test.context.SmartContextLoader SmartContextLoader}
|
||||
* SPI. Specifically, this method uses introspection to detect default
|
||||
* configuration classes that comply with the constraints required of
|
||||
* {@code @Configuration} class implementations. If a potential candidate
|
||||
* configuration class does meet these requirements, this method will log a
|
||||
* configuration class does not meet these requirements, this method will log a
|
||||
* warning, and the potential candidate class will be ignored.
|
||||
* @param declaringClass the test class that declared {@code @ContextConfiguration}
|
||||
* @return an array of default configuration classes, potentially empty but
|
||||
|
|
@ -163,6 +172,7 @@ public class AnnotationConfigContextLoader extends AbstractGenericContextLoader
|
|||
* {@link org.springframework.test.context.SmartContextLoader SmartContextLoader},
|
||||
* not as a legacy {@link org.springframework.test.context.ContextLoader ContextLoader}.
|
||||
* Consequently, this method is not supported.
|
||||
*
|
||||
* @see AbstractContextLoader#modifyLocations
|
||||
* @throws UnsupportedOperationException
|
||||
*/
|
||||
|
|
@ -177,6 +187,7 @@ public class AnnotationConfigContextLoader extends AbstractGenericContextLoader
|
|||
* {@link org.springframework.test.context.SmartContextLoader SmartContextLoader},
|
||||
* not as a legacy {@link org.springframework.test.context.ContextLoader ContextLoader}.
|
||||
* Consequently, this method is not supported.
|
||||
*
|
||||
* @see AbstractContextLoader#generateDefaultLocations
|
||||
* @throws UnsupportedOperationException
|
||||
*/
|
||||
|
|
@ -191,6 +202,7 @@ public class AnnotationConfigContextLoader extends AbstractGenericContextLoader
|
|||
* {@link org.springframework.test.context.SmartContextLoader SmartContextLoader},
|
||||
* not as a legacy {@link org.springframework.test.context.ContextLoader ContextLoader}.
|
||||
* Consequently, this method is not supported.
|
||||
*
|
||||
* @see AbstractContextLoader#getResourceSuffix
|
||||
* @throws UnsupportedOperationException
|
||||
*/
|
||||
|
|
@ -203,26 +215,29 @@ public class AnnotationConfigContextLoader extends AbstractGenericContextLoader
|
|||
// --- AbstractGenericContextLoader ----------------------------------------
|
||||
|
||||
/**
|
||||
* Register {@link org.springframework.context.annotation.Configuration configuration classes}
|
||||
* in the supplied {@link GenericApplicationContext context} from the classes
|
||||
* in the supplied {@link MergedContextConfiguration}.
|
||||
* <p>Each class must represent an annotated configuration class or component. An
|
||||
* Register classes in the supplied {@link GenericApplicationContext context}
|
||||
* from the classes in the supplied {@link MergedContextConfiguration}.
|
||||
*
|
||||
* <p>Each class must represent an <em>annotated class</em>. An
|
||||
* {@link AnnotatedBeanDefinitionReader} is used to register the appropriate
|
||||
* bean definitions.
|
||||
* <p>Note that this method does not call {@link #createBeanDefinitionReader}
|
||||
*
|
||||
* <p>Note that this method does not call {@link #createBeanDefinitionReader()}
|
||||
* since <code>AnnotatedBeanDefinitionReader</code> is not an instance of
|
||||
* {@link BeanDefinitionReader}.
|
||||
* @param context the context in which the configuration classes should be registered
|
||||
*
|
||||
* @param context the context in which the annotated classes should be registered
|
||||
* @param mergedConfig the merged configuration from which the classes should be retrieved
|
||||
*
|
||||
* @see AbstractGenericContextLoader#loadBeanDefinitions
|
||||
*/
|
||||
@Override
|
||||
protected void loadBeanDefinitions(GenericApplicationContext context, MergedContextConfiguration mergedConfig) {
|
||||
Class<?>[] configClasses = mergedConfig.getClasses();
|
||||
Class<?>[] annotatedClasses = mergedConfig.getClasses();
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Registering configuration classes: " + ObjectUtils.nullSafeToString(configClasses));
|
||||
logger.debug("Registering annotated classes: " + ObjectUtils.nullSafeToString(annotatedClasses));
|
||||
}
|
||||
new AnnotatedBeanDefinitionReader(context).register(configClasses);
|
||||
new AnnotatedBeanDefinitionReader(context).register(annotatedClasses);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -230,6 +245,7 @@ public class AnnotationConfigContextLoader extends AbstractGenericContextLoader
|
|||
* {@link org.springframework.test.context.SmartContextLoader SmartContextLoader},
|
||||
* not as a legacy {@link org.springframework.test.context.ContextLoader ContextLoader}.
|
||||
* Consequently, this method is not supported.
|
||||
*
|
||||
* @see #loadBeanDefinitions
|
||||
* @see AbstractGenericContextLoader#createBeanDefinitionReader
|
||||
* @throws UnsupportedOperationException
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 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.
|
||||
|
|
@ -48,7 +48,7 @@ import org.springframework.util.ObjectUtils;
|
|||
* {@link SmartContextLoader} is not explicitly declared via
|
||||
* {@code @ContextConfiguration}, {@code DelegatingSmartContextLoader} will be used as
|
||||
* the default loader, thus providing automatic support for either XML configuration
|
||||
* files or configuration classes, but not both simultaneously.
|
||||
* files or annotated classes, but not both simultaneously.
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 3.1
|
||||
|
|
@ -96,7 +96,7 @@ public class DelegatingSmartContextLoader implements SmartContextLoader {
|
|||
* Specifically, the delegation algorithm is as follows:
|
||||
*
|
||||
* <ul>
|
||||
* <li>If the resource locations or configuration classes in the supplied
|
||||
* <li>If the resource locations or annotated classes in the supplied
|
||||
* {@code ContextConfigurationAttributes} are not empty, the appropriate
|
||||
* candidate loader will be allowed to process the configuration <em>as is</em>,
|
||||
* without any checks for detection of defaults.</li>
|
||||
|
|
@ -113,7 +113,7 @@ public class DelegatingSmartContextLoader implements SmartContextLoader {
|
|||
* @param configAttributes the context configuration attributes to process
|
||||
* @throws IllegalArgumentException if the supplied configuration attributes are
|
||||
* <code>null</code>, or if the supplied configuration attributes include both
|
||||
* resource locations and configuration classes
|
||||
* resource locations and annotated classes
|
||||
* @throws IllegalStateException if {@code GenericXmlContextLoader} detects default
|
||||
* configuration classes; if {@code AnnotationConfigContextLoader} detects default
|
||||
* resource locations; if neither candidate loader detects defaults for the supplied
|
||||
|
|
@ -124,7 +124,7 @@ public class DelegatingSmartContextLoader implements SmartContextLoader {
|
|||
|
||||
Assert.notNull(configAttributes, "configAttributes must not be null");
|
||||
Assert.isTrue(!(configAttributes.hasLocations() && configAttributes.hasClasses()), String.format(
|
||||
"Cannot process locations AND configuration classes for context "
|
||||
"Cannot process locations AND classes for context "
|
||||
+ "configuration %s; configure one or the other, but not both.", configAttributes));
|
||||
|
||||
// If the original locations or classes were not empty, there's no
|
||||
|
|
@ -201,9 +201,9 @@ public class DelegatingSmartContextLoader implements SmartContextLoader {
|
|||
*
|
||||
* <ul>
|
||||
* <li>If the resource locations in the supplied {@code MergedContextConfiguration}
|
||||
* are not empty and the configuration classes are empty,
|
||||
* are not empty and the annotated classes are empty,
|
||||
* {@code GenericXmlContextLoader} will load the {@code ApplicationContext}.</li>
|
||||
* <li>If the configuration classes in the supplied {@code MergedContextConfiguration}
|
||||
* <li>If the annotated classes in the supplied {@code MergedContextConfiguration}
|
||||
* are not empty and the resource locations are empty,
|
||||
* {@code AnnotationConfigContextLoader} will load the {@code ApplicationContext}.</li>
|
||||
* </ul>
|
||||
|
|
|
|||
|
|
@ -47,8 +47,7 @@ public class DirtiesContextTestExecutionListener extends AbstractTestExecutionLi
|
|||
* {@link TestContext test context} as
|
||||
* {@link TestContext#markApplicationContextDirty() dirty}, and sets the
|
||||
* {@link DependencyInjectionTestExecutionListener#REINJECT_DEPENDENCIES_ATTRIBUTE
|
||||
* REINJECT_DEPENDENCIES_ATTRIBUTE} in the test context to <code>true</code>
|
||||
* .
|
||||
* REINJECT_DEPENDENCIES_ATTRIBUTE} in the test context to <code>true</code>.
|
||||
*/
|
||||
protected void dirtyContext(TestContext testContext) {
|
||||
testContext.markApplicationContextDirty();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2012 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.
|
||||
|
|
@ -68,10 +68,9 @@ import org.testng.annotations.BeforeMethod;
|
|||
* @see TestContextManager
|
||||
* @see TestExecutionListeners
|
||||
* @see AbstractTransactionalTestNGSpringContextTests
|
||||
* @see org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests
|
||||
* @see org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests
|
||||
*/
|
||||
@TestExecutionListeners( { DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class })
|
||||
@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class })
|
||||
public abstract class AbstractTestNGSpringContextTests implements IHookable, ApplicationContextAware {
|
||||
|
||||
/** Logger available to subclasses */
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 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.
|
||||
|
|
@ -62,7 +62,6 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
* @see org.springframework.test.annotation.NotTransactional
|
||||
* @see org.springframework.test.annotation.Rollback
|
||||
* @see org.springframework.test.jdbc.SimpleJdbcTestUtils
|
||||
* @see org.springframework.test.context.junit38.AbstractTransactionalJUnit38SpringContextTests
|
||||
* @see org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
|
|
|
|||
Loading…
Reference in New Issue