org.springframework.test.context.SmartContextLoader Java Examples

The following examples show how to use org.springframework.test.context.SmartContextLoader. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultCacheAwareContextLoaderDelegate.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Load the {@code ApplicationContext} for the supplied merged context configuration.
 * <p>Supports both the {@link SmartContextLoader} and {@link ContextLoader} SPIs.
 * @throws Exception if an error occurs while loading the application context
 */
protected ApplicationContext loadContextInternal(MergedContextConfiguration mergedContextConfiguration)
		throws Exception {

	ContextLoader contextLoader = mergedContextConfiguration.getContextLoader();
	Assert.notNull(contextLoader, "Cannot load an ApplicationContext with a NULL 'contextLoader'. " +
			"Consider annotating your test class with @ContextConfiguration or @ContextHierarchy.");

	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 or @ContextHierarchy.");
		applicationContext = contextLoader.loadContext(locations);
	}

	return applicationContext;
}
 
Example #2
Source File: DefaultCacheAwareContextLoaderDelegate.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Load the {@code ApplicationContext} for the supplied merged context configuration.
 * <p>Supports both the {@link SmartContextLoader} and {@link ContextLoader} SPIs.
 * @throws Exception if an error occurs while loading the application context
 */
protected ApplicationContext loadContextInternal(MergedContextConfiguration mergedContextConfiguration)
		throws Exception {

	ContextLoader contextLoader = mergedContextConfiguration.getContextLoader();
	Assert.notNull(contextLoader, "Cannot load an ApplicationContext with a NULL 'contextLoader'. " +
			"Consider annotating your test class with @ContextConfiguration or @ContextHierarchy.");

	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 or @ContextHierarchy.");
		applicationContext = contextLoader.loadContext(locations);
	}

	return applicationContext;
}
 
Example #3
Source File: WebDelegatingSmartContextLoader.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
public WebDelegatingSmartContextLoader() {
	if (groovyPresent) {
		try {
			Class<?> loaderClass = ClassUtils.forName(GROOVY_XML_WEB_CONTEXT_LOADER_CLASS_NAME,
				WebDelegatingSmartContextLoader.class.getClassLoader());
			this.xmlLoader = (SmartContextLoader) BeanUtils.instantiateClass(loaderClass);
		}
		catch (Throwable ex) {
			throw new IllegalStateException("Failed to enable support for Groovy scripts; "
					+ "could not load class: " + GROOVY_XML_WEB_CONTEXT_LOADER_CLASS_NAME, ex);
		}
	}
	else {
		this.xmlLoader = new GenericXmlWebContextLoader();
	}

	this.annotationConfigLoader = new AnnotationConfigWebContextLoader();
}
 
Example #4
Source File: DelegatingSmartContextLoader.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
public DelegatingSmartContextLoader() {
	if (groovyPresent) {
		try {
			Class<?> loaderClass = ClassUtils.forName(GROOVY_XML_CONTEXT_LOADER_CLASS_NAME,
				DelegatingSmartContextLoader.class.getClassLoader());
			this.xmlLoader = (SmartContextLoader) BeanUtils.instantiateClass(loaderClass);
		}
		catch (Throwable ex) {
			throw new IllegalStateException("Failed to enable support for Groovy scripts; "
					+ "could not load class: " + GROOVY_XML_CONTEXT_LOADER_CLASS_NAME, ex);
		}
	}
	else {
		this.xmlLoader = new GenericXmlContextLoader();
	}

	this.annotationConfigLoader = new AnnotationConfigContextLoader();
}
 
Example #5
Source File: DelegatingSmartContextLoader.java    From java-technology-stack with MIT License 6 votes vote down vote up
public DelegatingSmartContextLoader() {
	if (groovyPresent) {
		try {
			Class<?> loaderClass = ClassUtils.forName(GROOVY_XML_CONTEXT_LOADER_CLASS_NAME,
				DelegatingSmartContextLoader.class.getClassLoader());
			this.xmlLoader = (SmartContextLoader) BeanUtils.instantiateClass(loaderClass);
		}
		catch (Throwable ex) {
			throw new IllegalStateException("Failed to enable support for Groovy scripts; "
					+ "could not load class: " + GROOVY_XML_CONTEXT_LOADER_CLASS_NAME, ex);
		}
	}
	else {
		this.xmlLoader = new GenericXmlContextLoader();
	}

	this.annotationConfigLoader = new AnnotationConfigContextLoader();
}
 
Example #6
Source File: WebDelegatingSmartContextLoader.java    From java-technology-stack with MIT License 6 votes vote down vote up
public WebDelegatingSmartContextLoader() {
	if (groovyPresent) {
		try {
			Class<?> loaderClass = ClassUtils.forName(GROOVY_XML_WEB_CONTEXT_LOADER_CLASS_NAME,
				WebDelegatingSmartContextLoader.class.getClassLoader());
			this.xmlLoader = (SmartContextLoader) BeanUtils.instantiateClass(loaderClass);
		}
		catch (Throwable ex) {
			throw new IllegalStateException("Failed to enable support for Groovy scripts; "
					+ "could not load class: " + GROOVY_XML_WEB_CONTEXT_LOADER_CLASS_NAME, ex);
		}
	}
	else {
		this.xmlLoader = new GenericXmlWebContextLoader();
	}

	this.annotationConfigLoader = new AnnotationConfigWebContextLoader();
}
 
Example #7
Source File: WebDelegatingSmartContextLoader.java    From spring-analysis-note with MIT License 6 votes vote down vote up
public WebDelegatingSmartContextLoader() {
	if (groovyPresent) {
		try {
			Class<?> loaderClass = ClassUtils.forName(GROOVY_XML_WEB_CONTEXT_LOADER_CLASS_NAME,
				WebDelegatingSmartContextLoader.class.getClassLoader());
			this.xmlLoader = (SmartContextLoader) BeanUtils.instantiateClass(loaderClass);
		}
		catch (Throwable ex) {
			throw new IllegalStateException("Failed to enable support for Groovy scripts; "
					+ "could not load class: " + GROOVY_XML_WEB_CONTEXT_LOADER_CLASS_NAME, ex);
		}
	}
	else {
		this.xmlLoader = new GenericXmlWebContextLoader();
	}

	this.annotationConfigLoader = new AnnotationConfigWebContextLoader();
}
 
Example #8
Source File: DefaultCacheAwareContextLoaderDelegate.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Load the {@code ApplicationContext} for the supplied merged context configuration.
 * <p>Supports both the {@link SmartContextLoader} and {@link ContextLoader} SPIs.
 * @throws Exception if an error occurs while loading the application context
 */
protected ApplicationContext loadContextInternal(MergedContextConfiguration mergedContextConfiguration)
		throws Exception {

	ContextLoader contextLoader = mergedContextConfiguration.getContextLoader();
	Assert.notNull(contextLoader, "Cannot load an ApplicationContext with a NULL 'contextLoader'. " +
			"Consider annotating your test class with @ContextConfiguration or @ContextHierarchy.");

	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 or @ContextHierarchy.");
		applicationContext = contextLoader.loadContext(locations);
	}

	return applicationContext;
}
 
Example #9
Source File: DelegatingSmartContextLoader.java    From spring-analysis-note with MIT License 6 votes vote down vote up
public DelegatingSmartContextLoader() {
	if (groovyPresent) {
		try {
			Class<?> loaderClass = ClassUtils.forName(GROOVY_XML_CONTEXT_LOADER_CLASS_NAME,
				DelegatingSmartContextLoader.class.getClassLoader());
			this.xmlLoader = (SmartContextLoader) BeanUtils.instantiateClass(loaderClass);
		}
		catch (Throwable ex) {
			throw new IllegalStateException("Failed to enable support for Groovy scripts; "
					+ "could not load class: " + GROOVY_XML_CONTEXT_LOADER_CLASS_NAME, ex);
		}
	}
	else {
		this.xmlLoader = new GenericXmlContextLoader();
	}

	this.annotationConfigLoader = new AnnotationConfigContextLoader();
}
 
Example #10
Source File: AbstractDelegatingSmartContextLoader.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private static ApplicationContext delegateLoading(SmartContextLoader loader, MergedContextConfiguration mergedConfig)
		throws Exception {

	if (logger.isDebugEnabled()) {
		logger.debug(String.format("Delegating to %s to load context from %s.", name(loader), mergedConfig));
	}
	return loader.loadContext(mergedConfig);
}
 
Example #11
Source File: AbstractDelegatingSmartContextLoader.java    From java-technology-stack with MIT License 5 votes vote down vote up
private boolean supports(SmartContextLoader loader, MergedContextConfiguration mergedConfig) {
	if (loader == getAnnotationConfigLoader()) {
		return (mergedConfig.hasClasses() && !mergedConfig.hasLocations());
	}
	else {
		return (mergedConfig.hasLocations() && !mergedConfig.hasClasses());
	}
}
 
Example #12
Source File: AbstractDelegatingSmartContextLoader.java    From java-technology-stack with MIT License 5 votes vote down vote up
private static ApplicationContext delegateLoading(SmartContextLoader loader, MergedContextConfiguration mergedConfig)
		throws Exception {

	if (logger.isDebugEnabled()) {
		logger.debug(String.format("Delegating to %s to load context from %s.", name(loader), mergedConfig));
	}
	return loader.loadContext(mergedConfig);
}
 
Example #13
Source File: AbstractDelegatingSmartContextLoader.java    From java-technology-stack with MIT License 5 votes vote down vote up
private static void delegateProcessing(SmartContextLoader loader, ContextConfigurationAttributes configAttributes) {
	if (logger.isDebugEnabled()) {
		logger.debug(String.format("Delegating to %s to process context configuration %s.",
				name(loader), configAttributes));
	}
	loader.processContextConfiguration(configAttributes);
}
 
Example #14
Source File: AbstractDelegatingSmartContextLoader.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Delegates to an appropriate candidate {@code SmartContextLoader} to load
 * an {@link ApplicationContext}.
 * <p>Delegation is based on explicit knowledge of the implementations of the
 * default loaders for {@linkplain #getXmlLoader() XML configuration files and
 * Groovy scripts} and {@linkplain #getAnnotationConfigLoader() annotated classes}.
 * Specifically, the delegation algorithm is as follows:
 * <ul>
 * <li>If the resource locations in the supplied {@code MergedContextConfiguration}
 * are not empty and the annotated classes are empty,
 * the XML-based loader will load the {@code ApplicationContext}.</li>
 * <li>If the annotated classes in the supplied {@code MergedContextConfiguration}
 * are not empty and the resource locations are empty,
 * the annotation-based loader will load the {@code ApplicationContext}.</li>
 * </ul>
 * @param mergedConfig the merged context configuration to use to load the application context
 * @throws IllegalArgumentException if the supplied merged configuration is {@code null}
 * @throws IllegalStateException if neither candidate loader is capable of loading an
 * {@code ApplicationContext} from the supplied merged context configuration
 */
@Override
public ApplicationContext loadContext(MergedContextConfiguration mergedConfig) throws Exception {
	Assert.notNull(mergedConfig, "MergedContextConfiguration must not be null");

	Assert.state(!(mergedConfig.hasLocations() && mergedConfig.hasClasses()), () -> String.format(
			"Neither %s nor %s supports loading an ApplicationContext from %s: " +
			"declare either 'locations' or 'classes' but not both.", name(getXmlLoader()),
			name(getAnnotationConfigLoader()), mergedConfig));

	SmartContextLoader[] candidates = {getXmlLoader(), getAnnotationConfigLoader()};
	for (SmartContextLoader loader : candidates) {
		// Determine if each loader can load a context from the mergedConfig. If it
		// can, let it; otherwise, keep iterating.
		if (supports(loader, mergedConfig)) {
			return delegateLoading(loader, mergedConfig);
		}
	}

	// If neither of the candidates supports the mergedConfig based on resources but
	// ACIs or customizers were declared, then delegate to the annotation config
	// loader.
	if (!mergedConfig.getContextInitializerClasses().isEmpty() || !mergedConfig.getContextCustomizers().isEmpty()) {
		return delegateLoading(getAnnotationConfigLoader(), mergedConfig);
	}

	// else...
	throw new IllegalStateException(String.format(
			"Neither %s nor %s was able to load an ApplicationContext from %s.",
			name(getXmlLoader()), name(getAnnotationConfigLoader()), mergedConfig));
}
 
Example #15
Source File: AbstractDelegatingSmartContextLoader.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Delegates to an appropriate candidate {@code SmartContextLoader} to load
 * an {@link ApplicationContext}.
 * <p>Delegation is based on explicit knowledge of the implementations of the
 * default loaders for {@linkplain #getXmlLoader() XML configuration files and
 * Groovy scripts} and {@linkplain #getAnnotationConfigLoader() annotated classes}.
 * Specifically, the delegation algorithm is as follows:
 * <ul>
 * <li>If the resource locations in the supplied {@code MergedContextConfiguration}
 * are not empty and the annotated classes are empty,
 * the XML-based loader will load the {@code ApplicationContext}.</li>
 * <li>If the annotated classes in the supplied {@code MergedContextConfiguration}
 * are not empty and the resource locations are empty,
 * the annotation-based loader will load the {@code ApplicationContext}.</li>
 * </ul>
 * @param mergedConfig the merged context configuration to use to load the application context
 * @throws IllegalArgumentException if the supplied merged configuration is {@code null}
 * @throws IllegalStateException if neither candidate loader is capable of loading an
 * {@code ApplicationContext} from the supplied merged context configuration
 */
@Override
public ApplicationContext loadContext(MergedContextConfiguration mergedConfig) throws Exception {
	Assert.notNull(mergedConfig, "mergedConfig must not be null");
	List<SmartContextLoader> candidates = Arrays.asList(getXmlLoader(), getAnnotationConfigLoader());

	if (mergedConfig.hasLocations() && mergedConfig.hasClasses()) {
		throw new IllegalStateException(String.format(
			"Neither %s nor %s supports loading an ApplicationContext from %s: "
					+ "declare either 'locations' or 'classes' but not both.", name(getXmlLoader()),
			name(getAnnotationConfigLoader()), mergedConfig));
	}

	for (SmartContextLoader loader : candidates) {
		// Determine if each loader can load a context from the mergedConfig. If it
		// can, let it; otherwise, keep iterating.
		if (supports(loader, mergedConfig)) {
			return delegateLoading(loader, mergedConfig);
		}
	}

	// If neither of the candidates supports the mergedConfig based on resources but
	// ACIs were declared, then delegate to the annotation config loader.
	if (!mergedConfig.getContextInitializerClasses().isEmpty()) {
		return delegateLoading(getAnnotationConfigLoader(), mergedConfig);
	}

	// else...
	throw new IllegalStateException(String.format(
		"Neither %s nor %s was able to load an ApplicationContext from %s.", name(getXmlLoader()),
		name(getAnnotationConfigLoader()), mergedConfig));
}
 
Example #16
Source File: AbstractDelegatingSmartContextLoader.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private static void delegateProcessing(SmartContextLoader loader, ContextConfigurationAttributes configAttributes) {
	if (logger.isDebugEnabled()) {
		logger.debug(String.format("Delegating to %s to process context configuration %s.", name(loader),
			configAttributes));
	}
	loader.processContextConfiguration(configAttributes);
}
 
Example #17
Source File: AbstractDelegatingSmartContextLoader.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private boolean supports(SmartContextLoader loader, MergedContextConfiguration mergedConfig) {
	if (loader == getAnnotationConfigLoader()) {
		return (mergedConfig.hasClasses() && !mergedConfig.hasLocations());
	}
	else {
		return (mergedConfig.hasLocations() && !mergedConfig.hasClasses());
	}
}
 
Example #18
Source File: AbstractDelegatingSmartContextLoader.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private static ApplicationContext delegateLoading(SmartContextLoader loader, MergedContextConfiguration mergedConfig)
		throws Exception {

	if (logger.isDebugEnabled()) {
		logger.debug(String.format("Delegating to %s to load context from %s.", name(loader), mergedConfig));
	}
	return loader.loadContext(mergedConfig);
}
 
Example #19
Source File: AbstractDelegatingSmartContextLoader.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private static void delegateProcessing(SmartContextLoader loader, ContextConfigurationAttributes configAttributes) {
	if (logger.isDebugEnabled()) {
		logger.debug(String.format("Delegating to %s to process context configuration %s.",
				name(loader), configAttributes));
	}
	loader.processContextConfiguration(configAttributes);
}
 
Example #20
Source File: AbstractDelegatingSmartContextLoader.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Delegates to an appropriate candidate {@code SmartContextLoader} to load
 * an {@link ApplicationContext}.
 * <p>Delegation is based on explicit knowledge of the implementations of the
 * default loaders for {@linkplain #getXmlLoader() XML configuration files and
 * Groovy scripts} and {@linkplain #getAnnotationConfigLoader() annotated classes}.
 * Specifically, the delegation algorithm is as follows:
 * <ul>
 * <li>If the resource locations in the supplied {@code MergedContextConfiguration}
 * are not empty and the annotated classes are empty,
 * the XML-based loader will load the {@code ApplicationContext}.</li>
 * <li>If the annotated classes in the supplied {@code MergedContextConfiguration}
 * are not empty and the resource locations are empty,
 * the annotation-based loader will load the {@code ApplicationContext}.</li>
 * </ul>
 * @param mergedConfig the merged context configuration to use to load the application context
 * @throws IllegalArgumentException if the supplied merged configuration is {@code null}
 * @throws IllegalStateException if neither candidate loader is capable of loading an
 * {@code ApplicationContext} from the supplied merged context configuration
 */
@Override
public ApplicationContext loadContext(MergedContextConfiguration mergedConfig) throws Exception {
	Assert.notNull(mergedConfig, "MergedContextConfiguration must not be null");

	Assert.state(!(mergedConfig.hasLocations() && mergedConfig.hasClasses()), () -> String.format(
			"Neither %s nor %s supports loading an ApplicationContext from %s: " +
			"declare either 'locations' or 'classes' but not both.", name(getXmlLoader()),
			name(getAnnotationConfigLoader()), mergedConfig));

	SmartContextLoader[] candidates = {getXmlLoader(), getAnnotationConfigLoader()};
	for (SmartContextLoader loader : candidates) {
		// Determine if each loader can load a context from the mergedConfig. If it
		// can, let it; otherwise, keep iterating.
		if (supports(loader, mergedConfig)) {
			return delegateLoading(loader, mergedConfig);
		}
	}

	// If neither of the candidates supports the mergedConfig based on resources but
	// ACIs or customizers were declared, then delegate to the annotation config
	// loader.
	if (!mergedConfig.getContextInitializerClasses().isEmpty() || !mergedConfig.getContextCustomizers().isEmpty()) {
		return delegateLoading(getAnnotationConfigLoader(), mergedConfig);
	}

	// else...
	throw new IllegalStateException(String.format(
			"Neither %s nor %s was able to load an ApplicationContext from %s.",
			name(getXmlLoader()), name(getAnnotationConfigLoader()), mergedConfig));
}
 
Example #21
Source File: AbstractDelegatingSmartContextLoader.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private boolean supports(SmartContextLoader loader, MergedContextConfiguration mergedConfig) {
	if (loader == getAnnotationConfigLoader()) {
		return mergedConfig.hasClasses() && !mergedConfig.hasLocations();
	}
	else {
		return mergedConfig.hasLocations() && !mergedConfig.hasClasses();
	}
}
 
Example #22
Source File: WebDelegatingSmartContextLoader.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
protected SmartContextLoader getXmlLoader() {
	return this.xmlLoader;
}
 
Example #23
Source File: DelegatingSmartContextLoader.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
protected SmartContextLoader getAnnotationConfigLoader() {
	return this.annotationConfigLoader;
}
 
Example #24
Source File: DelegatingSmartContextLoader.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
protected SmartContextLoader getXmlLoader() {
	return this.xmlLoader;
}
 
Example #25
Source File: AbstractTestContextBootstrapper.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * Build the {@link MergedContextConfiguration merged context configuration}
 * for the supplied {@link Class testClass}, context configuration attributes,
 * and parent context configuration.
 * @param testClass the test class for which the {@code MergedContextConfiguration}
 * should be built (must not 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 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 ContextLoaderUtils#resolveContextConfigurationAttributes
 * @see SmartContextLoader#processContextConfiguration
 * @see ContextLoader#processLocations
 * @see ActiveProfilesUtils#resolveActiveProfiles
 * @see ApplicationContextInitializerUtils#resolveInitializerClasses
 * @see MergedContextConfiguration
 */
private MergedContextConfiguration buildMergedContextConfiguration(Class<?> testClass,
		List<ContextConfigurationAttributes> configAttributesList, MergedContextConfiguration parentConfig,
		CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate) {

	ContextLoader contextLoader = resolveContextLoader(testClass, configAttributesList);
	List<String> locationsList = new ArrayList<String>();
	List<Class<?>> classesList = new ArrayList<Class<?>>();

	for (ContextConfigurationAttributes configAttributes : configAttributesList) {
		if (logger.isTraceEnabled()) {
			logger.trace(String.format("Processing locations and classes for context configuration attributes %s",
				configAttributes));
		}
		if (contextLoader instanceof SmartContextLoader) {
			SmartContextLoader smartContextLoader = (SmartContextLoader) contextLoader;
			smartContextLoader.processContextConfiguration(configAttributes);
			locationsList.addAll(0, Arrays.asList(configAttributes.getLocations()));
			classesList.addAll(0, Arrays.asList(configAttributes.getClasses()));
		}
		else {
			String[] processedLocations = contextLoader.processLocations(configAttributes.getDeclaringClass(),
				configAttributes.getLocations());
			locationsList.addAll(0, Arrays.asList(processedLocations));
			// Legacy ContextLoaders don't know how to process classes
		}
		if (!configAttributes.isInheritLocations()) {
			break;
		}
	}

	String[] locations = StringUtils.toStringArray(locationsList);
	Class<?>[] classes = ClassUtils.toClassArray(classesList);
	Set<Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>> initializerClasses = //
	ApplicationContextInitializerUtils.resolveInitializerClasses(configAttributesList);
	String[] activeProfiles = ActiveProfilesUtils.resolveActiveProfiles(testClass);
	MergedTestPropertySources mergedTestPropertySources = TestPropertySourceUtils.buildMergedTestPropertySources(testClass);

	MergedContextConfiguration mergedConfig = new MergedContextConfiguration(testClass, locations, classes,
		initializerClasses, activeProfiles, mergedTestPropertySources.getLocations(),
		mergedTestPropertySources.getProperties(), contextLoader, cacheAwareContextLoaderDelegate, parentConfig);

	return processMergedContextConfiguration(mergedConfig);
}
 
Example #26
Source File: AbstractDelegatingSmartContextLoader.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
private static String name(SmartContextLoader loader) {
	return loader.getClass().getSimpleName();
}
 
Example #27
Source File: WebDelegatingSmartContextLoader.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
protected SmartContextLoader getAnnotationConfigLoader() {
	return this.annotationConfigLoader;
}
 
Example #28
Source File: WebDelegatingSmartContextLoader.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
protected SmartContextLoader getXmlLoader() {
	return this.xmlLoader;
}
 
Example #29
Source File: AbstractDelegatingSmartContextLoader.java    From java-technology-stack with MIT License 4 votes vote down vote up
private static String name(SmartContextLoader loader) {
	return loader.getClass().getSimpleName();
}
 
Example #30
Source File: WebDelegatingSmartContextLoader.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
protected SmartContextLoader getAnnotationConfigLoader() {
	return this.annotationConfigLoader;
}