|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2017 the original author or authors. |
|
|
|
* Copyright 2002-2018 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -16,8 +16,8 @@ |
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.test.context.support; |
|
|
|
package org.springframework.test.context.support; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.HashSet; |
|
|
|
import java.util.LinkedHashSet; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Set; |
|
|
|
import java.util.Set; |
|
|
|
|
|
|
|
|
|
|
|
@ -30,8 +30,8 @@ import org.springframework.test.context.ContextConfigurationAttributes; |
|
|
|
import org.springframework.util.Assert; |
|
|
|
import org.springframework.util.Assert; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Utility methods for working with {@link ApplicationContextInitializer |
|
|
|
* Utility methods for working with |
|
|
|
* ApplicationContextInitializers}. |
|
|
|
* {@link ApplicationContextInitializer ApplicationContextInitializers}. |
|
|
|
* |
|
|
|
* |
|
|
|
* <p>Although {@code ApplicationContextInitializerUtils} was first introduced |
|
|
|
* <p>Although {@code ApplicationContextInitializerUtils} was first introduced |
|
|
|
* in Spring Framework 4.1, the initial implementations of methods in this class
|
|
|
|
* in Spring Framework 4.1, the initial implementations of methods in this class
|
|
|
|
@ -46,21 +46,15 @@ abstract class ApplicationContextInitializerUtils { |
|
|
|
private static final Log logger = LogFactory.getLog(ApplicationContextInitializerUtils.class); |
|
|
|
private static final Log logger = LogFactory.getLog(ApplicationContextInitializerUtils.class); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private ApplicationContextInitializerUtils() { |
|
|
|
|
|
|
|
/* no-op */ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Resolve the set of merged {@code ApplicationContextInitializer} classes for the |
|
|
|
* Resolve the set of merged {@code ApplicationContextInitializer} classes for the |
|
|
|
* supplied list of {@code ContextConfigurationAttributes}. |
|
|
|
* supplied list of {@code ContextConfigurationAttributes}. |
|
|
|
* |
|
|
|
|
|
|
|
* <p>Note that the {@link ContextConfiguration#inheritInitializers inheritInitializers} |
|
|
|
* <p>Note that the {@link ContextConfiguration#inheritInitializers inheritInitializers} |
|
|
|
* flag of {@link ContextConfiguration @ContextConfiguration} will be taken into |
|
|
|
* flag of {@link ContextConfiguration @ContextConfiguration} will be taken into |
|
|
|
* consideration. Specifically, if the {@code inheritInitializers} flag is set to |
|
|
|
* consideration. Specifically, if the {@code inheritInitializers} flag is set to |
|
|
|
* {@code true} for a given level in the class hierarchy represented by the provided |
|
|
|
* {@code true} for a given level in the class hierarchy represented by the provided |
|
|
|
* configuration attributes, context initializer classes defined at the given level |
|
|
|
* configuration attributes, context initializer classes defined at the given level |
|
|
|
* will be merged with those defined in higher levels of the class hierarchy. |
|
|
|
* will be merged with those defined in higher levels of the class hierarchy. |
|
|
|
* |
|
|
|
|
|
|
|
* @param configAttributesList the list of configuration attributes to process; must |
|
|
|
* @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> |
|
|
|
* 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) |
|
|
|
* (i.e., as if we were traversing up the class hierarchy) |
|
|
|
@ -70,19 +64,15 @@ abstract class ApplicationContextInitializerUtils { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
static Set<Class<? extends ApplicationContextInitializer<?>>> resolveInitializerClasses( |
|
|
|
static Set<Class<? extends ApplicationContextInitializer<?>>> resolveInitializerClasses( |
|
|
|
List<ContextConfigurationAttributes> configAttributesList) { |
|
|
|
List<ContextConfigurationAttributes> configAttributesList) { |
|
|
|
Assert.notEmpty(configAttributesList, "ContextConfigurationAttributes list must not be empty"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final Set<Class<? extends ApplicationContextInitializer<?>>> initializerClasses = //
|
|
|
|
Assert.notEmpty(configAttributesList, "ContextConfigurationAttributes List must not be empty"); |
|
|
|
new HashSet<>(); |
|
|
|
Set<Class<? extends ApplicationContextInitializer<?>>> initializerClasses = new LinkedHashSet<>(); |
|
|
|
|
|
|
|
|
|
|
|
for (ContextConfigurationAttributes configAttributes : configAttributesList) { |
|
|
|
for (ContextConfigurationAttributes configAttributes : configAttributesList) { |
|
|
|
if (logger.isTraceEnabled()) { |
|
|
|
if (logger.isTraceEnabled()) { |
|
|
|
logger.trace(String.format("Processing context initializers for context configuration attributes %s", |
|
|
|
logger.trace("Processing context initializers for configuration attributes " + configAttributes); |
|
|
|
configAttributes)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
Collections.addAll(initializerClasses, configAttributes.getInitializers()); |
|
|
|
initializerClasses.addAll(Arrays.asList(configAttributes.getInitializers())); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!configAttributes.isInheritInitializers()) { |
|
|
|
if (!configAttributes.isInheritInitializers()) { |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|