language stringclasses 1
value | owner stringlengths 2 15 | repo stringlengths 2 21 | sha stringlengths 45 45 | message stringlengths 7 36.3k | path stringlengths 1 199 | patch stringlengths 15 102k | is_multipart bool 2
classes |
|---|---|---|---|---|---|---|---|
Other | spring-projects | spring-framework | 98074e776262292a9d6fa8d164e6718c5876ed6f.json | Provide support for context hierarchies in the TCF
Prior to this commit the Spring TestContext Framework supported creating
only flat, non-hierarchical contexts. There was no easy way to create
contexts with parent-child relationships.
This commit addresses this issue by introducing a new @ContextHierarchy
annotation that can be used in conjunction with @ContextConfiguration
for declaring hierarchies of application contexts, either within a
single test class or within a test class hierarchy. In addition,
@DirtiesContext now supports a new 'hierarchyMode' attribute for
controlling context cache clearing for context hierarchies.
- Introduced a new @ContextHierarchy annotation.
- Introduced 'name' attribute in @ContextConfiguration.
- Introduced 'name' property in ContextConfigurationAttributes.
- TestContext is now aware of @ContextHierarchy in addition to
@ContextConfiguration.
- Introduced findAnnotationDeclaringClassForTypes() in AnnotationUtils.
- Introduced resolveContextHierarchyAttributes() in ContextLoaderUtils.
- Introduced buildContextHierarchyMap() in ContextLoaderUtils.
- @ContextConfiguration and @ContextHierarchy may not be used as
top-level, class-level annotations simultaneously.
- Introduced reference to the parent configuration in
MergedContextConfiguration and WebMergedContextConfiguration.
- Introduced overloaded buildMergedContextConfiguration() methods in
ContextLoaderUtils in order to handle context hierarchies separately
from conventional, non-hierarchical contexts.
- Introduced hashCode() and equals() in ContextConfigurationAttributes.
- ContextLoaderUtils ensures uniqueness of @ContextConfiguration
elements within a single @ContextHierarchy declaration.
- Introduced CacheAwareContextLoaderDelegate that can be used for
loading contexts with transparent support for interacting with the
context cache -- for example, for retrieving the parent application
context in a context hierarchy.
- TestContext now delegates to CacheAwareContextLoaderDelegate for
loading contexts.
- Introduced getParentApplicationContext() in MergedContextConfiguration
- The loadContext(MergedContextConfiguration) methods in
AbstractGenericContextLoader and AbstractGenericWebContextLoader now
set the parent context as appropriate.
- Introduced 'hierarchyMode' attribute in @DirtiesContext with a
corresponding HierarchyMode enum that defines EXHAUSTIVE and
CURRENT_LEVEL cache removal modes.
- ContextCache now internally tracks the relationships between contexts
that make up a context hierarchy. Furthermore, when a context is
removed, if it is part of a context hierarchy all corresponding
contexts will be removed from the cache according to the supplied
HierarchyMode.
- AbstractGenericWebContextLoader will set a loaded context as the
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE in the MockServletContext when
context hierarchies are used if the context has no parent or if the
context has a parent that is not a WAC.
- Where appropriate, updated Javadoc to refer to the
ServletTestExecutionListener, which was introduced in 3.2.0.
- Updated Javadoc to avoid and/or suppress warnings in spring-test.
- Suppressed remaining warnings in code in spring-test.
Issue: SPR-5613, SPR-9863 | spring-test/src/main/java/org/springframework/test/context/ContextLoaderUtils.java | @@ -16,20 +16,24 @@
package org.springframework.test.context;
-import static org.springframework.beans.BeanUtils.*;
-import static org.springframework.core.annotation.AnnotationUtils.*;
+import static org.springframework.beans.BeanUtils.instantiateClass;
+import static org.springframework.core.annotation.AnnotationUtils.findAnnotationDeclaringClass;
+import static org.springframework.core.annotation.AnnotationUtils.findAnnotationDeclaringClassForTypes;
+import static org.springframework.core.annotation.AnnotationUtils.isAnnotationDeclaredLocally;
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.HashSet;
+import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.annotation.AnnotationUtils;
@@ -52,10 +56,13 @@
* @see ContextConfigurationAttributes
* @see ActiveProfiles
* @see ApplicationContextInitializer
+ * @see ContextHierarchy
* @see MergedContextConfiguration
*/
abstract class ContextLoaderUtils {
+ static final String GENERATED_CONTEXT_HIERARCHY_LEVEL_PREFIX = "ContextHierarchyLevel#";
+
private static final Log logger = LogFactory.getLog(ContextLoaderUtils.class);
private static final String DEFAULT_CONTEXT_LOADER_CLASS_NAME = "org.springframework.test.context.support.DelegatingSmartContextLoader";
@@ -70,30 +77,29 @@ private ContextLoaderUtils() {
}
/**
- * Resolve the {@link ContextLoader} {@linkplain Class class} to use for the
- * supplied list of {@link ContextConfigurationAttributes} and then
- * instantiate and return that {@code ContextLoader}.
+ * Resolve the {@link ContextLoader} {@linkplain Class class} to use for the supplied
+ * list of {@link ContextConfigurationAttributes} and then instantiate and return that
+ * {@code ContextLoader}.
*
- * <p>If the supplied {@code defaultContextLoaderClassName} is
- * {@code null} or <em>empty</em>, depending on the absence or presence
- * of {@link org.springframework.test.context.web.WebAppConfiguration @WebAppConfiguration}
- * either {@value #DEFAULT_CONTEXT_LOADER_CLASS_NAME}
- * or {@value #DEFAULT_WEB_CONTEXT_LOADER_CLASS_NAME} will be used as the
- * default context loader class name. For details on the class resolution
- * process, see {@link #resolveContextLoaderClass}.
+ * <p>If the supplied {@code defaultContextLoaderClassName} is {@code null} or
+ * <em>empty</em>, depending on the absence or presence of
+ * {@link org.springframework.test.context.web.WebAppConfiguration @WebAppConfiguration} either
+ * {@code "org.springframework.test.context.support.DelegatingSmartContextLoader"} or
+ * {@code "org.springframework.test.context.web.WebDelegatingSmartContextLoader"} will
+ * be used as the default context loader class name. 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}
- * @param configAttributesList the list of configuration attributes to process;
- * must not be {@code null} or <em>empty</em>; must be ordered <em>bottom-up</em>
+ * @param testClass the test class for which the {@code ContextLoader} should be
+ * resolved; must not be {@code null}
+ * @param configAttributesList the list of configuration attributes to process; must
+ * not be {@code null} or <em>empty</em>; must be ordered <em>bottom-up</em>
* (i.e., as if we were traversing up the class hierarchy)
- * @param defaultContextLoaderClassName the name of the default
- * {@code ContextLoader} class to use; may be {@code null} or <em>empty</em>
- * @return the resolved {@code ContextLoader} for the supplied
- * {@code testClass} (never {@code null})
+ * @param defaultContextLoaderClassName the name of the default {@code ContextLoader}
+ * class to use; may be {@code null} or <em>empty</em>
+ * @return the resolved {@code ContextLoader} for the supplied {@code testClass}
+ * (never {@code null})
* @see #resolveContextLoaderClass
*/
- @SuppressWarnings("javadoc")
static ContextLoader resolveContextLoader(Class<?> testClass,
List<ContextConfigurationAttributes> configAttributesList, String defaultContextLoaderClassName) {
Assert.notNull(testClass, "Class must not be null");
@@ -113,36 +119,35 @@ static ContextLoader resolveContextLoader(Class<?> testClass,
}
/**
- * Resolve the {@link ContextLoader} {@linkplain Class class} to use for the
- * supplied list of {@link ContextConfigurationAttributes}.
+ * Resolve the {@link ContextLoader} {@linkplain Class class} to use for the supplied
+ * list of {@link ContextConfigurationAttributes}.
*
- * <p>Beginning with the first level in the context configuration attributes
- * hierarchy:
+ * <p>Beginning with the first level in the context configuration attributes hierarchy:
*
* <ol>
* <li>If the {@link ContextConfigurationAttributes#getContextLoaderClass()
* contextLoaderClass} property of {@link ContextConfigurationAttributes} is
* configured with an explicit class, that class will be returned.</li>
- * <li>If an explicit {@code ContextLoader} class is not specified at the
- * current level in the hierarchy, traverse to the next level in the hierarchy
- * and return to step #1.</li>
- * <li>If no explicit {@code ContextLoader} class is found after traversing
- * the hierarchy, an attempt will be made to load and return the class
- * with the supplied {@code defaultContextLoaderClassName}.</li>
+ * <li>If an explicit {@code ContextLoader} class is not specified at the current
+ * level in the hierarchy, traverse to the next level in the hierarchy and return to
+ * step #1.</li>
+ * <li>If no explicit {@code ContextLoader} class is found after traversing the
+ * hierarchy, an attempt will be made to load and return the class with the supplied
+ * {@code defaultContextLoaderClassName}.</li>
* </ol>
*
- * @param testClass the class for which to resolve the {@code ContextLoader}
- * class; must not be {@code null}; only used for logging purposes
- * @param configAttributesList the list of configuration attributes to process;
- * must not be {@code null} or <em>empty</em>; must be ordered <em>bottom-up</em>
+ * @param testClass the class for which to resolve the {@code ContextLoader} class;
+ * must not be {@code null}; only used for logging purposes
+ * @param configAttributesList the list of configuration attributes to process; must
+ * not be {@code null} or <em>empty</em>; must be ordered <em>bottom-up</em>
* (i.e., as if we were traversing up the class hierarchy)
- * @param defaultContextLoaderClassName the name of the default
- * {@code ContextLoader} class to use; must not be {@code null} or empty
+ * @param defaultContextLoaderClassName the name of the default {@code ContextLoader}
+ * class to use; must not be {@code null} or empty
* @return the {@code ContextLoader} class to use for the supplied test class
* @throws IllegalArgumentException if {@code @ContextConfiguration} is not
* <em>present</em> on the supplied test class
- * @throws IllegalStateException if the default {@code ContextLoader} class
- * could not be loaded
+ * @throws IllegalStateException if the default {@code ContextLoader} class could not
+ * be loaded
*/
@SuppressWarnings("unchecked")
static Class<? extends ContextLoader> resolveContextLoaderClass(Class<?> testClass,
@@ -184,22 +189,201 @@ static Class<? extends ContextLoader> resolveContextLoaderClass(Class<?> testCla
}
/**
- * Resolve the list of {@link ContextConfigurationAttributes configuration
- * attributes} for the supplied {@link Class class} and its superclasses.
+ * Convenience method for creating a {@link ContextConfigurationAttributes} instance
+ * from the supplied {@link ContextConfiguration} and declaring class and then adding
+ * the attributes to the supplied list.
+ */
+ private static void convertContextConfigToConfigAttributesAndAddToList(ContextConfiguration contextConfiguration,
+ Class<?> declaringClass, final List<ContextConfigurationAttributes> attributesList) {
+ if (logger.isTraceEnabled()) {
+ logger.trace(String.format("Retrieved @ContextConfiguration [%s] for declaring class [%s].",
+ contextConfiguration, declaringClass.getName()));
+ }
+
+ ContextConfigurationAttributes attributes = new ContextConfigurationAttributes(declaringClass,
+ contextConfiguration);
+ if (logger.isTraceEnabled()) {
+ logger.trace("Resolved context configuration attributes: " + attributes);
+ }
+ attributesList.add(attributes);
+ }
+
+ /**
+ * Resolve the list of lists of {@linkplain ContextConfigurationAttributes context
+ * configuration attributes} for the supplied {@linkplain Class test class} and its
+ * superclasses, taking into account context hierarchies declared via
+ * {@link ContextHierarchy @ContextHierarchy} and
+ * {@link ContextConfiguration @ContextConfiguration}.
+ *
+ * <p>The outer list represents a top-down ordering of context configuration
+ * attributes, where each element in the list represents the context configuration
+ * declared on a given test class in the class hierarchy. Each nested list
+ * contains the context configuration attributes declared either via a single
+ * instance of {@code @ContextConfiguration} on the particular class or via
+ * multiple instances of {@code @ContextConfiguration} declared within a
+ * single {@code @ContextHierarchy} instance on the particular class.
+ * Furthermore, each nested list maintains the order in which
+ * {@code @ContextConfiguration} instances are declared.
+ *
+ * <p>Note that the {@link ContextConfiguration#inheritLocations inheritLocations} and
+ * {@link ContextConfiguration#inheritInitializers() inheritInitializers} flags of
+ * {@link ContextConfiguration @ContextConfiguration} will <strong>not</strong>
+ * be taken into consideration. If these flags need to be honored, that must be
+ * handled manually when traversing the nested lists returned by this method.
+ *
+ * @param testClass the class for which to resolve the context hierarchy attributes
+ * (must not be {@code null})
+ * @return the list of lists of configuration attributes for the specified class;
+ * never {@code null}
+ * @throws IllegalArgumentException if the supplied class is {@code null}; if
+ * neither {@code @ContextConfiguration} nor {@code @ContextHierarchy} is
+ * <em>present</em> on the supplied class; if a given class in the class hierarchy
+ * declares both {@code @ContextConfiguration} and {@code @ContextHierarchy} as
+ * top-level annotations; or if individual {@code @ContextConfiguration}
+ * elements within a {@code @ContextHierarchy} declaration on a given class
+ * in the class hierarchy do not define unique context configuration.
+ *
+ * @since 3.2.2
+ * @see #buildContextHierarchyMap(Class)
+ * @see #resolveContextConfigurationAttributes(Class)
+ */
+ static List<List<ContextConfigurationAttributes>> resolveContextHierarchyAttributes(Class<?> testClass) {
+ Assert.notNull(testClass, "Class must not be null");
+
+ final Class<ContextConfiguration> contextConfigType = ContextConfiguration.class;
+ final Class<ContextHierarchy> contextHierarchyType = ContextHierarchy.class;
+ final List<Class<? extends Annotation>> annotationTypes = Arrays.asList(contextConfigType, contextHierarchyType);
+
+ final List<List<ContextConfigurationAttributes>> hierarchyAttributes = new ArrayList<List<ContextConfigurationAttributes>>();
+
+ Class<?> declaringClass = findAnnotationDeclaringClassForTypes(annotationTypes, testClass);
+ Assert.notNull(declaringClass, String.format(
+ "Could not find an 'annotation declaring class' for annotation type [%s] or [%s] and test class [%s]",
+ contextConfigType.getName(), contextHierarchyType.getName(), testClass.getName()));
+
+ while (declaringClass != null) {
+
+ boolean contextConfigDeclaredLocally = isAnnotationDeclaredLocally(contextConfigType, declaringClass);
+ boolean contextHierarchyDeclaredLocally = isAnnotationDeclaredLocally(contextHierarchyType, declaringClass);
+
+ if (contextConfigDeclaredLocally && contextHierarchyDeclaredLocally) {
+ String msg = String.format("Test class [%s] has been configured with both @ContextConfiguration "
+ + "and @ContextHierarchy as class-level annotations. Only one of these annotations may "
+ + "be declared as a top-level annotation per test class.", declaringClass.getName());
+ logger.error(msg);
+ throw new IllegalStateException(msg);
+ }
+
+ final List<ContextConfigurationAttributes> configAttributesList = new ArrayList<ContextConfigurationAttributes>();
+
+ if (contextConfigDeclaredLocally) {
+ ContextConfiguration contextConfiguration = declaringClass.getAnnotation(contextConfigType);
+ convertContextConfigToConfigAttributesAndAddToList(contextConfiguration, declaringClass,
+ configAttributesList);
+ }
+ else if (contextHierarchyDeclaredLocally) {
+ ContextHierarchy contextHierarchy = declaringClass.getAnnotation(contextHierarchyType);
+ for (ContextConfiguration contextConfiguration : contextHierarchy.value()) {
+ convertContextConfigToConfigAttributesAndAddToList(contextConfiguration, declaringClass,
+ configAttributesList);
+ }
+
+ // Check for uniqueness
+ Set<ContextConfigurationAttributes> configAttributesSet = new HashSet<ContextConfigurationAttributes>(
+ configAttributesList);
+ if (configAttributesSet.size() != configAttributesList.size()) {
+ String msg = String.format("The @ContextConfiguration elements configured via "
+ + "@ContextHierarchy in test class [%s] must define unique contexts to load.",
+ declaringClass.getName());
+ logger.error(msg);
+ throw new IllegalStateException(msg);
+ }
+ }
+ else {
+ // This should theoretically actually never happen...
+ String msg = String.format("Test class [%s] has been configured with neither @ContextConfiguration "
+ + "nor @ContextHierarchy as a class-level annotation.", declaringClass.getName());
+ logger.error(msg);
+ throw new IllegalStateException(msg);
+ }
+
+ hierarchyAttributes.add(0, configAttributesList);
+
+ declaringClass = findAnnotationDeclaringClassForTypes(annotationTypes, declaringClass.getSuperclass());
+ }
+
+ return hierarchyAttributes;
+ }
+
+ /**
+ * Build a <em>context hierarchy map</em> for the supplied {@linkplain Class
+ * test class} and its superclasses, taking into account context hierarchies
+ * declared via {@link ContextHierarchy @ContextHierarchy} and
+ * {@link ContextConfiguration @ContextConfiguration}.
+ *
+ * <p>Each value in the map represents the consolidated list of {@linkplain
+ * ContextConfigurationAttributes context configuration attributes} for a
+ * given level in the context hierarchy (potentially across the test class
+ * hierarchy), keyed by the {@link ContextConfiguration#name() name} of the
+ * context hierarchy level.
+ *
+ * <p>If a given level in the context hierarchy does not have an explicit
+ * name (i.e., configured via {@link ContextConfiguration#name}), a name will
+ * be generated for that hierarchy level by appending the numerical level to
+ * the {@link #GENERATED_CONTEXT_HIERARCHY_LEVEL_PREFIX}.
+ *
+ * @param testClass the class for which to resolve the context hierarchy map
+ * (must not be {@code null})
+ * @return a map of context configuration attributes for the context hierarchy,
+ * keyed by context hierarchy level name; never {@code null}
+ *
+ * @since 3.2.2
+ * @see #resolveContextHierarchyAttributes(Class)
+ */
+ static Map<String, List<ContextConfigurationAttributes>> buildContextHierarchyMap(Class<?> testClass) {
+ final Map<String, List<ContextConfigurationAttributes>> map = new LinkedHashMap<String, List<ContextConfigurationAttributes>>();
+ int hierarchyLevel = 1;
+
+ for (List<ContextConfigurationAttributes> configAttributesList : resolveContextHierarchyAttributes(testClass)) {
+ for (ContextConfigurationAttributes configAttributes : configAttributesList) {
+ String name = configAttributes.getName();
+
+ // Assign a generated name?
+ if (!StringUtils.hasText(name)) {
+ name = GENERATED_CONTEXT_HIERARCHY_LEVEL_PREFIX + hierarchyLevel;
+ }
+
+ // Encountered a new context hierarchy level?
+ if (!map.containsKey(name)) {
+ hierarchyLevel++;
+ map.put(name, new ArrayList<ContextConfigurationAttributes>());
+ }
+
+ map.get(name).add(configAttributes);
+ }
+ }
+
+ return map;
+ }
+
+ /**
+ * Resolve the list of {@linkplain ContextConfigurationAttributes context
+ * configuration attributes} for the supplied {@linkplain Class test class} and its
+ * superclasses.
*
- * <p>Note that the {@link ContextConfiguration#inheritLocations
- * inheritLocations} and {@link ContextConfiguration#inheritInitializers()
- * inheritInitializers} flags of {@link ContextConfiguration
- * @ContextConfiguration} will <strong>not</strong> be taken into
- * consideration. If these flags need to be honored, that must be handled
- * manually when traversing the list returned by this method.
+ * <p>Note that the {@link ContextConfiguration#inheritLocations inheritLocations} and
+ * {@link ContextConfiguration#inheritInitializers() inheritInitializers} flags of
+ * {@link ContextConfiguration @ContextConfiguration} will <strong>not</strong>
+ * be taken into consideration. If these flags need to be honored, that must be
+ * handled manually when traversing the list returned by this method.
*
* @param testClass the class for which to resolve the configuration attributes (must
* not be {@code null})
- * @return the list of configuration attributes for the specified class, ordered <em>bottom-up</em>
- * (i.e., as if we were traversing up the class hierarchy); never {@code null}
- * @throws IllegalArgumentException if the supplied class is {@code null} or
- * if {@code @ContextConfiguration} is not <em>present</em> on the supplied class
+ * @return the list of configuration attributes for the specified class, ordered
+ * <em>bottom-up</em> (i.e., as if we were traversing up the class hierarchy);
+ * never {@code null}
+ * @throws IllegalArgumentException if the supplied class is {@code null} or if
+ * {@code @ContextConfiguration} is not <em>present</em> on the supplied class
*/
static List<ContextConfigurationAttributes> resolveContextConfigurationAttributes(Class<?> testClass) {
Assert.notNull(testClass, "Class must not be null");
@@ -214,42 +398,29 @@ static List<ContextConfigurationAttributes> resolveContextConfigurationAttribute
while (declaringClass != null) {
ContextConfiguration contextConfiguration = declaringClass.getAnnotation(annotationType);
- if (logger.isTraceEnabled()) {
- logger.trace(String.format("Retrieved @ContextConfiguration [%s] for declaring class [%s].",
- contextConfiguration, declaringClass.getName()));
- }
-
- ContextConfigurationAttributes attributes = new ContextConfigurationAttributes(declaringClass,
- contextConfiguration);
- if (logger.isTraceEnabled()) {
- logger.trace("Resolved context configuration attributes: " + attributes);
- }
-
- attributesList.add(attributes);
-
+ convertContextConfigToConfigAttributesAndAddToList(contextConfiguration, declaringClass, attributesList);
declaringClass = findAnnotationDeclaringClass(annotationType, declaringClass.getSuperclass());
}
return attributesList;
}
/**
- * Resolve the list of merged {@code ApplicationContextInitializer} classes
- * for the supplied list of {@code ContextConfigurationAttributes}.
+ * Resolve the list of merged {@code ApplicationContextInitializer} classes for the
+ * supplied list of {@code ContextConfigurationAttributes}.
*
* <p>Note that the {@link ContextConfiguration#inheritInitializers inheritInitializers}
* flag of {@link ContextConfiguration @ContextConfiguration} will be taken into
- * consideration. Specifically, if the {@code inheritInitializers} flag is
- * set to {@code true} for a given level in the class hierarchy represented by
- * the provided configuration attributes, context initializer classes defined
- * at the given level will be merged with those defined in higher levels
- * of the class hierarchy.
+ * consideration. Specifically, if the {@code inheritInitializers} flag is set to
+ * {@code true} for a given level in the class hierarchy represented by the provided
+ * configuration attributes, context initializer classes defined at the given level
+ * will be merged with those defined in higher levels of the class hierarchy.
*
- * @param configAttributesList the list of configuration attributes to process;
- * must not be {@code null} or <em>empty</em>; must be ordered <em>bottom-up</em>
+ * @param configAttributesList the list of configuration attributes to process; must
+ * not be {@code null} or <em>empty</em>; must be ordered <em>bottom-up</em>
* (i.e., as if we were traversing up the class hierarchy)
- * @return the set of merged context initializer classes, including those
- * from superclasses if appropriate (never {@code null})
+ * @return the set of merged context initializer classes, including those from
+ * superclasses if appropriate (never {@code null})
* @since 3.2
*/
static Set<Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>> resolveInitializerClasses(
@@ -278,16 +449,15 @@ static Set<Class<? extends ApplicationContextInitializer<? extends ConfigurableA
/**
* 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} flag is
- * set to {@code true}, profiles defined in the test class will be
- * merged with those defined in superclasses.
+ * <p>Note that the {@link ActiveProfiles#inheritProfiles inheritProfiles} flag of
+ * {@link ActiveProfiles @ActiveProfiles} will be taken into consideration.
+ * Specifically, if the {@code inheritProfiles} flag is set to {@code true}, profiles
+ * defined in the test class will be merged with those defined in superclasses.
*
- * @param testClass the class for which to resolve the active profiles (must
- * not be {@code null})
- * @return the set of active profiles for the specified class, including
- * active profiles from superclasses if appropriate (never {@code null})
+ * @param testClass the class for which to resolve the active profiles (must not be
+ * {@code null})
+ * @return the set of active profiles for the specified class, including active
+ * profiles from superclasses if appropriate (never {@code null})
* @see ActiveProfiles
* @see org.springframework.context.annotation.Profile
*/
@@ -342,14 +512,72 @@ else if (!ObjectUtils.isEmpty(valueProfiles)) {
}
/**
- * Build the {@link MergedContextConfiguration merged context configuration}
- * for the supplied {@link Class testClass} and
- * {@code defaultContextLoaderClassName}.
+ * Build the {@link MergedContextConfiguration merged context configuration} for
+ * the supplied {@link Class testClass} and {@code defaultContextLoaderClassName},
+ * taking into account context hierarchies declared via
+ * {@link ContextHierarchy @ContextHierarchy} and
+ * {@link ContextConfiguration @ContextConfiguration}.
+ *
+ * @param testClass the test class for which the {@code MergedContextConfiguration}
+ * should be built (must not be {@code null})
+ * @param defaultContextLoaderClassName the name of the default {@code ContextLoader}
+ * class to use (may be {@code null})
+ * @param cacheAwareContextLoaderDelegate the cache-aware context loader delegate to
+ * be passed to the {@code MergedContextConfiguration} constructor
+ * @return the merged context configuration
+ * @see #buildContextHierarchyMap(Class)
+ * @see #buildMergedContextConfiguration(Class, List, String, MergedContextConfiguration, CacheAwareContextLoaderDelegate)
+ */
+ @SuppressWarnings("javadoc")
+ static MergedContextConfiguration buildMergedContextConfiguration(Class<?> testClass,
+ String defaultContextLoaderClassName, CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate) {
+
+ if (testClass.isAnnotationPresent(ContextHierarchy.class)) {
+ Map<String, List<ContextConfigurationAttributes>> hierarchyMap = buildContextHierarchyMap(testClass);
+
+ MergedContextConfiguration parentConfig = null;
+ MergedContextConfiguration mergedConfig = null;
+
+ for (List<ContextConfigurationAttributes> list : hierarchyMap.values()) {
+ List<ContextConfigurationAttributes> reversedList = new ArrayList<ContextConfigurationAttributes>(list);
+ Collections.reverse(reversedList);
+
+ // Don't use the supplied testClass; instead ensure that we are
+ // building the MCC for the actual test class that declared the
+ // configuration for the current level in the context hierarchy.
+ Assert.notEmpty(reversedList, "ContextConfigurationAttributes list must not be empty");
+ Class<?> declaringClass = reversedList.get(0).getDeclaringClass();
+
+ mergedConfig = buildMergedContextConfiguration(declaringClass, reversedList,
+ defaultContextLoaderClassName, parentConfig, cacheAwareContextLoaderDelegate);
+ parentConfig = mergedConfig;
+ }
+
+ // Return the last level in the context hierarchy
+ return mergedConfig;
+ }
+ else {
+ return buildMergedContextConfiguration(testClass, resolveContextConfigurationAttributes(testClass),
+ defaultContextLoaderClassName, null, cacheAwareContextLoaderDelegate);
+ }
+ }
+
+ /**
+ * Build the {@link MergedContextConfiguration merged context configuration} for the
+ * supplied {@link Class testClass}, context configuration attributes,
+ * {@code defaultContextLoaderClassName}, and parent context configuration.
*
* @param testClass the test class for which the {@code MergedContextConfiguration}
* should be built (must not be {@code null})
- * @param defaultContextLoaderClassName the name of the default
- * {@code ContextLoader} class to use (may be {@code null})
+ * @param configAttributesList the list of context configuration attributes for the
+ * specified test class, ordered <em>bottom-up</em> (i.e., as if we were
+ * traversing up the class hierarchy); never {@code null} or empty
+ * @param defaultContextLoaderClassName the name of the default {@code ContextLoader}
+ * class to use (may be {@code null})
+ * @param parentConfig the merged context configuration for the parent application
+ * context in a context hierarchy, or {@code null} if there is no parent
+ * @param cacheAwareContextLoaderDelegate the cache-aware context loader delegate to
+ * be passed to the {@code MergedContextConfiguration} constructor
* @return the merged context configuration
* @see #resolveContextLoader
* @see #resolveContextConfigurationAttributes
@@ -358,10 +586,11 @@ else if (!ObjectUtils.isEmpty(valueProfiles)) {
* @see #resolveActiveProfiles
* @see MergedContextConfiguration
*/
- static MergedContextConfiguration buildMergedContextConfiguration(Class<?> testClass,
- String defaultContextLoaderClassName) {
+ private static MergedContextConfiguration buildMergedContextConfiguration(final Class<?> testClass,
+ final List<ContextConfigurationAttributes> configAttributesList,
+ final String defaultContextLoaderClassName, MergedContextConfiguration parentConfig,
+ CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate) {
- final List<ContextConfigurationAttributes> configAttributesList = resolveContextConfigurationAttributes(testClass);
final ContextLoader contextLoader = resolveContextLoader(testClass, configAttributesList,
defaultContextLoaderClassName);
final List<String> locationsList = new ArrayList<String>();
@@ -397,22 +626,21 @@ static MergedContextConfiguration buildMergedContextConfiguration(Class<?> testC
String[] activeProfiles = resolveActiveProfiles(testClass);
MergedContextConfiguration mergedConfig = buildWebMergedContextConfiguration(testClass, locations, classes,
- initializerClasses, activeProfiles, contextLoader);
+ initializerClasses, activeProfiles, contextLoader, cacheAwareContextLoaderDelegate, parentConfig);
if (mergedConfig == null) {
mergedConfig = new MergedContextConfiguration(testClass, locations, classes, initializerClasses,
- activeProfiles, contextLoader);
+ activeProfiles, contextLoader, cacheAwareContextLoaderDelegate, parentConfig);
}
return mergedConfig;
}
/**
- * Load the {@link org.springframework.test.context.web.WebAppConfiguration @WebAppConfiguration}
+ * Load the {@link org.springframework.test.context.web.WebAppConfiguration}
* class, using reflection in order to avoid package cycles.
*
- * @return the {@code @WebAppConfiguration} class or {@code null} if it
- * cannot be loaded
+ * @return the {@code @WebAppConfiguration} class or {@code null} if it cannot be loaded
* @since 3.2
*/
@SuppressWarnings("unchecked")
@@ -431,12 +659,10 @@ private static Class<? extends Annotation> loadWebAppConfigurationClass() {
}
/**
- * Attempt to build a {@link org.springframework.test.context.web.WebMergedContextConfiguration
- * WebMergedContextConfiguration} from the supplied arguments, using reflection
- * in order to avoid package cycles.
+ * Attempt to build a {@link org.springframework.test.context.web.WebMergedContextConfiguration}
+ * from the supplied arguments, using reflection in order to avoid package cycles.
*
- * @return the {@code WebMergedContextConfiguration} or {@code null} if
- * it could not be built
+ * @return the {@code WebMergedContextConfiguration} or {@code null} if it could not be built
* @since 3.2
*/
@SuppressWarnings("unchecked")
@@ -445,7 +671,8 @@ private static MergedContextConfiguration buildWebMergedContextConfiguration(
String[] locations,
Class<?>[] classes,
Set<Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>> initializerClasses,
- String[] activeProfiles, ContextLoader contextLoader) {
+ String[] activeProfiles, ContextLoader contextLoader,
+ CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate, MergedContextConfiguration parentConfig) {
Class<? extends Annotation> webAppConfigClass = loadWebAppConfigurationClass();
@@ -459,11 +686,12 @@ private static MergedContextConfiguration buildWebMergedContextConfiguration(
Constructor<? extends MergedContextConfiguration> constructor = ClassUtils.getConstructorIfAvailable(
webMergedConfigClass, Class.class, String[].class, Class[].class, Set.class, String[].class,
- String.class, ContextLoader.class);
+ String.class, ContextLoader.class, CacheAwareContextLoaderDelegate.class,
+ MergedContextConfiguration.class);
if (constructor != null) {
return instantiateClass(constructor, testClass, locations, classes, initializerClasses,
- activeProfiles, resourceBasePath, contextLoader);
+ activeProfiles, resourceBasePath, contextLoader, cacheAwareContextLoaderDelegate, parentConfig);
}
}
catch (Throwable t) { | true |
Other | spring-projects | spring-framework | 98074e776262292a9d6fa8d164e6718c5876ed6f.json | Provide support for context hierarchies in the TCF
Prior to this commit the Spring TestContext Framework supported creating
only flat, non-hierarchical contexts. There was no easy way to create
contexts with parent-child relationships.
This commit addresses this issue by introducing a new @ContextHierarchy
annotation that can be used in conjunction with @ContextConfiguration
for declaring hierarchies of application contexts, either within a
single test class or within a test class hierarchy. In addition,
@DirtiesContext now supports a new 'hierarchyMode' attribute for
controlling context cache clearing for context hierarchies.
- Introduced a new @ContextHierarchy annotation.
- Introduced 'name' attribute in @ContextConfiguration.
- Introduced 'name' property in ContextConfigurationAttributes.
- TestContext is now aware of @ContextHierarchy in addition to
@ContextConfiguration.
- Introduced findAnnotationDeclaringClassForTypes() in AnnotationUtils.
- Introduced resolveContextHierarchyAttributes() in ContextLoaderUtils.
- Introduced buildContextHierarchyMap() in ContextLoaderUtils.
- @ContextConfiguration and @ContextHierarchy may not be used as
top-level, class-level annotations simultaneously.
- Introduced reference to the parent configuration in
MergedContextConfiguration and WebMergedContextConfiguration.
- Introduced overloaded buildMergedContextConfiguration() methods in
ContextLoaderUtils in order to handle context hierarchies separately
from conventional, non-hierarchical contexts.
- Introduced hashCode() and equals() in ContextConfigurationAttributes.
- ContextLoaderUtils ensures uniqueness of @ContextConfiguration
elements within a single @ContextHierarchy declaration.
- Introduced CacheAwareContextLoaderDelegate that can be used for
loading contexts with transparent support for interacting with the
context cache -- for example, for retrieving the parent application
context in a context hierarchy.
- TestContext now delegates to CacheAwareContextLoaderDelegate for
loading contexts.
- Introduced getParentApplicationContext() in MergedContextConfiguration
- The loadContext(MergedContextConfiguration) methods in
AbstractGenericContextLoader and AbstractGenericWebContextLoader now
set the parent context as appropriate.
- Introduced 'hierarchyMode' attribute in @DirtiesContext with a
corresponding HierarchyMode enum that defines EXHAUSTIVE and
CURRENT_LEVEL cache removal modes.
- ContextCache now internally tracks the relationships between contexts
that make up a context hierarchy. Furthermore, when a context is
removed, if it is part of a context hierarchy all corresponding
contexts will be removed from the cache according to the supplied
HierarchyMode.
- AbstractGenericWebContextLoader will set a loaded context as the
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE in the MockServletContext when
context hierarchies are used if the context has no parent or if the
context has a parent that is not a WAC.
- Where appropriate, updated Javadoc to refer to the
ServletTestExecutionListener, which was introduced in 3.2.0.
- Updated Javadoc to avoid and/or suppress warnings in spring-test.
- Suppressed remaining warnings in code in spring-test.
Issue: SPR-5613, SPR-9863 | spring-test/src/main/java/org/springframework/test/context/MergedContextConfiguration.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,9 +23,11 @@
import java.util.SortedSet;
import java.util.TreeSet;
+import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.style.ToStringCreator;
+import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
@@ -72,6 +74,8 @@ public class MergedContextConfiguration implements Serializable {
private final Set<Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>> contextInitializerClasses;
private final String[] activeProfiles;
private final ContextLoader contextLoader;
+ private final CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate;
+ private final MergedContextConfiguration parent;
private static String[] processLocations(String[] locations) {
@@ -149,19 +153,56 @@ public MergedContextConfiguration(Class<?> testClass, String[] locations, Class<
* @param contextInitializerClasses the merged context initializer classes
* @param activeProfiles the merged active bean definition profiles
* @param contextLoader the resolved {@code ContextLoader}
+ * @see #MergedContextConfiguration(Class, String[], Class[], Set, String[], ContextLoader, CacheAwareContextLoaderDelegate, MergedContextConfiguration)
*/
public MergedContextConfiguration(
Class<?> testClass,
String[] locations,
Class<?>[] classes,
Set<Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>> contextInitializerClasses,
String[] activeProfiles, ContextLoader contextLoader) {
+ this(testClass, locations, classes, contextInitializerClasses, activeProfiles, contextLoader, null, null);
+ }
+
+ /**
+ * Create a new {@code MergedContextConfiguration} instance for the
+ * supplied test class, resource locations, annotated classes, context
+ * initializers, active profiles, {@code ContextLoader}, and parent
+ * configuration.
+ *
+ * <p>If a {@code null} value is supplied for {@code locations},
+ * {@code classes}, or {@code activeProfiles} an empty array will
+ * be stored instead. If a {@code null} value is supplied for the
+ * {@code contextInitializerClasses} an empty set will be stored instead.
+ * Furthermore, active profiles will be sorted, and duplicate 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 annotated classes
+ * @param contextInitializerClasses the merged context initializer classes
+ * @param activeProfiles the merged active bean definition profiles
+ * @param contextLoader the resolved {@code ContextLoader}
+ * @param cacheAwareContextLoaderDelegate a cache-aware context loader
+ * delegate with which to retrieve the parent context
+ * @param parent the parent configuration or {@code null} if there is no parent
+ * @since 3.2.2
+ */
+ public MergedContextConfiguration(
+ Class<?> testClass,
+ String[] locations,
+ Class<?>[] classes,
+ Set<Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>> contextInitializerClasses,
+ String[] activeProfiles, ContextLoader contextLoader,
+ CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate, MergedContextConfiguration parent) {
this.testClass = testClass;
this.locations = processLocations(locations);
this.classes = processClasses(classes);
this.contextInitializerClasses = processContextInitializerClasses(contextInitializerClasses);
this.activeProfiles = processActiveProfiles(activeProfiles);
this.contextLoader = contextLoader;
+ this.cacheAwareContextLoaderDelegate = cacheAwareContextLoaderDelegate;
+ this.parent = parent;
}
/**
@@ -207,6 +248,39 @@ public ContextLoader getContextLoader() {
return contextLoader;
}
+ /**
+ * Get the {@link MergedContextConfiguration} for the parent application context in a
+ * context hierarchy.
+ *
+ * @return the parent configuration or {@code null} if there is no parent
+ * @see #getParentApplicationContext()
+ * @since 3.2.2
+ */
+ public MergedContextConfiguration getParent() {
+ return this.parent;
+ }
+
+ /**
+ * Get the parent {@link ApplicationContext} for the context defined by this
+ * {@code MergedContextConfiguration} from the context cache.
+ * <p>
+ * If the parent context has not yet been loaded, it will be loaded, stored in the
+ * cache, and then returned.
+ *
+ * @return the parent {@code ApplicationContext} or {@code null} if there is no parent
+ * @see #getParent()
+ * @since 3.2.2
+ */
+ public ApplicationContext getParentApplicationContext() {
+ if (parent == null) {
+ return null;
+ }
+
+ Assert.state(cacheAwareContextLoaderDelegate != null,
+ "Cannot retrieve a parent application context without access to the CacheAwareContextLoaderDelegate.");
+ return cacheAwareContextLoaderDelegate.loadContext(parent);
+ }
+
/**
* Generate a unique hash code for all properties of this
* {@code MergedContextConfiguration} excluding the
@@ -220,6 +294,7 @@ public int hashCode() {
result = prime * result + Arrays.hashCode(classes);
result = prime * result + contextInitializerClasses.hashCode();
result = prime * result + Arrays.hashCode(activeProfiles);
+ result = prime * result + (parent == null ? 0 : parent.hashCode());
result = prime * result + nullSafeToString(contextLoader).hashCode();
return result;
}
@@ -229,8 +304,9 @@ public int hashCode() {
* instance by comparing both object's {@linkplain #getLocations() locations},
* {@linkplain #getClasses() annotated classes},
* {@linkplain #getContextInitializerClasses() context initializer classes},
- * {@linkplain #getActiveProfiles() active profiles}, and the fully qualified
- * names of their {@link #getContextLoader() ContextLoaders}.
+ * {@linkplain #getActiveProfiles() active profiles},
+ * {@linkplain #getParent() parents}, and the fully qualified names of their
+ * {@link #getContextLoader() ContextLoaders}.
*/
@Override
public boolean equals(Object obj) {
@@ -247,15 +323,28 @@ public boolean equals(Object obj) {
if (!Arrays.equals(this.locations, that.locations)) {
return false;
}
+
if (!Arrays.equals(this.classes, that.classes)) {
return false;
}
+
if (!this.contextInitializerClasses.equals(that.contextInitializerClasses)) {
return false;
}
+
if (!Arrays.equals(this.activeProfiles, that.activeProfiles)) {
return false;
}
+
+ if (this.parent == null) {
+ if (that.parent != null) {
+ return false;
+ }
+ }
+ else if (!this.parent.equals(that.parent)) {
+ return false;
+ }
+
if (!nullSafeToString(this.contextLoader).equals(nullSafeToString(that.contextLoader))) {
return false;
}
@@ -267,8 +356,9 @@ public boolean equals(Object obj) {
* Provide a String representation of the {@linkplain #getTestClass() test class},
* {@linkplain #getLocations() locations}, {@linkplain #getClasses() annotated classes},
* {@linkplain #getContextInitializerClasses() context initializer classes},
- * {@linkplain #getActiveProfiles() active profiles}, and the name of the
- * {@link #getContextLoader() ContextLoader}.
+ * {@linkplain #getActiveProfiles() active profiles}, the name of the
+ * {@link #getContextLoader() ContextLoader}, and the
+ * {@linkplain #getParent() parent configuration}.
*/
@Override
public String toString() {
@@ -279,6 +369,7 @@ public String toString() {
.append("contextInitializerClasses", ObjectUtils.nullSafeToString(contextInitializerClasses))//
.append("activeProfiles", ObjectUtils.nullSafeToString(activeProfiles))//
.append("contextLoader", nullSafeToString(contextLoader))//
+ .append("parent", parent)//
.toString();
}
| true |
Other | spring-projects | spring-framework | 98074e776262292a9d6fa8d164e6718c5876ed6f.json | Provide support for context hierarchies in the TCF
Prior to this commit the Spring TestContext Framework supported creating
only flat, non-hierarchical contexts. There was no easy way to create
contexts with parent-child relationships.
This commit addresses this issue by introducing a new @ContextHierarchy
annotation that can be used in conjunction with @ContextConfiguration
for declaring hierarchies of application contexts, either within a
single test class or within a test class hierarchy. In addition,
@DirtiesContext now supports a new 'hierarchyMode' attribute for
controlling context cache clearing for context hierarchies.
- Introduced a new @ContextHierarchy annotation.
- Introduced 'name' attribute in @ContextConfiguration.
- Introduced 'name' property in ContextConfigurationAttributes.
- TestContext is now aware of @ContextHierarchy in addition to
@ContextConfiguration.
- Introduced findAnnotationDeclaringClassForTypes() in AnnotationUtils.
- Introduced resolveContextHierarchyAttributes() in ContextLoaderUtils.
- Introduced buildContextHierarchyMap() in ContextLoaderUtils.
- @ContextConfiguration and @ContextHierarchy may not be used as
top-level, class-level annotations simultaneously.
- Introduced reference to the parent configuration in
MergedContextConfiguration and WebMergedContextConfiguration.
- Introduced overloaded buildMergedContextConfiguration() methods in
ContextLoaderUtils in order to handle context hierarchies separately
from conventional, non-hierarchical contexts.
- Introduced hashCode() and equals() in ContextConfigurationAttributes.
- ContextLoaderUtils ensures uniqueness of @ContextConfiguration
elements within a single @ContextHierarchy declaration.
- Introduced CacheAwareContextLoaderDelegate that can be used for
loading contexts with transparent support for interacting with the
context cache -- for example, for retrieving the parent application
context in a context hierarchy.
- TestContext now delegates to CacheAwareContextLoaderDelegate for
loading contexts.
- Introduced getParentApplicationContext() in MergedContextConfiguration
- The loadContext(MergedContextConfiguration) methods in
AbstractGenericContextLoader and AbstractGenericWebContextLoader now
set the parent context as appropriate.
- Introduced 'hierarchyMode' attribute in @DirtiesContext with a
corresponding HierarchyMode enum that defines EXHAUSTIVE and
CURRENT_LEVEL cache removal modes.
- ContextCache now internally tracks the relationships between contexts
that make up a context hierarchy. Furthermore, when a context is
removed, if it is part of a context hierarchy all corresponding
contexts will be removed from the cache according to the supplied
HierarchyMode.
- AbstractGenericWebContextLoader will set a loaded context as the
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE in the MockServletContext when
context hierarchies are used if the context has no parent or if the
context has a parent that is not a WAC.
- Where appropriate, updated Javadoc to refer to the
ServletTestExecutionListener, which was introduced in 3.2.0.
- Updated Javadoc to avoid and/or suppress warnings in spring-test.
- Suppressed remaining warnings in code in spring-test.
Issue: SPR-5613, SPR-9863 | spring-test/src/main/java/org/springframework/test/context/SmartContextLoader.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,8 +29,7 @@
* context that it loads (see {@link MergedContextConfiguration#getActiveProfiles()}
* and {@link #loadContext(MergedContextConfiguration)}).
*
- * <p>See the Javadoc for
- * {@link ContextConfiguration @ContextConfiguration}
+ * <p>See the Javadoc for {@link ContextConfiguration @ContextConfiguration}
* for a definition of <em>annotated class</em>.
*
* <p>Clients of a {@code SmartContextLoader} should call
@@ -48,8 +47,8 @@
* <p>Even though {@code SmartContextLoader} extends {@code ContextLoader},
* clients should favor {@code SmartContextLoader}-specific methods over those
* defined in {@code ContextLoader}, particularly because a
- * {@code SmartContextLoader} may choose not to support methods defined in
- * the {@code ContextLoader} SPI.
+ * {@code SmartContextLoader} may choose not to support methods defined in the
+ * {@code ContextLoader} SPI.
*
* <p>Concrete implementations must provide a {@code public} no-args constructor.
*
@@ -59,6 +58,9 @@
* <li>{@link org.springframework.test.context.support.AnnotationConfigContextLoader AnnotationConfigContextLoader}</li>
* <li>{@link org.springframework.test.context.support.GenericXmlContextLoader GenericXmlContextLoader}</li>
* <li>{@link org.springframework.test.context.support.GenericPropertiesContextLoader GenericPropertiesContextLoader}</li>
+ * <li>{@link org.springframework.test.context.web.WebDelegatingSmartContextLoader WebDelegatingSmartContextLoader}</li>
+ * <li>{@link org.springframework.test.context.web.AnnotationConfigWebContextLoader AnnotationConfigWebContextLoader}</li>
+ * <li>{@link org.springframework.test.context.web.GenericXmlWebContextLoader GenericXmlWebContextLoader}</li>
* </ul>
*
* @author Sam Brannen | true |
Other | spring-projects | spring-framework | 98074e776262292a9d6fa8d164e6718c5876ed6f.json | Provide support for context hierarchies in the TCF
Prior to this commit the Spring TestContext Framework supported creating
only flat, non-hierarchical contexts. There was no easy way to create
contexts with parent-child relationships.
This commit addresses this issue by introducing a new @ContextHierarchy
annotation that can be used in conjunction with @ContextConfiguration
for declaring hierarchies of application contexts, either within a
single test class or within a test class hierarchy. In addition,
@DirtiesContext now supports a new 'hierarchyMode' attribute for
controlling context cache clearing for context hierarchies.
- Introduced a new @ContextHierarchy annotation.
- Introduced 'name' attribute in @ContextConfiguration.
- Introduced 'name' property in ContextConfigurationAttributes.
- TestContext is now aware of @ContextHierarchy in addition to
@ContextConfiguration.
- Introduced findAnnotationDeclaringClassForTypes() in AnnotationUtils.
- Introduced resolveContextHierarchyAttributes() in ContextLoaderUtils.
- Introduced buildContextHierarchyMap() in ContextLoaderUtils.
- @ContextConfiguration and @ContextHierarchy may not be used as
top-level, class-level annotations simultaneously.
- Introduced reference to the parent configuration in
MergedContextConfiguration and WebMergedContextConfiguration.
- Introduced overloaded buildMergedContextConfiguration() methods in
ContextLoaderUtils in order to handle context hierarchies separately
from conventional, non-hierarchical contexts.
- Introduced hashCode() and equals() in ContextConfigurationAttributes.
- ContextLoaderUtils ensures uniqueness of @ContextConfiguration
elements within a single @ContextHierarchy declaration.
- Introduced CacheAwareContextLoaderDelegate that can be used for
loading contexts with transparent support for interacting with the
context cache -- for example, for retrieving the parent application
context in a context hierarchy.
- TestContext now delegates to CacheAwareContextLoaderDelegate for
loading contexts.
- Introduced getParentApplicationContext() in MergedContextConfiguration
- The loadContext(MergedContextConfiguration) methods in
AbstractGenericContextLoader and AbstractGenericWebContextLoader now
set the parent context as appropriate.
- Introduced 'hierarchyMode' attribute in @DirtiesContext with a
corresponding HierarchyMode enum that defines EXHAUSTIVE and
CURRENT_LEVEL cache removal modes.
- ContextCache now internally tracks the relationships between contexts
that make up a context hierarchy. Furthermore, when a context is
removed, if it is part of a context hierarchy all corresponding
contexts will be removed from the cache according to the supplied
HierarchyMode.
- AbstractGenericWebContextLoader will set a loaded context as the
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE in the MockServletContext when
context hierarchies are used if the context has no parent or if the
context has a parent that is not a WAC.
- Where appropriate, updated Javadoc to refer to the
ServletTestExecutionListener, which was introduced in 3.2.0.
- Updated Javadoc to avoid and/or suppress warnings in spring-test.
- Suppressed remaining warnings in code in spring-test.
Issue: SPR-5613, SPR-9863 | spring-test/src/main/java/org/springframework/test/context/TestContext.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,9 +20,11 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+
import org.springframework.context.ApplicationContext;
import org.springframework.core.AttributeAccessorSupport;
import org.springframework.core.style.ToStringCreator;
+import org.springframework.test.annotation.DirtiesContext.HierarchyMode;
import org.springframework.util.Assert;
/**
@@ -41,6 +43,8 @@ public class TestContext extends AttributeAccessorSupport {
private final ContextCache contextCache;
+ private final CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate;
+
private final MergedContextConfiguration mergedContextConfiguration;
private final Class<?> testClass;
@@ -61,16 +65,17 @@ public class TestContext extends AttributeAccessorSupport {
}
/**
- * Construct a new test context for the supplied {@link Class test class}
- * and {@link ContextCache context cache} and parse the corresponding
- * {@link ContextConfiguration @ContextConfiguration} annotation, if
- * present.
+ * Construct a new test context for the supplied {@linkplain Class test class}
+ * and {@linkplain ContextCache context cache} and parse the corresponding
+ * {@link ContextConfiguration @ContextConfiguration} or
+ * {@link ContextHierarchy @ContextHierarchy} annotation, if present.
* <p>If the supplied class name for the default {@code ContextLoader}
* is {@code null} or <em>empty</em> and no concrete {@code ContextLoader}
- * class is explicitly supplied via the {@code @ContextConfiguration}
- * annotation, a
+ * class is explicitly supplied via {@code @ContextConfiguration}, a
* {@link org.springframework.test.context.support.DelegatingSmartContextLoader
- * DelegatingSmartContextLoader} will be used instead.
+ * DelegatingSmartContextLoader} or
+ * {@link org.springframework.test.context.web.WebDelegatingSmartContextLoader
+ * WebDelegatingSmartContextLoader} will be used instead.
* @param testClass the test class for which the test context should be
* constructed (must not be {@code null})
* @param contextCache the context cache from which the constructed test
@@ -83,54 +88,27 @@ public class TestContext extends AttributeAccessorSupport {
Assert.notNull(testClass, "Test class must not be null");
Assert.notNull(contextCache, "ContextCache must not be null");
+ this.testClass = testClass;
+ this.contextCache = contextCache;
+ this.cacheAwareContextLoaderDelegate = new CacheAwareContextLoaderDelegate(contextCache);
+
MergedContextConfiguration mergedContextConfiguration;
- ContextConfiguration contextConfiguration = testClass.getAnnotation(ContextConfiguration.class);
- if (contextConfiguration == null) {
- if (logger.isInfoEnabled()) {
- logger.info(String.format("@ContextConfiguration not found for class [%s]", testClass));
- }
- mergedContextConfiguration = new MergedContextConfiguration(testClass, null, null, null, null);
+ if (testClass.isAnnotationPresent(ContextConfiguration.class)
+ || testClass.isAnnotationPresent(ContextHierarchy.class)) {
+ mergedContextConfiguration = ContextLoaderUtils.buildMergedContextConfiguration(testClass,
+ defaultContextLoaderClassName, cacheAwareContextLoaderDelegate);
}
else {
- if (logger.isTraceEnabled()) {
- logger.trace(String.format("Retrieved @ContextConfiguration [%s] for class [%s]", contextConfiguration,
- testClass));
+ if (logger.isInfoEnabled()) {
+ logger.info(String.format(
+ "Neither @ContextConfiguration nor @ContextHierarchy found for test class [%s]",
+ testClass.getName()));
}
- mergedContextConfiguration = ContextLoaderUtils.buildMergedContextConfiguration(testClass,
- defaultContextLoaderClassName);
+ mergedContextConfiguration = new MergedContextConfiguration(testClass, null, null, null, null);
}
- this.contextCache = contextCache;
this.mergedContextConfiguration = mergedContextConfiguration;
- this.testClass = testClass;
- }
-
- /**
- * Load an {@code ApplicationContext} for this test context using the
- * configured {@code ContextLoader} and merged context configuration. Supports
- * both the {@link SmartContextLoader} and {@link ContextLoader} SPIs.
- * @throws Exception if an error occurs while loading the application context
- */
- private ApplicationContext loadApplicationContext() throws Exception {
- ContextLoader contextLoader = mergedContextConfiguration.getContextLoader();
- Assert.notNull(contextLoader, "Cannot load an ApplicationContext with a NULL 'contextLoader'. "
- + "Consider annotating your test class with @ContextConfiguration.");
-
- ApplicationContext applicationContext;
-
- if (contextLoader instanceof SmartContextLoader) {
- SmartContextLoader smartContextLoader = (SmartContextLoader) contextLoader;
- applicationContext = smartContextLoader.loadContext(mergedContextConfiguration);
- }
- else {
- String[] locations = mergedContextConfiguration.getLocations();
- Assert.notNull(locations, "Cannot load an ApplicationContext with a NULL 'locations' array. "
- + "Consider annotating your test class with @ContextConfiguration.");
- applicationContext = contextLoader.loadContext(locations);
- }
-
- return applicationContext;
}
/**
@@ -141,31 +119,7 @@ private ApplicationContext loadApplicationContext() throws Exception {
* application context
*/
public ApplicationContext getApplicationContext() {
- synchronized (contextCache) {
- ApplicationContext context = contextCache.get(mergedContextConfiguration);
- if (context == null) {
- try {
- context = loadApplicationContext();
- if (logger.isDebugEnabled()) {
- logger.debug(String.format(
- "Storing ApplicationContext for test class [%s] in cache under key [%s].", testClass,
- mergedContextConfiguration));
- }
- contextCache.put(mergedContextConfiguration, context);
- }
- catch (Exception ex) {
- throw new IllegalStateException("Failed to load ApplicationContext", ex);
- }
- }
- else {
- if (logger.isDebugEnabled()) {
- logger.debug(String.format(
- "Retrieved ApplicationContext for test class [%s] from cache with key [%s].", testClass,
- mergedContextConfiguration));
- }
- }
- return context;
- }
+ return cacheAwareContextLoaderDelegate.loadContext(mergedContextConfiguration);
}
/**
@@ -209,15 +163,27 @@ public final Throwable getTestException() {
}
/**
- * Call this method to signal that the {@link ApplicationContext application
- * context} associated with this test context is <em>dirty</em> and should
- * be reloaded. Do this if a test has modified the context (for example, by
- * replacing a bean definition).
+ * Call this method to signal that the {@linkplain ApplicationContext application
+ * context} associated with this test context is <em>dirty</em> and should be
+ * discarded. Do this if a test has modified the context — for example,
+ * by replacing a bean definition or modifying the state of a singleton bean.
+ * @deprecated As of Spring 3.2.2, use {@link #markApplicationContextDirty(HierarchyMode)} instead.
*/
+ @Deprecated
public void markApplicationContextDirty() {
- synchronized (contextCache) {
- contextCache.setDirty(mergedContextConfiguration);
- }
+ markApplicationContextDirty((HierarchyMode) null);
+ }
+
+ /**
+ * Call this method to signal that the {@linkplain ApplicationContext application
+ * context} associated with this test context is <em>dirty</em> and should be
+ * discarded. Do this if a test has modified the context — for example,
+ * by replacing a bean definition or modifying the state of a singleton bean.
+ * @param hierarchyMode the context cache clearing mode to be applied if the
+ * context is part of a hierarchy (may be {@code null})
+ */
+ public void markApplicationContextDirty(HierarchyMode hierarchyMode) {
+ contextCache.remove(mergedContextConfiguration, hierarchyMode);
}
/** | true |
Other | spring-projects | spring-framework | 98074e776262292a9d6fa8d164e6718c5876ed6f.json | Provide support for context hierarchies in the TCF
Prior to this commit the Spring TestContext Framework supported creating
only flat, non-hierarchical contexts. There was no easy way to create
contexts with parent-child relationships.
This commit addresses this issue by introducing a new @ContextHierarchy
annotation that can be used in conjunction with @ContextConfiguration
for declaring hierarchies of application contexts, either within a
single test class or within a test class hierarchy. In addition,
@DirtiesContext now supports a new 'hierarchyMode' attribute for
controlling context cache clearing for context hierarchies.
- Introduced a new @ContextHierarchy annotation.
- Introduced 'name' attribute in @ContextConfiguration.
- Introduced 'name' property in ContextConfigurationAttributes.
- TestContext is now aware of @ContextHierarchy in addition to
@ContextConfiguration.
- Introduced findAnnotationDeclaringClassForTypes() in AnnotationUtils.
- Introduced resolveContextHierarchyAttributes() in ContextLoaderUtils.
- Introduced buildContextHierarchyMap() in ContextLoaderUtils.
- @ContextConfiguration and @ContextHierarchy may not be used as
top-level, class-level annotations simultaneously.
- Introduced reference to the parent configuration in
MergedContextConfiguration and WebMergedContextConfiguration.
- Introduced overloaded buildMergedContextConfiguration() methods in
ContextLoaderUtils in order to handle context hierarchies separately
from conventional, non-hierarchical contexts.
- Introduced hashCode() and equals() in ContextConfigurationAttributes.
- ContextLoaderUtils ensures uniqueness of @ContextConfiguration
elements within a single @ContextHierarchy declaration.
- Introduced CacheAwareContextLoaderDelegate that can be used for
loading contexts with transparent support for interacting with the
context cache -- for example, for retrieving the parent application
context in a context hierarchy.
- TestContext now delegates to CacheAwareContextLoaderDelegate for
loading contexts.
- Introduced getParentApplicationContext() in MergedContextConfiguration
- The loadContext(MergedContextConfiguration) methods in
AbstractGenericContextLoader and AbstractGenericWebContextLoader now
set the parent context as appropriate.
- Introduced 'hierarchyMode' attribute in @DirtiesContext with a
corresponding HierarchyMode enum that defines EXHAUSTIVE and
CURRENT_LEVEL cache removal modes.
- ContextCache now internally tracks the relationships between contexts
that make up a context hierarchy. Furthermore, when a context is
removed, if it is part of a context hierarchy all corresponding
contexts will be removed from the cache according to the supplied
HierarchyMode.
- AbstractGenericWebContextLoader will set a loaded context as the
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE in the MockServletContext when
context hierarchies are used if the context has no parent or if the
context has a parent that is not a WAC.
- Where appropriate, updated Javadoc to refer to the
ServletTestExecutionListener, which was introduced in 3.2.0.
- Updated Javadoc to avoid and/or suppress warnings in spring-test.
- Suppressed remaining warnings in code in spring-test.
Issue: SPR-5613, SPR-9863 | spring-test/src/main/java/org/springframework/test/context/TestContextManager.java | @@ -104,15 +104,14 @@ public TestContextManager(Class<?> testClass) {
}
/**
- * Constructs a new {@code TestContextManager} for the specified {@link Class test class}
- * and automatically {@link #registerTestExecutionListeners registers} the
+ * Constructs a new {@code TestContextManager} for the specified {@linkplain Class
+ * test class} and automatically {@link #registerTestExecutionListeners registers} the
* {@link TestExecutionListener TestExecutionListeners} configured for the test class
* via the {@link TestExecutionListeners @TestExecutionListeners} annotation.
* @param testClass the test class to be managed
- * @param defaultContextLoaderClassName the name of the default
- * {@code ContextLoader} class to use (may be {@code null})
+ * @param defaultContextLoaderClassName the name of the default {@code ContextLoader}
+ * class to use (may be {@code null})
* @see #registerTestExecutionListeners(TestExecutionListener...)
- * @see #retrieveTestExecutionListeners(Class)
*/
public TestContextManager(Class<?> testClass, String defaultContextLoaderClassName) {
this.testContext = new TestContext(testClass, contextCache, defaultContextLoaderClassName); | true |
Other | spring-projects | spring-framework | 98074e776262292a9d6fa8d164e6718c5876ed6f.json | Provide support for context hierarchies in the TCF
Prior to this commit the Spring TestContext Framework supported creating
only flat, non-hierarchical contexts. There was no easy way to create
contexts with parent-child relationships.
This commit addresses this issue by introducing a new @ContextHierarchy
annotation that can be used in conjunction with @ContextConfiguration
for declaring hierarchies of application contexts, either within a
single test class or within a test class hierarchy. In addition,
@DirtiesContext now supports a new 'hierarchyMode' attribute for
controlling context cache clearing for context hierarchies.
- Introduced a new @ContextHierarchy annotation.
- Introduced 'name' attribute in @ContextConfiguration.
- Introduced 'name' property in ContextConfigurationAttributes.
- TestContext is now aware of @ContextHierarchy in addition to
@ContextConfiguration.
- Introduced findAnnotationDeclaringClassForTypes() in AnnotationUtils.
- Introduced resolveContextHierarchyAttributes() in ContextLoaderUtils.
- Introduced buildContextHierarchyMap() in ContextLoaderUtils.
- @ContextConfiguration and @ContextHierarchy may not be used as
top-level, class-level annotations simultaneously.
- Introduced reference to the parent configuration in
MergedContextConfiguration and WebMergedContextConfiguration.
- Introduced overloaded buildMergedContextConfiguration() methods in
ContextLoaderUtils in order to handle context hierarchies separately
from conventional, non-hierarchical contexts.
- Introduced hashCode() and equals() in ContextConfigurationAttributes.
- ContextLoaderUtils ensures uniqueness of @ContextConfiguration
elements within a single @ContextHierarchy declaration.
- Introduced CacheAwareContextLoaderDelegate that can be used for
loading contexts with transparent support for interacting with the
context cache -- for example, for retrieving the parent application
context in a context hierarchy.
- TestContext now delegates to CacheAwareContextLoaderDelegate for
loading contexts.
- Introduced getParentApplicationContext() in MergedContextConfiguration
- The loadContext(MergedContextConfiguration) methods in
AbstractGenericContextLoader and AbstractGenericWebContextLoader now
set the parent context as appropriate.
- Introduced 'hierarchyMode' attribute in @DirtiesContext with a
corresponding HierarchyMode enum that defines EXHAUSTIVE and
CURRENT_LEVEL cache removal modes.
- ContextCache now internally tracks the relationships between contexts
that make up a context hierarchy. Furthermore, when a context is
removed, if it is part of a context hierarchy all corresponding
contexts will be removed from the cache according to the supplied
HierarchyMode.
- AbstractGenericWebContextLoader will set a loaded context as the
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE in the MockServletContext when
context hierarchies are used if the context has no parent or if the
context has a parent that is not a WAC.
- Where appropriate, updated Javadoc to refer to the
ServletTestExecutionListener, which was introduced in 3.2.0.
- Updated Javadoc to avoid and/or suppress warnings in spring-test.
- Suppressed remaining warnings in code in spring-test.
Issue: SPR-5613, SPR-9863 | spring-test/src/main/java/org/springframework/test/context/TestExecutionListener.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,29 +17,24 @@
package org.springframework.test.context;
/**
+ * {@code TestExecutionListener} defines a <em>listener</em> API for reacting to
+ * test execution events published by the {@link TestContextManager} with which
+ * the listener is registered.
* <p>
- * {@code TestExecutionListener} defines a <em>listener</em> API for
- * reacting to test execution events published by the {@link TestContextManager}
- * with which the listener is registered.
- * </p>
- * <p>
- * Concrete implementations must provide a {@code public} no-args
- * constructor, so that listeners can be instantiated transparently by tools and
- * configuration mechanisms.
- * </p>
+ * Concrete implementations must provide a {@code public} no-args constructor,
+ * so that listeners can be instantiated transparently by tools and configuration
+ * mechanisms.
* <p>
* Spring provides the following out-of-the-box implementations:
- * </p>
* <ul>
- * <li>
- * {@link org.springframework.test.context.support.DependencyInjectionTestExecutionListener
+ * <li>{@link org.springframework.test.context.support.DependencyInjectionTestExecutionListener
* DependencyInjectionTestExecutionListener}</li>
- * <li>
- * {@link org.springframework.test.context.support.DirtiesContextTestExecutionListener
+ * <li>{@link org.springframework.test.context.support.DirtiesContextTestExecutionListener
* DirtiesContextTestExecutionListener}</li>
- * <li>
- * {@link org.springframework.test.context.transaction.TransactionalTestExecutionListener
+ * <li>{@link org.springframework.test.context.transaction.TransactionalTestExecutionListener
* TransactionalTestExecutionListener}</li>
+ * <li>{@link org.springframework.test.context.web.ServletTestExecutionListener
+ * ServletTestExecutionListener}</li>
* </ul>
*
* @author Sam Brannen | true |
Other | spring-projects | spring-framework | 98074e776262292a9d6fa8d164e6718c5876ed6f.json | Provide support for context hierarchies in the TCF
Prior to this commit the Spring TestContext Framework supported creating
only flat, non-hierarchical contexts. There was no easy way to create
contexts with parent-child relationships.
This commit addresses this issue by introducing a new @ContextHierarchy
annotation that can be used in conjunction with @ContextConfiguration
for declaring hierarchies of application contexts, either within a
single test class or within a test class hierarchy. In addition,
@DirtiesContext now supports a new 'hierarchyMode' attribute for
controlling context cache clearing for context hierarchies.
- Introduced a new @ContextHierarchy annotation.
- Introduced 'name' attribute in @ContextConfiguration.
- Introduced 'name' property in ContextConfigurationAttributes.
- TestContext is now aware of @ContextHierarchy in addition to
@ContextConfiguration.
- Introduced findAnnotationDeclaringClassForTypes() in AnnotationUtils.
- Introduced resolveContextHierarchyAttributes() in ContextLoaderUtils.
- Introduced buildContextHierarchyMap() in ContextLoaderUtils.
- @ContextConfiguration and @ContextHierarchy may not be used as
top-level, class-level annotations simultaneously.
- Introduced reference to the parent configuration in
MergedContextConfiguration and WebMergedContextConfiguration.
- Introduced overloaded buildMergedContextConfiguration() methods in
ContextLoaderUtils in order to handle context hierarchies separately
from conventional, non-hierarchical contexts.
- Introduced hashCode() and equals() in ContextConfigurationAttributes.
- ContextLoaderUtils ensures uniqueness of @ContextConfiguration
elements within a single @ContextHierarchy declaration.
- Introduced CacheAwareContextLoaderDelegate that can be used for
loading contexts with transparent support for interacting with the
context cache -- for example, for retrieving the parent application
context in a context hierarchy.
- TestContext now delegates to CacheAwareContextLoaderDelegate for
loading contexts.
- Introduced getParentApplicationContext() in MergedContextConfiguration
- The loadContext(MergedContextConfiguration) methods in
AbstractGenericContextLoader and AbstractGenericWebContextLoader now
set the parent context as appropriate.
- Introduced 'hierarchyMode' attribute in @DirtiesContext with a
corresponding HierarchyMode enum that defines EXHAUSTIVE and
CURRENT_LEVEL cache removal modes.
- ContextCache now internally tracks the relationships between contexts
that make up a context hierarchy. Furthermore, when a context is
removed, if it is part of a context hierarchy all corresponding
contexts will be removed from the cache according to the supplied
HierarchyMode.
- AbstractGenericWebContextLoader will set a loaded context as the
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE in the MockServletContext when
context hierarchies are used if the context has no parent or if the
context has a parent that is not a WAC.
- Where appropriate, updated Javadoc to refer to the
ServletTestExecutionListener, which was introduced in 3.2.0.
- Updated Javadoc to avoid and/or suppress warnings in spring-test.
- Suppressed remaining warnings in code in spring-test.
Issue: SPR-5613, SPR-9863 | spring-test/src/main/java/org/springframework/test/context/TestExecutionListeners.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,9 +26,10 @@
/**
* {@code TestExecutionListeners} defines class-level metadata for
* configuring which {@link TestExecutionListener TestExecutionListeners} should
- * be registered with a {@link TestContextManager}. Typically,
- * {@code @TestExecutionListeners} will be used in conjunction with
- * {@link ContextConfiguration @ContextConfiguration}.
+ * be registered with a {@link TestContextManager}.
+ *
+ * <p>Typically, {@code @TestExecutionListeners} will be used in conjunction with
+ * {@link ContextConfiguration @ContextConfiguration}.
*
* @author Sam Brannen
* @since 2.5
@@ -43,11 +44,10 @@
public @interface TestExecutionListeners {
/**
- * <p>
* The {@link TestExecutionListener TestExecutionListeners} to register with
* a {@link TestContextManager}.
- * </p>
*
+ * @see org.springframework.test.context.web.ServletTestExecutionListener
* @see org.springframework.test.context.support.DependencyInjectionTestExecutionListener
* @see org.springframework.test.context.support.DirtiesContextTestExecutionListener
* @see org.springframework.test.context.transaction.TransactionalTestExecutionListener
@@ -60,10 +60,8 @@
Class<? extends TestExecutionListener>[] value() default {};
/**
- * <p>
* Whether or not {@link #value() TestExecutionListeners} from superclasses
* should be <em>inherited</em>.
- * </p>
* <p>
* The default value is {@code true}, which means that an annotated
* class will <em>inherit</em> the listeners defined by an annotated
@@ -77,26 +75,25 @@
* {@code DependencyInjectionTestExecutionListener},
* {@code DirtiesContextTestExecutionListener}, <strong>and</strong>
* {@code TransactionalTestExecutionListener}, in that order.
- * </p>
*
* <pre class="code">
- * @TestExecutionListeners({ DependencyInjectionTestExecutionListener.class,
- * DirtiesContextTestExecutionListener.class })
+ * @TestExecutionListeners({
+ * DependencyInjectionTestExecutionListener.class,
+ * DirtiesContextTestExecutionListener.class
+ * })
* public abstract class AbstractBaseTest {
* // ...
* }
*
* @TestExecutionListeners(TransactionalTestExecutionListener.class)
* public class TransactionalTest extends AbstractBaseTest {
* // ...
- * }
- * </pre>
+ * }</pre>
*
* <p>
- * If {@code inheritListeners} is set to {@code false}, the
- * listeners for the annotated class will <em>shadow</em> and effectively
- * replace any listeners defined by a superclass.
- * </p>
+ * If {@code inheritListeners} is set to {@code false}, the listeners for the
+ * annotated class will <em>shadow</em> and effectively replace any listeners
+ * defined by a superclass.
*/
boolean inheritListeners() default true;
| true |
Other | spring-projects | spring-framework | 98074e776262292a9d6fa8d164e6718c5876ed6f.json | Provide support for context hierarchies in the TCF
Prior to this commit the Spring TestContext Framework supported creating
only flat, non-hierarchical contexts. There was no easy way to create
contexts with parent-child relationships.
This commit addresses this issue by introducing a new @ContextHierarchy
annotation that can be used in conjunction with @ContextConfiguration
for declaring hierarchies of application contexts, either within a
single test class or within a test class hierarchy. In addition,
@DirtiesContext now supports a new 'hierarchyMode' attribute for
controlling context cache clearing for context hierarchies.
- Introduced a new @ContextHierarchy annotation.
- Introduced 'name' attribute in @ContextConfiguration.
- Introduced 'name' property in ContextConfigurationAttributes.
- TestContext is now aware of @ContextHierarchy in addition to
@ContextConfiguration.
- Introduced findAnnotationDeclaringClassForTypes() in AnnotationUtils.
- Introduced resolveContextHierarchyAttributes() in ContextLoaderUtils.
- Introduced buildContextHierarchyMap() in ContextLoaderUtils.
- @ContextConfiguration and @ContextHierarchy may not be used as
top-level, class-level annotations simultaneously.
- Introduced reference to the parent configuration in
MergedContextConfiguration and WebMergedContextConfiguration.
- Introduced overloaded buildMergedContextConfiguration() methods in
ContextLoaderUtils in order to handle context hierarchies separately
from conventional, non-hierarchical contexts.
- Introduced hashCode() and equals() in ContextConfigurationAttributes.
- ContextLoaderUtils ensures uniqueness of @ContextConfiguration
elements within a single @ContextHierarchy declaration.
- Introduced CacheAwareContextLoaderDelegate that can be used for
loading contexts with transparent support for interacting with the
context cache -- for example, for retrieving the parent application
context in a context hierarchy.
- TestContext now delegates to CacheAwareContextLoaderDelegate for
loading contexts.
- Introduced getParentApplicationContext() in MergedContextConfiguration
- The loadContext(MergedContextConfiguration) methods in
AbstractGenericContextLoader and AbstractGenericWebContextLoader now
set the parent context as appropriate.
- Introduced 'hierarchyMode' attribute in @DirtiesContext with a
corresponding HierarchyMode enum that defines EXHAUSTIVE and
CURRENT_LEVEL cache removal modes.
- ContextCache now internally tracks the relationships between contexts
that make up a context hierarchy. Furthermore, when a context is
removed, if it is part of a context hierarchy all corresponding
contexts will be removed from the cache according to the supplied
HierarchyMode.
- AbstractGenericWebContextLoader will set a loaded context as the
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE in the MockServletContext when
context hierarchies are used if the context has no parent or if the
context has a parent that is not a WAC.
- Where appropriate, updated Javadoc to refer to the
ServletTestExecutionListener, which was introduced in 3.2.0.
- Updated Javadoc to avoid and/or suppress warnings in spring-test.
- Suppressed remaining warnings in code in spring-test.
Issue: SPR-5613, SPR-9863 | spring-test/src/main/java/org/springframework/test/context/support/AbstractGenericContextLoader.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,10 +16,13 @@
package org.springframework.test.context.support;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+
import org.springframework.beans.factory.support.BeanDefinitionReader;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
+import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigUtils;
import org.springframework.context.support.GenericApplicationContext;
@@ -66,6 +69,12 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader
*
* <ul>
* <li>Creates a {@link GenericApplicationContext} instance.</li>
+ * <li>If the supplied {@code MergedContextConfiguration} references a
+ * {@linkplain MergedContextConfiguration#getParent() parent configuration},
+ * the corresponding {@link MergedContextConfiguration#getParentApplicationContext()
+ * ApplicationContext} will be retrieved and
+ * {@linkplain GenericApplicationContext#setParent(ApplicationContext) set as the parent}
+ * for the context created by this method.</li>
* <li>Calls {@link #prepareContext(GenericApplicationContext)} for backwards
* compatibility with the {@link org.springframework.test.context.ContextLoader
* ContextLoader} SPI.</li>
@@ -97,6 +106,11 @@ public final ConfigurableApplicationContext loadContext(MergedContextConfigurati
}
GenericApplicationContext context = new GenericApplicationContext();
+
+ ApplicationContext parent = mergedConfig.getParentApplicationContext();
+ if (parent != null) {
+ context.setParent(parent);
+ }
prepareContext(context);
prepareContext(context, mergedConfig);
customizeBeanFactory(context.getDefaultListableBeanFactory()); | true |
Other | spring-projects | spring-framework | 98074e776262292a9d6fa8d164e6718c5876ed6f.json | Provide support for context hierarchies in the TCF
Prior to this commit the Spring TestContext Framework supported creating
only flat, non-hierarchical contexts. There was no easy way to create
contexts with parent-child relationships.
This commit addresses this issue by introducing a new @ContextHierarchy
annotation that can be used in conjunction with @ContextConfiguration
for declaring hierarchies of application contexts, either within a
single test class or within a test class hierarchy. In addition,
@DirtiesContext now supports a new 'hierarchyMode' attribute for
controlling context cache clearing for context hierarchies.
- Introduced a new @ContextHierarchy annotation.
- Introduced 'name' attribute in @ContextConfiguration.
- Introduced 'name' property in ContextConfigurationAttributes.
- TestContext is now aware of @ContextHierarchy in addition to
@ContextConfiguration.
- Introduced findAnnotationDeclaringClassForTypes() in AnnotationUtils.
- Introduced resolveContextHierarchyAttributes() in ContextLoaderUtils.
- Introduced buildContextHierarchyMap() in ContextLoaderUtils.
- @ContextConfiguration and @ContextHierarchy may not be used as
top-level, class-level annotations simultaneously.
- Introduced reference to the parent configuration in
MergedContextConfiguration and WebMergedContextConfiguration.
- Introduced overloaded buildMergedContextConfiguration() methods in
ContextLoaderUtils in order to handle context hierarchies separately
from conventional, non-hierarchical contexts.
- Introduced hashCode() and equals() in ContextConfigurationAttributes.
- ContextLoaderUtils ensures uniqueness of @ContextConfiguration
elements within a single @ContextHierarchy declaration.
- Introduced CacheAwareContextLoaderDelegate that can be used for
loading contexts with transparent support for interacting with the
context cache -- for example, for retrieving the parent application
context in a context hierarchy.
- TestContext now delegates to CacheAwareContextLoaderDelegate for
loading contexts.
- Introduced getParentApplicationContext() in MergedContextConfiguration
- The loadContext(MergedContextConfiguration) methods in
AbstractGenericContextLoader and AbstractGenericWebContextLoader now
set the parent context as appropriate.
- Introduced 'hierarchyMode' attribute in @DirtiesContext with a
corresponding HierarchyMode enum that defines EXHAUSTIVE and
CURRENT_LEVEL cache removal modes.
- ContextCache now internally tracks the relationships between contexts
that make up a context hierarchy. Furthermore, when a context is
removed, if it is part of a context hierarchy all corresponding
contexts will be removed from the cache according to the supplied
HierarchyMode.
- AbstractGenericWebContextLoader will set a loaded context as the
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE in the MockServletContext when
context hierarchies are used if the context has no parent or if the
context has a parent that is not a WAC.
- Where appropriate, updated Javadoc to refer to the
ServletTestExecutionListener, which was introduced in 3.2.0.
- Updated Javadoc to avoid and/or suppress warnings in spring-test.
- Suppressed remaining warnings in code in spring-test.
Issue: SPR-5613, SPR-9863 | spring-test/src/main/java/org/springframework/test/context/support/DirtiesContextTestExecutionListener.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,6 +23,7 @@
import org.springframework.context.ApplicationContext;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
+import org.springframework.test.annotation.DirtiesContext.HierarchyMode;
import org.springframework.test.context.TestContext;
import org.springframework.util.Assert;
@@ -43,26 +44,47 @@ public class DirtiesContextTestExecutionListener extends AbstractTestExecutionLi
/**
- * Marks the {@link ApplicationContext application context} of the supplied
- * {@link TestContext test context} as
- * {@link TestContext#markApplicationContextDirty() dirty}, and sets the
+ * Marks the {@linkplain ApplicationContext application context} of the supplied
+ * {@linkplain TestContext test context} as
+ * {@linkplain TestContext#markApplicationContextDirty() dirty}, and sets the
* {@link DependencyInjectionTestExecutionListener#REINJECT_DEPENDENCIES_ATTRIBUTE
* REINJECT_DEPENDENCIES_ATTRIBUTE} in the test context to {@code true}.
+ * @param testContext the test context whose application context should
+ * marked as dirty
+ * @deprecated as of Spring 3.2.2, use {@link #dirtyContext(TestContext, HierarchyMode)} instead.
*/
+ @Deprecated
protected void dirtyContext(TestContext testContext) {
testContext.markApplicationContextDirty();
testContext.setAttribute(DependencyInjectionTestExecutionListener.REINJECT_DEPENDENCIES_ATTRIBUTE, Boolean.TRUE);
}
/**
- * If the current test method of the supplied {@link TestContext test
+ * Marks the {@linkplain ApplicationContext application context} of the supplied
+ * {@linkplain TestContext test context} as {@linkplain
+ * TestContext#markApplicationContextDirty(HierarchyMode) dirty} and sets the
+ * {@link DependencyInjectionTestExecutionListener#REINJECT_DEPENDENCIES_ATTRIBUTE
+ * REINJECT_DEPENDENCIES_ATTRIBUTE} in the test context to {@code true}.
+ * @param testContext the test context whose application context should
+ * marked as dirty
+ * @param hierarchyMode the context cache clearing mode to be applied if the
+ * context is part of a hierarchy; may be {@code null}
+ * @since 3.2.2
+ */
+ protected void dirtyContext(TestContext testContext, HierarchyMode hierarchyMode) {
+ testContext.markApplicationContextDirty(hierarchyMode);
+ testContext.setAttribute(DependencyInjectionTestExecutionListener.REINJECT_DEPENDENCIES_ATTRIBUTE, Boolean.TRUE);
+ }
+
+ /**
+ * If the current test method of the supplied {@linkplain TestContext test
* context} is annotated with {@link DirtiesContext @DirtiesContext},
* or if the test class is annotated with {@link DirtiesContext
- * @DirtiesContext} and the {@link DirtiesContext#classMode() class
+ * @DirtiesContext} and the {@linkplain DirtiesContext#classMode() class
* mode} is set to {@link ClassMode#AFTER_EACH_TEST_METHOD
- * AFTER_EACH_TEST_METHOD}, the {@link ApplicationContext application
+ * AFTER_EACH_TEST_METHOD}, the {@linkplain ApplicationContext application
* context} of the test context will be
- * {@link TestContext#markApplicationContextDirty() marked as dirty} and the
+ * {@linkplain TestContext#markApplicationContextDirty() marked as dirty} and the
* {@link DependencyInjectionTestExecutionListener#REINJECT_DEPENDENCIES_ATTRIBUTE
* REINJECT_DEPENDENCIES_ATTRIBUTE} in the test context will be set to
* {@code true}.
@@ -88,15 +110,17 @@ public void afterTestMethod(TestContext testContext) throws Exception {
}
if (methodDirtiesContext || (classDirtiesContext && classMode == ClassMode.AFTER_EACH_TEST_METHOD)) {
- dirtyContext(testContext);
+ HierarchyMode hierarchyMode = methodDirtiesContext ? testMethod.getAnnotation(annotationType).hierarchyMode()
+ : classDirtiesContextAnnotation.hierarchyMode();
+ dirtyContext(testContext, hierarchyMode);
}
}
/**
- * If the test class of the supplied {@link TestContext test context} is
+ * If the test class of the supplied {@linkplain TestContext test context} is
* annotated with {@link DirtiesContext @DirtiesContext}, the
- * {@link ApplicationContext application context} of the test context will
- * be {@link TestContext#markApplicationContextDirty() marked as dirty} ,
+ * {@linkplain ApplicationContext application context} of the test context will
+ * be {@linkplain TestContext#markApplicationContextDirty() marked as dirty} ,
* and the
* {@link DependencyInjectionTestExecutionListener#REINJECT_DEPENDENCIES_ATTRIBUTE
* REINJECT_DEPENDENCIES_ATTRIBUTE} in the test context will be set to
@@ -107,12 +131,15 @@ public void afterTestClass(TestContext testContext) throws Exception {
Class<?> testClass = testContext.getTestClass();
Assert.notNull(testClass, "The test class of the supplied TestContext must not be null");
- boolean dirtiesContext = testClass.isAnnotationPresent(DirtiesContext.class);
+ final Class<DirtiesContext> annotationType = DirtiesContext.class;
+
+ boolean dirtiesContext = testClass.isAnnotationPresent(annotationType);
if (logger.isDebugEnabled()) {
logger.debug("After test class: context [" + testContext + "], dirtiesContext [" + dirtiesContext + "].");
}
if (dirtiesContext) {
- dirtyContext(testContext);
+ HierarchyMode hierarchyMode = testClass.getAnnotation(annotationType).hierarchyMode();
+ dirtyContext(testContext, hierarchyMode);
}
}
| true |
Other | spring-projects | spring-framework | 98074e776262292a9d6fa8d164e6718c5876ed6f.json | Provide support for context hierarchies in the TCF
Prior to this commit the Spring TestContext Framework supported creating
only flat, non-hierarchical contexts. There was no easy way to create
contexts with parent-child relationships.
This commit addresses this issue by introducing a new @ContextHierarchy
annotation that can be used in conjunction with @ContextConfiguration
for declaring hierarchies of application contexts, either within a
single test class or within a test class hierarchy. In addition,
@DirtiesContext now supports a new 'hierarchyMode' attribute for
controlling context cache clearing for context hierarchies.
- Introduced a new @ContextHierarchy annotation.
- Introduced 'name' attribute in @ContextConfiguration.
- Introduced 'name' property in ContextConfigurationAttributes.
- TestContext is now aware of @ContextHierarchy in addition to
@ContextConfiguration.
- Introduced findAnnotationDeclaringClassForTypes() in AnnotationUtils.
- Introduced resolveContextHierarchyAttributes() in ContextLoaderUtils.
- Introduced buildContextHierarchyMap() in ContextLoaderUtils.
- @ContextConfiguration and @ContextHierarchy may not be used as
top-level, class-level annotations simultaneously.
- Introduced reference to the parent configuration in
MergedContextConfiguration and WebMergedContextConfiguration.
- Introduced overloaded buildMergedContextConfiguration() methods in
ContextLoaderUtils in order to handle context hierarchies separately
from conventional, non-hierarchical contexts.
- Introduced hashCode() and equals() in ContextConfigurationAttributes.
- ContextLoaderUtils ensures uniqueness of @ContextConfiguration
elements within a single @ContextHierarchy declaration.
- Introduced CacheAwareContextLoaderDelegate that can be used for
loading contexts with transparent support for interacting with the
context cache -- for example, for retrieving the parent application
context in a context hierarchy.
- TestContext now delegates to CacheAwareContextLoaderDelegate for
loading contexts.
- Introduced getParentApplicationContext() in MergedContextConfiguration
- The loadContext(MergedContextConfiguration) methods in
AbstractGenericContextLoader and AbstractGenericWebContextLoader now
set the parent context as appropriate.
- Introduced 'hierarchyMode' attribute in @DirtiesContext with a
corresponding HierarchyMode enum that defines EXHAUSTIVE and
CURRENT_LEVEL cache removal modes.
- ContextCache now internally tracks the relationships between contexts
that make up a context hierarchy. Furthermore, when a context is
removed, if it is part of a context hierarchy all corresponding
contexts will be removed from the cache according to the supplied
HierarchyMode.
- AbstractGenericWebContextLoader will set a loaded context as the
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE in the MockServletContext when
context hierarchies are used if the context has no parent or if the
context has a parent that is not a WAC.
- Where appropriate, updated Javadoc to refer to the
ServletTestExecutionListener, which was introduced in 3.2.0.
- Updated Javadoc to avoid and/or suppress warnings in spring-test.
- Suppressed remaining warnings in code in spring-test.
Issue: SPR-5613, SPR-9863 | spring-test/src/main/java/org/springframework/test/context/web/AbstractGenericWebContextLoader.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,6 +31,7 @@
import org.springframework.mock.web.MockServletContext;
import org.springframework.test.context.MergedContextConfiguration;
import org.springframework.test.context.support.AbstractContextLoader;
+import org.springframework.util.Assert;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.GenericWebApplicationContext;
@@ -71,6 +72,12 @@ public abstract class AbstractGenericWebContextLoader extends AbstractContextLoa
*
* <ul>
* <li>Creates a {@link GenericWebApplicationContext} instance.</li>
+ * <li>If the supplied {@code MergedContextConfiguration} references a
+ * {@linkplain MergedContextConfiguration#getParent() parent configuration},
+ * the corresponding {@link MergedContextConfiguration#getParentApplicationContext()
+ * ApplicationContext} will be retrieved and
+ * {@linkplain GenericWebApplicationContext#setParent(ApplicationContext) set as the parent}
+ * for the context created by this method.</li>
* <li>Delegates to {@link #configureWebResources} to create the
* {@link MockServletContext} and set it in the {@code WebApplicationContext}.</li>
* <li>Calls {@link #prepareContext} to allow for customizing the context
@@ -107,6 +114,11 @@ public final ConfigurableApplicationContext loadContext(MergedContextConfigurati
}
GenericWebApplicationContext context = new GenericWebApplicationContext();
+
+ ApplicationContext parent = mergedConfig.getParentApplicationContext();
+ if (parent != null) {
+ context.setParent(parent);
+ }
configureWebResources(context, webMergedConfig);
prepareContext(context, webMergedConfig);
customizeBeanFactory(context.getDefaultListableBeanFactory(), webMergedConfig);
@@ -119,9 +131,20 @@ public final ConfigurableApplicationContext loadContext(MergedContextConfigurati
}
/**
- * Configures web resources for the supplied web application context.
+ * Configures web resources for the supplied web application context (WAC).
*
- * <p>Implementation details:
+ * <h4>Implementation Details</h4>
+ *
+ * <p>If the supplied WAC has no parent or its parent is not a WAC, the
+ * supplied WAC will be configured as the Root WAC (see "<em>Root WAC
+ * Configuration</em>" below).
+ *
+ * <p>Otherwise the context hierarchy of the supplied WAC will be traversed
+ * to find the top-most WAC (i.e., the root); and the {@link ServletContext}
+ * of the Root WAC will be set as the {@code ServletContext} for the supplied
+ * WAC.
+ *
+ * <h4>Root WAC Configuration</h4>
*
* <ul>
* <li>The resource base path is retrieved from the supplied
@@ -146,13 +169,33 @@ public final ConfigurableApplicationContext loadContext(MergedContextConfigurati
protected void configureWebResources(GenericWebApplicationContext context,
WebMergedContextConfiguration webMergedConfig) {
- String resourceBasePath = webMergedConfig.getResourceBasePath();
- ResourceLoader resourceLoader = resourceBasePath.startsWith(ResourceLoader.CLASSPATH_URL_PREFIX) ? new DefaultResourceLoader()
- : new FileSystemResourceLoader();
+ ApplicationContext parent = context.getParent();
+
+ // if the WAC has no parent or the parent is not a WAC, set the WAC as
+ // the Root WAC:
+ if (parent == null || (!(parent instanceof WebApplicationContext))) {
+ String resourceBasePath = webMergedConfig.getResourceBasePath();
+ ResourceLoader resourceLoader = resourceBasePath.startsWith(ResourceLoader.CLASSPATH_URL_PREFIX) ? new DefaultResourceLoader()
+ : new FileSystemResourceLoader();
- ServletContext servletContext = new MockServletContext(resourceBasePath, resourceLoader);
- servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, context);
- context.setServletContext(servletContext);
+ ServletContext servletContext = new MockServletContext(resourceBasePath, resourceLoader);
+ servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, context);
+ context.setServletContext(servletContext);
+ }
+ else {
+ ServletContext servletContext = null;
+
+ // find the Root WAC
+ while (parent != null) {
+ if (parent instanceof WebApplicationContext && !(parent.getParent() instanceof WebApplicationContext)) {
+ servletContext = ((WebApplicationContext) parent).getServletContext();
+ break;
+ }
+ parent = parent.getParent();
+ }
+ Assert.state(servletContext != null, "Failed to find Root WebApplicationContext in the context hierarchy");
+ context.setServletContext(servletContext);
+ }
}
/** | true |
Other | spring-projects | spring-framework | 98074e776262292a9d6fa8d164e6718c5876ed6f.json | Provide support for context hierarchies in the TCF
Prior to this commit the Spring TestContext Framework supported creating
only flat, non-hierarchical contexts. There was no easy way to create
contexts with parent-child relationships.
This commit addresses this issue by introducing a new @ContextHierarchy
annotation that can be used in conjunction with @ContextConfiguration
for declaring hierarchies of application contexts, either within a
single test class or within a test class hierarchy. In addition,
@DirtiesContext now supports a new 'hierarchyMode' attribute for
controlling context cache clearing for context hierarchies.
- Introduced a new @ContextHierarchy annotation.
- Introduced 'name' attribute in @ContextConfiguration.
- Introduced 'name' property in ContextConfigurationAttributes.
- TestContext is now aware of @ContextHierarchy in addition to
@ContextConfiguration.
- Introduced findAnnotationDeclaringClassForTypes() in AnnotationUtils.
- Introduced resolveContextHierarchyAttributes() in ContextLoaderUtils.
- Introduced buildContextHierarchyMap() in ContextLoaderUtils.
- @ContextConfiguration and @ContextHierarchy may not be used as
top-level, class-level annotations simultaneously.
- Introduced reference to the parent configuration in
MergedContextConfiguration and WebMergedContextConfiguration.
- Introduced overloaded buildMergedContextConfiguration() methods in
ContextLoaderUtils in order to handle context hierarchies separately
from conventional, non-hierarchical contexts.
- Introduced hashCode() and equals() in ContextConfigurationAttributes.
- ContextLoaderUtils ensures uniqueness of @ContextConfiguration
elements within a single @ContextHierarchy declaration.
- Introduced CacheAwareContextLoaderDelegate that can be used for
loading contexts with transparent support for interacting with the
context cache -- for example, for retrieving the parent application
context in a context hierarchy.
- TestContext now delegates to CacheAwareContextLoaderDelegate for
loading contexts.
- Introduced getParentApplicationContext() in MergedContextConfiguration
- The loadContext(MergedContextConfiguration) methods in
AbstractGenericContextLoader and AbstractGenericWebContextLoader now
set the parent context as appropriate.
- Introduced 'hierarchyMode' attribute in @DirtiesContext with a
corresponding HierarchyMode enum that defines EXHAUSTIVE and
CURRENT_LEVEL cache removal modes.
- ContextCache now internally tracks the relationships between contexts
that make up a context hierarchy. Furthermore, when a context is
removed, if it is part of a context hierarchy all corresponding
contexts will be removed from the cache according to the supplied
HierarchyMode.
- AbstractGenericWebContextLoader will set a loaded context as the
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE in the MockServletContext when
context hierarchies are used if the context has no parent or if the
context has a parent that is not a WAC.
- Where appropriate, updated Javadoc to refer to the
ServletTestExecutionListener, which was introduced in 3.2.0.
- Updated Javadoc to avoid and/or suppress warnings in spring-test.
- Suppressed remaining warnings in code in spring-test.
Issue: SPR-5613, SPR-9863 | spring-test/src/main/java/org/springframework/test/context/web/ServletTestExecutionListener.java | @@ -69,6 +69,7 @@ public class ServletTestExecutionListener extends AbstractTestExecutionListener
* @see TestExecutionListener#prepareTestInstance(TestContext)
* @see #setUpRequestContextIfNecessary(TestContext)
*/
+ @SuppressWarnings("javadoc")
public void prepareTestInstance(TestContext testContext) throws Exception {
setUpRequestContextIfNecessary(testContext);
}
@@ -80,6 +81,7 @@ public void prepareTestInstance(TestContext testContext) throws Exception {
* @see TestExecutionListener#beforeTestMethod(TestContext)
* @see #setUpRequestContextIfNecessary(TestContext)
*/
+ @SuppressWarnings("javadoc")
public void beforeTestMethod(TestContext testContext) throws Exception {
setUpRequestContextIfNecessary(testContext);
} | true |
Other | spring-projects | spring-framework | 98074e776262292a9d6fa8d164e6718c5876ed6f.json | Provide support for context hierarchies in the TCF
Prior to this commit the Spring TestContext Framework supported creating
only flat, non-hierarchical contexts. There was no easy way to create
contexts with parent-child relationships.
This commit addresses this issue by introducing a new @ContextHierarchy
annotation that can be used in conjunction with @ContextConfiguration
for declaring hierarchies of application contexts, either within a
single test class or within a test class hierarchy. In addition,
@DirtiesContext now supports a new 'hierarchyMode' attribute for
controlling context cache clearing for context hierarchies.
- Introduced a new @ContextHierarchy annotation.
- Introduced 'name' attribute in @ContextConfiguration.
- Introduced 'name' property in ContextConfigurationAttributes.
- TestContext is now aware of @ContextHierarchy in addition to
@ContextConfiguration.
- Introduced findAnnotationDeclaringClassForTypes() in AnnotationUtils.
- Introduced resolveContextHierarchyAttributes() in ContextLoaderUtils.
- Introduced buildContextHierarchyMap() in ContextLoaderUtils.
- @ContextConfiguration and @ContextHierarchy may not be used as
top-level, class-level annotations simultaneously.
- Introduced reference to the parent configuration in
MergedContextConfiguration and WebMergedContextConfiguration.
- Introduced overloaded buildMergedContextConfiguration() methods in
ContextLoaderUtils in order to handle context hierarchies separately
from conventional, non-hierarchical contexts.
- Introduced hashCode() and equals() in ContextConfigurationAttributes.
- ContextLoaderUtils ensures uniqueness of @ContextConfiguration
elements within a single @ContextHierarchy declaration.
- Introduced CacheAwareContextLoaderDelegate that can be used for
loading contexts with transparent support for interacting with the
context cache -- for example, for retrieving the parent application
context in a context hierarchy.
- TestContext now delegates to CacheAwareContextLoaderDelegate for
loading contexts.
- Introduced getParentApplicationContext() in MergedContextConfiguration
- The loadContext(MergedContextConfiguration) methods in
AbstractGenericContextLoader and AbstractGenericWebContextLoader now
set the parent context as appropriate.
- Introduced 'hierarchyMode' attribute in @DirtiesContext with a
corresponding HierarchyMode enum that defines EXHAUSTIVE and
CURRENT_LEVEL cache removal modes.
- ContextCache now internally tracks the relationships between contexts
that make up a context hierarchy. Furthermore, when a context is
removed, if it is part of a context hierarchy all corresponding
contexts will be removed from the cache according to the supplied
HierarchyMode.
- AbstractGenericWebContextLoader will set a loaded context as the
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE in the MockServletContext when
context hierarchies are used if the context has no parent or if the
context has a parent that is not a WAC.
- Where appropriate, updated Javadoc to refer to the
ServletTestExecutionListener, which was introduced in 3.2.0.
- Updated Javadoc to avoid and/or suppress warnings in spring-test.
- Suppressed remaining warnings in code in spring-test.
Issue: SPR-5613, SPR-9863 | spring-test/src/main/java/org/springframework/test/context/web/WebMergedContextConfiguration.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.style.ToStringCreator;
+import org.springframework.test.context.CacheAwareContextLoaderDelegate;
import org.springframework.test.context.ContextLoader;
import org.springframework.test.context.MergedContextConfiguration;
import org.springframework.util.ObjectUtils;
@@ -77,15 +78,57 @@ public class WebMergedContextConfiguration extends MergedContextConfiguration {
* @param activeProfiles the merged active bean definition profiles
* @param resourceBasePath the resource path to the root directory of the web application
* @param contextLoader the resolved {@code ContextLoader}
+ * @see #WebMergedContextConfiguration(Class, String[], Class[], Set, String[], String, ContextLoader, CacheAwareContextLoaderDelegate, MergedContextConfiguration)
+ * @deprecated as of Spring 3.2.2, use
+ * {@link #WebMergedContextConfiguration(Class, String[], Class[], Set, String[], String, ContextLoader, CacheAwareContextLoaderDelegate, MergedContextConfiguration)} instead.
*/
+ @Deprecated
public WebMergedContextConfiguration(
Class<?> testClass,
String[] locations,
Class<?>[] classes,
Set<Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>> contextInitializerClasses,
String[] activeProfiles, String resourceBasePath, ContextLoader contextLoader) {
- super(testClass, locations, classes, contextInitializerClasses, activeProfiles, contextLoader);
+ this(testClass, locations, classes, contextInitializerClasses, activeProfiles, resourceBasePath, contextLoader,
+ null, null);
+ }
+
+ /**
+ * Create a new {@code WebMergedContextConfiguration} instance for the
+ * supplied test class, resource locations, annotated classes, context
+ * initializers, active profiles, resource base path, and {@code ContextLoader}.
+ *
+ * <p>If a {@code null} value is supplied for {@code locations},
+ * {@code classes}, or {@code activeProfiles} an empty array will
+ * be stored instead. If a {@code null} value is supplied for the
+ * {@code contextInitializerClasses} an empty set will be stored instead.
+ * If an <em>empty</em> value is supplied for the {@code resourceBasePath}
+ * an empty string will be used. Furthermore, active profiles will be sorted,
+ * and duplicate 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 annotated classes
+ * @param contextInitializerClasses the merged context initializer classes
+ * @param activeProfiles the merged active bean definition profiles
+ * @param resourceBasePath the resource path to the root directory of the web application
+ * @param contextLoader the resolved {@code ContextLoader}
+ * @param cacheAwareContextLoaderDelegate a cache-aware context loader
+ * delegate with which to retrieve the parent context
+ * @param parent the parent configuration or {@code null} if there is no parent
+ * @since 3.2.2
+ */
+ public WebMergedContextConfiguration(
+ Class<?> testClass,
+ String[] locations,
+ Class<?>[] classes,
+ Set<Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>> contextInitializerClasses,
+ String[] activeProfiles, String resourceBasePath, ContextLoader contextLoader,
+ CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate, MergedContextConfiguration parent) {
+
+ super(testClass, locations, classes, contextInitializerClasses, activeProfiles, contextLoader,
+ cacheAwareContextLoaderDelegate, parent);
this.resourceBasePath = !StringUtils.hasText(resourceBasePath) ? "" : resourceBasePath;
}
@@ -118,8 +161,9 @@ public int hashCode() {
* {@linkplain #getClasses() annotated classes},
* {@linkplain #getContextInitializerClasses() context initializer classes},
* {@linkplain #getActiveProfiles() active profiles},
- * {@linkplain #getResourceBasePath() resource base path}, and the fully
- * qualified names of their {@link #getContextLoader() ContextLoaders}.
+ * {@linkplain #getResourceBasePath() resource base path},
+ * {@linkplain #getParent() parents}, and the fully qualified names of their
+ * {@link #getContextLoader() ContextLoaders}.
*/
@Override
public boolean equals(Object obj) {
@@ -141,8 +185,9 @@ public boolean equals(Object obj) {
* {@linkplain #getLocations() locations}, {@linkplain #getClasses() annotated classes},
* {@linkplain #getContextInitializerClasses() context initializer classes},
* {@linkplain #getActiveProfiles() active profiles},
- * {@linkplain #getResourceBasePath() resource base path}, and the name of the
- * {@link #getContextLoader() ContextLoader}.
+ * {@linkplain #getResourceBasePath() resource base path}, the name of the
+ * {@link #getContextLoader() ContextLoader}, and the
+ * {@linkplain #getParent() parent configuration}.
*/
@Override
public String toString() {
@@ -154,6 +199,7 @@ public String toString() {
.append("activeProfiles", ObjectUtils.nullSafeToString(getActiveProfiles()))//
.append("resourceBasePath", getResourceBasePath())//
.append("contextLoader", nullSafeToString(getContextLoader()))//
+ .append("parent", getParent())//
.toString();
}
| true |
Other | spring-projects | spring-framework | 98074e776262292a9d6fa8d164e6718c5876ed6f.json | Provide support for context hierarchies in the TCF
Prior to this commit the Spring TestContext Framework supported creating
only flat, non-hierarchical contexts. There was no easy way to create
contexts with parent-child relationships.
This commit addresses this issue by introducing a new @ContextHierarchy
annotation that can be used in conjunction with @ContextConfiguration
for declaring hierarchies of application contexts, either within a
single test class or within a test class hierarchy. In addition,
@DirtiesContext now supports a new 'hierarchyMode' attribute for
controlling context cache clearing for context hierarchies.
- Introduced a new @ContextHierarchy annotation.
- Introduced 'name' attribute in @ContextConfiguration.
- Introduced 'name' property in ContextConfigurationAttributes.
- TestContext is now aware of @ContextHierarchy in addition to
@ContextConfiguration.
- Introduced findAnnotationDeclaringClassForTypes() in AnnotationUtils.
- Introduced resolveContextHierarchyAttributes() in ContextLoaderUtils.
- Introduced buildContextHierarchyMap() in ContextLoaderUtils.
- @ContextConfiguration and @ContextHierarchy may not be used as
top-level, class-level annotations simultaneously.
- Introduced reference to the parent configuration in
MergedContextConfiguration and WebMergedContextConfiguration.
- Introduced overloaded buildMergedContextConfiguration() methods in
ContextLoaderUtils in order to handle context hierarchies separately
from conventional, non-hierarchical contexts.
- Introduced hashCode() and equals() in ContextConfigurationAttributes.
- ContextLoaderUtils ensures uniqueness of @ContextConfiguration
elements within a single @ContextHierarchy declaration.
- Introduced CacheAwareContextLoaderDelegate that can be used for
loading contexts with transparent support for interacting with the
context cache -- for example, for retrieving the parent application
context in a context hierarchy.
- TestContext now delegates to CacheAwareContextLoaderDelegate for
loading contexts.
- Introduced getParentApplicationContext() in MergedContextConfiguration
- The loadContext(MergedContextConfiguration) methods in
AbstractGenericContextLoader and AbstractGenericWebContextLoader now
set the parent context as appropriate.
- Introduced 'hierarchyMode' attribute in @DirtiesContext with a
corresponding HierarchyMode enum that defines EXHAUSTIVE and
CURRENT_LEVEL cache removal modes.
- ContextCache now internally tracks the relationships between contexts
that make up a context hierarchy. Furthermore, when a context is
removed, if it is part of a context hierarchy all corresponding
contexts will be removed from the cache according to the supplied
HierarchyMode.
- AbstractGenericWebContextLoader will set a loaded context as the
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE in the MockServletContext when
context hierarchies are used if the context has no parent or if the
context has a parent that is not a WAC.
- Where appropriate, updated Javadoc to refer to the
ServletTestExecutionListener, which was introduced in 3.2.0.
- Updated Javadoc to avoid and/or suppress warnings in spring-test.
- Suppressed remaining warnings in code in spring-test.
Issue: SPR-5613, SPR-9863 | spring-test/src/test/java/org/springframework/test/context/ContextCacheTests.java | @@ -0,0 +1,329 @@
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.test.context;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext.HierarchyMode;
+import org.springframework.test.context.support.AnnotationConfigContextLoader;
+import org.springframework.test.util.ReflectionTestUtils;
+
+import static org.junit.Assert.*;
+import static org.springframework.test.context.SpringRunnerContextCacheTests.*;
+
+/**
+ * Integration tests for verifying proper behavior of the {@link ContextCache} in
+ * conjunction with cache keys used in {@link TestContext}.
+ *
+ * @author Sam Brannen
+ * @since 3.1
+ * @see SpringRunnerContextCacheTests
+ */
+public class ContextCacheTests {
+
+ private ContextCache contextCache = new ContextCache();
+
+
+ @Before
+ public void initialCacheState() {
+ assertContextCacheStatistics(contextCache, "initial state", 0, 0, 0);
+ assertParentContextCount(0);
+ }
+
+ private void assertParentContextCount(int expected) {
+ assertEquals("parent context count", expected, contextCache.getParentContextCount());
+ }
+
+ private MergedContextConfiguration getMergedContextConfiguration(TestContext testContext) {
+ return (MergedContextConfiguration) ReflectionTestUtils.getField(testContext, "mergedContextConfiguration");
+ }
+
+ private ApplicationContext loadContext(Class<?> testClass) {
+ TestContext testContext = new TestContext(testClass, contextCache);
+ return testContext.getApplicationContext();
+ }
+
+ private void loadCtxAndAssertStats(Class<?> testClass, int expectedSize, int expectedHitCount, int expectedMissCount) {
+ assertNotNull(loadContext(testClass));
+ assertContextCacheStatistics(contextCache, testClass.getName(), expectedSize, expectedHitCount,
+ expectedMissCount);
+ }
+
+ @Test
+ public void verifyCacheKeyIsBasedOnContextLoader() {
+ loadCtxAndAssertStats(AnnotationConfigContextLoaderTestCase.class, 1, 0, 1);
+ loadCtxAndAssertStats(AnnotationConfigContextLoaderTestCase.class, 1, 1, 1);
+ loadCtxAndAssertStats(CustomAnnotationConfigContextLoaderTestCase.class, 2, 1, 2);
+ loadCtxAndAssertStats(CustomAnnotationConfigContextLoaderTestCase.class, 2, 2, 2);
+ loadCtxAndAssertStats(AnnotationConfigContextLoaderTestCase.class, 2, 3, 2);
+ loadCtxAndAssertStats(CustomAnnotationConfigContextLoaderTestCase.class, 2, 4, 2);
+ }
+
+ @Test
+ public void verifyCacheKeyIsBasedOnActiveProfiles() {
+ loadCtxAndAssertStats(FooBarProfilesTestCase.class, 1, 0, 1);
+ loadCtxAndAssertStats(FooBarProfilesTestCase.class, 1, 1, 1);
+ // Profiles {foo, bar} should hash to the same as {bar,foo}
+ loadCtxAndAssertStats(BarFooProfilesTestCase.class, 1, 2, 1);
+ loadCtxAndAssertStats(FooBarProfilesTestCase.class, 1, 3, 1);
+ loadCtxAndAssertStats(FooBarProfilesTestCase.class, 1, 4, 1);
+ loadCtxAndAssertStats(BarFooProfilesTestCase.class, 1, 5, 1);
+ }
+
+ @Test
+ public void verifyCacheBehaviorForContextHierarchies() {
+ int size = 0;
+ int hits = 0;
+ int misses = 0;
+
+ // Level 1
+ loadCtxAndAssertStats(ClassHierarchyContextHierarchyLevel1TestCase.class, ++size, hits, ++misses);
+ loadCtxAndAssertStats(ClassHierarchyContextHierarchyLevel1TestCase.class, size, ++hits, misses);
+
+ // Level 2
+ loadCtxAndAssertStats(ClassHierarchyContextHierarchyLevel2TestCase.class, ++size /* L2 */, ++hits /* L1 */,
+ ++misses /* L2 */);
+ loadCtxAndAssertStats(ClassHierarchyContextHierarchyLevel2TestCase.class, size, ++hits /* L2 */, misses);
+ loadCtxAndAssertStats(ClassHierarchyContextHierarchyLevel2TestCase.class, size, ++hits /* L2 */, misses);
+
+ // Level 3-A
+ loadCtxAndAssertStats(ClassHierarchyContextHierarchyLevel3aTestCase.class, ++size /* L3A */, ++hits /* L2 */,
+ ++misses /* L3A */);
+ loadCtxAndAssertStats(ClassHierarchyContextHierarchyLevel3aTestCase.class, size, ++hits /* L3A */, misses);
+
+ // Level 3-B
+ loadCtxAndAssertStats(ClassHierarchyContextHierarchyLevel3bTestCase.class, ++size /* L3B */, ++hits /* L2 */,
+ ++misses /* L3B */);
+ loadCtxAndAssertStats(ClassHierarchyContextHierarchyLevel3bTestCase.class, size, ++hits /* L3B */, misses);
+ }
+
+ @Test
+ public void removeContextHierarchyCacheLevel1() {
+
+ // Load Level 3-A
+ TestContext testContext3a = new TestContext(ClassHierarchyContextHierarchyLevel3aTestCase.class, contextCache);
+ testContext3a.getApplicationContext();
+ assertContextCacheStatistics(contextCache, "level 3, A", 3, 0, 3);
+ assertParentContextCount(2);
+
+ // Load Level 3-B
+ TestContext testContext3b = new TestContext(ClassHierarchyContextHierarchyLevel3bTestCase.class, contextCache);
+ testContext3b.getApplicationContext();
+ assertContextCacheStatistics(contextCache, "level 3, A and B", 4, 1, 4);
+ assertParentContextCount(2);
+
+ // Remove Level 1
+ // Should also remove Levels 2, 3-A, and 3-B, leaving nothing.
+ contextCache.remove(getMergedContextConfiguration(testContext3a).getParent().getParent(),
+ HierarchyMode.CURRENT_LEVEL);
+ assertContextCacheStatistics(contextCache, "removed level 1", 0, 1, 4);
+ assertParentContextCount(0);
+ }
+
+ @Test
+ public void removeContextHierarchyCacheLevel1WithExhaustiveMode() {
+
+ // Load Level 3-A
+ TestContext testContext3a = new TestContext(ClassHierarchyContextHierarchyLevel3aTestCase.class, contextCache);
+ testContext3a.getApplicationContext();
+ assertContextCacheStatistics(contextCache, "level 3, A", 3, 0, 3);
+ assertParentContextCount(2);
+
+ // Load Level 3-B
+ TestContext testContext3b = new TestContext(ClassHierarchyContextHierarchyLevel3bTestCase.class, contextCache);
+ testContext3b.getApplicationContext();
+ assertContextCacheStatistics(contextCache, "level 3, A and B", 4, 1, 4);
+ assertParentContextCount(2);
+
+ // Remove Level 1
+ // Should also remove Levels 2, 3-A, and 3-B, leaving nothing.
+ contextCache.remove(getMergedContextConfiguration(testContext3a).getParent().getParent(),
+ HierarchyMode.EXHAUSTIVE);
+ assertContextCacheStatistics(contextCache, "removed level 1", 0, 1, 4);
+ assertParentContextCount(0);
+ }
+
+ @Test
+ public void removeContextHierarchyCacheLevel2() {
+
+ // Load Level 3-A
+ TestContext testContext3a = new TestContext(ClassHierarchyContextHierarchyLevel3aTestCase.class, contextCache);
+ testContext3a.getApplicationContext();
+ assertContextCacheStatistics(contextCache, "level 3, A", 3, 0, 3);
+ assertParentContextCount(2);
+
+ // Load Level 3-B
+ TestContext testContext3b = new TestContext(ClassHierarchyContextHierarchyLevel3bTestCase.class, contextCache);
+ testContext3b.getApplicationContext();
+ assertContextCacheStatistics(contextCache, "level 3, A and B", 4, 1, 4);
+ assertParentContextCount(2);
+
+ // Remove Level 2
+ // Should also remove Levels 3-A and 3-B, leaving only Level 1 as a context in the
+ // cache but also removing the Level 1 hierarchy since all children have been
+ // removed.
+ contextCache.remove(getMergedContextConfiguration(testContext3a).getParent(), HierarchyMode.CURRENT_LEVEL);
+ assertContextCacheStatistics(contextCache, "removed level 2", 1, 1, 4);
+ assertParentContextCount(0);
+ }
+
+ @Test
+ public void removeContextHierarchyCacheLevel2WithExhaustiveMode() {
+
+ // Load Level 3-A
+ TestContext testContext3a = new TestContext(ClassHierarchyContextHierarchyLevel3aTestCase.class, contextCache);
+ testContext3a.getApplicationContext();
+ assertContextCacheStatistics(contextCache, "level 3, A", 3, 0, 3);
+ assertParentContextCount(2);
+
+ // Load Level 3-B
+ TestContext testContext3b = new TestContext(ClassHierarchyContextHierarchyLevel3bTestCase.class, contextCache);
+ testContext3b.getApplicationContext();
+ assertContextCacheStatistics(contextCache, "level 3, A and B", 4, 1, 4);
+ assertParentContextCount(2);
+
+ // Remove Level 2
+ // Should wipe the cache
+ contextCache.remove(getMergedContextConfiguration(testContext3a).getParent(), HierarchyMode.EXHAUSTIVE);
+ assertContextCacheStatistics(contextCache, "removed level 2", 0, 1, 4);
+ assertParentContextCount(0);
+ }
+
+ @Test
+ public void removeContextHierarchyCacheLevel3Then2() {
+
+ // Load Level 3-A
+ TestContext testContext3a = new TestContext(ClassHierarchyContextHierarchyLevel3aTestCase.class, contextCache);
+ testContext3a.getApplicationContext();
+ assertContextCacheStatistics(contextCache, "level 3, A", 3, 0, 3);
+ assertParentContextCount(2);
+
+ // Load Level 3-B
+ TestContext testContext3b = new TestContext(ClassHierarchyContextHierarchyLevel3bTestCase.class, contextCache);
+ testContext3b.getApplicationContext();
+ assertContextCacheStatistics(contextCache, "level 3, A and B", 4, 1, 4);
+ assertParentContextCount(2);
+
+ // Remove Level 3-A
+ contextCache.remove(getMergedContextConfiguration(testContext3a), HierarchyMode.CURRENT_LEVEL);
+ assertContextCacheStatistics(contextCache, "removed level 3-A", 3, 1, 4);
+ assertParentContextCount(2);
+
+ // Remove Level 2
+ // Should also remove Level 3-B, leaving only Level 1.
+ contextCache.remove(getMergedContextConfiguration(testContext3b).getParent(), HierarchyMode.CURRENT_LEVEL);
+ assertContextCacheStatistics(contextCache, "removed level 2", 1, 1, 4);
+ assertParentContextCount(0);
+ }
+
+ @Test
+ public void removeContextHierarchyCacheLevel3Then2WithExhaustiveMode() {
+
+ // Load Level 3-A
+ TestContext testContext3a = new TestContext(ClassHierarchyContextHierarchyLevel3aTestCase.class, contextCache);
+ testContext3a.getApplicationContext();
+ assertContextCacheStatistics(contextCache, "level 3, A", 3, 0, 3);
+ assertParentContextCount(2);
+
+ // Load Level 3-B
+ TestContext testContext3b = new TestContext(ClassHierarchyContextHierarchyLevel3bTestCase.class, contextCache);
+ testContext3b.getApplicationContext();
+ assertContextCacheStatistics(contextCache, "level 3, A and B", 4, 1, 4);
+ assertParentContextCount(2);
+
+ // Remove Level 3-A
+ // Should wipe the cache.
+ contextCache.remove(getMergedContextConfiguration(testContext3a), HierarchyMode.EXHAUSTIVE);
+ assertContextCacheStatistics(contextCache, "removed level 3-A", 0, 1, 4);
+ assertParentContextCount(0);
+
+ // Remove Level 2
+ // Should not actually do anything since the cache was cleared in the
+ // previous step. So the stats should remain the same.
+ contextCache.remove(getMergedContextConfiguration(testContext3b).getParent(), HierarchyMode.EXHAUSTIVE);
+ assertContextCacheStatistics(contextCache, "removed level 2", 0, 1, 4);
+ assertParentContextCount(0);
+ }
+
+
+ @Configuration
+ static class Config {
+ }
+
+ @ContextConfiguration(classes = Config.class, loader = AnnotationConfigContextLoader.class)
+ private static class AnnotationConfigContextLoaderTestCase {
+ }
+
+ @ContextConfiguration(classes = Config.class, loader = CustomAnnotationConfigContextLoader.class)
+ private static class CustomAnnotationConfigContextLoaderTestCase {
+ }
+
+ private static class CustomAnnotationConfigContextLoader extends AnnotationConfigContextLoader {
+ }
+
+ @ActiveProfiles({ "foo", "bar" })
+ @ContextConfiguration(classes = Config.class, loader = AnnotationConfigContextLoader.class)
+ private static class FooBarProfilesTestCase {
+ }
+
+ @ActiveProfiles({ "bar", "foo" })
+ @ContextConfiguration(classes = Config.class, loader = AnnotationConfigContextLoader.class)
+ private static class BarFooProfilesTestCase {
+ }
+
+ @ContextHierarchy({ @ContextConfiguration })
+ private static class ClassHierarchyContextHierarchyLevel1TestCase {
+
+ @Configuration
+ static class Level1Config {
+
+ }
+ }
+
+ @ContextHierarchy({ @ContextConfiguration })
+ private static class ClassHierarchyContextHierarchyLevel2TestCase extends
+ ClassHierarchyContextHierarchyLevel1TestCase {
+
+ @Configuration
+ static class Level2Config {
+
+ }
+ }
+
+ @ContextHierarchy({ @ContextConfiguration })
+ private static class ClassHierarchyContextHierarchyLevel3aTestCase extends
+ ClassHierarchyContextHierarchyLevel2TestCase {
+
+ @Configuration
+ static class Level3aConfig {
+
+ }
+ }
+
+ @ContextHierarchy({ @ContextConfiguration })
+ private static class ClassHierarchyContextHierarchyLevel3bTestCase extends
+ ClassHierarchyContextHierarchyLevel2TestCase {
+
+ @Configuration
+ static class Level3bConfig {
+
+ }
+ }
+
+} | true |
Other | spring-projects | spring-framework | 98074e776262292a9d6fa8d164e6718c5876ed6f.json | Provide support for context hierarchies in the TCF
Prior to this commit the Spring TestContext Framework supported creating
only flat, non-hierarchical contexts. There was no easy way to create
contexts with parent-child relationships.
This commit addresses this issue by introducing a new @ContextHierarchy
annotation that can be used in conjunction with @ContextConfiguration
for declaring hierarchies of application contexts, either within a
single test class or within a test class hierarchy. In addition,
@DirtiesContext now supports a new 'hierarchyMode' attribute for
controlling context cache clearing for context hierarchies.
- Introduced a new @ContextHierarchy annotation.
- Introduced 'name' attribute in @ContextConfiguration.
- Introduced 'name' property in ContextConfigurationAttributes.
- TestContext is now aware of @ContextHierarchy in addition to
@ContextConfiguration.
- Introduced findAnnotationDeclaringClassForTypes() in AnnotationUtils.
- Introduced resolveContextHierarchyAttributes() in ContextLoaderUtils.
- Introduced buildContextHierarchyMap() in ContextLoaderUtils.
- @ContextConfiguration and @ContextHierarchy may not be used as
top-level, class-level annotations simultaneously.
- Introduced reference to the parent configuration in
MergedContextConfiguration and WebMergedContextConfiguration.
- Introduced overloaded buildMergedContextConfiguration() methods in
ContextLoaderUtils in order to handle context hierarchies separately
from conventional, non-hierarchical contexts.
- Introduced hashCode() and equals() in ContextConfigurationAttributes.
- ContextLoaderUtils ensures uniqueness of @ContextConfiguration
elements within a single @ContextHierarchy declaration.
- Introduced CacheAwareContextLoaderDelegate that can be used for
loading contexts with transparent support for interacting with the
context cache -- for example, for retrieving the parent application
context in a context hierarchy.
- TestContext now delegates to CacheAwareContextLoaderDelegate for
loading contexts.
- Introduced getParentApplicationContext() in MergedContextConfiguration
- The loadContext(MergedContextConfiguration) methods in
AbstractGenericContextLoader and AbstractGenericWebContextLoader now
set the parent context as appropriate.
- Introduced 'hierarchyMode' attribute in @DirtiesContext with a
corresponding HierarchyMode enum that defines EXHAUSTIVE and
CURRENT_LEVEL cache removal modes.
- ContextCache now internally tracks the relationships between contexts
that make up a context hierarchy. Furthermore, when a context is
removed, if it is part of a context hierarchy all corresponding
contexts will be removed from the cache according to the supplied
HierarchyMode.
- AbstractGenericWebContextLoader will set a loaded context as the
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE in the MockServletContext when
context hierarchies are used if the context has no parent or if the
context has a parent that is not a WAC.
- Where appropriate, updated Javadoc to refer to the
ServletTestExecutionListener, which was introduced in 3.2.0.
- Updated Javadoc to avoid and/or suppress warnings in spring-test.
- Suppressed remaining warnings in code in spring-test.
Issue: SPR-5613, SPR-9863 | spring-test/src/test/java/org/springframework/test/context/ContextHierarchyDirtiesContextTests.java | @@ -0,0 +1,212 @@
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.test.context;
+
+import org.junit.After;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runner.JUnitCore;
+import org.junit.runner.Result;
+import org.junit.runner.RunWith;
+import org.junit.runners.MethodSorters;
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.annotation.DirtiesContext.HierarchyMode;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import static org.hamcrest.CoreMatchers.*;
+import static org.junit.Assert.*;
+
+/**
+ * Integration tests that verify proper behavior of {@link DirtiesContext @DirtiesContext}
+ * in conjunction with context hierarchies configured via {@link ContextHierarchy @ContextHierarchy}.
+ *
+ * @author Sam Brannen
+ * @author Tadaya Tsuyukubo
+ * @since 3.2.2
+ */
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class ContextHierarchyDirtiesContextTests {
+
+ private static ApplicationContext context;
+
+
+ @After
+ public void cleanUp() {
+ ContextHierarchyDirtiesContextTests.context = null;
+ }
+
+ @Test
+ public void classLevelDirtiesContextWithCurrentLevelHierarchyMode() {
+ runTestAndVerifyHierarchies(ClassLevelDirtiesContextWithCurrentLevelModeTestCase.class, true, true, false);
+ }
+
+ @Test
+ public void classLevelDirtiesContextWithExhaustiveHierarchyMode() {
+ runTestAndVerifyHierarchies(ClassLevelDirtiesContextWithExhaustiveModeTestCase.class, false, false, false);
+ }
+
+ @Test
+ public void methodLevelDirtiesContextWithCurrentLevelHierarchyMode() {
+ runTestAndVerifyHierarchies(MethodLevelDirtiesContextWithCurrentLevelModeTestCase.class, true, true, false);
+ }
+
+ @Test
+ public void methodLevelDirtiesContextWithExhaustiveHierarchyMode() {
+ runTestAndVerifyHierarchies(MethodLevelDirtiesContextWithExhaustiveModeTestCase.class, false, false, false);
+ }
+
+ private void runTestAndVerifyHierarchies(Class<? extends FooTestCase> testClass, boolean isFooContextActive,
+ boolean isBarContextActive, boolean isBazContextActive) {
+
+ JUnitCore jUnitCore = new JUnitCore();
+ Result result = jUnitCore.run(testClass);
+ assertTrue("all tests passed", result.wasSuccessful());
+
+ assertThat(ContextHierarchyDirtiesContextTests.context, notNullValue());
+
+ ConfigurableApplicationContext bazContext = (ConfigurableApplicationContext) ContextHierarchyDirtiesContextTests.context;
+ assertEquals("baz", bazContext.getBean("bean", String.class));
+ assertThat("bazContext#isActive()", bazContext.isActive(), is(isBazContextActive));
+
+ ConfigurableApplicationContext barContext = (ConfigurableApplicationContext) bazContext.getParent();
+ assertThat(barContext, notNullValue());
+ assertEquals("bar", barContext.getBean("bean", String.class));
+ assertThat("barContext#isActive()", barContext.isActive(), is(isBarContextActive));
+
+ ConfigurableApplicationContext fooContext = (ConfigurableApplicationContext) barContext.getParent();
+ assertThat(fooContext, notNullValue());
+ assertEquals("foo", fooContext.getBean("bean", String.class));
+ assertThat("fooContext#isActive()", fooContext.isActive(), is(isFooContextActive));
+ }
+
+
+ // -------------------------------------------------------------------------
+
+ @RunWith(SpringJUnit4ClassRunner.class)
+ @ContextHierarchy(@ContextConfiguration(name = "foo"))
+ static abstract class FooTestCase implements ApplicationContextAware {
+
+ @Configuration
+ static class Config {
+
+ @Bean
+ public String bean() {
+ return "foo";
+ }
+ }
+
+
+ public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
+ ContextHierarchyDirtiesContextTests.context = applicationContext;
+ }
+ }
+
+ @ContextHierarchy(@ContextConfiguration(name = "bar"))
+ static abstract class BarTestCase extends FooTestCase {
+
+ @Configuration
+ static class Config {
+
+ @Bean
+ public String bean() {
+ return "bar";
+ }
+ }
+ }
+
+ @ContextHierarchy(@ContextConfiguration(name = "baz"))
+ static abstract class BazTestCase extends BarTestCase {
+
+ @Configuration
+ static class Config {
+
+ @Bean
+ public String bean() {
+ return "baz";
+ }
+ }
+ }
+
+ // -------------------------------------------------------------------------
+
+ /**
+ * {@link DirtiesContext} is declared at the class level, without specifying
+ * the {@link DirtiesContext.HierarchyMode}.
+ * <p>After running this test class, the context cache should be <em>exhaustively</em>
+ * cleared beginning from the current context hierarchy, upwards to the highest
+ * parent context, and then back down through all subhierarchies of the parent
+ * context.
+ */
+ @DirtiesContext
+ public static class ClassLevelDirtiesContextWithExhaustiveModeTestCase extends BazTestCase {
+
+ @Test
+ public void test() {
+ }
+ }
+
+ /**
+ * {@link DirtiesContext} is declared at the class level, specifying the
+ * {@link DirtiesContext.HierarchyMode#CURRENT_LEVEL CURRENT_LEVEL} hierarchy mode.
+ * <p>After running this test class, the context cache should be cleared
+ * beginning from the current context hierarchy and down through all subhierarchies.
+ */
+ @DirtiesContext(hierarchyMode = HierarchyMode.CURRENT_LEVEL)
+ public static class ClassLevelDirtiesContextWithCurrentLevelModeTestCase extends BazTestCase {
+
+ @Test
+ public void test() {
+ }
+ }
+
+ /**
+ * {@link DirtiesContext} is declared at the method level, without specifying
+ * the {@link DirtiesContext.HierarchyMode}.
+ * <p>After running this test class, the context cache should be <em>exhaustively</em>
+ * cleared beginning from the current context hierarchy, upwards to the highest
+ * parent context, and then back down through all subhierarchies of the parent
+ * context.
+ */
+ public static class MethodLevelDirtiesContextWithExhaustiveModeTestCase extends BazTestCase {
+
+ @Test
+ @DirtiesContext
+ public void test() {
+ }
+ }
+
+ /**
+ * {@link DirtiesContext} is declared at the method level, specifying the
+ * {@link DirtiesContext.HierarchyMode#CURRENT_LEVEL CURRENT_LEVEL} hierarchy mode.
+ * <p>After running this test class, the context cache should be cleared
+ * beginning from the current context hierarchy and down through all subhierarchies.
+ */
+ public static class MethodLevelDirtiesContextWithCurrentLevelModeTestCase extends BazTestCase {
+
+ @Test
+ @DirtiesContext(hierarchyMode = HierarchyMode.CURRENT_LEVEL)
+ public void test() {
+ }
+ }
+
+} | true |
Other | spring-projects | spring-framework | 98074e776262292a9d6fa8d164e6718c5876ed6f.json | Provide support for context hierarchies in the TCF
Prior to this commit the Spring TestContext Framework supported creating
only flat, non-hierarchical contexts. There was no easy way to create
contexts with parent-child relationships.
This commit addresses this issue by introducing a new @ContextHierarchy
annotation that can be used in conjunction with @ContextConfiguration
for declaring hierarchies of application contexts, either within a
single test class or within a test class hierarchy. In addition,
@DirtiesContext now supports a new 'hierarchyMode' attribute for
controlling context cache clearing for context hierarchies.
- Introduced a new @ContextHierarchy annotation.
- Introduced 'name' attribute in @ContextConfiguration.
- Introduced 'name' property in ContextConfigurationAttributes.
- TestContext is now aware of @ContextHierarchy in addition to
@ContextConfiguration.
- Introduced findAnnotationDeclaringClassForTypes() in AnnotationUtils.
- Introduced resolveContextHierarchyAttributes() in ContextLoaderUtils.
- Introduced buildContextHierarchyMap() in ContextLoaderUtils.
- @ContextConfiguration and @ContextHierarchy may not be used as
top-level, class-level annotations simultaneously.
- Introduced reference to the parent configuration in
MergedContextConfiguration and WebMergedContextConfiguration.
- Introduced overloaded buildMergedContextConfiguration() methods in
ContextLoaderUtils in order to handle context hierarchies separately
from conventional, non-hierarchical contexts.
- Introduced hashCode() and equals() in ContextConfigurationAttributes.
- ContextLoaderUtils ensures uniqueness of @ContextConfiguration
elements within a single @ContextHierarchy declaration.
- Introduced CacheAwareContextLoaderDelegate that can be used for
loading contexts with transparent support for interacting with the
context cache -- for example, for retrieving the parent application
context in a context hierarchy.
- TestContext now delegates to CacheAwareContextLoaderDelegate for
loading contexts.
- Introduced getParentApplicationContext() in MergedContextConfiguration
- The loadContext(MergedContextConfiguration) methods in
AbstractGenericContextLoader and AbstractGenericWebContextLoader now
set the parent context as appropriate.
- Introduced 'hierarchyMode' attribute in @DirtiesContext with a
corresponding HierarchyMode enum that defines EXHAUSTIVE and
CURRENT_LEVEL cache removal modes.
- ContextCache now internally tracks the relationships between contexts
that make up a context hierarchy. Furthermore, when a context is
removed, if it is part of a context hierarchy all corresponding
contexts will be removed from the cache according to the supplied
HierarchyMode.
- AbstractGenericWebContextLoader will set a loaded context as the
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE in the MockServletContext when
context hierarchies are used if the context has no parent or if the
context has a parent that is not a WAC.
- Where appropriate, updated Javadoc to refer to the
ServletTestExecutionListener, which was introduced in 3.2.0.
- Updated Javadoc to avoid and/or suppress warnings in spring-test.
- Suppressed remaining warnings in code in spring-test.
Issue: SPR-5613, SPR-9863 | spring-test/src/test/java/org/springframework/test/context/ContextLoaderUtilsTests.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,13 +16,16 @@
package org.springframework.test.context;
+import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.springframework.test.context.ContextLoaderUtils.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import org.junit.Test;
@@ -105,6 +108,233 @@ private void assertMergedConfig(
assertEquals(expectedInitializerClasses, mergedConfig.getContextInitializerClasses());
}
+ private void debugConfigAttributes(List<ContextConfigurationAttributes> configAttributesList) {
+ // for (ContextConfigurationAttributes configAttributes : configAttributesList) {
+ // System.err.println(configAttributes);
+ // }
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void resolveContextHierarchyAttributesForSingleTestClassWithContextConfigurationAndContextHierarchy() {
+ resolveContextHierarchyAttributes(SingleTestClassWithContextConfigurationAndContextHierarchy.class);
+ }
+
+ @Test
+ public void resolveContextHierarchyAttributesForSingleTestClassWithImplicitSingleLevelContextHierarchy() {
+ List<List<ContextConfigurationAttributes>> hierarchyAttributes = resolveContextHierarchyAttributes(BareAnnotations.class);
+ assertEquals(1, hierarchyAttributes.size());
+ List<ContextConfigurationAttributes> configAttributesList = hierarchyAttributes.get(0);
+ assertEquals(1, configAttributesList.size());
+ debugConfigAttributes(configAttributesList);
+ }
+
+ @Test
+ public void resolveContextHierarchyAttributesForSingleTestClassWithSingleLevelContextHierarchy() {
+ List<List<ContextConfigurationAttributes>> hierarchyAttributes = resolveContextHierarchyAttributes(SingleTestClassWithSingleLevelContextHierarchy.class);
+ assertEquals(1, hierarchyAttributes.size());
+ List<ContextConfigurationAttributes> configAttributesList = hierarchyAttributes.get(0);
+ assertEquals(1, configAttributesList.size());
+ debugConfigAttributes(configAttributesList);
+ }
+
+ @Test
+ public void resolveContextHierarchyAttributesForSingleTestClassWithTripleLevelContextHierarchy() {
+ List<List<ContextConfigurationAttributes>> hierarchyAttributes = resolveContextHierarchyAttributes(SingleTestClassWithTripleLevelContextHierarchy.class);
+ assertEquals(1, hierarchyAttributes.size());
+ List<ContextConfigurationAttributes> configAttributesList = hierarchyAttributes.get(0);
+ assertEquals(3, configAttributesList.size());
+ debugConfigAttributes(configAttributesList);
+ }
+
+ @Test
+ public void resolveContextHierarchyAttributesForTestClassHierarchyWithSingleLevelContextHierarchies() {
+ List<List<ContextConfigurationAttributes>> hierarchyAttributes = resolveContextHierarchyAttributes(TestClass3WithSingleLevelContextHierarchy.class);
+ assertEquals(3, hierarchyAttributes.size());
+
+ List<ContextConfigurationAttributes> configAttributesListClassLevel1 = hierarchyAttributes.get(0);
+ debugConfigAttributes(configAttributesListClassLevel1);
+ assertEquals(1, configAttributesListClassLevel1.size());
+ assertThat(configAttributesListClassLevel1.get(0).getLocations()[0], equalTo("one.xml"));
+
+ List<ContextConfigurationAttributes> configAttributesListClassLevel2 = hierarchyAttributes.get(1);
+ debugConfigAttributes(configAttributesListClassLevel2);
+ assertEquals(1, configAttributesListClassLevel2.size());
+ assertArrayEquals(new String[] { "two-A.xml", "two-B.xml" },
+ configAttributesListClassLevel2.get(0).getLocations());
+
+ List<ContextConfigurationAttributes> configAttributesListClassLevel3 = hierarchyAttributes.get(2);
+ debugConfigAttributes(configAttributesListClassLevel3);
+ assertEquals(1, configAttributesListClassLevel3.size());
+ assertThat(configAttributesListClassLevel3.get(0).getLocations()[0], equalTo("three.xml"));
+ }
+
+ @Test
+ public void resolveContextHierarchyAttributesForTestClassHierarchyWithBareContextConfigurationInSubclass() {
+ List<List<ContextConfigurationAttributes>> hierarchyAttributes = resolveContextHierarchyAttributes(TestClass2WithBareContextConfigurationInSubclass.class);
+ assertEquals(2, hierarchyAttributes.size());
+
+ List<ContextConfigurationAttributes> configAttributesListClassLevel1 = hierarchyAttributes.get(0);
+ debugConfigAttributes(configAttributesListClassLevel1);
+ assertEquals(1, configAttributesListClassLevel1.size());
+ assertThat(configAttributesListClassLevel1.get(0).getLocations()[0], equalTo("one.xml"));
+
+ List<ContextConfigurationAttributes> configAttributesListClassLevel2 = hierarchyAttributes.get(1);
+ debugConfigAttributes(configAttributesListClassLevel2);
+ assertEquals(1, configAttributesListClassLevel2.size());
+ assertThat(configAttributesListClassLevel2.get(0).getLocations()[0], equalTo("two.xml"));
+ }
+
+ @Test
+ public void resolveContextHierarchyAttributesForTestClassHierarchyWithBareContextConfigurationInSuperclass() {
+ List<List<ContextConfigurationAttributes>> hierarchyAttributes = resolveContextHierarchyAttributes(TestClass2WithBareContextConfigurationInSuperclass.class);
+ assertEquals(2, hierarchyAttributes.size());
+
+ List<ContextConfigurationAttributes> configAttributesListClassLevel1 = hierarchyAttributes.get(0);
+ debugConfigAttributes(configAttributesListClassLevel1);
+ assertEquals(1, configAttributesListClassLevel1.size());
+ assertThat(configAttributesListClassLevel1.get(0).getLocations()[0], equalTo("one.xml"));
+
+ List<ContextConfigurationAttributes> configAttributesListClassLevel2 = hierarchyAttributes.get(1);
+ debugConfigAttributes(configAttributesListClassLevel2);
+ assertEquals(1, configAttributesListClassLevel2.size());
+ assertThat(configAttributesListClassLevel2.get(0).getLocations()[0], equalTo("two.xml"));
+ }
+
+ @Test
+ public void resolveContextHierarchyAttributesForTestClassHierarchyWithMultiLevelContextHierarchies() {
+ List<List<ContextConfigurationAttributes>> hierarchyAttributes = resolveContextHierarchyAttributes(TestClass3WithMultiLevelContextHierarchy.class);
+ assertEquals(3, hierarchyAttributes.size());
+
+ List<ContextConfigurationAttributes> configAttributesListClassLevel1 = hierarchyAttributes.get(0);
+ debugConfigAttributes(configAttributesListClassLevel1);
+ assertEquals(2, configAttributesListClassLevel1.size());
+ assertThat(configAttributesListClassLevel1.get(0).getLocations()[0], equalTo("1-A.xml"));
+ assertThat(configAttributesListClassLevel1.get(1).getLocations()[0], equalTo("1-B.xml"));
+
+ List<ContextConfigurationAttributes> configAttributesListClassLevel2 = hierarchyAttributes.get(1);
+ debugConfigAttributes(configAttributesListClassLevel2);
+ assertEquals(2, configAttributesListClassLevel2.size());
+ assertThat(configAttributesListClassLevel2.get(0).getLocations()[0], equalTo("2-A.xml"));
+ assertThat(configAttributesListClassLevel2.get(1).getLocations()[0], equalTo("2-B.xml"));
+
+ List<ContextConfigurationAttributes> configAttributesListClassLevel3 = hierarchyAttributes.get(2);
+ debugConfigAttributes(configAttributesListClassLevel3);
+ assertEquals(3, configAttributesListClassLevel3.size());
+ assertThat(configAttributesListClassLevel3.get(0).getLocations()[0], equalTo("3-A.xml"));
+ assertThat(configAttributesListClassLevel3.get(1).getLocations()[0], equalTo("3-B.xml"));
+ assertThat(configAttributesListClassLevel3.get(2).getLocations()[0], equalTo("3-C.xml"));
+ }
+
+ private void assertContextConfigEntriesAreNotUnique(Class<?> testClass) {
+ try {
+ resolveContextHierarchyAttributes(testClass);
+ fail("Should throw an IllegalStateException");
+ }
+ catch (IllegalStateException e) {
+ String msg = String.format(
+ "The @ContextConfiguration elements configured via @ContextHierarchy in test class [%s] must define unique contexts to load.",
+ testClass.getName());
+ assertEquals(msg, e.getMessage());
+ }
+ }
+
+ @Test
+ public void resolveContextHierarchyAttributesForSingleTestClassWithMultiLevelContextHierarchyWithEmptyContextConfig() {
+ assertContextConfigEntriesAreNotUnique(SingleTestClassWithMultiLevelContextHierarchyWithEmptyContextConfig.class);
+ }
+
+ @Test
+ public void resolveContextHierarchyAttributesForSingleTestClassWithMultiLevelContextHierarchyWithDuplicatedContextConfig() {
+ assertContextConfigEntriesAreNotUnique(SingleTestClassWithMultiLevelContextHierarchyWithDuplicatedContextConfig.class);
+ }
+
+ @Test
+ public void buildContextHierarchyMapForTestClassHierarchyWithMultiLevelContextHierarchies() {
+ Map<String, List<ContextConfigurationAttributes>> map = buildContextHierarchyMap(TestClass3WithMultiLevelContextHierarchy.class);
+
+ assertThat(map.size(), is(3));
+ assertThat(map.keySet(), hasItems("alpha", "beta", "gamma"));
+
+ List<ContextConfigurationAttributes> alphaConfig = map.get("alpha");
+ assertThat(alphaConfig.size(), is(3));
+ assertThat(alphaConfig.get(0).getLocations()[0], is("1-A.xml"));
+ assertThat(alphaConfig.get(1).getLocations()[0], is("2-A.xml"));
+ assertThat(alphaConfig.get(2).getLocations()[0], is("3-A.xml"));
+
+ List<ContextConfigurationAttributes> betaConfig = map.get("beta");
+ assertThat(betaConfig.size(), is(3));
+ assertThat(betaConfig.get(0).getLocations()[0], is("1-B.xml"));
+ assertThat(betaConfig.get(1).getLocations()[0], is("2-B.xml"));
+ assertThat(betaConfig.get(2).getLocations()[0], is("3-B.xml"));
+
+ List<ContextConfigurationAttributes> gammaConfig = map.get("gamma");
+ assertThat(gammaConfig.size(), is(1));
+ assertThat(gammaConfig.get(0).getLocations()[0], is("3-C.xml"));
+ }
+
+ @Test
+ public void buildContextHierarchyMapForTestClassHierarchyWithMultiLevelContextHierarchiesAndUnnamedConfig() {
+ Map<String, List<ContextConfigurationAttributes>> map = buildContextHierarchyMap(TestClass3WithMultiLevelContextHierarchyAndUnnamedConfig.class);
+
+ String level1 = GENERATED_CONTEXT_HIERARCHY_LEVEL_PREFIX + 1;
+ String level2 = GENERATED_CONTEXT_HIERARCHY_LEVEL_PREFIX + 2;
+ String level3 = GENERATED_CONTEXT_HIERARCHY_LEVEL_PREFIX + 3;
+ String level4 = GENERATED_CONTEXT_HIERARCHY_LEVEL_PREFIX + 4;
+ String level5 = GENERATED_CONTEXT_HIERARCHY_LEVEL_PREFIX + 5;
+ String level6 = GENERATED_CONTEXT_HIERARCHY_LEVEL_PREFIX + 6;
+ String level7 = GENERATED_CONTEXT_HIERARCHY_LEVEL_PREFIX + 7;
+
+ assertThat(map.size(), is(7));
+ assertThat(map.keySet(), hasItems(level1, level2, level3, level4, level5, level6, level7));
+
+ List<ContextConfigurationAttributes> level1Config = map.get(level1);
+ assertThat(level1Config.size(), is(1));
+ assertThat(level1Config.get(0).getLocations()[0], is("1-A.xml"));
+
+ List<ContextConfigurationAttributes> level2Config = map.get(level2);
+ assertThat(level2Config.size(), is(1));
+ assertThat(level2Config.get(0).getLocations()[0], is("1-B.xml"));
+
+ List<ContextConfigurationAttributes> level3Config = map.get(level3);
+ assertThat(level3Config.size(), is(1));
+ assertThat(level3Config.get(0).getLocations()[0], is("2-A.xml"));
+
+ // ...
+
+ List<ContextConfigurationAttributes> level7Config = map.get(level7);
+ assertThat(level7Config.size(), is(1));
+ assertThat(level7Config.get(0).getLocations()[0], is("3-C.xml"));
+ }
+
+ @Test
+ public void buildContextHierarchyMapForTestClassHierarchyWithMultiLevelContextHierarchiesAndPartiallyNamedConfig() {
+ Map<String, List<ContextConfigurationAttributes>> map = buildContextHierarchyMap(TestClass2WithMultiLevelContextHierarchyAndPartiallyNamedConfig.class);
+
+ String level1 = "parent";
+ String level2 = GENERATED_CONTEXT_HIERARCHY_LEVEL_PREFIX + 2;
+ String level3 = GENERATED_CONTEXT_HIERARCHY_LEVEL_PREFIX + 3;
+
+ assertThat(map.size(), is(3));
+ assertThat(map.keySet(), hasItems(level1, level2, level3));
+ Iterator<String> levels = map.keySet().iterator();
+ assertThat(levels.next(), is(level1));
+ assertThat(levels.next(), is(level2));
+ assertThat(levels.next(), is(level3));
+
+ List<ContextConfigurationAttributes> level1Config = map.get(level1);
+ assertThat(level1Config.size(), is(2));
+ assertThat(level1Config.get(0).getLocations()[0], is("1-A.xml"));
+ assertThat(level1Config.get(1).getLocations()[0], is("2-A.xml"));
+
+ List<ContextConfigurationAttributes> level2Config = map.get(level2);
+ assertThat(level2Config.size(), is(1));
+ assertThat(level2Config.get(0).getLocations()[0], is("1-B.xml"));
+
+ List<ContextConfigurationAttributes> level3Config = map.get(level3);
+ assertThat(level3Config.size(), is(1));
+ assertThat(level3Config.get(0).getLocations()[0], is("2-C.xml"));
+ }
+
@Test(expected = IllegalStateException.class)
public void resolveConfigAttributesWithConflictingLocations() {
resolveContextConfigurationAttributes(ConflictingLocations.class);
@@ -155,13 +385,13 @@ public void resolveConfigAttributesWithLocalAndInheritedAnnotationsAndClasses()
@Test(expected = IllegalArgumentException.class)
public void buildMergedConfigWithoutAnnotation() {
- buildMergedContextConfiguration(Enigma.class, null);
+ buildMergedContextConfiguration(Enigma.class, null, null);
}
@Test
public void buildMergedConfigWithBareAnnotations() {
Class<BareAnnotations> testClass = BareAnnotations.class;
- MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass, null);
+ MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass, null, null);
assertMergedConfig(
mergedConfig,
@@ -173,7 +403,7 @@ public void buildMergedConfigWithBareAnnotations() {
@Test
public void buildMergedConfigWithLocalAnnotationAndLocations() {
Class<?> testClass = LocationsFoo.class;
- MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass, null);
+ MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass, null, null);
assertMergedConfig(mergedConfig, testClass, new String[] { "classpath:/foo.xml" }, EMPTY_CLASS_ARRAY,
DelegatingSmartContextLoader.class);
@@ -182,7 +412,7 @@ public void buildMergedConfigWithLocalAnnotationAndLocations() {
@Test
public void buildMergedConfigWithLocalAnnotationAndClasses() {
Class<?> testClass = ClassesFoo.class;
- MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass, null);
+ MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass, null, null);
assertMergedConfig(mergedConfig, testClass, EMPTY_STRING_ARRAY, new Class<?>[] { FooConfig.class },
DelegatingSmartContextLoader.class);
@@ -193,7 +423,7 @@ public void buildMergedConfigWithLocalAnnotationAndOverriddenContextLoaderAndLoc
Class<?> testClass = LocationsFoo.class;
Class<? extends ContextLoader> expectedContextLoaderClass = GenericPropertiesContextLoader.class;
MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass,
- expectedContextLoaderClass.getName());
+ expectedContextLoaderClass.getName(), null);
assertMergedConfig(mergedConfig, testClass, new String[] { "classpath:/foo.xml" }, EMPTY_CLASS_ARRAY,
expectedContextLoaderClass);
@@ -204,7 +434,7 @@ public void buildMergedConfigWithLocalAnnotationAndOverriddenContextLoaderAndCla
Class<?> testClass = ClassesFoo.class;
Class<? extends ContextLoader> expectedContextLoaderClass = GenericPropertiesContextLoader.class;
MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass,
- expectedContextLoaderClass.getName());
+ expectedContextLoaderClass.getName(), null);
assertMergedConfig(mergedConfig, testClass, EMPTY_STRING_ARRAY, new Class<?>[] { FooConfig.class },
expectedContextLoaderClass);
@@ -215,7 +445,7 @@ public void buildMergedConfigWithLocalAndInheritedAnnotationsAndLocations() {
Class<?> testClass = LocationsBar.class;
String[] expectedLocations = new String[] { "/foo.xml", "/bar.xml" };
- MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass, null);
+ MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass, null, null);
assertMergedConfig(mergedConfig, testClass, expectedLocations, EMPTY_CLASS_ARRAY,
AnnotationConfigContextLoader.class);
}
@@ -225,7 +455,7 @@ public void buildMergedConfigWithLocalAndInheritedAnnotationsAndClasses() {
Class<?> testClass = ClassesBar.class;
Class<?>[] expectedClasses = new Class<?>[] { FooConfig.class, BarConfig.class };
- MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass, null);
+ MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass, null, null);
assertMergedConfig(mergedConfig, testClass, EMPTY_STRING_ARRAY, expectedClasses,
AnnotationConfigContextLoader.class);
}
@@ -235,7 +465,7 @@ public void buildMergedConfigWithAnnotationsAndOverriddenLocations() {
Class<?> testClass = OverriddenLocationsBar.class;
String[] expectedLocations = new String[] { "/bar.xml" };
- MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass, null);
+ MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass, null, null);
assertMergedConfig(mergedConfig, testClass, expectedLocations, EMPTY_CLASS_ARRAY,
AnnotationConfigContextLoader.class);
}
@@ -245,7 +475,7 @@ public void buildMergedConfigWithAnnotationsAndOverriddenClasses() {
Class<?> testClass = OverriddenClassesBar.class;
Class<?>[] expectedClasses = new Class<?>[] { BarConfig.class };
- MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass, null);
+ MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass, null, null);
assertMergedConfig(mergedConfig, testClass, EMPTY_STRING_ARRAY, expectedClasses,
AnnotationConfigContextLoader.class);
}
@@ -258,7 +488,7 @@ public void buildMergedConfigWithLocalInitializer() {
= new HashSet<Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>>();
expectedInitializerClasses.add(FooInitializer.class);
- MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass, null);
+ MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass, null, null);
assertMergedConfig(mergedConfig, testClass, EMPTY_STRING_ARRAY, expectedClasses, expectedInitializerClasses,
DelegatingSmartContextLoader.class);
}
@@ -272,7 +502,7 @@ public void buildMergedConfigWithLocalAndInheritedInitializer() {
expectedInitializerClasses.add(FooInitializer.class);
expectedInitializerClasses.add(BarInitializer.class);
- MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass, null);
+ MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass, null, null);
assertMergedConfig(mergedConfig, testClass, EMPTY_STRING_ARRAY, expectedClasses, expectedInitializerClasses,
DelegatingSmartContextLoader.class);
}
@@ -285,7 +515,7 @@ public void buildMergedConfigWithOverriddenInitializers() {
= new HashSet<Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>>();
expectedInitializerClasses.add(BarInitializer.class);
- MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass, null);
+ MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass, null, null);
assertMergedConfig(mergedConfig, testClass, EMPTY_STRING_ARRAY, expectedClasses, expectedInitializerClasses,
DelegatingSmartContextLoader.class);
}
@@ -298,7 +528,7 @@ public void buildMergedConfigWithOverriddenInitializersAndClasses() {
= new HashSet<Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>>();
expectedInitializerClasses.add(BarInitializer.class);
- MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass, null);
+ MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass, null, null);
assertMergedConfig(mergedConfig, testClass, EMPTY_STRING_ARRAY, expectedClasses, expectedInitializerClasses,
DelegatingSmartContextLoader.class);
}
@@ -377,6 +607,8 @@ public void resolveActiveProfilesWithOverriddenAnnotation() {
}
+ // -------------------------------------------------------------------------
+
private static class Enigma {
}
@@ -475,4 +707,140 @@ private static class OverriddenInitializersBar extends InitializersFoo {
private static class OverriddenInitializersAndClassesBar extends InitializersFoo {
}
+ @ContextConfiguration("foo.xml")
+ @ContextHierarchy(@ContextConfiguration("bar.xml"))
+ private static class SingleTestClassWithContextConfigurationAndContextHierarchy {
+ }
+
+ @ContextHierarchy(@ContextConfiguration("A.xml"))
+ private static class SingleTestClassWithSingleLevelContextHierarchy {
+ }
+
+ @ContextHierarchy({//
+ //
+ @ContextConfiguration("A.xml"),//
+ @ContextConfiguration("B.xml"),//
+ @ContextConfiguration("C.xml") //
+ })
+ private static class SingleTestClassWithTripleLevelContextHierarchy {
+ }
+
+ @ContextHierarchy(@ContextConfiguration("one.xml"))
+ private static class TestClass1WithSingleLevelContextHierarchy {
+ }
+
+ @ContextHierarchy(@ContextConfiguration({ "two-A.xml", "two-B.xml" }))
+ private static class TestClass2WithSingleLevelContextHierarchy extends TestClass1WithSingleLevelContextHierarchy {
+ }
+
+ @ContextHierarchy(@ContextConfiguration("three.xml"))
+ private static class TestClass3WithSingleLevelContextHierarchy extends TestClass2WithSingleLevelContextHierarchy {
+ }
+
+ @ContextConfiguration("one.xml")
+ private static class TestClass1WithBareContextConfigurationInSuperclass {
+ }
+
+ @ContextHierarchy(@ContextConfiguration("two.xml"))
+ private static class TestClass2WithBareContextConfigurationInSuperclass extends
+ TestClass1WithBareContextConfigurationInSuperclass {
+ }
+
+ @ContextHierarchy(@ContextConfiguration("one.xml"))
+ private static class TestClass1WithBareContextConfigurationInSubclass {
+ }
+
+ @ContextConfiguration("two.xml")
+ private static class TestClass2WithBareContextConfigurationInSubclass extends
+ TestClass1WithBareContextConfigurationInSuperclass {
+ }
+
+ @ContextHierarchy({//
+ //
+ @ContextConfiguration(locations = "1-A.xml", name = "alpha"),//
+ @ContextConfiguration(locations = "1-B.xml", name = "beta") //
+ })
+ private static class TestClass1WithMultiLevelContextHierarchy {
+ }
+
+ @ContextHierarchy({//
+ //
+ @ContextConfiguration(locations = "2-A.xml", name = "alpha"),//
+ @ContextConfiguration(locations = "2-B.xml", name = "beta") //
+ })
+ private static class TestClass2WithMultiLevelContextHierarchy extends TestClass1WithMultiLevelContextHierarchy {
+ }
+
+ @ContextHierarchy({//
+ //
+ @ContextConfiguration(locations = "3-A.xml", name = "alpha"),//
+ @ContextConfiguration(locations = "3-B.xml", name = "beta"),//
+ @ContextConfiguration(locations = "3-C.xml", name = "gamma") //
+ })
+ private static class TestClass3WithMultiLevelContextHierarchy extends TestClass2WithMultiLevelContextHierarchy {
+ }
+
+ @ContextHierarchy({//
+ //
+ @ContextConfiguration(locations = "1-A.xml"),//
+ @ContextConfiguration(locations = "1-B.xml") //
+ })
+ private static class TestClass1WithMultiLevelContextHierarchyAndUnnamedConfig {
+ }
+
+ @ContextHierarchy({//
+ //
+ @ContextConfiguration(locations = "2-A.xml"),//
+ @ContextConfiguration(locations = "2-B.xml") //
+ })
+ private static class TestClass2WithMultiLevelContextHierarchyAndUnnamedConfig extends
+ TestClass1WithMultiLevelContextHierarchyAndUnnamedConfig {
+ }
+
+ @ContextHierarchy({//
+ //
+ @ContextConfiguration(locations = "3-A.xml"),//
+ @ContextConfiguration(locations = "3-B.xml"),//
+ @ContextConfiguration(locations = "3-C.xml") //
+ })
+ private static class TestClass3WithMultiLevelContextHierarchyAndUnnamedConfig extends
+ TestClass2WithMultiLevelContextHierarchyAndUnnamedConfig {
+ }
+
+ @ContextHierarchy({//
+ //
+ @ContextConfiguration(locations = "1-A.xml", name = "parent"),//
+ @ContextConfiguration(locations = "1-B.xml") //
+ })
+ private static class TestClass1WithMultiLevelContextHierarchyAndPartiallyNamedConfig {
+ }
+
+ @ContextHierarchy({//
+ //
+ @ContextConfiguration(locations = "2-A.xml", name = "parent"),//
+ @ContextConfiguration(locations = "2-C.xml") //
+ })
+ private static class TestClass2WithMultiLevelContextHierarchyAndPartiallyNamedConfig extends
+ TestClass1WithMultiLevelContextHierarchyAndPartiallyNamedConfig {
+ }
+
+ @ContextHierarchy({
+ //
+ @ContextConfiguration,//
+ @ContextConfiguration //
+ })
+ private static class SingleTestClassWithMultiLevelContextHierarchyWithEmptyContextConfig {
+ }
+
+ @ContextHierarchy({
+ //
+ @ContextConfiguration("foo.xml"),//
+ @ContextConfiguration(classes = BarConfig.class),// duplicate!
+ @ContextConfiguration("baz.xml"),//
+ @ContextConfiguration(classes = BarConfig.class),// duplicate!
+ @ContextConfiguration(loader = AnnotationConfigContextLoader.class) //
+ })
+ private static class SingleTestClassWithMultiLevelContextHierarchyWithDuplicatedContextConfig {
+ }
+
} | true |
Other | spring-projects | spring-framework | 98074e776262292a9d6fa8d164e6718c5876ed6f.json | Provide support for context hierarchies in the TCF
Prior to this commit the Spring TestContext Framework supported creating
only flat, non-hierarchical contexts. There was no easy way to create
contexts with parent-child relationships.
This commit addresses this issue by introducing a new @ContextHierarchy
annotation that can be used in conjunction with @ContextConfiguration
for declaring hierarchies of application contexts, either within a
single test class or within a test class hierarchy. In addition,
@DirtiesContext now supports a new 'hierarchyMode' attribute for
controlling context cache clearing for context hierarchies.
- Introduced a new @ContextHierarchy annotation.
- Introduced 'name' attribute in @ContextConfiguration.
- Introduced 'name' property in ContextConfigurationAttributes.
- TestContext is now aware of @ContextHierarchy in addition to
@ContextConfiguration.
- Introduced findAnnotationDeclaringClassForTypes() in AnnotationUtils.
- Introduced resolveContextHierarchyAttributes() in ContextLoaderUtils.
- Introduced buildContextHierarchyMap() in ContextLoaderUtils.
- @ContextConfiguration and @ContextHierarchy may not be used as
top-level, class-level annotations simultaneously.
- Introduced reference to the parent configuration in
MergedContextConfiguration and WebMergedContextConfiguration.
- Introduced overloaded buildMergedContextConfiguration() methods in
ContextLoaderUtils in order to handle context hierarchies separately
from conventional, non-hierarchical contexts.
- Introduced hashCode() and equals() in ContextConfigurationAttributes.
- ContextLoaderUtils ensures uniqueness of @ContextConfiguration
elements within a single @ContextHierarchy declaration.
- Introduced CacheAwareContextLoaderDelegate that can be used for
loading contexts with transparent support for interacting with the
context cache -- for example, for retrieving the parent application
context in a context hierarchy.
- TestContext now delegates to CacheAwareContextLoaderDelegate for
loading contexts.
- Introduced getParentApplicationContext() in MergedContextConfiguration
- The loadContext(MergedContextConfiguration) methods in
AbstractGenericContextLoader and AbstractGenericWebContextLoader now
set the parent context as appropriate.
- Introduced 'hierarchyMode' attribute in @DirtiesContext with a
corresponding HierarchyMode enum that defines EXHAUSTIVE and
CURRENT_LEVEL cache removal modes.
- ContextCache now internally tracks the relationships between contexts
that make up a context hierarchy. Furthermore, when a context is
removed, if it is part of a context hierarchy all corresponding
contexts will be removed from the cache according to the supplied
HierarchyMode.
- AbstractGenericWebContextLoader will set a loaded context as the
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE in the MockServletContext when
context hierarchies are used if the context has no parent or if the
context has a parent that is not a WAC.
- Where appropriate, updated Javadoc to refer to the
ServletTestExecutionListener, which was introduced in 3.2.0.
- Updated Javadoc to avoid and/or suppress warnings in spring-test.
- Suppressed remaining warnings in code in spring-test.
Issue: SPR-5613, SPR-9863 | spring-test/src/test/java/org/springframework/test/context/MergedContextConfigurationTests.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -76,7 +76,7 @@ public void hashCodeWithEmptyArraysAndDifferentLoaders() {
EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader);
MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY,
EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, new AnnotationConfigContextLoader());
- assertFalse(mergedConfig1.hashCode() == mergedConfig2.hashCode());
+ assertNotEquals(mergedConfig1.hashCode(), mergedConfig2.hashCode());
}
@Test
@@ -97,7 +97,7 @@ public void hashCodeWithDifferentLocations() {
EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader);
MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(), locations2,
EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader);
- assertFalse(mergedConfig1.hashCode() == mergedConfig2.hashCode());
+ assertNotEquals(mergedConfig1.hashCode(), mergedConfig2.hashCode());
}
@Test
@@ -118,7 +118,7 @@ public void hashCodeWithDifferentConfigClasses() {
classes1, EMPTY_STRING_ARRAY, loader);
MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY,
classes2, EMPTY_STRING_ARRAY, loader);
- assertFalse(mergedConfig1.hashCode() == mergedConfig2.hashCode());
+ assertNotEquals(mergedConfig1.hashCode(), mergedConfig2.hashCode());
}
@Test
@@ -161,7 +161,7 @@ public void hashCodeWithDifferentProfiles() {
EMPTY_CLASS_ARRAY, activeProfiles1, loader);
MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY,
EMPTY_CLASS_ARRAY, activeProfiles2, loader);
- assertFalse(mergedConfig1.hashCode() == mergedConfig2.hashCode());
+ assertNotEquals(mergedConfig1.hashCode(), mergedConfig2.hashCode());
}
@Test
@@ -197,15 +197,47 @@ public void hashCodeWithDifferentInitializers() {
EMPTY_CLASS_ARRAY, initializerClasses1, EMPTY_STRING_ARRAY, loader);
MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY,
EMPTY_CLASS_ARRAY, initializerClasses2, EMPTY_STRING_ARRAY, loader);
- assertFalse(mergedConfig1.hashCode() == mergedConfig2.hashCode());
+ assertNotEquals(mergedConfig1.hashCode(), mergedConfig2.hashCode());
+ }
+
+ /**
+ * @since 3.2.2
+ */
+ @Test
+ public void hashCodeWithSameParent() {
+ MergedContextConfiguration parent = new MergedContextConfiguration(getClass(), new String[] { "foo", "bar}" },
+ EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader);
+
+ MergedContextConfiguration mergedConfig1 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY,
+ EMPTY_CLASS_ARRAY, null, EMPTY_STRING_ARRAY, loader, null, parent);
+ MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY,
+ EMPTY_CLASS_ARRAY, null, EMPTY_STRING_ARRAY, loader, null, parent);
+ assertEquals(mergedConfig1.hashCode(), mergedConfig2.hashCode());
+ }
+
+ /**
+ * @since 3.2.2
+ */
+ @Test
+ public void hashCodeWithDifferentParents() {
+ MergedContextConfiguration parent1 = new MergedContextConfiguration(getClass(), new String[] { "foo", "bar}" },
+ EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader);
+ MergedContextConfiguration parent2 = new MergedContextConfiguration(getClass(), new String[] { "baz", "quux" },
+ EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader);
+
+ MergedContextConfiguration mergedConfig1 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY,
+ EMPTY_CLASS_ARRAY, null, EMPTY_STRING_ARRAY, loader, null, parent1);
+ MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY,
+ EMPTY_CLASS_ARRAY, null, EMPTY_STRING_ARRAY, loader, null, parent2);
+ assertNotEquals(mergedConfig1.hashCode(), mergedConfig2.hashCode());
}
@Test
public void equalsBasics() {
MergedContextConfiguration mergedConfig = new MergedContextConfiguration(null, null, null, null, null);
- assertTrue(mergedConfig.equals(mergedConfig));
- assertFalse(mergedConfig.equals(null));
- assertFalse(mergedConfig.equals(new Integer(1)));
+ assertEquals(mergedConfig, mergedConfig);
+ assertNotEquals(mergedConfig, null);
+ assertNotEquals(mergedConfig, new Integer(1));
}
@Test
@@ -237,8 +269,8 @@ public void equalsWithEmptyArraysAndDifferentLoaders() {
EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader);
MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY,
EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, new AnnotationConfigContextLoader());
- assertFalse(mergedConfig1.equals(mergedConfig2));
- assertFalse(mergedConfig2.equals(mergedConfig1));
+ assertNotEquals(mergedConfig1, mergedConfig2);
+ assertNotEquals(mergedConfig2, mergedConfig1);
}
@Test
@@ -259,8 +291,8 @@ public void equalsWithDifferentLocations() {
EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader);
MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(), locations2,
EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader);
- assertFalse(mergedConfig1.equals(mergedConfig2));
- assertFalse(mergedConfig2.equals(mergedConfig1));
+ assertNotEquals(mergedConfig1, mergedConfig2);
+ assertNotEquals(mergedConfig2, mergedConfig1);
}
@Test
@@ -281,8 +313,8 @@ public void equalsWithDifferentConfigClasses() {
classes1, EMPTY_STRING_ARRAY, loader);
MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY,
classes2, EMPTY_STRING_ARRAY, loader);
- assertFalse(mergedConfig1.equals(mergedConfig2));
- assertFalse(mergedConfig2.equals(mergedConfig1));
+ assertNotEquals(mergedConfig1, mergedConfig2);
+ assertNotEquals(mergedConfig2, mergedConfig1);
}
@Test
@@ -325,8 +357,8 @@ public void equalsWithDifferentProfiles() {
EMPTY_CLASS_ARRAY, activeProfiles1, loader);
MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY,
EMPTY_CLASS_ARRAY, activeProfiles2, loader);
- assertFalse(mergedConfig1.equals(mergedConfig2));
- assertFalse(mergedConfig2.equals(mergedConfig1));
+ assertNotEquals(mergedConfig1, mergedConfig2);
+ assertNotEquals(mergedConfig2, mergedConfig1);
}
@Test
@@ -362,8 +394,42 @@ public void equalsWithDifferentInitializers() {
EMPTY_CLASS_ARRAY, initializerClasses1, EMPTY_STRING_ARRAY, loader);
MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY,
EMPTY_CLASS_ARRAY, initializerClasses2, EMPTY_STRING_ARRAY, loader);
- assertFalse(mergedConfig1.equals(mergedConfig2));
- assertFalse(mergedConfig2.equals(mergedConfig1));
+ assertNotEquals(mergedConfig1, mergedConfig2);
+ assertNotEquals(mergedConfig2, mergedConfig1);
+ }
+
+ /**
+ * @since 3.2.2
+ */
+ @Test
+ public void equalsWithSameParent() {
+ MergedContextConfiguration parent = new MergedContextConfiguration(getClass(), new String[] { "foo", "bar}" },
+ EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader);
+
+ MergedContextConfiguration mergedConfig1 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY,
+ EMPTY_CLASS_ARRAY, null, EMPTY_STRING_ARRAY, loader, null, parent);
+ MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY,
+ EMPTY_CLASS_ARRAY, null, EMPTY_STRING_ARRAY, loader, null, parent);
+ assertEquals(mergedConfig1, mergedConfig2);
+ assertEquals(mergedConfig2, mergedConfig1);
+ }
+
+ /**
+ * @since 3.2.2
+ */
+ @Test
+ public void equalsWithDifferentParents() {
+ MergedContextConfiguration parent1 = new MergedContextConfiguration(getClass(), new String[] { "foo", "bar}" },
+ EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader);
+ MergedContextConfiguration parent2 = new MergedContextConfiguration(getClass(), new String[] { "baz", "quux" },
+ EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader);
+
+ MergedContextConfiguration mergedConfig1 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY,
+ EMPTY_CLASS_ARRAY, null, EMPTY_STRING_ARRAY, loader, null, parent1);
+ MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY,
+ EMPTY_CLASS_ARRAY, null, EMPTY_STRING_ARRAY, loader, null, parent2);
+ assertNotEquals(mergedConfig1, mergedConfig2);
+ assertNotEquals(mergedConfig2, mergedConfig1);
}
| true |
Other | spring-projects | spring-framework | 98074e776262292a9d6fa8d164e6718c5876ed6f.json | Provide support for context hierarchies in the TCF
Prior to this commit the Spring TestContext Framework supported creating
only flat, non-hierarchical contexts. There was no easy way to create
contexts with parent-child relationships.
This commit addresses this issue by introducing a new @ContextHierarchy
annotation that can be used in conjunction with @ContextConfiguration
for declaring hierarchies of application contexts, either within a
single test class or within a test class hierarchy. In addition,
@DirtiesContext now supports a new 'hierarchyMode' attribute for
controlling context cache clearing for context hierarchies.
- Introduced a new @ContextHierarchy annotation.
- Introduced 'name' attribute in @ContextConfiguration.
- Introduced 'name' property in ContextConfigurationAttributes.
- TestContext is now aware of @ContextHierarchy in addition to
@ContextConfiguration.
- Introduced findAnnotationDeclaringClassForTypes() in AnnotationUtils.
- Introduced resolveContextHierarchyAttributes() in ContextLoaderUtils.
- Introduced buildContextHierarchyMap() in ContextLoaderUtils.
- @ContextConfiguration and @ContextHierarchy may not be used as
top-level, class-level annotations simultaneously.
- Introduced reference to the parent configuration in
MergedContextConfiguration and WebMergedContextConfiguration.
- Introduced overloaded buildMergedContextConfiguration() methods in
ContextLoaderUtils in order to handle context hierarchies separately
from conventional, non-hierarchical contexts.
- Introduced hashCode() and equals() in ContextConfigurationAttributes.
- ContextLoaderUtils ensures uniqueness of @ContextConfiguration
elements within a single @ContextHierarchy declaration.
- Introduced CacheAwareContextLoaderDelegate that can be used for
loading contexts with transparent support for interacting with the
context cache -- for example, for retrieving the parent application
context in a context hierarchy.
- TestContext now delegates to CacheAwareContextLoaderDelegate for
loading contexts.
- Introduced getParentApplicationContext() in MergedContextConfiguration
- The loadContext(MergedContextConfiguration) methods in
AbstractGenericContextLoader and AbstractGenericWebContextLoader now
set the parent context as appropriate.
- Introduced 'hierarchyMode' attribute in @DirtiesContext with a
corresponding HierarchyMode enum that defines EXHAUSTIVE and
CURRENT_LEVEL cache removal modes.
- ContextCache now internally tracks the relationships between contexts
that make up a context hierarchy. Furthermore, when a context is
removed, if it is part of a context hierarchy all corresponding
contexts will be removed from the cache according to the supplied
HierarchyMode.
- AbstractGenericWebContextLoader will set a loaded context as the
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE in the MockServletContext when
context hierarchies are used if the context has no parent or if the
context has a parent that is not a WAC.
- Where appropriate, updated Javadoc to refer to the
ServletTestExecutionListener, which was introduced in 3.2.0.
- Updated Javadoc to avoid and/or suppress warnings in spring-test.
- Suppressed remaining warnings in code in spring-test.
Issue: SPR-5613, SPR-9863 | spring-test/src/test/java/org/springframework/test/context/SpringRunnerContextCacheTests.java | @@ -44,7 +44,7 @@
* @author Sam Brannen
* @author Juergen Hoeller
* @since 2.5
- * @see TestContextCacheKeyTests
+ * @see ContextCacheTests
*/
@RunWith(OrderedMethodsSpringJUnit4ClassRunner.class)
@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class }) | true |
Other | spring-projects | spring-framework | 98074e776262292a9d6fa8d164e6718c5876ed6f.json | Provide support for context hierarchies in the TCF
Prior to this commit the Spring TestContext Framework supported creating
only flat, non-hierarchical contexts. There was no easy way to create
contexts with parent-child relationships.
This commit addresses this issue by introducing a new @ContextHierarchy
annotation that can be used in conjunction with @ContextConfiguration
for declaring hierarchies of application contexts, either within a
single test class or within a test class hierarchy. In addition,
@DirtiesContext now supports a new 'hierarchyMode' attribute for
controlling context cache clearing for context hierarchies.
- Introduced a new @ContextHierarchy annotation.
- Introduced 'name' attribute in @ContextConfiguration.
- Introduced 'name' property in ContextConfigurationAttributes.
- TestContext is now aware of @ContextHierarchy in addition to
@ContextConfiguration.
- Introduced findAnnotationDeclaringClassForTypes() in AnnotationUtils.
- Introduced resolveContextHierarchyAttributes() in ContextLoaderUtils.
- Introduced buildContextHierarchyMap() in ContextLoaderUtils.
- @ContextConfiguration and @ContextHierarchy may not be used as
top-level, class-level annotations simultaneously.
- Introduced reference to the parent configuration in
MergedContextConfiguration and WebMergedContextConfiguration.
- Introduced overloaded buildMergedContextConfiguration() methods in
ContextLoaderUtils in order to handle context hierarchies separately
from conventional, non-hierarchical contexts.
- Introduced hashCode() and equals() in ContextConfigurationAttributes.
- ContextLoaderUtils ensures uniqueness of @ContextConfiguration
elements within a single @ContextHierarchy declaration.
- Introduced CacheAwareContextLoaderDelegate that can be used for
loading contexts with transparent support for interacting with the
context cache -- for example, for retrieving the parent application
context in a context hierarchy.
- TestContext now delegates to CacheAwareContextLoaderDelegate for
loading contexts.
- Introduced getParentApplicationContext() in MergedContextConfiguration
- The loadContext(MergedContextConfiguration) methods in
AbstractGenericContextLoader and AbstractGenericWebContextLoader now
set the parent context as appropriate.
- Introduced 'hierarchyMode' attribute in @DirtiesContext with a
corresponding HierarchyMode enum that defines EXHAUSTIVE and
CURRENT_LEVEL cache removal modes.
- ContextCache now internally tracks the relationships between contexts
that make up a context hierarchy. Furthermore, when a context is
removed, if it is part of a context hierarchy all corresponding
contexts will be removed from the cache according to the supplied
HierarchyMode.
- AbstractGenericWebContextLoader will set a loaded context as the
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE in the MockServletContext when
context hierarchies are used if the context has no parent or if the
context has a parent that is not a WAC.
- Where appropriate, updated Javadoc to refer to the
ServletTestExecutionListener, which was introduced in 3.2.0.
- Updated Javadoc to avoid and/or suppress warnings in spring-test.
- Suppressed remaining warnings in code in spring-test.
Issue: SPR-5613, SPR-9863 | spring-test/src/test/java/org/springframework/test/context/TestContextCacheKeyTests.java | @@ -1,102 +0,0 @@
-/*
- * 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.test.context;
-
-import static org.junit.Assert.assertNotNull;
-import static org.springframework.test.context.SpringRunnerContextCacheTests.assertContextCacheStatistics;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.test.context.support.AnnotationConfigContextLoader;
-
-/**
- * Unit tests for verifying proper behavior of the {@link ContextCache} in
- * conjunction with cache keys used in {@link TestContext}.
- *
- * @author Sam Brannen
- * @since 3.1
- * @see SpringRunnerContextCacheTests
- */
-public class TestContextCacheKeyTests {
-
- private ContextCache contextCache = new ContextCache();
-
-
- @Before
- public void initialCacheState() {
- assertContextCacheStatistics(contextCache, "initial state", 0, 0, 0);
- }
-
- private void loadAppCtxAndAssertCacheStats(Class<?> testClass, int expectedSize, int expectedHitCount,
- int expectedMissCount) {
- TestContext testContext = new TestContext(testClass, contextCache);
- ApplicationContext context = testContext.getApplicationContext();
- assertNotNull(context);
- assertContextCacheStatistics(contextCache, testClass.getName(), expectedSize, expectedHitCount,
- expectedMissCount);
- }
-
- @Test
- public void verifyCacheKeyIsBasedOnContextLoader() {
- loadAppCtxAndAssertCacheStats(AnnotationConfigContextLoaderTestCase.class, 1, 0, 1);
- loadAppCtxAndAssertCacheStats(AnnotationConfigContextLoaderTestCase.class, 1, 1, 1);
- loadAppCtxAndAssertCacheStats(CustomAnnotationConfigContextLoaderTestCase.class, 2, 1, 2);
- loadAppCtxAndAssertCacheStats(CustomAnnotationConfigContextLoaderTestCase.class, 2, 2, 2);
- loadAppCtxAndAssertCacheStats(AnnotationConfigContextLoaderTestCase.class, 2, 3, 2);
- loadAppCtxAndAssertCacheStats(CustomAnnotationConfigContextLoaderTestCase.class, 2, 4, 2);
- }
-
- @Test
- public void verifyCacheKeyIsBasedOnActiveProfiles() {
- loadAppCtxAndAssertCacheStats(FooBarProfilesTestCase.class, 1, 0, 1);
- loadAppCtxAndAssertCacheStats(FooBarProfilesTestCase.class, 1, 1, 1);
- // Profiles {foo, bar} should hash to the same as {bar,foo}
- loadAppCtxAndAssertCacheStats(BarFooProfilesTestCase.class, 1, 2, 1);
- loadAppCtxAndAssertCacheStats(FooBarProfilesTestCase.class, 1, 3, 1);
- loadAppCtxAndAssertCacheStats(FooBarProfilesTestCase.class, 1, 4, 1);
- loadAppCtxAndAssertCacheStats(BarFooProfilesTestCase.class, 1, 5, 1);
- }
-
-
- @Configuration
- static class Config {
- }
-
- @ContextConfiguration(classes = Config.class, loader = AnnotationConfigContextLoader.class)
- private static class AnnotationConfigContextLoaderTestCase {
- }
-
- @ContextConfiguration(classes = Config.class, loader = CustomAnnotationConfigContextLoader.class)
- private static class CustomAnnotationConfigContextLoaderTestCase {
- }
-
- private static class CustomAnnotationConfigContextLoader extends AnnotationConfigContextLoader {
- }
-
- @ActiveProfiles({ "foo", "bar" })
- @ContextConfiguration(classes = Config.class, loader = AnnotationConfigContextLoader.class)
- private static class FooBarProfilesTestCase {
- }
-
- @ActiveProfiles({ "bar", "foo" })
- @ContextConfiguration(classes = Config.class, loader = AnnotationConfigContextLoader.class)
- private static class BarFooProfilesTestCase {
- }
-
-} | true |
Other | spring-projects | spring-framework | 98074e776262292a9d6fa8d164e6718c5876ed6f.json | Provide support for context hierarchies in the TCF
Prior to this commit the Spring TestContext Framework supported creating
only flat, non-hierarchical contexts. There was no easy way to create
contexts with parent-child relationships.
This commit addresses this issue by introducing a new @ContextHierarchy
annotation that can be used in conjunction with @ContextConfiguration
for declaring hierarchies of application contexts, either within a
single test class or within a test class hierarchy. In addition,
@DirtiesContext now supports a new 'hierarchyMode' attribute for
controlling context cache clearing for context hierarchies.
- Introduced a new @ContextHierarchy annotation.
- Introduced 'name' attribute in @ContextConfiguration.
- Introduced 'name' property in ContextConfigurationAttributes.
- TestContext is now aware of @ContextHierarchy in addition to
@ContextConfiguration.
- Introduced findAnnotationDeclaringClassForTypes() in AnnotationUtils.
- Introduced resolveContextHierarchyAttributes() in ContextLoaderUtils.
- Introduced buildContextHierarchyMap() in ContextLoaderUtils.
- @ContextConfiguration and @ContextHierarchy may not be used as
top-level, class-level annotations simultaneously.
- Introduced reference to the parent configuration in
MergedContextConfiguration and WebMergedContextConfiguration.
- Introduced overloaded buildMergedContextConfiguration() methods in
ContextLoaderUtils in order to handle context hierarchies separately
from conventional, non-hierarchical contexts.
- Introduced hashCode() and equals() in ContextConfigurationAttributes.
- ContextLoaderUtils ensures uniqueness of @ContextConfiguration
elements within a single @ContextHierarchy declaration.
- Introduced CacheAwareContextLoaderDelegate that can be used for
loading contexts with transparent support for interacting with the
context cache -- for example, for retrieving the parent application
context in a context hierarchy.
- TestContext now delegates to CacheAwareContextLoaderDelegate for
loading contexts.
- Introduced getParentApplicationContext() in MergedContextConfiguration
- The loadContext(MergedContextConfiguration) methods in
AbstractGenericContextLoader and AbstractGenericWebContextLoader now
set the parent context as appropriate.
- Introduced 'hierarchyMode' attribute in @DirtiesContext with a
corresponding HierarchyMode enum that defines EXHAUSTIVE and
CURRENT_LEVEL cache removal modes.
- ContextCache now internally tracks the relationships between contexts
that make up a context hierarchy. Furthermore, when a context is
removed, if it is part of a context hierarchy all corresponding
contexts will be removed from the cache according to the supplied
HierarchyMode.
- AbstractGenericWebContextLoader will set a loaded context as the
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE in the MockServletContext when
context hierarchies are used if the context has no parent or if the
context has a parent that is not a WAC.
- Where appropriate, updated Javadoc to refer to the
ServletTestExecutionListener, which was introduced in 3.2.0.
- Updated Javadoc to avoid and/or suppress warnings in spring-test.
- Suppressed remaining warnings in code in spring-test.
Issue: SPR-5613, SPR-9863 | spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/ClassHierarchyWithMergedConfigLevelOneTests.java | @@ -0,0 +1,96 @@
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.test.context.hierarchies.standard;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.ContextHierarchy;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+/**
+ * @author Sam Brannen
+ * @since 3.2.2
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextHierarchy({
+//
+ @ContextConfiguration(name = "parent", classes = ClassHierarchyWithMergedConfigLevelOneTests.AppConfig.class),//
+ @ContextConfiguration(name = "child", classes = ClassHierarchyWithMergedConfigLevelOneTests.UserConfig.class) //
+})
+public class ClassHierarchyWithMergedConfigLevelOneTests {
+
+ @Configuration
+ static class AppConfig {
+
+ @Bean
+ public String parent() {
+ return "parent";
+ }
+ }
+
+ @Configuration
+ static class UserConfig {
+
+ @Autowired
+ private AppConfig appConfig;
+
+
+ @Bean
+ public String user() {
+ return appConfig.parent() + " + user";
+ }
+
+ @Bean
+ public String beanFromUserConfig() {
+ return "from UserConfig";
+ }
+ }
+
+
+ @Autowired
+ protected String parent;
+
+ @Autowired
+ protected String user;
+
+ @Autowired(required = false)
+ @Qualifier("beanFromUserConfig")
+ protected String beanFromUserConfig;
+
+ @Autowired
+ protected ApplicationContext context;
+
+
+ @Test
+ public void loadContextHierarchy() {
+ assertNotNull("child ApplicationContext", context);
+ assertNotNull("parent ApplicationContext", context.getParent());
+ assertNull("grandparent ApplicationContext", context.getParent().getParent());
+ assertEquals("parent", parent);
+ assertEquals("parent + user", user);
+ assertEquals("from UserConfig", beanFromUserConfig);
+ }
+
+} | true |
Other | spring-projects | spring-framework | 98074e776262292a9d6fa8d164e6718c5876ed6f.json | Provide support for context hierarchies in the TCF
Prior to this commit the Spring TestContext Framework supported creating
only flat, non-hierarchical contexts. There was no easy way to create
contexts with parent-child relationships.
This commit addresses this issue by introducing a new @ContextHierarchy
annotation that can be used in conjunction with @ContextConfiguration
for declaring hierarchies of application contexts, either within a
single test class or within a test class hierarchy. In addition,
@DirtiesContext now supports a new 'hierarchyMode' attribute for
controlling context cache clearing for context hierarchies.
- Introduced a new @ContextHierarchy annotation.
- Introduced 'name' attribute in @ContextConfiguration.
- Introduced 'name' property in ContextConfigurationAttributes.
- TestContext is now aware of @ContextHierarchy in addition to
@ContextConfiguration.
- Introduced findAnnotationDeclaringClassForTypes() in AnnotationUtils.
- Introduced resolveContextHierarchyAttributes() in ContextLoaderUtils.
- Introduced buildContextHierarchyMap() in ContextLoaderUtils.
- @ContextConfiguration and @ContextHierarchy may not be used as
top-level, class-level annotations simultaneously.
- Introduced reference to the parent configuration in
MergedContextConfiguration and WebMergedContextConfiguration.
- Introduced overloaded buildMergedContextConfiguration() methods in
ContextLoaderUtils in order to handle context hierarchies separately
from conventional, non-hierarchical contexts.
- Introduced hashCode() and equals() in ContextConfigurationAttributes.
- ContextLoaderUtils ensures uniqueness of @ContextConfiguration
elements within a single @ContextHierarchy declaration.
- Introduced CacheAwareContextLoaderDelegate that can be used for
loading contexts with transparent support for interacting with the
context cache -- for example, for retrieving the parent application
context in a context hierarchy.
- TestContext now delegates to CacheAwareContextLoaderDelegate for
loading contexts.
- Introduced getParentApplicationContext() in MergedContextConfiguration
- The loadContext(MergedContextConfiguration) methods in
AbstractGenericContextLoader and AbstractGenericWebContextLoader now
set the parent context as appropriate.
- Introduced 'hierarchyMode' attribute in @DirtiesContext with a
corresponding HierarchyMode enum that defines EXHAUSTIVE and
CURRENT_LEVEL cache removal modes.
- ContextCache now internally tracks the relationships between contexts
that make up a context hierarchy. Furthermore, when a context is
removed, if it is part of a context hierarchy all corresponding
contexts will be removed from the cache according to the supplied
HierarchyMode.
- AbstractGenericWebContextLoader will set a loaded context as the
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE in the MockServletContext when
context hierarchies are used if the context has no parent or if the
context has a parent that is not a WAC.
- Where appropriate, updated Javadoc to refer to the
ServletTestExecutionListener, which was introduced in 3.2.0.
- Updated Javadoc to avoid and/or suppress warnings in spring-test.
- Suppressed remaining warnings in code in spring-test.
Issue: SPR-5613, SPR-9863 | spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/ClassHierarchyWithMergedConfigLevelTwoTests.java | @@ -0,0 +1,62 @@
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.test.context.hierarchies.standard;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.ContextHierarchy;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+/**
+ * @author Sam Brannen
+ * @since 3.2.2
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextHierarchy(@ContextConfiguration(name = "child", classes = ClassHierarchyWithMergedConfigLevelTwoTests.OrderConfig.class))
+public class ClassHierarchyWithMergedConfigLevelTwoTests extends ClassHierarchyWithMergedConfigLevelOneTests {
+
+ @Configuration
+ static class OrderConfig {
+
+ @Autowired
+ private ClassHierarchyWithMergedConfigLevelOneTests.UserConfig userConfig;
+
+ @Bean
+ public String order() {
+ return userConfig.user() + " + order";
+ }
+ }
+
+
+ @Autowired
+ private String order;
+
+
+ @Test
+ @Override
+ public void loadContextHierarchy() {
+ super.loadContextHierarchy();
+ assertEquals("parent + user + order", order);
+ }
+
+} | true |
Other | spring-projects | spring-framework | 98074e776262292a9d6fa8d164e6718c5876ed6f.json | Provide support for context hierarchies in the TCF
Prior to this commit the Spring TestContext Framework supported creating
only flat, non-hierarchical contexts. There was no easy way to create
contexts with parent-child relationships.
This commit addresses this issue by introducing a new @ContextHierarchy
annotation that can be used in conjunction with @ContextConfiguration
for declaring hierarchies of application contexts, either within a
single test class or within a test class hierarchy. In addition,
@DirtiesContext now supports a new 'hierarchyMode' attribute for
controlling context cache clearing for context hierarchies.
- Introduced a new @ContextHierarchy annotation.
- Introduced 'name' attribute in @ContextConfiguration.
- Introduced 'name' property in ContextConfigurationAttributes.
- TestContext is now aware of @ContextHierarchy in addition to
@ContextConfiguration.
- Introduced findAnnotationDeclaringClassForTypes() in AnnotationUtils.
- Introduced resolveContextHierarchyAttributes() in ContextLoaderUtils.
- Introduced buildContextHierarchyMap() in ContextLoaderUtils.
- @ContextConfiguration and @ContextHierarchy may not be used as
top-level, class-level annotations simultaneously.
- Introduced reference to the parent configuration in
MergedContextConfiguration and WebMergedContextConfiguration.
- Introduced overloaded buildMergedContextConfiguration() methods in
ContextLoaderUtils in order to handle context hierarchies separately
from conventional, non-hierarchical contexts.
- Introduced hashCode() and equals() in ContextConfigurationAttributes.
- ContextLoaderUtils ensures uniqueness of @ContextConfiguration
elements within a single @ContextHierarchy declaration.
- Introduced CacheAwareContextLoaderDelegate that can be used for
loading contexts with transparent support for interacting with the
context cache -- for example, for retrieving the parent application
context in a context hierarchy.
- TestContext now delegates to CacheAwareContextLoaderDelegate for
loading contexts.
- Introduced getParentApplicationContext() in MergedContextConfiguration
- The loadContext(MergedContextConfiguration) methods in
AbstractGenericContextLoader and AbstractGenericWebContextLoader now
set the parent context as appropriate.
- Introduced 'hierarchyMode' attribute in @DirtiesContext with a
corresponding HierarchyMode enum that defines EXHAUSTIVE and
CURRENT_LEVEL cache removal modes.
- ContextCache now internally tracks the relationships between contexts
that make up a context hierarchy. Furthermore, when a context is
removed, if it is part of a context hierarchy all corresponding
contexts will be removed from the cache according to the supplied
HierarchyMode.
- AbstractGenericWebContextLoader will set a loaded context as the
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE in the MockServletContext when
context hierarchies are used if the context has no parent or if the
context has a parent that is not a WAC.
- Where appropriate, updated Javadoc to refer to the
ServletTestExecutionListener, which was introduced in 3.2.0.
- Updated Javadoc to avoid and/or suppress warnings in spring-test.
- Suppressed remaining warnings in code in spring-test.
Issue: SPR-5613, SPR-9863 | spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/ClassHierarchyWithOverriddenConfigLevelTwoTests.java | @@ -0,0 +1,73 @@
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.test.context.hierarchies.standard;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.ContextHierarchy;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+/**
+ * @author Sam Brannen
+ * @since 3.2.2
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextHierarchy(@ContextConfiguration(name = "child", classes = ClassHierarchyWithOverriddenConfigLevelTwoTests.TestUserConfig.class, inheritLocations = false))
+public class ClassHierarchyWithOverriddenConfigLevelTwoTests extends ClassHierarchyWithMergedConfigLevelOneTests {
+
+ @Configuration
+ static class TestUserConfig {
+
+ @Autowired
+ private ClassHierarchyWithMergedConfigLevelOneTests.AppConfig appConfig;
+
+
+ @Bean
+ public String user() {
+ return appConfig.parent() + " + test user";
+ }
+
+ @Bean
+ public String beanFromTestUserConfig() {
+ return "from TestUserConfig";
+ }
+ }
+
+
+ @Autowired
+ private String beanFromTestUserConfig;
+
+
+ @Test
+ @Override
+ public void loadContextHierarchy() {
+ assertNotNull("child ApplicationContext", context);
+ assertNotNull("parent ApplicationContext", context.getParent());
+ assertNull("grandparent ApplicationContext", context.getParent().getParent());
+ assertEquals("parent", parent);
+ assertEquals("parent + test user", user);
+ assertEquals("from TestUserConfig", beanFromTestUserConfig);
+ assertNull("Bean from UserConfig should not be present.", beanFromUserConfig);
+ }
+
+} | true |
Other | spring-projects | spring-framework | 98074e776262292a9d6fa8d164e6718c5876ed6f.json | Provide support for context hierarchies in the TCF
Prior to this commit the Spring TestContext Framework supported creating
only flat, non-hierarchical contexts. There was no easy way to create
contexts with parent-child relationships.
This commit addresses this issue by introducing a new @ContextHierarchy
annotation that can be used in conjunction with @ContextConfiguration
for declaring hierarchies of application contexts, either within a
single test class or within a test class hierarchy. In addition,
@DirtiesContext now supports a new 'hierarchyMode' attribute for
controlling context cache clearing for context hierarchies.
- Introduced a new @ContextHierarchy annotation.
- Introduced 'name' attribute in @ContextConfiguration.
- Introduced 'name' property in ContextConfigurationAttributes.
- TestContext is now aware of @ContextHierarchy in addition to
@ContextConfiguration.
- Introduced findAnnotationDeclaringClassForTypes() in AnnotationUtils.
- Introduced resolveContextHierarchyAttributes() in ContextLoaderUtils.
- Introduced buildContextHierarchyMap() in ContextLoaderUtils.
- @ContextConfiguration and @ContextHierarchy may not be used as
top-level, class-level annotations simultaneously.
- Introduced reference to the parent configuration in
MergedContextConfiguration and WebMergedContextConfiguration.
- Introduced overloaded buildMergedContextConfiguration() methods in
ContextLoaderUtils in order to handle context hierarchies separately
from conventional, non-hierarchical contexts.
- Introduced hashCode() and equals() in ContextConfigurationAttributes.
- ContextLoaderUtils ensures uniqueness of @ContextConfiguration
elements within a single @ContextHierarchy declaration.
- Introduced CacheAwareContextLoaderDelegate that can be used for
loading contexts with transparent support for interacting with the
context cache -- for example, for retrieving the parent application
context in a context hierarchy.
- TestContext now delegates to CacheAwareContextLoaderDelegate for
loading contexts.
- Introduced getParentApplicationContext() in MergedContextConfiguration
- The loadContext(MergedContextConfiguration) methods in
AbstractGenericContextLoader and AbstractGenericWebContextLoader now
set the parent context as appropriate.
- Introduced 'hierarchyMode' attribute in @DirtiesContext with a
corresponding HierarchyMode enum that defines EXHAUSTIVE and
CURRENT_LEVEL cache removal modes.
- ContextCache now internally tracks the relationships between contexts
that make up a context hierarchy. Furthermore, when a context is
removed, if it is part of a context hierarchy all corresponding
contexts will be removed from the cache according to the supplied
HierarchyMode.
- AbstractGenericWebContextLoader will set a loaded context as the
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE in the MockServletContext when
context hierarchies are used if the context has no parent or if the
context has a parent that is not a WAC.
- Where appropriate, updated Javadoc to refer to the
ServletTestExecutionListener, which was introduced in 3.2.0.
- Updated Javadoc to avoid and/or suppress warnings in spring-test.
- Suppressed remaining warnings in code in spring-test.
Issue: SPR-5613, SPR-9863 | spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/DirtiesContextWithContextHierarchyTests.java | @@ -0,0 +1,149 @@
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.test.context.hierarchies.standard;
+
+import org.junit.Before;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.MethodSorters;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.annotation.DirtiesContext.HierarchyMode;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.ContextHierarchy;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import static org.junit.Assert.*;
+
+/**
+ * Integration tests that verify support for {@link DirtiesContext.HierarchyMode}
+ * in conjunction with context hierarchies configured via {@link ContextHierarchy}.
+ *
+ * <p>Note that correct method execution order is essential, thus the use of
+ * {@link FixMethodOrder}.
+ *
+ * @author Sam Brannen
+ * @since 3.2.2
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextHierarchy({ @ContextConfiguration(classes = DirtiesContextWithContextHierarchyTests.ParentConfig.class),
+ @ContextConfiguration(classes = DirtiesContextWithContextHierarchyTests.ChildConfig.class) })
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class DirtiesContextWithContextHierarchyTests {
+
+ @Configuration
+ static class ParentConfig {
+
+ @Bean
+ public StringBuffer foo() {
+ return new StringBuffer("foo");
+ }
+
+ @Bean
+ public StringBuffer baz() {
+ return new StringBuffer("baz-parent");
+ }
+ }
+
+ @Configuration
+ static class ChildConfig {
+
+ @Bean
+ public StringBuffer baz() {
+ return new StringBuffer("baz-child");
+ }
+ }
+
+
+ @Autowired
+ private StringBuffer foo;
+
+ @Autowired
+ private StringBuffer baz;
+
+ @Autowired
+ private ApplicationContext context;
+
+
+ // -------------------------------------------------------------------------
+
+ private void reverseStringBuffers() {
+ foo.reverse();
+ baz.reverse();
+ }
+
+ private void assertOriginalState() {
+ assertCleanParentContext();
+ assertCleanChildContext();
+ }
+
+ private void assertCleanParentContext() {
+ assertEquals("foo", foo.toString());
+ }
+
+ private void assertCleanChildContext() {
+ assertEquals("baz-child", baz.toString());
+ }
+
+ private void assertDirtyParentContext() {
+ assertEquals("oof", foo.toString());
+ }
+
+ private void assertDirtyChildContext() {
+ assertEquals("dlihc-zab", baz.toString());
+ }
+
+ // -------------------------------------------------------------------------
+
+ @Before
+ public void verifyContextHierarchy() {
+ assertNotNull("child ApplicationContext", context);
+ assertNotNull("parent ApplicationContext", context.getParent());
+ assertNull("grandparent ApplicationContext", context.getParent().getParent());
+ }
+
+ @Test
+ public void test1_verifyOriginalStateAndDirtyContexts() {
+ assertOriginalState();
+ reverseStringBuffers();
+ }
+
+ @Test
+ @DirtiesContext
+ public void test2_verifyContextsWereDirtiedAndTriggerExhaustiveCacheClearing() {
+ assertDirtyParentContext();
+ assertDirtyChildContext();
+ }
+
+ @Test
+ @DirtiesContext(hierarchyMode = HierarchyMode.CURRENT_LEVEL)
+ public void test3_verifyOriginalStateWasReinstatedAndDirtyContextsAndTriggerCurrentLevelCacheClearing() {
+ assertOriginalState();
+ reverseStringBuffers();
+ }
+
+ @Test
+ public void test4_verifyParentContextIsStillDirtyButChildContextHasBeenReinstated() {
+ assertDirtyParentContext();
+ assertCleanChildContext();
+ }
+
+} | true |
Other | spring-projects | spring-framework | 98074e776262292a9d6fa8d164e6718c5876ed6f.json | Provide support for context hierarchies in the TCF
Prior to this commit the Spring TestContext Framework supported creating
only flat, non-hierarchical contexts. There was no easy way to create
contexts with parent-child relationships.
This commit addresses this issue by introducing a new @ContextHierarchy
annotation that can be used in conjunction with @ContextConfiguration
for declaring hierarchies of application contexts, either within a
single test class or within a test class hierarchy. In addition,
@DirtiesContext now supports a new 'hierarchyMode' attribute for
controlling context cache clearing for context hierarchies.
- Introduced a new @ContextHierarchy annotation.
- Introduced 'name' attribute in @ContextConfiguration.
- Introduced 'name' property in ContextConfigurationAttributes.
- TestContext is now aware of @ContextHierarchy in addition to
@ContextConfiguration.
- Introduced findAnnotationDeclaringClassForTypes() in AnnotationUtils.
- Introduced resolveContextHierarchyAttributes() in ContextLoaderUtils.
- Introduced buildContextHierarchyMap() in ContextLoaderUtils.
- @ContextConfiguration and @ContextHierarchy may not be used as
top-level, class-level annotations simultaneously.
- Introduced reference to the parent configuration in
MergedContextConfiguration and WebMergedContextConfiguration.
- Introduced overloaded buildMergedContextConfiguration() methods in
ContextLoaderUtils in order to handle context hierarchies separately
from conventional, non-hierarchical contexts.
- Introduced hashCode() and equals() in ContextConfigurationAttributes.
- ContextLoaderUtils ensures uniqueness of @ContextConfiguration
elements within a single @ContextHierarchy declaration.
- Introduced CacheAwareContextLoaderDelegate that can be used for
loading contexts with transparent support for interacting with the
context cache -- for example, for retrieving the parent application
context in a context hierarchy.
- TestContext now delegates to CacheAwareContextLoaderDelegate for
loading contexts.
- Introduced getParentApplicationContext() in MergedContextConfiguration
- The loadContext(MergedContextConfiguration) methods in
AbstractGenericContextLoader and AbstractGenericWebContextLoader now
set the parent context as appropriate.
- Introduced 'hierarchyMode' attribute in @DirtiesContext with a
corresponding HierarchyMode enum that defines EXHAUSTIVE and
CURRENT_LEVEL cache removal modes.
- ContextCache now internally tracks the relationships between contexts
that make up a context hierarchy. Furthermore, when a context is
removed, if it is part of a context hierarchy all corresponding
contexts will be removed from the cache according to the supplied
HierarchyMode.
- AbstractGenericWebContextLoader will set a loaded context as the
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE in the MockServletContext when
context hierarchies are used if the context has no parent or if the
context has a parent that is not a WAC.
- Where appropriate, updated Javadoc to refer to the
ServletTestExecutionListener, which was introduced in 3.2.0.
- Updated Javadoc to avoid and/or suppress warnings in spring-test.
- Suppressed remaining warnings in code in spring-test.
Issue: SPR-5613, SPR-9863 | spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/SingleTestClassWithSingleLevelContextHierarchyTests.java | @@ -0,0 +1,63 @@
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.test.context.hierarchies.standard;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.ContextHierarchy;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+/**
+ * @author Sam Brannen
+ * @since 3.2.2
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextHierarchy(@ContextConfiguration)
+public class SingleTestClassWithSingleLevelContextHierarchyTests {
+
+ @Configuration
+ static class Config {
+
+ @Bean
+ public String foo() {
+ return "foo";
+ }
+ }
+
+
+ @Autowired
+ private String foo;
+
+ @Autowired
+ private ApplicationContext context;
+
+
+ @Test
+ public void loadContextHierarchy() {
+ assertNotNull("child ApplicationContext", context);
+ assertNull("parent ApplicationContext", context.getParent());
+ assertEquals("foo", foo);
+ }
+
+} | true |
Other | spring-projects | spring-framework | 98074e776262292a9d6fa8d164e6718c5876ed6f.json | Provide support for context hierarchies in the TCF
Prior to this commit the Spring TestContext Framework supported creating
only flat, non-hierarchical contexts. There was no easy way to create
contexts with parent-child relationships.
This commit addresses this issue by introducing a new @ContextHierarchy
annotation that can be used in conjunction with @ContextConfiguration
for declaring hierarchies of application contexts, either within a
single test class or within a test class hierarchy. In addition,
@DirtiesContext now supports a new 'hierarchyMode' attribute for
controlling context cache clearing for context hierarchies.
- Introduced a new @ContextHierarchy annotation.
- Introduced 'name' attribute in @ContextConfiguration.
- Introduced 'name' property in ContextConfigurationAttributes.
- TestContext is now aware of @ContextHierarchy in addition to
@ContextConfiguration.
- Introduced findAnnotationDeclaringClassForTypes() in AnnotationUtils.
- Introduced resolveContextHierarchyAttributes() in ContextLoaderUtils.
- Introduced buildContextHierarchyMap() in ContextLoaderUtils.
- @ContextConfiguration and @ContextHierarchy may not be used as
top-level, class-level annotations simultaneously.
- Introduced reference to the parent configuration in
MergedContextConfiguration and WebMergedContextConfiguration.
- Introduced overloaded buildMergedContextConfiguration() methods in
ContextLoaderUtils in order to handle context hierarchies separately
from conventional, non-hierarchical contexts.
- Introduced hashCode() and equals() in ContextConfigurationAttributes.
- ContextLoaderUtils ensures uniqueness of @ContextConfiguration
elements within a single @ContextHierarchy declaration.
- Introduced CacheAwareContextLoaderDelegate that can be used for
loading contexts with transparent support for interacting with the
context cache -- for example, for retrieving the parent application
context in a context hierarchy.
- TestContext now delegates to CacheAwareContextLoaderDelegate for
loading contexts.
- Introduced getParentApplicationContext() in MergedContextConfiguration
- The loadContext(MergedContextConfiguration) methods in
AbstractGenericContextLoader and AbstractGenericWebContextLoader now
set the parent context as appropriate.
- Introduced 'hierarchyMode' attribute in @DirtiesContext with a
corresponding HierarchyMode enum that defines EXHAUSTIVE and
CURRENT_LEVEL cache removal modes.
- ContextCache now internally tracks the relationships between contexts
that make up a context hierarchy. Furthermore, when a context is
removed, if it is part of a context hierarchy all corresponding
contexts will be removed from the cache according to the supplied
HierarchyMode.
- AbstractGenericWebContextLoader will set a loaded context as the
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE in the MockServletContext when
context hierarchies are used if the context has no parent or if the
context has a parent that is not a WAC.
- Where appropriate, updated Javadoc to refer to the
ServletTestExecutionListener, which was introduced in 3.2.0.
- Updated Javadoc to avoid and/or suppress warnings in spring-test.
- Suppressed remaining warnings in code in spring-test.
Issue: SPR-5613, SPR-9863 | spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/SingleTestClassWithTwoLevelContextHierarchyAndMixedConfigTypesTests.java | @@ -0,0 +1,79 @@
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.test.context.hierarchies.standard;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.ContextHierarchy;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+/**
+ * @author Sam Brannen
+ * @since 3.2.2
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextHierarchy({
+ @ContextConfiguration(classes = SingleTestClassWithTwoLevelContextHierarchyAndMixedConfigTypesTests.ParentConfig.class),
+ @ContextConfiguration("SingleTestClassWithTwoLevelContextHierarchyAndMixedConfigTypesTests-ChildConfig.xml") })
+public class SingleTestClassWithTwoLevelContextHierarchyAndMixedConfigTypesTests {
+
+ @Configuration
+ static class ParentConfig {
+
+ @Bean
+ public String foo() {
+ return "foo";
+ }
+
+ @Bean
+ public String baz() {
+ return "baz-parent";
+ }
+ }
+
+
+ @Autowired
+ private String foo;
+
+ @Autowired
+ private String bar;
+
+ @Autowired
+ private String baz;
+
+ @Autowired
+ private ApplicationContext context;
+
+
+ @Test
+ public void loadContextHierarchy() {
+ assertNotNull("child ApplicationContext", context);
+ assertNotNull("parent ApplicationContext", context.getParent());
+ assertNull("grandparent ApplicationContext", context.getParent().getParent());
+ assertEquals("foo", foo);
+ assertEquals("bar", bar);
+ assertEquals("baz-child", baz);
+ }
+
+} | true |
Other | spring-projects | spring-framework | 98074e776262292a9d6fa8d164e6718c5876ed6f.json | Provide support for context hierarchies in the TCF
Prior to this commit the Spring TestContext Framework supported creating
only flat, non-hierarchical contexts. There was no easy way to create
contexts with parent-child relationships.
This commit addresses this issue by introducing a new @ContextHierarchy
annotation that can be used in conjunction with @ContextConfiguration
for declaring hierarchies of application contexts, either within a
single test class or within a test class hierarchy. In addition,
@DirtiesContext now supports a new 'hierarchyMode' attribute for
controlling context cache clearing for context hierarchies.
- Introduced a new @ContextHierarchy annotation.
- Introduced 'name' attribute in @ContextConfiguration.
- Introduced 'name' property in ContextConfigurationAttributes.
- TestContext is now aware of @ContextHierarchy in addition to
@ContextConfiguration.
- Introduced findAnnotationDeclaringClassForTypes() in AnnotationUtils.
- Introduced resolveContextHierarchyAttributes() in ContextLoaderUtils.
- Introduced buildContextHierarchyMap() in ContextLoaderUtils.
- @ContextConfiguration and @ContextHierarchy may not be used as
top-level, class-level annotations simultaneously.
- Introduced reference to the parent configuration in
MergedContextConfiguration and WebMergedContextConfiguration.
- Introduced overloaded buildMergedContextConfiguration() methods in
ContextLoaderUtils in order to handle context hierarchies separately
from conventional, non-hierarchical contexts.
- Introduced hashCode() and equals() in ContextConfigurationAttributes.
- ContextLoaderUtils ensures uniqueness of @ContextConfiguration
elements within a single @ContextHierarchy declaration.
- Introduced CacheAwareContextLoaderDelegate that can be used for
loading contexts with transparent support for interacting with the
context cache -- for example, for retrieving the parent application
context in a context hierarchy.
- TestContext now delegates to CacheAwareContextLoaderDelegate for
loading contexts.
- Introduced getParentApplicationContext() in MergedContextConfiguration
- The loadContext(MergedContextConfiguration) methods in
AbstractGenericContextLoader and AbstractGenericWebContextLoader now
set the parent context as appropriate.
- Introduced 'hierarchyMode' attribute in @DirtiesContext with a
corresponding HierarchyMode enum that defines EXHAUSTIVE and
CURRENT_LEVEL cache removal modes.
- ContextCache now internally tracks the relationships between contexts
that make up a context hierarchy. Furthermore, when a context is
removed, if it is part of a context hierarchy all corresponding
contexts will be removed from the cache according to the supplied
HierarchyMode.
- AbstractGenericWebContextLoader will set a loaded context as the
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE in the MockServletContext when
context hierarchies are used if the context has no parent or if the
context has a parent that is not a WAC.
- Where appropriate, updated Javadoc to refer to the
ServletTestExecutionListener, which was introduced in 3.2.0.
- Updated Javadoc to avoid and/or suppress warnings in spring-test.
- Suppressed remaining warnings in code in spring-test.
Issue: SPR-5613, SPR-9863 | spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/SingleTestClassWithTwoLevelContextHierarchyTests.java | @@ -0,0 +1,93 @@
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.test.context.hierarchies.standard;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.ContextHierarchy;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+/**
+ * @author Sam Brannen
+ * @since 3.2.2
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextHierarchy({
+ @ContextConfiguration(classes = SingleTestClassWithTwoLevelContextHierarchyTests.ParentConfig.class),
+ @ContextConfiguration(classes = SingleTestClassWithTwoLevelContextHierarchyTests.ChildConfig.class) })
+public class SingleTestClassWithTwoLevelContextHierarchyTests {
+
+ @Configuration
+ static class ParentConfig {
+
+ @Bean
+ public String foo() {
+ return "foo";
+ }
+
+ @Bean
+ public String baz() {
+ return "baz-parent";
+ }
+ }
+
+ @Configuration
+ static class ChildConfig {
+
+ @Bean
+ public String bar() {
+ return "bar";
+ }
+
+ @Bean
+ public String baz() {
+ return "baz-child";
+ }
+ }
+
+
+ @Autowired
+ private String foo;
+
+ @Autowired
+ private String bar;
+
+ @Autowired
+ private String baz;
+
+ @Autowired
+ private ApplicationContext context;
+
+
+ @Test
+ public void loadContextHierarchy() {
+ assertNotNull("child ApplicationContext", context);
+ assertNotNull("parent ApplicationContext", context.getParent());
+ assertNull("grandparent ApplicationContext", context.getParent().getParent());
+ assertEquals("foo", foo);
+ assertEquals("bar", bar);
+ assertEquals("baz-child", baz);
+ }
+
+} | true |
Other | spring-projects | spring-framework | 98074e776262292a9d6fa8d164e6718c5876ed6f.json | Provide support for context hierarchies in the TCF
Prior to this commit the Spring TestContext Framework supported creating
only flat, non-hierarchical contexts. There was no easy way to create
contexts with parent-child relationships.
This commit addresses this issue by introducing a new @ContextHierarchy
annotation that can be used in conjunction with @ContextConfiguration
for declaring hierarchies of application contexts, either within a
single test class or within a test class hierarchy. In addition,
@DirtiesContext now supports a new 'hierarchyMode' attribute for
controlling context cache clearing for context hierarchies.
- Introduced a new @ContextHierarchy annotation.
- Introduced 'name' attribute in @ContextConfiguration.
- Introduced 'name' property in ContextConfigurationAttributes.
- TestContext is now aware of @ContextHierarchy in addition to
@ContextConfiguration.
- Introduced findAnnotationDeclaringClassForTypes() in AnnotationUtils.
- Introduced resolveContextHierarchyAttributes() in ContextLoaderUtils.
- Introduced buildContextHierarchyMap() in ContextLoaderUtils.
- @ContextConfiguration and @ContextHierarchy may not be used as
top-level, class-level annotations simultaneously.
- Introduced reference to the parent configuration in
MergedContextConfiguration and WebMergedContextConfiguration.
- Introduced overloaded buildMergedContextConfiguration() methods in
ContextLoaderUtils in order to handle context hierarchies separately
from conventional, non-hierarchical contexts.
- Introduced hashCode() and equals() in ContextConfigurationAttributes.
- ContextLoaderUtils ensures uniqueness of @ContextConfiguration
elements within a single @ContextHierarchy declaration.
- Introduced CacheAwareContextLoaderDelegate that can be used for
loading contexts with transparent support for interacting with the
context cache -- for example, for retrieving the parent application
context in a context hierarchy.
- TestContext now delegates to CacheAwareContextLoaderDelegate for
loading contexts.
- Introduced getParentApplicationContext() in MergedContextConfiguration
- The loadContext(MergedContextConfiguration) methods in
AbstractGenericContextLoader and AbstractGenericWebContextLoader now
set the parent context as appropriate.
- Introduced 'hierarchyMode' attribute in @DirtiesContext with a
corresponding HierarchyMode enum that defines EXHAUSTIVE and
CURRENT_LEVEL cache removal modes.
- ContextCache now internally tracks the relationships between contexts
that make up a context hierarchy. Furthermore, when a context is
removed, if it is part of a context hierarchy all corresponding
contexts will be removed from the cache according to the supplied
HierarchyMode.
- AbstractGenericWebContextLoader will set a loaded context as the
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE in the MockServletContext when
context hierarchies are used if the context has no parent or if the
context has a parent that is not a WAC.
- Where appropriate, updated Javadoc to refer to the
ServletTestExecutionListener, which was introduced in 3.2.0.
- Updated Javadoc to avoid and/or suppress warnings in spring-test.
- Suppressed remaining warnings in code in spring-test.
Issue: SPR-5613, SPR-9863 | spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/TestHierarchyLevelOneWithBareContextConfigurationInSubclassTests.java | @@ -0,0 +1,72 @@
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.test.context.hierarchies.standard;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.ContextHierarchy;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+/**
+ * @author Sam Brannen
+ * @since 3.2.2
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextHierarchy(@ContextConfiguration)
+public class TestHierarchyLevelOneWithBareContextConfigurationInSubclassTests {
+
+ @Configuration
+ static class Config {
+
+ @Bean
+ public String foo() {
+ return "foo-level-1";
+ }
+
+ @Bean
+ public String bar() {
+ return "bar";
+ }
+ }
+
+
+ @Autowired
+ private String foo;
+
+ @Autowired
+ private String bar;
+
+ @Autowired
+ private ApplicationContext context;
+
+
+ @Test
+ public void loadContextHierarchy() {
+ assertNotNull("child ApplicationContext", context);
+ assertNull("parent ApplicationContext", context.getParent());
+ assertEquals("foo-level-1", foo);
+ assertEquals("bar", bar);
+ }
+
+} | true |
Other | spring-projects | spring-framework | 98074e776262292a9d6fa8d164e6718c5876ed6f.json | Provide support for context hierarchies in the TCF
Prior to this commit the Spring TestContext Framework supported creating
only flat, non-hierarchical contexts. There was no easy way to create
contexts with parent-child relationships.
This commit addresses this issue by introducing a new @ContextHierarchy
annotation that can be used in conjunction with @ContextConfiguration
for declaring hierarchies of application contexts, either within a
single test class or within a test class hierarchy. In addition,
@DirtiesContext now supports a new 'hierarchyMode' attribute for
controlling context cache clearing for context hierarchies.
- Introduced a new @ContextHierarchy annotation.
- Introduced 'name' attribute in @ContextConfiguration.
- Introduced 'name' property in ContextConfigurationAttributes.
- TestContext is now aware of @ContextHierarchy in addition to
@ContextConfiguration.
- Introduced findAnnotationDeclaringClassForTypes() in AnnotationUtils.
- Introduced resolveContextHierarchyAttributes() in ContextLoaderUtils.
- Introduced buildContextHierarchyMap() in ContextLoaderUtils.
- @ContextConfiguration and @ContextHierarchy may not be used as
top-level, class-level annotations simultaneously.
- Introduced reference to the parent configuration in
MergedContextConfiguration and WebMergedContextConfiguration.
- Introduced overloaded buildMergedContextConfiguration() methods in
ContextLoaderUtils in order to handle context hierarchies separately
from conventional, non-hierarchical contexts.
- Introduced hashCode() and equals() in ContextConfigurationAttributes.
- ContextLoaderUtils ensures uniqueness of @ContextConfiguration
elements within a single @ContextHierarchy declaration.
- Introduced CacheAwareContextLoaderDelegate that can be used for
loading contexts with transparent support for interacting with the
context cache -- for example, for retrieving the parent application
context in a context hierarchy.
- TestContext now delegates to CacheAwareContextLoaderDelegate for
loading contexts.
- Introduced getParentApplicationContext() in MergedContextConfiguration
- The loadContext(MergedContextConfiguration) methods in
AbstractGenericContextLoader and AbstractGenericWebContextLoader now
set the parent context as appropriate.
- Introduced 'hierarchyMode' attribute in @DirtiesContext with a
corresponding HierarchyMode enum that defines EXHAUSTIVE and
CURRENT_LEVEL cache removal modes.
- ContextCache now internally tracks the relationships between contexts
that make up a context hierarchy. Furthermore, when a context is
removed, if it is part of a context hierarchy all corresponding
contexts will be removed from the cache according to the supplied
HierarchyMode.
- AbstractGenericWebContextLoader will set a loaded context as the
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE in the MockServletContext when
context hierarchies are used if the context has no parent or if the
context has a parent that is not a WAC.
- Where appropriate, updated Javadoc to refer to the
ServletTestExecutionListener, which was introduced in 3.2.0.
- Updated Javadoc to avoid and/or suppress warnings in spring-test.
- Suppressed remaining warnings in code in spring-test.
Issue: SPR-5613, SPR-9863 | spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/TestHierarchyLevelOneWithBareContextConfigurationInSuperclassTests.java | @@ -0,0 +1,71 @@
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.test.context.hierarchies.standard;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+/**
+ * @author Sam Brannen
+ * @since 3.2.2
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration
+public class TestHierarchyLevelOneWithBareContextConfigurationInSuperclassTests {
+
+ @Configuration
+ static class Config {
+
+ @Bean
+ public String foo() {
+ return "foo-level-1";
+ }
+
+ @Bean
+ public String bar() {
+ return "bar";
+ }
+ }
+
+
+ @Autowired
+ private String foo;
+
+ @Autowired
+ private String bar;
+
+ @Autowired
+ private ApplicationContext context;
+
+
+ @Test
+ public void loadContextHierarchy() {
+ assertNotNull("child ApplicationContext", context);
+ assertNull("parent ApplicationContext", context.getParent());
+ assertEquals("foo-level-1", foo);
+ assertEquals("bar", bar);
+ }
+
+} | true |
Other | spring-projects | spring-framework | 98074e776262292a9d6fa8d164e6718c5876ed6f.json | Provide support for context hierarchies in the TCF
Prior to this commit the Spring TestContext Framework supported creating
only flat, non-hierarchical contexts. There was no easy way to create
contexts with parent-child relationships.
This commit addresses this issue by introducing a new @ContextHierarchy
annotation that can be used in conjunction with @ContextConfiguration
for declaring hierarchies of application contexts, either within a
single test class or within a test class hierarchy. In addition,
@DirtiesContext now supports a new 'hierarchyMode' attribute for
controlling context cache clearing for context hierarchies.
- Introduced a new @ContextHierarchy annotation.
- Introduced 'name' attribute in @ContextConfiguration.
- Introduced 'name' property in ContextConfigurationAttributes.
- TestContext is now aware of @ContextHierarchy in addition to
@ContextConfiguration.
- Introduced findAnnotationDeclaringClassForTypes() in AnnotationUtils.
- Introduced resolveContextHierarchyAttributes() in ContextLoaderUtils.
- Introduced buildContextHierarchyMap() in ContextLoaderUtils.
- @ContextConfiguration and @ContextHierarchy may not be used as
top-level, class-level annotations simultaneously.
- Introduced reference to the parent configuration in
MergedContextConfiguration and WebMergedContextConfiguration.
- Introduced overloaded buildMergedContextConfiguration() methods in
ContextLoaderUtils in order to handle context hierarchies separately
from conventional, non-hierarchical contexts.
- Introduced hashCode() and equals() in ContextConfigurationAttributes.
- ContextLoaderUtils ensures uniqueness of @ContextConfiguration
elements within a single @ContextHierarchy declaration.
- Introduced CacheAwareContextLoaderDelegate that can be used for
loading contexts with transparent support for interacting with the
context cache -- for example, for retrieving the parent application
context in a context hierarchy.
- TestContext now delegates to CacheAwareContextLoaderDelegate for
loading contexts.
- Introduced getParentApplicationContext() in MergedContextConfiguration
- The loadContext(MergedContextConfiguration) methods in
AbstractGenericContextLoader and AbstractGenericWebContextLoader now
set the parent context as appropriate.
- Introduced 'hierarchyMode' attribute in @DirtiesContext with a
corresponding HierarchyMode enum that defines EXHAUSTIVE and
CURRENT_LEVEL cache removal modes.
- ContextCache now internally tracks the relationships between contexts
that make up a context hierarchy. Furthermore, when a context is
removed, if it is part of a context hierarchy all corresponding
contexts will be removed from the cache according to the supplied
HierarchyMode.
- AbstractGenericWebContextLoader will set a loaded context as the
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE in the MockServletContext when
context hierarchies are used if the context has no parent or if the
context has a parent that is not a WAC.
- Where appropriate, updated Javadoc to refer to the
ServletTestExecutionListener, which was introduced in 3.2.0.
- Updated Javadoc to avoid and/or suppress warnings in spring-test.
- Suppressed remaining warnings in code in spring-test.
Issue: SPR-5613, SPR-9863 | spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/TestHierarchyLevelOneWithSingleLevelContextHierarchyTests.java | @@ -0,0 +1,72 @@
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.test.context.hierarchies.standard;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.ContextHierarchy;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+/**
+ * @author Sam Brannen
+ * @since 3.2.2
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextHierarchy(@ContextConfiguration)
+public class TestHierarchyLevelOneWithSingleLevelContextHierarchyTests {
+
+ @Configuration
+ static class Config {
+
+ @Bean
+ public String foo() {
+ return "foo-level-1";
+ }
+
+ @Bean
+ public String bar() {
+ return "bar";
+ }
+ }
+
+
+ @Autowired
+ private String foo;
+
+ @Autowired
+ private String bar;
+
+ @Autowired
+ private ApplicationContext context;
+
+
+ @Test
+ public void loadContextHierarchy() {
+ assertNotNull("child ApplicationContext", context);
+ assertNull("parent ApplicationContext", context.getParent());
+ assertEquals("foo-level-1", foo);
+ assertEquals("bar", bar);
+ }
+
+} | true |
Other | spring-projects | spring-framework | 98074e776262292a9d6fa8d164e6718c5876ed6f.json | Provide support for context hierarchies in the TCF
Prior to this commit the Spring TestContext Framework supported creating
only flat, non-hierarchical contexts. There was no easy way to create
contexts with parent-child relationships.
This commit addresses this issue by introducing a new @ContextHierarchy
annotation that can be used in conjunction with @ContextConfiguration
for declaring hierarchies of application contexts, either within a
single test class or within a test class hierarchy. In addition,
@DirtiesContext now supports a new 'hierarchyMode' attribute for
controlling context cache clearing for context hierarchies.
- Introduced a new @ContextHierarchy annotation.
- Introduced 'name' attribute in @ContextConfiguration.
- Introduced 'name' property in ContextConfigurationAttributes.
- TestContext is now aware of @ContextHierarchy in addition to
@ContextConfiguration.
- Introduced findAnnotationDeclaringClassForTypes() in AnnotationUtils.
- Introduced resolveContextHierarchyAttributes() in ContextLoaderUtils.
- Introduced buildContextHierarchyMap() in ContextLoaderUtils.
- @ContextConfiguration and @ContextHierarchy may not be used as
top-level, class-level annotations simultaneously.
- Introduced reference to the parent configuration in
MergedContextConfiguration and WebMergedContextConfiguration.
- Introduced overloaded buildMergedContextConfiguration() methods in
ContextLoaderUtils in order to handle context hierarchies separately
from conventional, non-hierarchical contexts.
- Introduced hashCode() and equals() in ContextConfigurationAttributes.
- ContextLoaderUtils ensures uniqueness of @ContextConfiguration
elements within a single @ContextHierarchy declaration.
- Introduced CacheAwareContextLoaderDelegate that can be used for
loading contexts with transparent support for interacting with the
context cache -- for example, for retrieving the parent application
context in a context hierarchy.
- TestContext now delegates to CacheAwareContextLoaderDelegate for
loading contexts.
- Introduced getParentApplicationContext() in MergedContextConfiguration
- The loadContext(MergedContextConfiguration) methods in
AbstractGenericContextLoader and AbstractGenericWebContextLoader now
set the parent context as appropriate.
- Introduced 'hierarchyMode' attribute in @DirtiesContext with a
corresponding HierarchyMode enum that defines EXHAUSTIVE and
CURRENT_LEVEL cache removal modes.
- ContextCache now internally tracks the relationships between contexts
that make up a context hierarchy. Furthermore, when a context is
removed, if it is part of a context hierarchy all corresponding
contexts will be removed from the cache according to the supplied
HierarchyMode.
- AbstractGenericWebContextLoader will set a loaded context as the
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE in the MockServletContext when
context hierarchies are used if the context has no parent or if the
context has a parent that is not a WAC.
- Where appropriate, updated Javadoc to refer to the
ServletTestExecutionListener, which was introduced in 3.2.0.
- Updated Javadoc to avoid and/or suppress warnings in spring-test.
- Suppressed remaining warnings in code in spring-test.
Issue: SPR-5613, SPR-9863 | spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/TestHierarchyLevelTwoWithBareContextConfigurationInSubclassTests.java | @@ -0,0 +1,78 @@
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.test.context.hierarchies.standard;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+/**
+ * @author Sam Brannen
+ * @since 3.2.2
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration
+public class TestHierarchyLevelTwoWithBareContextConfigurationInSubclassTests extends
+ TestHierarchyLevelOneWithBareContextConfigurationInSubclassTests {
+
+ @Configuration
+ static class Config {
+
+ @Bean
+ public String foo() {
+ return "foo-level-2";
+ }
+
+ @Bean
+ public String baz() {
+ return "baz";
+ }
+ }
+
+
+ @Autowired
+ private String foo;
+
+ @Autowired
+ private String bar;
+
+ @Autowired
+ private String baz;
+
+ @Autowired
+ private ApplicationContext context;
+
+
+ @Test
+ @Override
+ public void loadContextHierarchy() {
+ assertNotNull("child ApplicationContext", context);
+ assertNotNull("parent ApplicationContext", context.getParent());
+ assertNull("grandparent ApplicationContext", context.getParent().getParent());
+ assertEquals("foo-level-2", foo);
+ assertEquals("bar", bar);
+ assertEquals("baz", baz);
+ }
+
+} | true |
Other | spring-projects | spring-framework | 98074e776262292a9d6fa8d164e6718c5876ed6f.json | Provide support for context hierarchies in the TCF
Prior to this commit the Spring TestContext Framework supported creating
only flat, non-hierarchical contexts. There was no easy way to create
contexts with parent-child relationships.
This commit addresses this issue by introducing a new @ContextHierarchy
annotation that can be used in conjunction with @ContextConfiguration
for declaring hierarchies of application contexts, either within a
single test class or within a test class hierarchy. In addition,
@DirtiesContext now supports a new 'hierarchyMode' attribute for
controlling context cache clearing for context hierarchies.
- Introduced a new @ContextHierarchy annotation.
- Introduced 'name' attribute in @ContextConfiguration.
- Introduced 'name' property in ContextConfigurationAttributes.
- TestContext is now aware of @ContextHierarchy in addition to
@ContextConfiguration.
- Introduced findAnnotationDeclaringClassForTypes() in AnnotationUtils.
- Introduced resolveContextHierarchyAttributes() in ContextLoaderUtils.
- Introduced buildContextHierarchyMap() in ContextLoaderUtils.
- @ContextConfiguration and @ContextHierarchy may not be used as
top-level, class-level annotations simultaneously.
- Introduced reference to the parent configuration in
MergedContextConfiguration and WebMergedContextConfiguration.
- Introduced overloaded buildMergedContextConfiguration() methods in
ContextLoaderUtils in order to handle context hierarchies separately
from conventional, non-hierarchical contexts.
- Introduced hashCode() and equals() in ContextConfigurationAttributes.
- ContextLoaderUtils ensures uniqueness of @ContextConfiguration
elements within a single @ContextHierarchy declaration.
- Introduced CacheAwareContextLoaderDelegate that can be used for
loading contexts with transparent support for interacting with the
context cache -- for example, for retrieving the parent application
context in a context hierarchy.
- TestContext now delegates to CacheAwareContextLoaderDelegate for
loading contexts.
- Introduced getParentApplicationContext() in MergedContextConfiguration
- The loadContext(MergedContextConfiguration) methods in
AbstractGenericContextLoader and AbstractGenericWebContextLoader now
set the parent context as appropriate.
- Introduced 'hierarchyMode' attribute in @DirtiesContext with a
corresponding HierarchyMode enum that defines EXHAUSTIVE and
CURRENT_LEVEL cache removal modes.
- ContextCache now internally tracks the relationships between contexts
that make up a context hierarchy. Furthermore, when a context is
removed, if it is part of a context hierarchy all corresponding
contexts will be removed from the cache according to the supplied
HierarchyMode.
- AbstractGenericWebContextLoader will set a loaded context as the
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE in the MockServletContext when
context hierarchies are used if the context has no parent or if the
context has a parent that is not a WAC.
- Where appropriate, updated Javadoc to refer to the
ServletTestExecutionListener, which was introduced in 3.2.0.
- Updated Javadoc to avoid and/or suppress warnings in spring-test.
- Suppressed remaining warnings in code in spring-test.
Issue: SPR-5613, SPR-9863 | spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/TestHierarchyLevelTwoWithBareContextConfigurationInSuperclassTests.java | @@ -0,0 +1,79 @@
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.test.context.hierarchies.standard;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.ContextHierarchy;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+/**
+ * @author Sam Brannen
+ * @since 3.2.2
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextHierarchy(@ContextConfiguration)
+public class TestHierarchyLevelTwoWithBareContextConfigurationInSuperclassTests extends
+ TestHierarchyLevelOneWithBareContextConfigurationInSuperclassTests {
+
+ @Configuration
+ static class Config {
+
+ @Bean
+ public String foo() {
+ return "foo-level-2";
+ }
+
+ @Bean
+ public String baz() {
+ return "baz";
+ }
+ }
+
+
+ @Autowired
+ private String foo;
+
+ @Autowired
+ private String bar;
+
+ @Autowired
+ private String baz;
+
+ @Autowired
+ private ApplicationContext context;
+
+
+ @Test
+ @Override
+ public void loadContextHierarchy() {
+ assertNotNull("child ApplicationContext", context);
+ assertNotNull("parent ApplicationContext", context.getParent());
+ assertNull("grandparent ApplicationContext", context.getParent().getParent());
+ assertEquals("foo-level-2", foo);
+ assertEquals("bar", bar);
+ assertEquals("baz", baz);
+ }
+
+} | true |
Other | spring-projects | spring-framework | 98074e776262292a9d6fa8d164e6718c5876ed6f.json | Provide support for context hierarchies in the TCF
Prior to this commit the Spring TestContext Framework supported creating
only flat, non-hierarchical contexts. There was no easy way to create
contexts with parent-child relationships.
This commit addresses this issue by introducing a new @ContextHierarchy
annotation that can be used in conjunction with @ContextConfiguration
for declaring hierarchies of application contexts, either within a
single test class or within a test class hierarchy. In addition,
@DirtiesContext now supports a new 'hierarchyMode' attribute for
controlling context cache clearing for context hierarchies.
- Introduced a new @ContextHierarchy annotation.
- Introduced 'name' attribute in @ContextConfiguration.
- Introduced 'name' property in ContextConfigurationAttributes.
- TestContext is now aware of @ContextHierarchy in addition to
@ContextConfiguration.
- Introduced findAnnotationDeclaringClassForTypes() in AnnotationUtils.
- Introduced resolveContextHierarchyAttributes() in ContextLoaderUtils.
- Introduced buildContextHierarchyMap() in ContextLoaderUtils.
- @ContextConfiguration and @ContextHierarchy may not be used as
top-level, class-level annotations simultaneously.
- Introduced reference to the parent configuration in
MergedContextConfiguration and WebMergedContextConfiguration.
- Introduced overloaded buildMergedContextConfiguration() methods in
ContextLoaderUtils in order to handle context hierarchies separately
from conventional, non-hierarchical contexts.
- Introduced hashCode() and equals() in ContextConfigurationAttributes.
- ContextLoaderUtils ensures uniqueness of @ContextConfiguration
elements within a single @ContextHierarchy declaration.
- Introduced CacheAwareContextLoaderDelegate that can be used for
loading contexts with transparent support for interacting with the
context cache -- for example, for retrieving the parent application
context in a context hierarchy.
- TestContext now delegates to CacheAwareContextLoaderDelegate for
loading contexts.
- Introduced getParentApplicationContext() in MergedContextConfiguration
- The loadContext(MergedContextConfiguration) methods in
AbstractGenericContextLoader and AbstractGenericWebContextLoader now
set the parent context as appropriate.
- Introduced 'hierarchyMode' attribute in @DirtiesContext with a
corresponding HierarchyMode enum that defines EXHAUSTIVE and
CURRENT_LEVEL cache removal modes.
- ContextCache now internally tracks the relationships between contexts
that make up a context hierarchy. Furthermore, when a context is
removed, if it is part of a context hierarchy all corresponding
contexts will be removed from the cache according to the supplied
HierarchyMode.
- AbstractGenericWebContextLoader will set a loaded context as the
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE in the MockServletContext when
context hierarchies are used if the context has no parent or if the
context has a parent that is not a WAC.
- Where appropriate, updated Javadoc to refer to the
ServletTestExecutionListener, which was introduced in 3.2.0.
- Updated Javadoc to avoid and/or suppress warnings in spring-test.
- Suppressed remaining warnings in code in spring-test.
Issue: SPR-5613, SPR-9863 | spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/TestHierarchyLevelTwoWithSingleLevelContextHierarchyAndMixedConfigTypesTests.java | @@ -0,0 +1,62 @@
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.test.context.hierarchies.standard;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.ContextHierarchy;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+/**
+ * @author Sam Brannen
+ * @since 3.2.2
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextHierarchy(@ContextConfiguration)
+public class TestHierarchyLevelTwoWithSingleLevelContextHierarchyAndMixedConfigTypesTests extends
+ TestHierarchyLevelOneWithSingleLevelContextHierarchyTests {
+
+ @Autowired
+ private String foo;
+
+ @Autowired
+ private String bar;
+
+ @Autowired
+ private String baz;
+
+ @Autowired
+ private ApplicationContext context;
+
+
+ @Test
+ @Override
+ public void loadContextHierarchy() {
+ assertNotNull("child ApplicationContext", context);
+ assertNotNull("parent ApplicationContext", context.getParent());
+ assertNull("grandparent ApplicationContext", context.getParent().getParent());
+ assertEquals("foo-level-2", foo);
+ assertEquals("bar", bar);
+ assertEquals("baz", baz);
+ }
+
+} | true |
Other | spring-projects | spring-framework | 98074e776262292a9d6fa8d164e6718c5876ed6f.json | Provide support for context hierarchies in the TCF
Prior to this commit the Spring TestContext Framework supported creating
only flat, non-hierarchical contexts. There was no easy way to create
contexts with parent-child relationships.
This commit addresses this issue by introducing a new @ContextHierarchy
annotation that can be used in conjunction with @ContextConfiguration
for declaring hierarchies of application contexts, either within a
single test class or within a test class hierarchy. In addition,
@DirtiesContext now supports a new 'hierarchyMode' attribute for
controlling context cache clearing for context hierarchies.
- Introduced a new @ContextHierarchy annotation.
- Introduced 'name' attribute in @ContextConfiguration.
- Introduced 'name' property in ContextConfigurationAttributes.
- TestContext is now aware of @ContextHierarchy in addition to
@ContextConfiguration.
- Introduced findAnnotationDeclaringClassForTypes() in AnnotationUtils.
- Introduced resolveContextHierarchyAttributes() in ContextLoaderUtils.
- Introduced buildContextHierarchyMap() in ContextLoaderUtils.
- @ContextConfiguration and @ContextHierarchy may not be used as
top-level, class-level annotations simultaneously.
- Introduced reference to the parent configuration in
MergedContextConfiguration and WebMergedContextConfiguration.
- Introduced overloaded buildMergedContextConfiguration() methods in
ContextLoaderUtils in order to handle context hierarchies separately
from conventional, non-hierarchical contexts.
- Introduced hashCode() and equals() in ContextConfigurationAttributes.
- ContextLoaderUtils ensures uniqueness of @ContextConfiguration
elements within a single @ContextHierarchy declaration.
- Introduced CacheAwareContextLoaderDelegate that can be used for
loading contexts with transparent support for interacting with the
context cache -- for example, for retrieving the parent application
context in a context hierarchy.
- TestContext now delegates to CacheAwareContextLoaderDelegate for
loading contexts.
- Introduced getParentApplicationContext() in MergedContextConfiguration
- The loadContext(MergedContextConfiguration) methods in
AbstractGenericContextLoader and AbstractGenericWebContextLoader now
set the parent context as appropriate.
- Introduced 'hierarchyMode' attribute in @DirtiesContext with a
corresponding HierarchyMode enum that defines EXHAUSTIVE and
CURRENT_LEVEL cache removal modes.
- ContextCache now internally tracks the relationships between contexts
that make up a context hierarchy. Furthermore, when a context is
removed, if it is part of a context hierarchy all corresponding
contexts will be removed from the cache according to the supplied
HierarchyMode.
- AbstractGenericWebContextLoader will set a loaded context as the
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE in the MockServletContext when
context hierarchies are used if the context has no parent or if the
context has a parent that is not a WAC.
- Where appropriate, updated Javadoc to refer to the
ServletTestExecutionListener, which was introduced in 3.2.0.
- Updated Javadoc to avoid and/or suppress warnings in spring-test.
- Suppressed remaining warnings in code in spring-test.
Issue: SPR-5613, SPR-9863 | spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/TestHierarchyLevelTwoWithSingleLevelContextHierarchyTests.java | @@ -0,0 +1,78 @@
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.test.context.hierarchies.standard;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.ContextHierarchy;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+/**
+ * @author Sam Brannen
+ * @since 3.2.2
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextHierarchy(@ContextConfiguration)
+public class TestHierarchyLevelTwoWithSingleLevelContextHierarchyTests extends
+ TestHierarchyLevelOneWithSingleLevelContextHierarchyTests {
+
+ @Configuration
+ static class Config {
+
+ @Bean
+ public String foo() {
+ return "foo-level-2";
+ }
+
+ @Bean
+ public String baz() {
+ return "baz";
+ }
+ }
+
+
+ @Autowired
+ private String foo;
+
+ @Autowired
+ private String bar;
+
+ @Autowired
+ private String baz;
+
+ @Autowired
+ private ApplicationContext context;
+
+
+ @Test
+ @Override
+ public void loadContextHierarchy() {
+ assertNotNull("child ApplicationContext", context);
+ assertNotNull("parent ApplicationContext", context.getParent());
+ assertEquals("foo-level-2", foo);
+ assertEquals("bar", bar);
+ assertEquals("baz", baz);
+ }
+
+} | true |
Other | spring-projects | spring-framework | 98074e776262292a9d6fa8d164e6718c5876ed6f.json | Provide support for context hierarchies in the TCF
Prior to this commit the Spring TestContext Framework supported creating
only flat, non-hierarchical contexts. There was no easy way to create
contexts with parent-child relationships.
This commit addresses this issue by introducing a new @ContextHierarchy
annotation that can be used in conjunction with @ContextConfiguration
for declaring hierarchies of application contexts, either within a
single test class or within a test class hierarchy. In addition,
@DirtiesContext now supports a new 'hierarchyMode' attribute for
controlling context cache clearing for context hierarchies.
- Introduced a new @ContextHierarchy annotation.
- Introduced 'name' attribute in @ContextConfiguration.
- Introduced 'name' property in ContextConfigurationAttributes.
- TestContext is now aware of @ContextHierarchy in addition to
@ContextConfiguration.
- Introduced findAnnotationDeclaringClassForTypes() in AnnotationUtils.
- Introduced resolveContextHierarchyAttributes() in ContextLoaderUtils.
- Introduced buildContextHierarchyMap() in ContextLoaderUtils.
- @ContextConfiguration and @ContextHierarchy may not be used as
top-level, class-level annotations simultaneously.
- Introduced reference to the parent configuration in
MergedContextConfiguration and WebMergedContextConfiguration.
- Introduced overloaded buildMergedContextConfiguration() methods in
ContextLoaderUtils in order to handle context hierarchies separately
from conventional, non-hierarchical contexts.
- Introduced hashCode() and equals() in ContextConfigurationAttributes.
- ContextLoaderUtils ensures uniqueness of @ContextConfiguration
elements within a single @ContextHierarchy declaration.
- Introduced CacheAwareContextLoaderDelegate that can be used for
loading contexts with transparent support for interacting with the
context cache -- for example, for retrieving the parent application
context in a context hierarchy.
- TestContext now delegates to CacheAwareContextLoaderDelegate for
loading contexts.
- Introduced getParentApplicationContext() in MergedContextConfiguration
- The loadContext(MergedContextConfiguration) methods in
AbstractGenericContextLoader and AbstractGenericWebContextLoader now
set the parent context as appropriate.
- Introduced 'hierarchyMode' attribute in @DirtiesContext with a
corresponding HierarchyMode enum that defines EXHAUSTIVE and
CURRENT_LEVEL cache removal modes.
- ContextCache now internally tracks the relationships between contexts
that make up a context hierarchy. Furthermore, when a context is
removed, if it is part of a context hierarchy all corresponding
contexts will be removed from the cache according to the supplied
HierarchyMode.
- AbstractGenericWebContextLoader will set a loaded context as the
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE in the MockServletContext when
context hierarchies are used if the context has no parent or if the
context has a parent that is not a WAC.
- Where appropriate, updated Javadoc to refer to the
ServletTestExecutionListener, which was introduced in 3.2.0.
- Updated Javadoc to avoid and/or suppress warnings in spring-test.
- Suppressed remaining warnings in code in spring-test.
Issue: SPR-5613, SPR-9863 | spring-test/src/test/java/org/springframework/test/context/hierarchies/web/ControllerIntegrationTests.java | @@ -0,0 +1,102 @@
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.test.context.hierarchies.web;
+
+import javax.servlet.ServletContext;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.ContextHierarchy;
+import org.springframework.test.context.hierarchies.web.ControllerIntegrationTests.AppConfig;
+import org.springframework.test.context.hierarchies.web.ControllerIntegrationTests.WebConfig;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.web.WebAppConfiguration;
+import org.springframework.web.context.WebApplicationContext;
+
+import static org.junit.Assert.*;
+
+/**
+ * @author Sam Brannen
+ * @since 3.2.2
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@WebAppConfiguration
+@ContextHierarchy({
+ //
+ @ContextConfiguration(name = "root", classes = AppConfig.class),
+ @ContextConfiguration(name = "dispatcher", classes = WebConfig.class) //
+})
+public class ControllerIntegrationTests {
+
+ @Configuration
+ static class AppConfig {
+
+ @Bean
+ public String foo() {
+ return "foo";
+ }
+ }
+
+ @Configuration
+ static class WebConfig {
+
+ @Bean
+ public String bar() {
+ return "bar";
+ }
+ }
+
+
+ // -------------------------------------------------------------------------
+
+ @Autowired
+ private WebApplicationContext wac;
+
+ @Autowired
+ private String foo;
+
+ @Autowired
+ private String bar;
+
+
+ @Test
+ public void verifyRootWacSupport() {
+ assertEquals("foo", foo);
+ assertEquals("bar", bar);
+
+ ApplicationContext parent = wac.getParent();
+ assertNotNull(parent);
+ assertTrue(parent instanceof WebApplicationContext);
+ WebApplicationContext root = (WebApplicationContext) parent;
+ assertFalse(root.getBeansOfType(String.class).containsKey("bar"));
+
+ ServletContext childServletContext = wac.getServletContext();
+ assertNotNull(childServletContext);
+ ServletContext rootServletContext = root.getServletContext();
+ assertNotNull(rootServletContext);
+ assertSame(childServletContext, rootServletContext);
+
+ assertSame(root, rootServletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE));
+ assertSame(root, childServletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE));
+ }
+
+} | true |
Other | spring-projects | spring-framework | 98074e776262292a9d6fa8d164e6718c5876ed6f.json | Provide support for context hierarchies in the TCF
Prior to this commit the Spring TestContext Framework supported creating
only flat, non-hierarchical contexts. There was no easy way to create
contexts with parent-child relationships.
This commit addresses this issue by introducing a new @ContextHierarchy
annotation that can be used in conjunction with @ContextConfiguration
for declaring hierarchies of application contexts, either within a
single test class or within a test class hierarchy. In addition,
@DirtiesContext now supports a new 'hierarchyMode' attribute for
controlling context cache clearing for context hierarchies.
- Introduced a new @ContextHierarchy annotation.
- Introduced 'name' attribute in @ContextConfiguration.
- Introduced 'name' property in ContextConfigurationAttributes.
- TestContext is now aware of @ContextHierarchy in addition to
@ContextConfiguration.
- Introduced findAnnotationDeclaringClassForTypes() in AnnotationUtils.
- Introduced resolveContextHierarchyAttributes() in ContextLoaderUtils.
- Introduced buildContextHierarchyMap() in ContextLoaderUtils.
- @ContextConfiguration and @ContextHierarchy may not be used as
top-level, class-level annotations simultaneously.
- Introduced reference to the parent configuration in
MergedContextConfiguration and WebMergedContextConfiguration.
- Introduced overloaded buildMergedContextConfiguration() methods in
ContextLoaderUtils in order to handle context hierarchies separately
from conventional, non-hierarchical contexts.
- Introduced hashCode() and equals() in ContextConfigurationAttributes.
- ContextLoaderUtils ensures uniqueness of @ContextConfiguration
elements within a single @ContextHierarchy declaration.
- Introduced CacheAwareContextLoaderDelegate that can be used for
loading contexts with transparent support for interacting with the
context cache -- for example, for retrieving the parent application
context in a context hierarchy.
- TestContext now delegates to CacheAwareContextLoaderDelegate for
loading contexts.
- Introduced getParentApplicationContext() in MergedContextConfiguration
- The loadContext(MergedContextConfiguration) methods in
AbstractGenericContextLoader and AbstractGenericWebContextLoader now
set the parent context as appropriate.
- Introduced 'hierarchyMode' attribute in @DirtiesContext with a
corresponding HierarchyMode enum that defines EXHAUSTIVE and
CURRENT_LEVEL cache removal modes.
- ContextCache now internally tracks the relationships between contexts
that make up a context hierarchy. Furthermore, when a context is
removed, if it is part of a context hierarchy all corresponding
contexts will be removed from the cache according to the supplied
HierarchyMode.
- AbstractGenericWebContextLoader will set a loaded context as the
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE in the MockServletContext when
context hierarchies are used if the context has no parent or if the
context has a parent that is not a WAC.
- Where appropriate, updated Javadoc to refer to the
ServletTestExecutionListener, which was introduced in 3.2.0.
- Updated Javadoc to avoid and/or suppress warnings in spring-test.
- Suppressed remaining warnings in code in spring-test.
Issue: SPR-5613, SPR-9863 | spring-test/src/test/java/org/springframework/test/context/hierarchies/web/DispatcherWacRootWacEarTests.java | @@ -0,0 +1,88 @@
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.test.context.hierarchies.web;
+
+import javax.servlet.ServletContext;
+
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.ContextHierarchy;
+import org.springframework.web.context.WebApplicationContext;
+
+import static org.junit.Assert.*;
+
+/**
+ * @author Sam Brannen
+ * @since 3.2.2
+ */
+@ContextHierarchy(@ContextConfiguration)
+public class DispatcherWacRootWacEarTests extends RootWacEarTests {
+
+ @Autowired
+ private WebApplicationContext wac;
+
+ @Autowired
+ private String ear;
+
+ @Autowired
+ private String root;
+
+ @Autowired
+ private String dispatcher;
+
+
+ @Test
+ @Override
+ public void verifyEarConfig() {
+ /* no-op */
+ }
+
+ @Test
+ @Override
+ public void verifyRootWacConfig() {
+ /* no-op */
+ }
+
+ @Test
+ public void verifyDispatcherWacConfig() {
+ ApplicationContext parent = wac.getParent();
+ assertNotNull(parent);
+ assertTrue(parent instanceof WebApplicationContext);
+
+ ApplicationContext grandParent = parent.getParent();
+ assertNotNull(grandParent);
+ assertFalse(grandParent instanceof WebApplicationContext);
+
+ ServletContext dispatcherServletContext = wac.getServletContext();
+ assertNotNull(dispatcherServletContext);
+ ServletContext rootServletContext = ((WebApplicationContext) parent).getServletContext();
+ assertNotNull(rootServletContext);
+ assertSame(dispatcherServletContext, rootServletContext);
+
+ assertSame(parent,
+ rootServletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE));
+ assertSame(parent,
+ dispatcherServletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE));
+
+ assertEquals("ear", ear);
+ assertEquals("root", root);
+ assertEquals("dispatcher", dispatcher);
+ }
+
+} | true |
Other | spring-projects | spring-framework | 98074e776262292a9d6fa8d164e6718c5876ed6f.json | Provide support for context hierarchies in the TCF
Prior to this commit the Spring TestContext Framework supported creating
only flat, non-hierarchical contexts. There was no easy way to create
contexts with parent-child relationships.
This commit addresses this issue by introducing a new @ContextHierarchy
annotation that can be used in conjunction with @ContextConfiguration
for declaring hierarchies of application contexts, either within a
single test class or within a test class hierarchy. In addition,
@DirtiesContext now supports a new 'hierarchyMode' attribute for
controlling context cache clearing for context hierarchies.
- Introduced a new @ContextHierarchy annotation.
- Introduced 'name' attribute in @ContextConfiguration.
- Introduced 'name' property in ContextConfigurationAttributes.
- TestContext is now aware of @ContextHierarchy in addition to
@ContextConfiguration.
- Introduced findAnnotationDeclaringClassForTypes() in AnnotationUtils.
- Introduced resolveContextHierarchyAttributes() in ContextLoaderUtils.
- Introduced buildContextHierarchyMap() in ContextLoaderUtils.
- @ContextConfiguration and @ContextHierarchy may not be used as
top-level, class-level annotations simultaneously.
- Introduced reference to the parent configuration in
MergedContextConfiguration and WebMergedContextConfiguration.
- Introduced overloaded buildMergedContextConfiguration() methods in
ContextLoaderUtils in order to handle context hierarchies separately
from conventional, non-hierarchical contexts.
- Introduced hashCode() and equals() in ContextConfigurationAttributes.
- ContextLoaderUtils ensures uniqueness of @ContextConfiguration
elements within a single @ContextHierarchy declaration.
- Introduced CacheAwareContextLoaderDelegate that can be used for
loading contexts with transparent support for interacting with the
context cache -- for example, for retrieving the parent application
context in a context hierarchy.
- TestContext now delegates to CacheAwareContextLoaderDelegate for
loading contexts.
- Introduced getParentApplicationContext() in MergedContextConfiguration
- The loadContext(MergedContextConfiguration) methods in
AbstractGenericContextLoader and AbstractGenericWebContextLoader now
set the parent context as appropriate.
- Introduced 'hierarchyMode' attribute in @DirtiesContext with a
corresponding HierarchyMode enum that defines EXHAUSTIVE and
CURRENT_LEVEL cache removal modes.
- ContextCache now internally tracks the relationships between contexts
that make up a context hierarchy. Furthermore, when a context is
removed, if it is part of a context hierarchy all corresponding
contexts will be removed from the cache according to the supplied
HierarchyMode.
- AbstractGenericWebContextLoader will set a loaded context as the
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE in the MockServletContext when
context hierarchies are used if the context has no parent or if the
context has a parent that is not a WAC.
- Where appropriate, updated Javadoc to refer to the
ServletTestExecutionListener, which was introduced in 3.2.0.
- Updated Javadoc to avoid and/or suppress warnings in spring-test.
- Suppressed remaining warnings in code in spring-test.
Issue: SPR-5613, SPR-9863 | spring-test/src/test/java/org/springframework/test/context/hierarchies/web/EarTests.java | @@ -0,0 +1,65 @@
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.test.context.hierarchies.web;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.web.context.WebApplicationContext;
+
+import static org.junit.Assert.*;
+
+/**
+ * @author Sam Brannen
+ * @since 3.2.2
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration
+public class EarTests {
+
+ @Configuration
+ static class EarConfig {
+
+ @Bean
+ public String ear() {
+ return "ear";
+ }
+ }
+
+
+ // -------------------------------------------------------------------------
+
+ @Autowired
+ private ApplicationContext context;
+
+ @Autowired
+ private String ear;
+
+
+ @Test
+ public void verifyEarConfig() {
+ assertFalse(context instanceof WebApplicationContext);
+ assertNull(context.getParent());
+ assertEquals("ear", ear);
+ }
+
+} | true |
Other | spring-projects | spring-framework | 98074e776262292a9d6fa8d164e6718c5876ed6f.json | Provide support for context hierarchies in the TCF
Prior to this commit the Spring TestContext Framework supported creating
only flat, non-hierarchical contexts. There was no easy way to create
contexts with parent-child relationships.
This commit addresses this issue by introducing a new @ContextHierarchy
annotation that can be used in conjunction with @ContextConfiguration
for declaring hierarchies of application contexts, either within a
single test class or within a test class hierarchy. In addition,
@DirtiesContext now supports a new 'hierarchyMode' attribute for
controlling context cache clearing for context hierarchies.
- Introduced a new @ContextHierarchy annotation.
- Introduced 'name' attribute in @ContextConfiguration.
- Introduced 'name' property in ContextConfigurationAttributes.
- TestContext is now aware of @ContextHierarchy in addition to
@ContextConfiguration.
- Introduced findAnnotationDeclaringClassForTypes() in AnnotationUtils.
- Introduced resolveContextHierarchyAttributes() in ContextLoaderUtils.
- Introduced buildContextHierarchyMap() in ContextLoaderUtils.
- @ContextConfiguration and @ContextHierarchy may not be used as
top-level, class-level annotations simultaneously.
- Introduced reference to the parent configuration in
MergedContextConfiguration and WebMergedContextConfiguration.
- Introduced overloaded buildMergedContextConfiguration() methods in
ContextLoaderUtils in order to handle context hierarchies separately
from conventional, non-hierarchical contexts.
- Introduced hashCode() and equals() in ContextConfigurationAttributes.
- ContextLoaderUtils ensures uniqueness of @ContextConfiguration
elements within a single @ContextHierarchy declaration.
- Introduced CacheAwareContextLoaderDelegate that can be used for
loading contexts with transparent support for interacting with the
context cache -- for example, for retrieving the parent application
context in a context hierarchy.
- TestContext now delegates to CacheAwareContextLoaderDelegate for
loading contexts.
- Introduced getParentApplicationContext() in MergedContextConfiguration
- The loadContext(MergedContextConfiguration) methods in
AbstractGenericContextLoader and AbstractGenericWebContextLoader now
set the parent context as appropriate.
- Introduced 'hierarchyMode' attribute in @DirtiesContext with a
corresponding HierarchyMode enum that defines EXHAUSTIVE and
CURRENT_LEVEL cache removal modes.
- ContextCache now internally tracks the relationships between contexts
that make up a context hierarchy. Furthermore, when a context is
removed, if it is part of a context hierarchy all corresponding
contexts will be removed from the cache according to the supplied
HierarchyMode.
- AbstractGenericWebContextLoader will set a loaded context as the
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE in the MockServletContext when
context hierarchies are used if the context has no parent or if the
context has a parent that is not a WAC.
- Where appropriate, updated Javadoc to refer to the
ServletTestExecutionListener, which was introduced in 3.2.0.
- Updated Javadoc to avoid and/or suppress warnings in spring-test.
- Suppressed remaining warnings in code in spring-test.
Issue: SPR-5613, SPR-9863 | spring-test/src/test/java/org/springframework/test/context/hierarchies/web/RootWacEarTests.java | @@ -0,0 +1,76 @@
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.test.context.hierarchies.web;
+
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.ContextHierarchy;
+import org.springframework.test.context.web.WebAppConfiguration;
+import org.springframework.web.context.WebApplicationContext;
+
+import static org.junit.Assert.*;
+
+/**
+ * @author Sam Brannen
+ * @since 3.2.2
+ */
+@WebAppConfiguration
+@ContextHierarchy(@ContextConfiguration)
+public class RootWacEarTests extends EarTests {
+
+ @Configuration
+ static class RootWacConfig {
+
+ @Bean
+ public String root() {
+ return "root";
+ }
+ }
+
+
+ // -------------------------------------------------------------------------
+
+ @Autowired
+ private WebApplicationContext wac;
+
+ @Autowired
+ private String ear;
+
+ @Autowired
+ private String root;
+
+
+ @Test
+ @Override
+ public void verifyEarConfig() {
+ /* no-op */
+ }
+
+ @Test
+ public void verifyRootWacConfig() {
+ ApplicationContext parent = wac.getParent();
+ assertNotNull(parent);
+ assertFalse(parent instanceof WebApplicationContext);
+ assertEquals("ear", ear);
+ assertEquals("root", root);
+ }
+
+} | true |
Other | spring-projects | spring-framework | 98074e776262292a9d6fa8d164e6718c5876ed6f.json | Provide support for context hierarchies in the TCF
Prior to this commit the Spring TestContext Framework supported creating
only flat, non-hierarchical contexts. There was no easy way to create
contexts with parent-child relationships.
This commit addresses this issue by introducing a new @ContextHierarchy
annotation that can be used in conjunction with @ContextConfiguration
for declaring hierarchies of application contexts, either within a
single test class or within a test class hierarchy. In addition,
@DirtiesContext now supports a new 'hierarchyMode' attribute for
controlling context cache clearing for context hierarchies.
- Introduced a new @ContextHierarchy annotation.
- Introduced 'name' attribute in @ContextConfiguration.
- Introduced 'name' property in ContextConfigurationAttributes.
- TestContext is now aware of @ContextHierarchy in addition to
@ContextConfiguration.
- Introduced findAnnotationDeclaringClassForTypes() in AnnotationUtils.
- Introduced resolveContextHierarchyAttributes() in ContextLoaderUtils.
- Introduced buildContextHierarchyMap() in ContextLoaderUtils.
- @ContextConfiguration and @ContextHierarchy may not be used as
top-level, class-level annotations simultaneously.
- Introduced reference to the parent configuration in
MergedContextConfiguration and WebMergedContextConfiguration.
- Introduced overloaded buildMergedContextConfiguration() methods in
ContextLoaderUtils in order to handle context hierarchies separately
from conventional, non-hierarchical contexts.
- Introduced hashCode() and equals() in ContextConfigurationAttributes.
- ContextLoaderUtils ensures uniqueness of @ContextConfiguration
elements within a single @ContextHierarchy declaration.
- Introduced CacheAwareContextLoaderDelegate that can be used for
loading contexts with transparent support for interacting with the
context cache -- for example, for retrieving the parent application
context in a context hierarchy.
- TestContext now delegates to CacheAwareContextLoaderDelegate for
loading contexts.
- Introduced getParentApplicationContext() in MergedContextConfiguration
- The loadContext(MergedContextConfiguration) methods in
AbstractGenericContextLoader and AbstractGenericWebContextLoader now
set the parent context as appropriate.
- Introduced 'hierarchyMode' attribute in @DirtiesContext with a
corresponding HierarchyMode enum that defines EXHAUSTIVE and
CURRENT_LEVEL cache removal modes.
- ContextCache now internally tracks the relationships between contexts
that make up a context hierarchy. Furthermore, when a context is
removed, if it is part of a context hierarchy all corresponding
contexts will be removed from the cache according to the supplied
HierarchyMode.
- AbstractGenericWebContextLoader will set a loaded context as the
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE in the MockServletContext when
context hierarchies are used if the context has no parent or if the
context has a parent that is not a WAC.
- Where appropriate, updated Javadoc to refer to the
ServletTestExecutionListener, which was introduced in 3.2.0.
- Updated Javadoc to avoid and/or suppress warnings in spring-test.
- Suppressed remaining warnings in code in spring-test.
Issue: SPR-5613, SPR-9863 | spring-test/src/test/java/org/springframework/test/context/junit4/PropertiesBasedSpringJUnit4ClassRunnerAppCtxTests.java | @@ -33,21 +33,21 @@
/**
* <p>
* JUnit 4 based test class, which verifies the expected functionality of
- * {@link SpringJUnit4ClassRunner} in conjunction with support for application
- * contexts loaded from Java {@link Properties} files. Specifically, the
- * {@link ContextConfiguration#loader() loaderClass} and
- * {@link ContextConfiguration#resourceSuffix() resourceSuffix} attributes of
- * @ContextConfiguration are tested.
+ * {@link SpringJUnit4ClassRunner} in conjunction with support for application contexts
+ * loaded from Java {@link Properties} files. Specifically, the
+ * {@link ContextConfiguration#loader() loader} attribute of {@code ContextConfiguration}
+ * and the
+ * {@link org.springframework.test.context.support.GenericPropertiesContextLoader#getResourceSuffix()
+ * resourceSuffix} property of {@code GenericPropertiesContextLoader} are tested.
* </p>
* <p>
- * Since no {@link ContextConfiguration#locations() locations} are explicitly
- * defined, the {@link ContextConfiguration#resourceSuffix() resourceSuffix} is
- * set to "-context.properties", and
- * {@link ContextConfiguration#generateDefaultLocations() generateDefaultLocations}
- * is left set to its default value of {@code true}, this test class's
- * dependencies will be injected via
- * {@link Autowired annotation-based autowiring} from beans defined in the
- * {@link ApplicationContext} loaded from the default classpath resource: "{@code /org/springframework/test/junit4/PropertiesBasedSpringJUnit4ClassRunnerAppCtxTests-context.properties}".
+ * Since no {@link ContextConfiguration#locations() locations} are explicitly defined, the
+ * {@code resourceSuffix} is set to "-context.properties", and since default
+ * resource locations will be detected by default, this test class's dependencies will be
+ * injected via {@link Autowired annotation-based autowiring} from beans defined in the
+ * {@link ApplicationContext} loaded from the default classpath resource: "
+ * {@code /org/springframework/test/junit4/PropertiesBasedSpringJUnit4ClassRunnerAppCtxTests-context.properties}
+ * ".
* </p>
*
* @author Sam Brannen | true |
Other | spring-projects | spring-framework | 98074e776262292a9d6fa8d164e6718c5876ed6f.json | Provide support for context hierarchies in the TCF
Prior to this commit the Spring TestContext Framework supported creating
only flat, non-hierarchical contexts. There was no easy way to create
contexts with parent-child relationships.
This commit addresses this issue by introducing a new @ContextHierarchy
annotation that can be used in conjunction with @ContextConfiguration
for declaring hierarchies of application contexts, either within a
single test class or within a test class hierarchy. In addition,
@DirtiesContext now supports a new 'hierarchyMode' attribute for
controlling context cache clearing for context hierarchies.
- Introduced a new @ContextHierarchy annotation.
- Introduced 'name' attribute in @ContextConfiguration.
- Introduced 'name' property in ContextConfigurationAttributes.
- TestContext is now aware of @ContextHierarchy in addition to
@ContextConfiguration.
- Introduced findAnnotationDeclaringClassForTypes() in AnnotationUtils.
- Introduced resolveContextHierarchyAttributes() in ContextLoaderUtils.
- Introduced buildContextHierarchyMap() in ContextLoaderUtils.
- @ContextConfiguration and @ContextHierarchy may not be used as
top-level, class-level annotations simultaneously.
- Introduced reference to the parent configuration in
MergedContextConfiguration and WebMergedContextConfiguration.
- Introduced overloaded buildMergedContextConfiguration() methods in
ContextLoaderUtils in order to handle context hierarchies separately
from conventional, non-hierarchical contexts.
- Introduced hashCode() and equals() in ContextConfigurationAttributes.
- ContextLoaderUtils ensures uniqueness of @ContextConfiguration
elements within a single @ContextHierarchy declaration.
- Introduced CacheAwareContextLoaderDelegate that can be used for
loading contexts with transparent support for interacting with the
context cache -- for example, for retrieving the parent application
context in a context hierarchy.
- TestContext now delegates to CacheAwareContextLoaderDelegate for
loading contexts.
- Introduced getParentApplicationContext() in MergedContextConfiguration
- The loadContext(MergedContextConfiguration) methods in
AbstractGenericContextLoader and AbstractGenericWebContextLoader now
set the parent context as appropriate.
- Introduced 'hierarchyMode' attribute in @DirtiesContext with a
corresponding HierarchyMode enum that defines EXHAUSTIVE and
CURRENT_LEVEL cache removal modes.
- ContextCache now internally tracks the relationships between contexts
that make up a context hierarchy. Furthermore, when a context is
removed, if it is part of a context hierarchy all corresponding
contexts will be removed from the cache according to the supplied
HierarchyMode.
- AbstractGenericWebContextLoader will set a loaded context as the
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE in the MockServletContext when
context hierarchies are used if the context has no parent or if the
context has a parent that is not a WAC.
- Where appropriate, updated Javadoc to refer to the
ServletTestExecutionListener, which was introduced in 3.2.0.
- Updated Javadoc to avoid and/or suppress warnings in spring-test.
- Suppressed remaining warnings in code in spring-test.
Issue: SPR-5613, SPR-9863 | spring-test/src/test/java/org/springframework/test/context/junit4/spr8849/Spr8849Tests.java | @@ -38,6 +38,7 @@
* @author Sam Brannen
* @since 3.2
*/
+@SuppressWarnings("javadoc")
@RunWith(Suite.class)
@SuiteClasses({ TestClass1.class, TestClass2.class })
public class Spr8849Tests { | true |
Other | spring-projects | spring-framework | 98074e776262292a9d6fa8d164e6718c5876ed6f.json | Provide support for context hierarchies in the TCF
Prior to this commit the Spring TestContext Framework supported creating
only flat, non-hierarchical contexts. There was no easy way to create
contexts with parent-child relationships.
This commit addresses this issue by introducing a new @ContextHierarchy
annotation that can be used in conjunction with @ContextConfiguration
for declaring hierarchies of application contexts, either within a
single test class or within a test class hierarchy. In addition,
@DirtiesContext now supports a new 'hierarchyMode' attribute for
controlling context cache clearing for context hierarchies.
- Introduced a new @ContextHierarchy annotation.
- Introduced 'name' attribute in @ContextConfiguration.
- Introduced 'name' property in ContextConfigurationAttributes.
- TestContext is now aware of @ContextHierarchy in addition to
@ContextConfiguration.
- Introduced findAnnotationDeclaringClassForTypes() in AnnotationUtils.
- Introduced resolveContextHierarchyAttributes() in ContextLoaderUtils.
- Introduced buildContextHierarchyMap() in ContextLoaderUtils.
- @ContextConfiguration and @ContextHierarchy may not be used as
top-level, class-level annotations simultaneously.
- Introduced reference to the parent configuration in
MergedContextConfiguration and WebMergedContextConfiguration.
- Introduced overloaded buildMergedContextConfiguration() methods in
ContextLoaderUtils in order to handle context hierarchies separately
from conventional, non-hierarchical contexts.
- Introduced hashCode() and equals() in ContextConfigurationAttributes.
- ContextLoaderUtils ensures uniqueness of @ContextConfiguration
elements within a single @ContextHierarchy declaration.
- Introduced CacheAwareContextLoaderDelegate that can be used for
loading contexts with transparent support for interacting with the
context cache -- for example, for retrieving the parent application
context in a context hierarchy.
- TestContext now delegates to CacheAwareContextLoaderDelegate for
loading contexts.
- Introduced getParentApplicationContext() in MergedContextConfiguration
- The loadContext(MergedContextConfiguration) methods in
AbstractGenericContextLoader and AbstractGenericWebContextLoader now
set the parent context as appropriate.
- Introduced 'hierarchyMode' attribute in @DirtiesContext with a
corresponding HierarchyMode enum that defines EXHAUSTIVE and
CURRENT_LEVEL cache removal modes.
- ContextCache now internally tracks the relationships between contexts
that make up a context hierarchy. Furthermore, when a context is
removed, if it is part of a context hierarchy all corresponding
contexts will be removed from the cache according to the supplied
HierarchyMode.
- AbstractGenericWebContextLoader will set a loaded context as the
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE in the MockServletContext when
context hierarchies are used if the context has no parent or if the
context has a parent that is not a WAC.
- Where appropriate, updated Javadoc to refer to the
ServletTestExecutionListener, which was introduced in 3.2.0.
- Updated Javadoc to avoid and/or suppress warnings in spring-test.
- Suppressed remaining warnings in code in spring-test.
Issue: SPR-5613, SPR-9863 | spring-test/src/test/java/org/springframework/test/context/testng/AnnotationConfigTransactionalTestNGSpringContextTests.java | @@ -43,10 +43,11 @@
/**
* Integration tests that verify support for
- * {@link import org.springframework.context.annotation.Configuration @Configuration}
- * classes with TestNG-based tests.
+ * {@link org.springframework.context.annotation.Configuration @Configuration} classes
+ * with TestNG-based tests.
*
- * <p>Configuration will be loaded from
+ * <p>
+ * Configuration will be loaded from
* {@link AnnotationConfigTransactionalTestNGSpringContextTests.ContextConfiguration}.
*
* @author Sam Brannen | true |
Other | spring-projects | spring-framework | 98074e776262292a9d6fa8d164e6718c5876ed6f.json | Provide support for context hierarchies in the TCF
Prior to this commit the Spring TestContext Framework supported creating
only flat, non-hierarchical contexts. There was no easy way to create
contexts with parent-child relationships.
This commit addresses this issue by introducing a new @ContextHierarchy
annotation that can be used in conjunction with @ContextConfiguration
for declaring hierarchies of application contexts, either within a
single test class or within a test class hierarchy. In addition,
@DirtiesContext now supports a new 'hierarchyMode' attribute for
controlling context cache clearing for context hierarchies.
- Introduced a new @ContextHierarchy annotation.
- Introduced 'name' attribute in @ContextConfiguration.
- Introduced 'name' property in ContextConfigurationAttributes.
- TestContext is now aware of @ContextHierarchy in addition to
@ContextConfiguration.
- Introduced findAnnotationDeclaringClassForTypes() in AnnotationUtils.
- Introduced resolveContextHierarchyAttributes() in ContextLoaderUtils.
- Introduced buildContextHierarchyMap() in ContextLoaderUtils.
- @ContextConfiguration and @ContextHierarchy may not be used as
top-level, class-level annotations simultaneously.
- Introduced reference to the parent configuration in
MergedContextConfiguration and WebMergedContextConfiguration.
- Introduced overloaded buildMergedContextConfiguration() methods in
ContextLoaderUtils in order to handle context hierarchies separately
from conventional, non-hierarchical contexts.
- Introduced hashCode() and equals() in ContextConfigurationAttributes.
- ContextLoaderUtils ensures uniqueness of @ContextConfiguration
elements within a single @ContextHierarchy declaration.
- Introduced CacheAwareContextLoaderDelegate that can be used for
loading contexts with transparent support for interacting with the
context cache -- for example, for retrieving the parent application
context in a context hierarchy.
- TestContext now delegates to CacheAwareContextLoaderDelegate for
loading contexts.
- Introduced getParentApplicationContext() in MergedContextConfiguration
- The loadContext(MergedContextConfiguration) methods in
AbstractGenericContextLoader and AbstractGenericWebContextLoader now
set the parent context as appropriate.
- Introduced 'hierarchyMode' attribute in @DirtiesContext with a
corresponding HierarchyMode enum that defines EXHAUSTIVE and
CURRENT_LEVEL cache removal modes.
- ContextCache now internally tracks the relationships between contexts
that make up a context hierarchy. Furthermore, when a context is
removed, if it is part of a context hierarchy all corresponding
contexts will be removed from the cache according to the supplied
HierarchyMode.
- AbstractGenericWebContextLoader will set a loaded context as the
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE in the MockServletContext when
context hierarchies are used if the context has no parent or if the
context has a parent that is not a WAC.
- Where appropriate, updated Javadoc to refer to the
ServletTestExecutionListener, which was introduced in 3.2.0.
- Updated Javadoc to avoid and/or suppress warnings in spring-test.
- Suppressed remaining warnings in code in spring-test.
Issue: SPR-5613, SPR-9863 | spring-test/src/test/resources/org/springframework/test/context/hierarchies/standard/SingleTestClassWithTwoLevelContextHierarchyAndMixedConfigTypesTests-ChildConfig.xml | @@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:c="http://www.springframework.org/schema/c" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
+
+ <bean id="bar" class="java.lang.String" c:_="bar" />
+
+ <bean id="baz" class="java.lang.String" c:_="baz-child" />
+
+</beans> | true |
Other | spring-projects | spring-framework | 98074e776262292a9d6fa8d164e6718c5876ed6f.json | Provide support for context hierarchies in the TCF
Prior to this commit the Spring TestContext Framework supported creating
only flat, non-hierarchical contexts. There was no easy way to create
contexts with parent-child relationships.
This commit addresses this issue by introducing a new @ContextHierarchy
annotation that can be used in conjunction with @ContextConfiguration
for declaring hierarchies of application contexts, either within a
single test class or within a test class hierarchy. In addition,
@DirtiesContext now supports a new 'hierarchyMode' attribute for
controlling context cache clearing for context hierarchies.
- Introduced a new @ContextHierarchy annotation.
- Introduced 'name' attribute in @ContextConfiguration.
- Introduced 'name' property in ContextConfigurationAttributes.
- TestContext is now aware of @ContextHierarchy in addition to
@ContextConfiguration.
- Introduced findAnnotationDeclaringClassForTypes() in AnnotationUtils.
- Introduced resolveContextHierarchyAttributes() in ContextLoaderUtils.
- Introduced buildContextHierarchyMap() in ContextLoaderUtils.
- @ContextConfiguration and @ContextHierarchy may not be used as
top-level, class-level annotations simultaneously.
- Introduced reference to the parent configuration in
MergedContextConfiguration and WebMergedContextConfiguration.
- Introduced overloaded buildMergedContextConfiguration() methods in
ContextLoaderUtils in order to handle context hierarchies separately
from conventional, non-hierarchical contexts.
- Introduced hashCode() and equals() in ContextConfigurationAttributes.
- ContextLoaderUtils ensures uniqueness of @ContextConfiguration
elements within a single @ContextHierarchy declaration.
- Introduced CacheAwareContextLoaderDelegate that can be used for
loading contexts with transparent support for interacting with the
context cache -- for example, for retrieving the parent application
context in a context hierarchy.
- TestContext now delegates to CacheAwareContextLoaderDelegate for
loading contexts.
- Introduced getParentApplicationContext() in MergedContextConfiguration
- The loadContext(MergedContextConfiguration) methods in
AbstractGenericContextLoader and AbstractGenericWebContextLoader now
set the parent context as appropriate.
- Introduced 'hierarchyMode' attribute in @DirtiesContext with a
corresponding HierarchyMode enum that defines EXHAUSTIVE and
CURRENT_LEVEL cache removal modes.
- ContextCache now internally tracks the relationships between contexts
that make up a context hierarchy. Furthermore, when a context is
removed, if it is part of a context hierarchy all corresponding
contexts will be removed from the cache according to the supplied
HierarchyMode.
- AbstractGenericWebContextLoader will set a loaded context as the
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE in the MockServletContext when
context hierarchies are used if the context has no parent or if the
context has a parent that is not a WAC.
- Where appropriate, updated Javadoc to refer to the
ServletTestExecutionListener, which was introduced in 3.2.0.
- Updated Javadoc to avoid and/or suppress warnings in spring-test.
- Suppressed remaining warnings in code in spring-test.
Issue: SPR-5613, SPR-9863 | spring-test/src/test/resources/org/springframework/test/context/hierarchies/standard/TestHierarchyLevelTwoWithSingleLevelContextHierarchyAndMixedConfigTypesTests-context.xml | @@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:c="http://www.springframework.org/schema/c" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
+
+ <bean id="foo" class="java.lang.String" c:_="foo-level-2" />
+
+ <bean id="baz" class="java.lang.String" c:_="baz" />
+
+</beans> | true |
Other | spring-projects | spring-framework | 98074e776262292a9d6fa8d164e6718c5876ed6f.json | Provide support for context hierarchies in the TCF
Prior to this commit the Spring TestContext Framework supported creating
only flat, non-hierarchical contexts. There was no easy way to create
contexts with parent-child relationships.
This commit addresses this issue by introducing a new @ContextHierarchy
annotation that can be used in conjunction with @ContextConfiguration
for declaring hierarchies of application contexts, either within a
single test class or within a test class hierarchy. In addition,
@DirtiesContext now supports a new 'hierarchyMode' attribute for
controlling context cache clearing for context hierarchies.
- Introduced a new @ContextHierarchy annotation.
- Introduced 'name' attribute in @ContextConfiguration.
- Introduced 'name' property in ContextConfigurationAttributes.
- TestContext is now aware of @ContextHierarchy in addition to
@ContextConfiguration.
- Introduced findAnnotationDeclaringClassForTypes() in AnnotationUtils.
- Introduced resolveContextHierarchyAttributes() in ContextLoaderUtils.
- Introduced buildContextHierarchyMap() in ContextLoaderUtils.
- @ContextConfiguration and @ContextHierarchy may not be used as
top-level, class-level annotations simultaneously.
- Introduced reference to the parent configuration in
MergedContextConfiguration and WebMergedContextConfiguration.
- Introduced overloaded buildMergedContextConfiguration() methods in
ContextLoaderUtils in order to handle context hierarchies separately
from conventional, non-hierarchical contexts.
- Introduced hashCode() and equals() in ContextConfigurationAttributes.
- ContextLoaderUtils ensures uniqueness of @ContextConfiguration
elements within a single @ContextHierarchy declaration.
- Introduced CacheAwareContextLoaderDelegate that can be used for
loading contexts with transparent support for interacting with the
context cache -- for example, for retrieving the parent application
context in a context hierarchy.
- TestContext now delegates to CacheAwareContextLoaderDelegate for
loading contexts.
- Introduced getParentApplicationContext() in MergedContextConfiguration
- The loadContext(MergedContextConfiguration) methods in
AbstractGenericContextLoader and AbstractGenericWebContextLoader now
set the parent context as appropriate.
- Introduced 'hierarchyMode' attribute in @DirtiesContext with a
corresponding HierarchyMode enum that defines EXHAUSTIVE and
CURRENT_LEVEL cache removal modes.
- ContextCache now internally tracks the relationships between contexts
that make up a context hierarchy. Furthermore, when a context is
removed, if it is part of a context hierarchy all corresponding
contexts will be removed from the cache according to the supplied
HierarchyMode.
- AbstractGenericWebContextLoader will set a loaded context as the
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE in the MockServletContext when
context hierarchies are used if the context has no parent or if the
context has a parent that is not a WAC.
- Where appropriate, updated Javadoc to refer to the
ServletTestExecutionListener, which was introduced in 3.2.0.
- Updated Javadoc to avoid and/or suppress warnings in spring-test.
- Suppressed remaining warnings in code in spring-test.
Issue: SPR-5613, SPR-9863 | spring-test/src/test/resources/org/springframework/test/context/hierarchies/web/DispatcherWacRootWacEarTests-context.xml | @@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:c="http://www.springframework.org/schema/c" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
+
+ <bean id="dispatcher" class="java.lang.String" c:_="dispatcher" />
+
+</beans> | true |
Other | spring-projects | spring-framework | 98074e776262292a9d6fa8d164e6718c5876ed6f.json | Provide support for context hierarchies in the TCF
Prior to this commit the Spring TestContext Framework supported creating
only flat, non-hierarchical contexts. There was no easy way to create
contexts with parent-child relationships.
This commit addresses this issue by introducing a new @ContextHierarchy
annotation that can be used in conjunction with @ContextConfiguration
for declaring hierarchies of application contexts, either within a
single test class or within a test class hierarchy. In addition,
@DirtiesContext now supports a new 'hierarchyMode' attribute for
controlling context cache clearing for context hierarchies.
- Introduced a new @ContextHierarchy annotation.
- Introduced 'name' attribute in @ContextConfiguration.
- Introduced 'name' property in ContextConfigurationAttributes.
- TestContext is now aware of @ContextHierarchy in addition to
@ContextConfiguration.
- Introduced findAnnotationDeclaringClassForTypes() in AnnotationUtils.
- Introduced resolveContextHierarchyAttributes() in ContextLoaderUtils.
- Introduced buildContextHierarchyMap() in ContextLoaderUtils.
- @ContextConfiguration and @ContextHierarchy may not be used as
top-level, class-level annotations simultaneously.
- Introduced reference to the parent configuration in
MergedContextConfiguration and WebMergedContextConfiguration.
- Introduced overloaded buildMergedContextConfiguration() methods in
ContextLoaderUtils in order to handle context hierarchies separately
from conventional, non-hierarchical contexts.
- Introduced hashCode() and equals() in ContextConfigurationAttributes.
- ContextLoaderUtils ensures uniqueness of @ContextConfiguration
elements within a single @ContextHierarchy declaration.
- Introduced CacheAwareContextLoaderDelegate that can be used for
loading contexts with transparent support for interacting with the
context cache -- for example, for retrieving the parent application
context in a context hierarchy.
- TestContext now delegates to CacheAwareContextLoaderDelegate for
loading contexts.
- Introduced getParentApplicationContext() in MergedContextConfiguration
- The loadContext(MergedContextConfiguration) methods in
AbstractGenericContextLoader and AbstractGenericWebContextLoader now
set the parent context as appropriate.
- Introduced 'hierarchyMode' attribute in @DirtiesContext with a
corresponding HierarchyMode enum that defines EXHAUSTIVE and
CURRENT_LEVEL cache removal modes.
- ContextCache now internally tracks the relationships between contexts
that make up a context hierarchy. Furthermore, when a context is
removed, if it is part of a context hierarchy all corresponding
contexts will be removed from the cache according to the supplied
HierarchyMode.
- AbstractGenericWebContextLoader will set a loaded context as the
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE in the MockServletContext when
context hierarchies are used if the context has no parent or if the
context has a parent that is not a WAC.
- Where appropriate, updated Javadoc to refer to the
ServletTestExecutionListener, which was introduced in 3.2.0.
- Updated Javadoc to avoid and/or suppress warnings in spring-test.
- Suppressed remaining warnings in code in spring-test.
Issue: SPR-5613, SPR-9863 | src/dist/changelog.txt | @@ -41,6 +41,8 @@ Changes in version 3.2.2 (2013-03-11)
* MappingJackson(2)JsonView allows subclasses to access the ObjectMapper and to override content writing (SPR-7619)
* Log4jWebConfigurer supports resolving placeholders against ServletContext init-parameters as well (SPR-10284)
* consistent use of LinkedHashMaps and independent getAttributeNames Enumeration in Servlet/Portlet mocks (SPR-10224)
+* introduced support for context hierarchies in the TestContext framework (SPR-5613)
+* introduced support for WebApplicationContext hierarchies in the TestContext framework (SPR-9863)
Changes in version 3.2.1 (2013-01-24) | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | build.gradle | @@ -13,7 +13,6 @@ configure(allprojects) { project ->
version = qualifyVersionIfNecessary(version)
ext.aspectjVersion = "1.7.2"
- ext.easymockVersion = "2.5.2"
ext.hsqldbVersion = "1.8.0.10"
ext.junitVersion = "4.11"
ext.slf4jVersion = "1.6.1"
@@ -69,13 +68,6 @@ configure(allprojects) { project ->
testCompile("junit:junit:${junitVersion}")
testCompile("org.hamcrest:hamcrest-all:1.3")
testCompile("org.mockito:mockito-core:1.9.5")
- if (project.name in ["spring",
- "spring-orm-hibernate4", "spring-oxm", "spring-struts",
- "spring-test", "spring-test-mvc", "spring-tx", "spring-web",
- "spring-webmvc", "spring-webmvc-portlet", "spring-webmvc-tiles3"]) {
- testCompile("org.easymock:easymock:${easymockVersion}")
- testCompile "org.easymock:easymockclassextension:${easymockVersion}"
- }
}
ext.javadocLinks = [ | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-aop/src/test/java/org/springframework/aop/framework/adapter/ThrowsAdviceInterceptorTests.java | @@ -16,11 +16,6 @@
package org.springframework.aop.framework.adapter;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.Mockito.mock;
-
import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.reflect.Method;
@@ -33,6 +28,9 @@
import org.springframework.aop.ThrowsAdvice;
import org.springframework.tests.aop.advice.MethodCounter;
+import static org.junit.Assert.*;
+import static org.mockito.BDDMockito.*;
+
/**
* @author Rod Johnson | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-aop/src/test/java/org/springframework/aop/interceptor/CustomizableTraceInterceptorTests.java | @@ -16,18 +16,13 @@
package org.springframework.aop.interceptor;
-import static org.junit.Assert.*;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-
import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.logging.Log;
import org.junit.Test;
+import static org.junit.Assert.*;
+import static org.mockito.BDDMockito.*;
+
/**
* @author Rob Harrop
* @author Rick Evans | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-aop/src/test/java/org/springframework/aop/interceptor/DebugInterceptorTests.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,18 +16,13 @@
package org.springframework.aop.interceptor;
-import static org.junit.Assert.*;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-
import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.logging.Log;
import org.junit.Test;
+import static org.junit.Assert.*;
+import static org.mockito.BDDMockito.*;
+
/**
* Unit tests for the {@link DebugInterceptor} class.
* | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-aop/src/test/java/org/springframework/aop/interceptor/PerformanceMonitorInterceptorTests.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,16 +16,13 @@
package org.springframework.aop.interceptor;
-import static org.junit.Assert.*;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.logging.Log;
import org.junit.Test;
+import static org.junit.Assert.*;
+import static org.mockito.BDDMockito.*;
+
/**
* @author Rob Harrop
* @author Rick Evans | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-aop/src/test/java/org/springframework/aop/interceptor/SimpleTraceInterceptorTests.java | @@ -16,18 +16,13 @@
package org.springframework.aop.interceptor;
-import static org.junit.Assert.fail;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-
import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.logging.Log;
import org.junit.Test;
+import static org.junit.Assert.*;
+import static org.mockito.BDDMockito.*;
+
/**
* Unit tests for the {@link SimpleTraceInterceptor} class.
* | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-aop/src/test/java/org/springframework/aop/scope/DefaultScopedObjectTests.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,11 +16,11 @@
package org.springframework.aop.scope;
-import static org.mockito.Mockito.mock;
-
import org.junit.Test;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
+import static org.mockito.BDDMockito.*;
+
/**
* Unit tests for the {@link DefaultScopedObject} class.
* | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-aop/src/test/java/org/springframework/aop/support/DelegatingIntroductionInterceptorTests.java | @@ -16,14 +16,6 @@
package org.springframework.aop.support;
-import static org.hamcrest.Matchers.instanceOf;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.Mockito.mock;
-
import java.io.Serializable;
import org.aopalliance.intercept.MethodInterceptor;
@@ -41,6 +33,10 @@
import org.springframework.tests.sample.beans.TestBean;
import org.springframework.util.SerializationTestUtils;
+import static org.hamcrest.Matchers.*;
+import static org.junit.Assert.*;
+import static org.mockito.BDDMockito.*;
+
/**
* @author Rod Johnson
* @author Chris Beams | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-beans/src/test/java/org/springframework/beans/factory/DefaultListableBeanFactoryTests.java | @@ -16,24 +16,6 @@
package org.springframework.beans.factory;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.Matchers.containsString;
-import static org.hamcrest.Matchers.equalTo;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.Matchers.isNull;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
-
import java.io.Closeable;
import java.lang.reflect.Field;
import java.net.MalformedURLException;
@@ -104,6 +86,10 @@
import org.springframework.util.StopWatch;
import org.springframework.util.StringValueResolver;
+import static org.hamcrest.Matchers.*;
+import static org.junit.Assert.*;
+import static org.mockito.BDDMockito.*;
+
/**
* Tests properties population and autowire behavior.
*
@@ -2261,8 +2247,8 @@ public void testContainsBeanReturnsTrueEvenForAbstractBeanDefinition() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.registerBeanDefinition("abs", BeanDefinitionBuilder
.rootBeanDefinition(TestBean.class).setAbstract(true).getBeanDefinition());
- assertThat(bf.containsBean("abs"), is(true));
- assertThat(bf.containsBean("bogus"), is(false));
+ assertThat(bf.containsBean("abs"), equalTo(true));
+ assertThat(bf.containsBean("bogus"), equalTo(false));
}
@Test | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-beans/src/test/java/org/springframework/beans/factory/config/CustomScopeConfigurerTests.java | @@ -16,16 +16,16 @@
package org.springframework.beans.factory.config;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-
import java.util.HashMap;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
+import static org.junit.Assert.*;
+import static org.mockito.BDDMockito.*;
+
/**
* Unit tests for {@link CustomScopeConfigurer}.
* | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-beans/src/test/java/org/springframework/beans/factory/config/ObjectFactoryCreatingFactoryBeanTests.java | @@ -16,14 +16,6 @@
package org.springframework.beans.factory.config;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.Mockito.mock;
-import static org.springframework.tests.TestResourceUtils.qualifiedResource;
-
import java.util.Date;
import javax.inject.Provider;
@@ -38,6 +30,10 @@
import org.springframework.core.io.Resource;
import org.springframework.util.SerializationTestUtils;
+import static org.junit.Assert.*;
+import static org.mockito.BDDMockito.*;
+import static org.springframework.tests.TestResourceUtils.*;
+
/**
* @author Colin Sampaleanu
* @author Juergen Hoeller | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-beans/src/test/java/org/springframework/beans/factory/config/ServiceLocatorFactoryBeanTests.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,10 +16,6 @@
package org.springframework.beans.factory.config;
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.mock;
-import static org.springframework.beans.factory.support.BeanDefinitionBuilder.genericBeanDefinition;
-
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
@@ -30,6 +26,10 @@
import org.springframework.core.NestedCheckedException;
import org.springframework.core.NestedRuntimeException;
+import static org.junit.Assert.*;
+import static org.mockito.BDDMockito.*;
+import static org.springframework.beans.factory.support.BeanDefinitionBuilder.*;
+
/**
* Unit tests for {@link ServiceLocatorFactoryBean}.
* | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-beans/src/test/java/org/springframework/beans/factory/parsing/FailFastProblemReporterTests.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,15 +16,13 @@
package org.springframework.beans.factory.parsing;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.isA;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
import org.apache.commons.logging.Log;
import org.junit.Test;
import org.springframework.core.io.DescriptiveResource;
+import static org.mockito.Matchers.*;
+import static org.mockito.BDDMockito.*;
+
/**
* @author Rick Evans
* @author Juergen Hoeller | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-beans/src/test/java/org/springframework/beans/factory/wiring/BeanConfigurerSupportTests.java | @@ -16,16 +16,15 @@
package org.springframework.beans.factory.wiring;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
import junit.framework.TestCase;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.tests.sample.beans.TestBean;
+import static org.mockito.BDDMockito.*;
+
/**
* @author Rick Evans | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-context-support/src/test/java/org/springframework/scheduling/quartz/QuartzSupportTests.java | @@ -16,15 +16,6 @@
package org.springframework.scheduling.quartz;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
@@ -52,19 +43,22 @@
import org.quartz.TriggerListener;
import org.quartz.impl.SchedulerRepository;
import org.quartz.spi.JobFactory;
-import org.springframework.tests.context.TestMethodInvokingTask;
-import org.springframework.tests.sample.beans.TestBean;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.factory.support.StaticListableBeanFactory;
-import org.springframework.tests.Assume;
-import org.springframework.tests.TestGroup;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.StaticApplicationContext;
import org.springframework.core.io.FileSystemResourceLoader;
import org.springframework.core.task.TaskExecutor;
import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.tests.Assume;
+import org.springframework.tests.TestGroup;
+import org.springframework.tests.context.TestMethodInvokingTask;
+import org.springframework.tests.sample.beans.TestBean;
+
+import static org.junit.Assert.*;
+import static org.mockito.BDDMockito.*;
/**
* @author Juergen Hoeller | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-context/src/test/java/org/springframework/aop/aspectj/AfterAdviceBindingTests.java | @@ -16,18 +16,17 @@
package org.springframework.aop.aspectj;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
import org.junit.Before;
import org.junit.Test;
import org.springframework.aop.aspectj.AdviceBindingTestAspect.AdviceBindingCollaborator;
import org.springframework.aop.framework.Advised;
import org.springframework.aop.support.AopUtils;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.TestBean;
-import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+import static org.junit.Assert.*;
+import static org.mockito.BDDMockito.*;
/**
* Tests for various parameter binding scenarios with before advice. | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-context/src/test/java/org/springframework/aop/aspectj/AfterReturningAdviceBindingTests.java | @@ -16,19 +16,17 @@
package org.springframework.aop.aspectj;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyZeroInteractions;
-
import org.junit.Before;
import org.junit.Test;
import org.springframework.aop.aspectj.AfterReturningAdviceBindingTestAspect.AfterReturningAdviceBindingCollaborator;
import org.springframework.aop.framework.Advised;
import org.springframework.aop.support.AopUtils;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.TestBean;
-import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+import static org.junit.Assert.*;
+import static org.mockito.BDDMockito.*;
/**
* Tests for various parameter binding scenarios with before advice. | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-context/src/test/java/org/springframework/aop/aspectj/AfterThrowingAdviceBindingTests.java | @@ -16,14 +16,13 @@
package org.springframework.aop.aspectj;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
import org.junit.Before;
import org.junit.Test;
import org.springframework.aop.aspectj.AfterThrowingAdviceBindingTestAspect.AfterThrowingAdviceBindingCollaborator;
-import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.tests.sample.beans.ITestBean;
+
+import static org.mockito.BDDMockito.*;
/**
* Tests for various parameter binding scenarios with before advice. | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-context/src/test/java/org/springframework/aop/aspectj/AroundAdviceBindingTests.java | @@ -16,20 +16,19 @@
package org.springframework.aop.aspectj;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
import org.aspectj.lang.ProceedingJoinPoint;
import org.junit.Before;
import org.junit.Test;
import org.springframework.aop.aspectj.AroundAdviceBindingTestAspect.AroundAdviceBindingCollaborator;
import org.springframework.aop.framework.Advised;
import org.springframework.aop.support.AopUtils;
-import org.springframework.tests.sample.beans.ITestBean;
-import org.springframework.tests.sample.beans.TestBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.tests.sample.beans.ITestBean;
+import org.springframework.tests.sample.beans.TestBean;
+
+import static org.junit.Assert.*;
+import static org.mockito.BDDMockito.*;
/**
* Tests for various parameter binding scenarios with before advice. | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-context/src/test/java/org/springframework/aop/aspectj/BeforeAdviceBindingTests.java | @@ -16,18 +16,17 @@
package org.springframework.aop.aspectj;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
import org.junit.Before;
import org.junit.Test;
import org.springframework.aop.aspectj.AdviceBindingTestAspect.AdviceBindingCollaborator;
import org.springframework.aop.framework.Advised;
import org.springframework.aop.support.AopUtils;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.TestBean;
-import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+import static org.junit.Assert.*;
+import static org.mockito.BDDMockito.*;
/**
* Tests for various parameter binding scenarios with before advice. | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-context/src/test/java/org/springframework/aop/config/MethodLocatingFactoryBeanTests.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,19 +16,15 @@
package org.springframework.aop.config;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
import java.lang.reflect.Method;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.BeanFactory;
+import static org.junit.Assert.*;
+import static org.mockito.BDDMockito.*;
+
/**
* @author Rick Evans
* @author Chris Beams | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-context/src/test/java/org/springframework/aop/framework/JdkDynamicProxyTests.java | @@ -16,21 +16,19 @@
package org.springframework.aop.framework;
-import static org.junit.Assert.*;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.Mockito.mock;
-
import java.io.Serializable;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
-
import org.springframework.aop.interceptor.ExposeInvocationInterceptor;
import org.springframework.aop.support.AopUtils;
import org.springframework.tests.sample.beans.IOther;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.TestBean;
+import static org.junit.Assert.*;
+import static org.mockito.BDDMockito.*;
+
/**
* @since 13.03.2003
* @author Rod Johnson | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-context/src/test/java/org/springframework/context/access/ContextBeanFactoryReferenceTests.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,13 +16,12 @@
package org.springframework.context.access;
-import static org.junit.Assert.assertNotNull;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
import org.junit.Test;
import org.springframework.context.ConfigurableApplicationContext;
+import static org.junit.Assert.*;
+import static org.mockito.BDDMockito.*;
+
/**
* Unit test for {@link ContextBeanFactoryReference}
* | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-context/src/test/java/org/springframework/context/annotation/EnableLoadTimeWeavingTests.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,18 +16,16 @@
package org.springframework.context.annotation;
-import static org.mockito.Matchers.isA;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyZeroInteractions;
-
import java.lang.instrument.ClassFileTransformer;
import org.junit.Test;
import org.springframework.context.annotation.EnableLoadTimeWeaving.AspectJWeaving;
import org.springframework.context.support.GenericXmlApplicationContext;
import org.springframework.instrument.classloading.LoadTimeWeaver;
+import static org.mockito.Matchers.*;
+import static org.mockito.BDDMockito.*;
+
/**
* Unit tests for @EnableLoadTimeWeaving
* | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-context/src/test/java/org/springframework/context/event/ApplicationContextEventTests.java | @@ -20,16 +20,8 @@
import java.util.Set;
import org.aopalliance.intercept.MethodInvocation;
-import static org.junit.Assert.*;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.Matchers.isA;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
import org.junit.Test;
-
import org.springframework.aop.framework.ProxyFactory;
-import org.springframework.tests.sample.beans.TestBean;
import org.springframework.beans.factory.config.RuntimeBeanReference;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.ApplicationContext;
@@ -39,6 +31,10 @@
import org.springframework.context.BeanThatListens;
import org.springframework.context.support.StaticApplicationContext;
import org.springframework.core.Ordered;
+import org.springframework.tests.sample.beans.TestBean;
+
+import static org.junit.Assert.*;
+import static org.mockito.BDDMockito.*;
/**
* Unit and integration tests for the ApplicationContext event support. | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-context/src/test/java/org/springframework/context/event/EventPublicationInterceptorTests.java | @@ -16,21 +16,21 @@
package org.springframework.context.event;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-
import org.junit.Before;
import org.junit.Test;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.beans.BeansException;
-import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.beans.MutablePropertyValues;
-import org.springframework.tests.sample.beans.TestBean;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.TestListener;
import org.springframework.context.support.StaticApplicationContext;
+import org.springframework.tests.sample.beans.ITestBean;
+import org.springframework.tests.sample.beans.TestBean;
+
+import static org.junit.Assert.*;
+import static org.mockito.BDDMockito.*;
/**
* @author Dmitriy Kopylenko | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-context/src/test/java/org/springframework/ejb/access/LocalSlsbInvokerInterceptorTests.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,11 +16,6 @@
package org.springframework.ejb.access;
-import static org.junit.Assert.*;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
import javax.ejb.CreateException;
import javax.ejb.EJBLocalHome;
import javax.ejb.EJBLocalObject;
@@ -31,6 +26,9 @@
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.jndi.JndiTemplate;
+import static org.junit.Assert.*;
+import static org.mockito.BDDMockito.*;
+
/**
* @author Rod Johnson
* @author Juergen Hoeller | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-context/src/test/java/org/springframework/ejb/access/LocalStatelessSessionProxyFactoryBeanTests.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,12 +16,6 @@
package org.springframework.ejb.access;
-import static org.junit.Assert.*;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyZeroInteractions;
-
import java.lang.reflect.Proxy;
import javax.ejb.CreateException;
@@ -32,6 +26,9 @@
import org.junit.Test;
import org.springframework.jndi.JndiTemplate;
+import static org.junit.Assert.*;
+import static org.mockito.BDDMockito.*;
+
/**
* @author Rod Johnson
* @author Juergen Hoeller | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-context/src/test/java/org/springframework/ejb/access/SimpleRemoteSlsbInvokerInterceptorTests.java | @@ -16,12 +16,6 @@
package org.springframework.ejb.access;
-import static org.junit.Assert.*;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-
import java.rmi.ConnectException;
import java.rmi.RemoteException;
@@ -36,6 +30,9 @@
import org.springframework.jndi.JndiTemplate;
import org.springframework.remoting.RemoteAccessException;
+import static org.junit.Assert.*;
+import static org.mockito.BDDMockito.*;
+
/**
* @author Rod Johnson
* @author Juergen Hoeller | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-context/src/test/java/org/springframework/ejb/access/SimpleRemoteStatelessSessionProxyFactoryBeanTests.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,12 +16,6 @@
package org.springframework.ejb.access;
-import static org.junit.Assert.*;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyZeroInteractions;
-
import java.lang.reflect.Proxy;
import java.rmi.RemoteException;
@@ -34,6 +28,9 @@
import org.springframework.jndi.JndiTemplate;
import org.springframework.remoting.RemoteAccessException;
+import static org.junit.Assert.*;
+import static org.mockito.BDDMockito.*;
+
/**
* @author Rod Johnson
* @author Juergen Hoeller | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-context/src/test/java/org/springframework/jndi/JndiObjectFactoryBeanTests.java | @@ -16,12 +16,6 @@
package org.springframework.jndi;
-import static org.junit.Assert.*;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-
import javax.naming.Context;
import javax.naming.NamingException;
@@ -31,6 +25,9 @@
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.TestBean;
+import static org.junit.Assert.*;
+import static org.mockito.BDDMockito.*;
+
/**
* @author Rod Johnson
* @author Juergen Hoeller | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-context/src/test/java/org/springframework/jndi/JndiTemplateTests.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,16 +16,14 @@
package org.springframework.jndi;
-import static org.junit.Assert.*;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
import javax.naming.Context;
import javax.naming.NameNotFoundException;
import org.junit.Test;
+import static org.junit.Assert.*;
+import static org.mockito.BDDMockito.*;
+
/**
* @author Rod Johnson
* @author Juergen Hoeller | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-context/src/test/java/org/springframework/scripting/bsh/BshScriptFactoryTests.java | @@ -16,17 +16,13 @@
package org.springframework.scripting.bsh;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.Mockito.mock;
-
import java.util.Arrays;
import java.util.Collection;
import junit.framework.TestCase;
import org.springframework.aop.support.AopUtils;
import org.springframework.aop.target.dynamic.Refreshable;
-import org.springframework.tests.sample.beans.TestBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.support.ClassPathXmlApplicationContext;
@@ -38,6 +34,9 @@
import org.springframework.scripting.ScriptSource;
import org.springframework.scripting.TestBeanAwareMessenger;
import org.springframework.scripting.support.ScriptFactoryPostProcessor;
+import org.springframework.tests.sample.beans.TestBean;
+
+import static org.mockito.BDDMockito.*;
/**
* @author Rob Harrop | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-context/src/test/java/org/springframework/scripting/groovy/GroovyScriptFactoryTests.java | @@ -16,16 +16,16 @@
package org.springframework.scripting.groovy;
+import groovy.lang.DelegatingMetaClass;
+import groovy.lang.GroovyObject;
+
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Map;
-import groovy.lang.DelegatingMetaClass;
-import groovy.lang.GroovyObject;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
-
import org.springframework.aop.support.AopUtils;
import org.springframework.aop.target.dynamic.Refreshable;
import org.springframework.beans.factory.BeanCreationException;
@@ -52,7 +52,6 @@
import static org.junit.Assert.*;
import static org.mockito.BDDMockito.*;
-import static org.mockito.Mockito.mock;
/**
* @author Rob Harrop | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-context/src/test/java/org/springframework/scripting/support/RefreshableScriptTargetSourceTests.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,11 +16,12 @@
package org.springframework.scripting.support;
-import static org.mockito.Mockito.mock;
import junit.framework.TestCase;
import org.springframework.beans.factory.BeanFactory;
+import static org.mockito.BDDMockito.*;
+
/**
* @author Rick Evans
*/ | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-context/src/test/java/org/springframework/scripting/support/ResourceScriptSourceTests.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,9 +16,6 @@
package org.springframework.scripting.support;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.Mockito.mock;
-
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -27,6 +24,8 @@
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.Resource;
+import static org.mockito.BDDMockito.*;
+
/**
* @author Rick Evans
* @author Juergen Hoeller | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-context/src/test/java/org/springframework/scripting/support/ScriptFactoryPostProcessorTests.java | @@ -16,11 +16,8 @@
package org.springframework.scripting.support;
-import static org.mockito.Mockito.mock;
-
import org.junit.Before;
import org.junit.Test;
-
import org.springframework.beans.FatalBeanException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.config.BeanDefinition;
@@ -34,6 +31,7 @@
import org.springframework.tests.TestGroup;
import static org.junit.Assert.*;
+import static org.mockito.BDDMockito.*;
/**
* @author Rick Evans | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-core/src/test/java/org/springframework/util/StreamUtilsTests.java | @@ -16,14 +16,6 @@
package org.springframework.util;
-import static org.hamcrest.Matchers.equalTo;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.inOrder;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
@@ -36,6 +28,10 @@
import org.junit.Test;
import org.mockito.InOrder;
+import static org.hamcrest.Matchers.*;
+import static org.junit.Assert.*;
+import static org.mockito.BDDMockito.*;
+
/**
* Tests for {@link StreamUtils}.
* | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-core/src/test/java/org/springframework/util/xml/AbstractStaxXMLReaderTestCase.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,12 +16,6 @@
package org.springframework.util.xml;
-import static org.mockito.BDDMockito.willAnswer;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyInt;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.mock;
-
import java.io.InputStream;
import javax.xml.stream.XMLInputFactory;
@@ -44,6 +38,8 @@
import org.xml.sax.helpers.AttributesImpl;
import org.xml.sax.helpers.XMLReaderFactory;
+import static org.mockito.BDDMockito.*;
+
public abstract class AbstractStaxXMLReaderTestCase {
protected static XMLInputFactory inputFactory; | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-core/src/test/java/org/springframework/util/xml/StaxEventXMLReaderTests.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,11 +16,9 @@
package org.springframework.util.xml;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
import java.io.InputStream;
import java.io.StringReader;
+
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
@@ -29,6 +27,8 @@
import org.xml.sax.InputSource;
import org.xml.sax.helpers.AttributesImpl;
+import static org.mockito.BDDMockito.*;
+
public class StaxEventXMLReaderTests extends AbstractStaxXMLReaderTestCase {
public static final String CONTENT = "<root xmlns='http://springframework.org/spring-ws'><child/></root>"; | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-core/src/test/java/org/springframework/util/xml/StaxStreamXMLReaderTests.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,23 +18,22 @@
import java.io.InputStream;
import java.io.StringReader;
+
import javax.xml.namespace.QName;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
-import static org.junit.Assert.*;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
import org.junit.Test;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
import org.xml.sax.Locator;
+import static org.junit.Assert.*;
+import static org.mockito.Matchers.*;
+import static org.mockito.BDDMockito.*;
+
public class StaxStreamXMLReaderTests extends AbstractStaxXMLReaderTestCase {
public static final String CONTENT = "<root xmlns='http://springframework.org/spring-ws'><child/></root>"; | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-jdbc/src/test/java/org/springframework/jdbc/core/AbstractRowMapperTests.java | @@ -16,12 +16,6 @@
package org.springframework.jdbc.core;
-import static org.junit.Assert.assertEquals;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.ResultSet;
@@ -35,6 +29,9 @@
import org.springframework.jdbc.datasource.SingleConnectionDataSource;
import org.springframework.jdbc.support.SQLStateSQLExceptionTranslator;
+import static org.junit.Assert.*;
+import static org.mockito.BDDMockito.*;
+
/**
* Mock object based abstract class for RowMapper tests.
* Initializes mock objects and verifies results. | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-jdbc/src/test/java/org/springframework/jdbc/core/JdbcTemplateQueryTests.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,14 +16,6 @@
package org.springframework.jdbc.core;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.Connection;
@@ -43,6 +35,9 @@
import org.junit.rules.ExpectedException;
import org.springframework.dao.IncorrectResultSizeDataAccessException;
+import static org.junit.Assert.*;
+import static org.mockito.BDDMockito.*;
+
/**
* @author Juergen Hoeller
* @author Phillip Webb | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-jdbc/src/test/java/org/springframework/jdbc/core/JdbcTemplateTests.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,26 +16,6 @@
package org.springframework.jdbc.core;
-import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.instanceOf;
-import static org.hamcrest.Matchers.sameInstance;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.BDDMockito.willThrow;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.atLeastOnce;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.reset;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.springframework.tests.Matchers.exceptionCause;
-
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
@@ -71,6 +51,11 @@
import org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractorAdapter;
import org.springframework.util.LinkedCaseInsensitiveMap;
+import static org.hamcrest.Matchers.*;
+import static org.junit.Assert.*;
+import static org.mockito.BDDMockito.*;
+import static org.springframework.tests.Matchers.*;
+
/**
* Mock object based tests for JdbcTemplate.
* | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-jdbc/src/test/java/org/springframework/jdbc/core/RowMapperTests.java | @@ -16,11 +16,6 @@
package org.springframework.jdbc.core;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@@ -34,9 +29,11 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import org.springframework.tests.sample.beans.TestBean;
import org.springframework.jdbc.datasource.SingleConnectionDataSource;
import org.springframework.jdbc.support.SQLStateSQLExceptionTranslator;
+import org.springframework.tests.sample.beans.TestBean;
+
+import static org.mockito.BDDMockito.*;
/**
* @author Juergen Hoeller | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-jdbc/src/test/java/org/springframework/jdbc/core/StatementCreatorUtilsTests.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,10 +16,6 @@
package org.springframework.jdbc.core;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
@@ -30,6 +26,8 @@
import org.junit.Before;
import org.junit.Test;
+import static org.mockito.BDDMockito.*;
+
/**
* @author Juergen Hoeller
* @since 31.08.2004 | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-jdbc/src/test/java/org/springframework/jdbc/core/namedparam/NamedParameterJdbcTemplateTests.java | @@ -27,13 +27,13 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+
import javax.sql.DataSource;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.Customer;
import org.springframework.jdbc.core.JdbcOperations;
@@ -46,11 +46,6 @@
import static org.junit.Assert.*;
import static org.mockito.BDDMockito.*;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.atLeastOnce;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
/**
* @author Rick Evans | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-jdbc/src/test/java/org/springframework/jdbc/core/namedparam/NamedParameterQueryTests.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,13 +16,6 @@
package org.springframework.jdbc.core.namedparam;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@@ -42,6 +35,9 @@
import org.junit.Test;
import org.springframework.jdbc.core.RowMapper;
+import static org.junit.Assert.*;
+import static org.mockito.BDDMockito.*;
+
/**
* @author Thomas Risberg
* @author Phillip Webb | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/CallMetaDataContextTests.java | @@ -1,11 +1,5 @@
package org.springframework.jdbc.core.simple;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.Types;
@@ -24,6 +18,9 @@
import org.springframework.jdbc.core.metadata.CallMetaDataContext;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
+import static org.junit.Assert.*;
+import static org.mockito.BDDMockito.*;
+
/**
* Mock object based tests for CallMetaDataContext.
* | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/SimpleJdbcCallTests.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,14 +16,6 @@
package org.springframework.jdbc.core.simple;
-import static org.hamcrest.Matchers.sameInstance;
-import static org.junit.Assert.assertEquals;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.Mockito.atLeastOnce;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.springframework.tests.Matchers.exceptionCause;
-
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
@@ -43,6 +35,11 @@
import org.springframework.jdbc.core.SqlParameter;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
+import static org.hamcrest.Matchers.*;
+import static org.junit.Assert.*;
+import static org.mockito.BDDMockito.*;
+import static org.springframework.tests.Matchers.*;
+
/**
* Mock object based tests for SimpleJdbcCall.
* | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/SimpleJdbcInsertTests.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,10 +16,6 @@
package org.springframework.jdbc.core.simple;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
@@ -34,6 +30,8 @@
import org.junit.rules.ExpectedException;
import org.springframework.dao.InvalidDataAccessApiUsageException;
+import static org.mockito.BDDMockito.*;
+
/**
* Mock object based tests for SimpleJdbcInsert.
* | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/SimpleJdbcTemplateTests.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,15 +16,6 @@
package org.springframework.jdbc.core.simple;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
@@ -48,6 +39,9 @@
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
+import static org.junit.Assert.*;
+import static org.mockito.BDDMockito.*;
+
/**
* @author Rod Johnson
* @author Rob Harrop | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/TableMetaDataContextTests.java | @@ -16,12 +16,6 @@
package org.springframework.jdbc.core.simple;
-import static org.junit.Assert.*;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.Mockito.atLeastOnce;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
@@ -38,6 +32,9 @@
import org.springframework.jdbc.core.metadata.TableMetaDataContext;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
+import static org.junit.Assert.*;
+import static org.mockito.BDDMockito.*;
+
/**
* Mock object based tests for TableMetaDataContext.
* | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-jdbc/src/test/java/org/springframework/jdbc/core/support/JdbcBeanDefinitionReaderTests.java | @@ -16,20 +16,18 @@
package org.springframework.jdbc.core.support;
-import static org.junit.Assert.assertEquals;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.sql.DataSource;
import org.junit.Test;
-import org.springframework.tests.sample.beans.TestBean;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
+import org.springframework.tests.sample.beans.TestBean;
+
+import static org.junit.Assert.*;
+import static org.mockito.BDDMockito.*;
/**
* @author Rod Johnson | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-jdbc/src/test/java/org/springframework/jdbc/core/support/JdbcDaoSupportTests.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,9 +16,6 @@
package org.springframework.jdbc.core.support;
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.mock;
-
import java.util.ArrayList;
import java.util.List;
@@ -27,6 +24,9 @@
import org.junit.Test;
import org.springframework.jdbc.core.JdbcTemplate;
+import static org.junit.Assert.*;
+import static org.mockito.BDDMockito.*;
+
/**
* @author Juergen Hoeller
* @since 30.07.2003 | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-jdbc/src/test/java/org/springframework/jdbc/core/support/LobSupportTests.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,12 +16,6 @@
package org.springframework.jdbc.core.support;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@@ -36,6 +30,9 @@
import org.springframework.jdbc.support.lob.LobCreator;
import org.springframework.jdbc.support.lob.LobHandler;
+import static org.junit.Assert.*;
+import static org.mockito.BDDMockito.*;
+
/**
* @author Alef Arendsen
*/ | true |
Other | spring-projects | spring-framework | 05765d752062f37b202e7dfd20593c995dc47df0.json | Replace EasyMock with Mockito
Issue: SPR-10126 | spring-jdbc/src/test/java/org/springframework/jdbc/core/support/SqlLobValueTests.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,14 +15,6 @@
*/
package org.springframework.jdbc.core.support;
-import static org.hamcrest.Matchers.equalTo;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.fail;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -40,6 +32,10 @@
import org.springframework.jdbc.support.lob.LobCreator;
import org.springframework.jdbc.support.lob.LobHandler;
+import static org.hamcrest.Matchers.*;
+import static org.junit.Assert.*;
+import static org.mockito.BDDMockito.*;
+
/**
* Test cases for the sql lob value:
* | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.