|
|
|
@ -123,8 +123,8 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot |
|
|
|
List<Class<? extends TestExecutionListener>> classesList = new ArrayList<Class<? extends TestExecutionListener>>(); |
|
|
|
List<Class<? extends TestExecutionListener>> classesList = new ArrayList<Class<? extends TestExecutionListener>>(); |
|
|
|
boolean usingDefaults = false; |
|
|
|
boolean usingDefaults = false; |
|
|
|
|
|
|
|
|
|
|
|
AnnotationDescriptor<TestExecutionListeners> descriptor = MetaAnnotationUtils.findAnnotationDescriptor(clazz, |
|
|
|
AnnotationDescriptor<TestExecutionListeners> descriptor = |
|
|
|
annotationType); |
|
|
|
MetaAnnotationUtils.findAnnotationDescriptor(clazz, annotationType); |
|
|
|
|
|
|
|
|
|
|
|
// Use defaults?
|
|
|
|
// Use defaults?
|
|
|
|
if (descriptor == null) { |
|
|
|
if (descriptor == null) { |
|
|
|
@ -146,17 +146,17 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
boolean inheritListeners = testExecutionListeners.inheritListeners(); |
|
|
|
boolean inheritListeners = testExecutionListeners.inheritListeners(); |
|
|
|
AnnotationDescriptor<TestExecutionListeners> superDescriptor = MetaAnnotationUtils.findAnnotationDescriptor( |
|
|
|
AnnotationDescriptor<TestExecutionListeners> superDescriptor = |
|
|
|
|
|
|
|
MetaAnnotationUtils.findAnnotationDescriptor( |
|
|
|
descriptor.getRootDeclaringClass().getSuperclass(), annotationType); |
|
|
|
descriptor.getRootDeclaringClass().getSuperclass(), annotationType); |
|
|
|
|
|
|
|
|
|
|
|
// If there are no listeners to inherit, we might need to merge the
|
|
|
|
// If there are no listeners to inherit, we might need to merge the
|
|
|
|
// locally declared listeners with the defaults.
|
|
|
|
// locally declared listeners with the defaults.
|
|
|
|
if ((!inheritListeners || superDescriptor == null) |
|
|
|
if ((!inheritListeners || superDescriptor == null) && |
|
|
|
&& (testExecutionListeners.mergeMode() == MergeMode.MERGE_WITH_DEFAULTS)) { |
|
|
|
testExecutionListeners.mergeMode() == MergeMode.MERGE_WITH_DEFAULTS) { |
|
|
|
if (logger.isDebugEnabled()) { |
|
|
|
if (logger.isDebugEnabled()) { |
|
|
|
logger.debug(String.format( |
|
|
|
logger.debug(String.format("Merging default listeners with listeners configured via " + |
|
|
|
"Merging default listeners with listeners configured via @TestExecutionListeners for class [%s].", |
|
|
|
"@TestExecutionListeners for class [%s].", descriptor.getRootDeclaringClass().getName())); |
|
|
|
descriptor.getRootDeclaringClass().getName())); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
usingDefaults = true; |
|
|
|
usingDefaults = true; |
|
|
|
classesList.addAll(getDefaultTestExecutionListenerClasses()); |
|
|
|
classesList.addAll(getDefaultTestExecutionListenerClasses()); |
|
|
|
@ -206,9 +206,9 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot |
|
|
|
} |
|
|
|
} |
|
|
|
if (ncdfe != null) { |
|
|
|
if (ncdfe != null) { |
|
|
|
if (logger.isInfoEnabled()) { |
|
|
|
if (logger.isInfoEnabled()) { |
|
|
|
logger.info(String.format("Could not instantiate TestExecutionListener [%s]. " |
|
|
|
logger.info(String.format("Could not instantiate TestExecutionListener [%s]. " + |
|
|
|
+ "Specify custom listener classes or make the default listener classes " |
|
|
|
"Specify custom listener classes or make the default listener classes " + |
|
|
|
+ "(and their required dependencies) available. Offending class: [%s]", |
|
|
|
"(and their required dependencies) available. Offending class: [%s]", |
|
|
|
listenerClass.getName(), ncdfe.getMessage())); |
|
|
|
listenerClass.getName(), ncdfe.getMessage())); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -234,8 +234,8 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Throwable ex) { |
|
|
|
catch (Throwable ex) { |
|
|
|
if (logger.isDebugEnabled()) { |
|
|
|
if (logger.isDebugEnabled()) { |
|
|
|
logger.debug("Could not load default TestExecutionListener class [" + className |
|
|
|
logger.debug("Could not load default TestExecutionListener class [" + className + |
|
|
|
+ "]. Specify custom listener classes or make the default listener classes available.", ex); |
|
|
|
"]. Specify custom listener classes or make the default listener classes available.", ex); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -254,9 +254,8 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot |
|
|
|
* @see SpringFactoriesLoader#loadFactoryNames |
|
|
|
* @see SpringFactoriesLoader#loadFactoryNames |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected List<String> getDefaultTestExecutionListenerClassNames() { |
|
|
|
protected List<String> getDefaultTestExecutionListenerClassNames() { |
|
|
|
final List<String> classNames = SpringFactoriesLoader.loadFactoryNames(TestExecutionListener.class, |
|
|
|
List<String> classNames = |
|
|
|
getClass().getClassLoader()); |
|
|
|
SpringFactoriesLoader.loadFactoryNames(TestExecutionListener.class, getClass().getClassLoader()); |
|
|
|
|
|
|
|
|
|
|
|
if (logger.isInfoEnabled()) { |
|
|
|
if (logger.isInfoEnabled()) { |
|
|
|
logger.info(String.format("Loaded default TestExecutionListener class names from location [%s]: %s", |
|
|
|
logger.info(String.format("Loaded default TestExecutionListener class names from location [%s]: %s", |
|
|
|
SpringFactoriesLoader.FACTORIES_RESOURCE_LOCATION, classNames)); |
|
|
|
SpringFactoriesLoader.FACTORIES_RESOURCE_LOCATION, classNames)); |
|
|
|
@ -273,13 +272,14 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot |
|
|
|
Class<?> testClass = getBootstrapContext().getTestClass(); |
|
|
|
Class<?> testClass = getBootstrapContext().getTestClass(); |
|
|
|
CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate = getCacheAwareContextLoaderDelegate(); |
|
|
|
CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate = getCacheAwareContextLoaderDelegate(); |
|
|
|
|
|
|
|
|
|
|
|
if (MetaAnnotationUtils.findAnnotationDescriptorForTypes(testClass, ContextConfiguration.class, |
|
|
|
if (MetaAnnotationUtils.findAnnotationDescriptorForTypes( |
|
|
|
ContextHierarchy.class) == null) { |
|
|
|
testClass, ContextConfiguration.class, ContextHierarchy.class) == null) { |
|
|
|
return buildDefaultMergedContextConfiguration(testClass, cacheAwareContextLoaderDelegate); |
|
|
|
return buildDefaultMergedContextConfiguration(testClass, cacheAwareContextLoaderDelegate); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (AnnotationUtils.findAnnotation(testClass, ContextHierarchy.class) != null) { |
|
|
|
if (AnnotationUtils.findAnnotation(testClass, ContextHierarchy.class) != null) { |
|
|
|
Map<String, List<ContextConfigurationAttributes>> hierarchyMap = ContextLoaderUtils.buildContextHierarchyMap(testClass); |
|
|
|
Map<String, List<ContextConfigurationAttributes>> hierarchyMap = |
|
|
|
|
|
|
|
ContextLoaderUtils.buildContextHierarchyMap(testClass); |
|
|
|
MergedContextConfiguration parentConfig = null; |
|
|
|
MergedContextConfiguration parentConfig = null; |
|
|
|
MergedContextConfiguration mergedConfig = null; |
|
|
|
MergedContextConfiguration mergedConfig = null; |
|
|
|
|
|
|
|
|
|
|
|
@ -293,8 +293,8 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot |
|
|
|
Assert.notEmpty(reversedList, "ContextConfigurationAttributes list must not be empty"); |
|
|
|
Assert.notEmpty(reversedList, "ContextConfigurationAttributes list must not be empty"); |
|
|
|
Class<?> declaringClass = reversedList.get(0).getDeclaringClass(); |
|
|
|
Class<?> declaringClass = reversedList.get(0).getDeclaringClass(); |
|
|
|
|
|
|
|
|
|
|
|
mergedConfig = buildMergedContextConfiguration(declaringClass, reversedList, parentConfig, |
|
|
|
mergedConfig = buildMergedContextConfiguration( |
|
|
|
cacheAwareContextLoaderDelegate, true); |
|
|
|
declaringClass, reversedList, parentConfig, cacheAwareContextLoaderDelegate, true); |
|
|
|
parentConfig = mergedConfig; |
|
|
|
parentConfig = mergedConfig; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -303,8 +303,8 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
return buildMergedContextConfiguration(testClass, |
|
|
|
return buildMergedContextConfiguration(testClass, |
|
|
|
ContextLoaderUtils.resolveContextConfigurationAttributes(testClass), null, |
|
|
|
ContextLoaderUtils.resolveContextConfigurationAttributes(testClass), |
|
|
|
cacheAwareContextLoaderDelegate, true); |
|
|
|
null, cacheAwareContextLoaderDelegate, true); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -390,14 +390,16 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot |
|
|
|
Set<ContextCustomizer> contextCustomizers = getContextCustomizers(testClass, |
|
|
|
Set<ContextCustomizer> contextCustomizers = getContextCustomizers(testClass, |
|
|
|
Collections.unmodifiableList(configAttributesList)); |
|
|
|
Collections.unmodifiableList(configAttributesList)); |
|
|
|
|
|
|
|
|
|
|
|
if (requireLocationsClassesOrInitializers && areAllEmpty(locations, classes, initializers, contextCustomizers)) { |
|
|
|
if (requireLocationsClassesOrInitializers && |
|
|
|
|
|
|
|
areAllEmpty(locations, classes, initializers, contextCustomizers)) { |
|
|
|
throw new IllegalStateException(String.format( |
|
|
|
throw new IllegalStateException(String.format( |
|
|
|
"%s was unable to detect defaults, and no ApplicationContextInitializers " |
|
|
|
"%s was unable to detect defaults, and no ApplicationContextInitializers " + |
|
|
|
+ "or ContextCustomizers were declared for context configuration attributes %s", |
|
|
|
"or ContextCustomizers were declared for context configuration attributes %s", |
|
|
|
contextLoader.getClass().getSimpleName(), configAttributesList)); |
|
|
|
contextLoader.getClass().getSimpleName(), configAttributesList)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
MergedTestPropertySources mergedTestPropertySources = TestPropertySourceUtils.buildMergedTestPropertySources(testClass); |
|
|
|
MergedTestPropertySources mergedTestPropertySources = |
|
|
|
|
|
|
|
TestPropertySourceUtils.buildMergedTestPropertySources(testClass); |
|
|
|
MergedContextConfiguration mergedConfig = new MergedContextConfiguration(testClass, |
|
|
|
MergedContextConfiguration mergedConfig = new MergedContextConfiguration(testClass, |
|
|
|
StringUtils.toStringArray(locations), |
|
|
|
StringUtils.toStringArray(locations), |
|
|
|
ClassUtils.toClassArray(classes), |
|
|
|
ClassUtils.toClassArray(classes), |
|
|
|
|