Java Code Examples for org.springframework.test.context.SmartContextLoader#loadContext()

The following examples show how to use org.springframework.test.context.SmartContextLoader#loadContext() . 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: 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 4
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 5
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 6
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);
}