Java Code Examples for org.springframework.test.context.ContextLoader

The following examples show how to use org.springframework.test.context.ContextLoader. These examples are extracted from open source projects. 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
@Test
public void resolveContextHierarchyAttributesForSingleTestClassWithTripleLevelContextHierarchy() {
	Class<SingleTestClassWithTripleLevelContextHierarchy> testClass = SingleTestClassWithTripleLevelContextHierarchy.class;
	List<List<ContextConfigurationAttributes>> hierarchyAttributes = resolveContextHierarchyAttributes(testClass);
	assertEquals(1, hierarchyAttributes.size());

	List<ContextConfigurationAttributes> configAttributesList = hierarchyAttributes.get(0);
	assertNotNull(configAttributesList);
	assertEquals(3, configAttributesList.size());
	debugConfigAttributes(configAttributesList);
	assertAttributes(configAttributesList.get(0), testClass, new String[] { "A.xml" }, EMPTY_CLASS_ARRAY,
		ContextLoader.class, true);
	assertAttributes(configAttributesList.get(1), testClass, new String[] { "B.xml" }, EMPTY_CLASS_ARRAY,
		ContextLoader.class, true);
	assertAttributes(configAttributesList.get(2), testClass, new String[] { "C.xml" }, EMPTY_CLASS_ARRAY,
		ContextLoader.class, true);
}
 
Example 2
/**
 * 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:
 * <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>
 * </ol>
 * @param configAttributesList the list of configuration attributes to process;
 * must not be {@code null}; must be ordered <em>bottom-up</em>
 * (i.e., as if we were traversing up the class hierarchy)
 * @return the {@code ContextLoader} class to use for the supplied configuration
 * attributes, or {@code null} if no explicit loader is found
 * @throws IllegalArgumentException if supplied configuration attributes are
 * {@code null} or <em>empty</em>
 */
@Nullable
protected Class<? extends ContextLoader> resolveExplicitContextLoaderClass(
		List<ContextConfigurationAttributes> configAttributesList) {

	Assert.notNull(configAttributesList, "ContextConfigurationAttributes list must not be null");

	for (ContextConfigurationAttributes configAttributes : configAttributesList) {
		if (logger.isTraceEnabled()) {
			logger.trace(String.format("Resolving ContextLoader for context configuration attributes %s",
					configAttributes));
		}
		Class<? extends ContextLoader> contextLoaderClass = configAttributes.getContextLoaderClass();
		if (ContextLoader.class != contextLoaderClass) {
			if (logger.isDebugEnabled()) {
				logger.debug(String.format(
						"Found explicit ContextLoader class [%s] for context configuration attributes %s",
						contextLoaderClass.getName(), configAttributes));
			}
			return contextLoaderClass;
		}
	}
	return null;
}
 
Example 3
/**
 * 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
@Test
public void assertContextConfigurationLocations() throws Exception {

	final ContextConfiguration contextConfig = this.testClass.getAnnotation(ContextConfiguration.class);
	final ContextLoader contextLoader = new GenericXmlContextLoader();
	final String[] configuredLocations = (String[]) AnnotationUtils.getValue(contextConfig);
	final String[] processedLocations = contextLoader.processLocations(this.testClass, configuredLocations);

	if (logger.isDebugEnabled()) {
		logger.debug("----------------------------------------------------------------------");
		logger.debug("Configured locations: " + ObjectUtils.nullSafeToString(configuredLocations));
		logger.debug("Expected   locations: " + ObjectUtils.nullSafeToString(this.expectedLocations));
		logger.debug("Processed  locations: " + ObjectUtils.nullSafeToString(processedLocations));
	}

	assertArrayEquals("Verifying locations for test [" + this.testClass + "].", this.expectedLocations,
		processedLocations);
}
 
Example 5
void assertMergedConfig(
		MergedContextConfiguration mergedConfig,
		Class<?> expectedTestClass,
		String[] expectedLocations,
		Class<?>[] expectedClasses,
		Set<Class<? extends ApplicationContextInitializer<?>>> expectedInitializerClasses,
		Class<? extends ContextLoader> expectedContextLoaderClass) {

	assertNotNull(mergedConfig);
	assertEquals(expectedTestClass, mergedConfig.getTestClass());
	assertNotNull(mergedConfig.getLocations());
	assertArrayEquals(expectedLocations, mergedConfig.getLocations());
	assertNotNull(mergedConfig.getClasses());
	assertArrayEquals(expectedClasses, mergedConfig.getClasses());
	assertNotNull(mergedConfig.getActiveProfiles());
	if (expectedContextLoaderClass == null) {
		assertNull(mergedConfig.getContextLoader());
	}
	else {
		assertEquals(expectedContextLoaderClass, mergedConfig.getContextLoader().getClass());
	}
	assertNotNull(mergedConfig.getContextInitializerClasses());
	assertEquals(expectedInitializerClasses, mergedConfig.getContextInitializerClasses());
}
 
Example 6
@Test
public void resolveContextHierarchyAttributesForSingleTestClassWithTripleLevelContextHierarchy() {
	Class<SingleTestClassWithTripleLevelContextHierarchy> testClass = SingleTestClassWithTripleLevelContextHierarchy.class;
	List<List<ContextConfigurationAttributes>> hierarchyAttributes = resolveContextHierarchyAttributes(testClass);
	assertEquals(1, hierarchyAttributes.size());

	List<ContextConfigurationAttributes> configAttributesList = hierarchyAttributes.get(0);
	assertNotNull(configAttributesList);
	assertEquals(3, configAttributesList.size());
	debugConfigAttributes(configAttributesList);
	assertAttributes(configAttributesList.get(0), testClass, new String[] { "A.xml" }, EMPTY_CLASS_ARRAY,
		ContextLoader.class, true);
	assertAttributes(configAttributesList.get(1), testClass, new String[] { "B.xml" }, EMPTY_CLASS_ARRAY,
		ContextLoader.class, true);
	assertAttributes(configAttributesList.get(2), testClass, new String[] { "C.xml" }, EMPTY_CLASS_ARRAY,
		ContextLoader.class, true);
}
 
Example 7
/**
 * 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:
 * <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>
 * </ol>
 * @param configAttributesList the list of configuration attributes to process;
 * must not be {@code null}; must be ordered <em>bottom-up</em>
 * (i.e., as if we were traversing up the class hierarchy)
 * @return the {@code ContextLoader} class to use for the supplied configuration
 * attributes, or {@code null} if no explicit loader is found
 * @throws IllegalArgumentException if supplied configuration attributes are
 * {@code null} or <em>empty</em>
 */
@Nullable
protected Class<? extends ContextLoader> resolveExplicitContextLoaderClass(
		List<ContextConfigurationAttributes> configAttributesList) {

	Assert.notNull(configAttributesList, "ContextConfigurationAttributes list must not be null");

	for (ContextConfigurationAttributes configAttributes : configAttributesList) {
		if (logger.isTraceEnabled()) {
			logger.trace(String.format("Resolving ContextLoader for context configuration attributes %s",
					configAttributes));
		}
		Class<? extends ContextLoader> contextLoaderClass = configAttributes.getContextLoaderClass();
		if (ContextLoader.class != contextLoaderClass) {
			if (logger.isDebugEnabled()) {
				logger.debug(String.format(
						"Found explicit ContextLoader class [%s] for context configuration attributes %s",
						contextLoaderClass.getName(), configAttributes));
			}
			return contextLoaderClass;
		}
	}
	return null;
}
 
Example 8
/**
 * 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
@Test
public void assertContextConfigurationLocations() throws Exception {

	final ContextConfiguration contextConfig = this.testClass.getAnnotation(ContextConfiguration.class);
	final ContextLoader contextLoader = new GenericXmlContextLoader();
	final String[] configuredLocations = (String[]) AnnotationUtils.getValue(contextConfig);
	final String[] processedLocations = contextLoader.processLocations(this.testClass, configuredLocations);

	if (logger.isDebugEnabled()) {
		logger.debug("----------------------------------------------------------------------");
		logger.debug("Configured locations: " + ObjectUtils.nullSafeToString(configuredLocations));
		logger.debug("Expected   locations: " + ObjectUtils.nullSafeToString(this.expectedLocations));
		logger.debug("Processed  locations: " + ObjectUtils.nullSafeToString(processedLocations));
	}

	assertArrayEquals("Verifying locations for test [" + this.testClass + "].", this.expectedLocations,
		processedLocations);
}
 
Example 10
void assertMergedConfig(
		MergedContextConfiguration mergedConfig,
		Class<?> expectedTestClass,
		String[] expectedLocations,
		Class<?>[] expectedClasses,
		Set<Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>> expectedInitializerClasses,
		Class<? extends ContextLoader> expectedContextLoaderClass) {

	assertNotNull(mergedConfig);
	assertEquals(expectedTestClass, mergedConfig.getTestClass());
	assertNotNull(mergedConfig.getLocations());
	assertArrayEquals(expectedLocations, mergedConfig.getLocations());
	assertNotNull(mergedConfig.getClasses());
	assertArrayEquals(expectedClasses, mergedConfig.getClasses());
	assertNotNull(mergedConfig.getActiveProfiles());
	if (expectedContextLoaderClass == null) {
		assertNull(mergedConfig.getContextLoader());
	}
	else {
		assertEquals(expectedContextLoaderClass, mergedConfig.getContextLoader().getClass());
	}
	assertNotNull(mergedConfig.getContextInitializerClasses());
	assertEquals(expectedInitializerClasses, mergedConfig.getContextInitializerClasses());
}
 
Example 11
@Test
public void resolveContextHierarchyAttributesForSingleTestClassWithTripleLevelContextHierarchy() {
	Class<SingleTestClassWithTripleLevelContextHierarchy> testClass = SingleTestClassWithTripleLevelContextHierarchy.class;
	List<List<ContextConfigurationAttributes>> hierarchyAttributes = resolveContextHierarchyAttributes(testClass);
	assertEquals(1, hierarchyAttributes.size());

	List<ContextConfigurationAttributes> configAttributesList = hierarchyAttributes.get(0);
	assertNotNull(configAttributesList);
	assertEquals(3, configAttributesList.size());
	debugConfigAttributes(configAttributesList);
	assertAttributes(configAttributesList.get(0), testClass, new String[] { "A.xml" }, EMPTY_CLASS_ARRAY,
		ContextLoader.class, true);
	assertAttributes(configAttributesList.get(1), testClass, new String[] { "B.xml" }, EMPTY_CLASS_ARRAY,
		ContextLoader.class, true);
	assertAttributes(configAttributesList.get(2), testClass, new String[] { "C.xml" }, EMPTY_CLASS_ARRAY,
		ContextLoader.class, true);
}
 
Example 12
/**
 * 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 user has not explicitly declared which loader to use, the value
 * returned from {@link #getDefaultContextLoaderClass} will be used as the
 * default context loader class. For details on the class resolution process,
 * see {@link #resolveExplicitContextLoaderClass} and
 * {@link #getDefaultContextLoaderClass}.
 * @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)
 * @return the resolved {@code ContextLoader} for the supplied {@code testClass}
 * (never {@code null})
 * @throws IllegalStateException if {@link #getDefaultContextLoaderClass(Class)}
 * returns {@code null}
 */
protected ContextLoader resolveContextLoader(Class<?> testClass,
		List<ContextConfigurationAttributes> configAttributesList) {

	Assert.notNull(testClass, "Class must not be null");
	Assert.notEmpty(configAttributesList, "ContextConfigurationAttributes list must not be empty");

	Class<? extends ContextLoader> contextLoaderClass = resolveExplicitContextLoaderClass(configAttributesList);
	if (contextLoaderClass == null) {
		contextLoaderClass = getDefaultContextLoaderClass(testClass);
		if (contextLoaderClass == null) {
			throw new IllegalStateException("getDefaultContextLoaderClass() must not return null");
		}
	}
	if (logger.isTraceEnabled()) {
		logger.trace(String.format("Using ContextLoader class [%s] for test class [%s]",
			contextLoaderClass.getName(), testClass.getName()));
	}
	return BeanUtils.instantiateClass(contextLoaderClass, ContextLoader.class);
}
 
Example 13
/**
 * 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 14
@Test
public void assertContextConfigurationLocations() throws Exception {

	final ContextConfiguration contextConfig = this.testClass.getAnnotation(ContextConfiguration.class);
	final ContextLoader contextLoader = new GenericXmlContextLoader();
	final String[] configuredLocations = (String[]) AnnotationUtils.getValue(contextConfig);
	final String[] processedLocations = contextLoader.processLocations(this.testClass, configuredLocations);

	if (logger.isDebugEnabled()) {
		logger.debug("----------------------------------------------------------------------");
		logger.debug("Configured locations: " + ObjectUtils.nullSafeToString(configuredLocations));
		logger.debug("Expected   locations: " + ObjectUtils.nullSafeToString(this.expectedLocations));
		logger.debug("Processed  locations: " + ObjectUtils.nullSafeToString(processedLocations));
	}

	assertArrayEquals("Verifying locations for test [" + this.testClass + "].", this.expectedLocations,
		processedLocations);
}
 
Example 15
Source Project: spring-analysis-note   Source File: WebTestContextBootstrapper.java    License: MIT License 5 votes vote down vote up
/**
 * Returns {@link WebDelegatingSmartContextLoader} if the supplied class is
 * annotated with {@link WebAppConfiguration @WebAppConfiguration} and
 * otherwise delegates to the superclass.
 */
@Override
protected Class<? extends ContextLoader> getDefaultContextLoaderClass(Class<?> testClass) {
	if (AnnotatedElementUtils.hasAnnotation(testClass, WebAppConfiguration.class)) {
		return WebDelegatingSmartContextLoader.class;
	}
	else {
		return super.getDefaultContextLoaderClass(testClass);
	}
}
 
Example 16
private MergedContextConfiguration buildDefaultMergedContextConfiguration(Class<?> testClass,
		CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate) {

	List<ContextConfigurationAttributes> defaultConfigAttributesList =
			Collections.singletonList(new ContextConfigurationAttributes(testClass));

	ContextLoader contextLoader = resolveContextLoader(testClass, defaultConfigAttributesList);
	if (logger.isInfoEnabled()) {
		logger.info(String.format(
				"Neither @ContextConfiguration nor @ContextHierarchy found for test class [%s], using %s",
				testClass.getName(), contextLoader.getClass().getSimpleName()));
	}
	return buildMergedContextConfiguration(testClass, defaultConfigAttributesList, null,
			cacheAwareContextLoaderDelegate, false);
}
 
Example 17
@Test
public void buildMergedConfigWithLocalAnnotationAndOverriddenContextLoaderAndLocations() {
	Class<?> testClass = PropertiesLocationsFoo.class;
	Class<? extends ContextLoader> expectedContextLoaderClass = GenericPropertiesContextLoader.class;
	MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass);

	assertMergedConfig(mergedConfig, testClass, new String[] { "classpath:/foo.properties" }, EMPTY_CLASS_ARRAY,
		expectedContextLoaderClass);
}
 
Example 18
@Test
public void resolveContextHierarchyAttributesForSingleTestClassWithSingleLevelContextHierarchyFromMetaAnnotation() {
	Class<SingleTestClassWithSingleLevelContextHierarchyFromMetaAnnotation> testClass = SingleTestClassWithSingleLevelContextHierarchyFromMetaAnnotation.class;
	List<List<ContextConfigurationAttributes>> hierarchyAttributes = resolveContextHierarchyAttributes(testClass);
	assertEquals(1, hierarchyAttributes.size());

	List<ContextConfigurationAttributes> configAttributesList = hierarchyAttributes.get(0);
	assertNotNull(configAttributesList);
	assertEquals(1, configAttributesList.size());
	debugConfigAttributes(configAttributesList);
	assertAttributes(configAttributesList.get(0), testClass, new String[] { "A.xml" }, EMPTY_CLASS_ARRAY,
		ContextLoader.class, true);
}
 
Example 19
@Test
public void resolveConfigAttributesWithBareAnnotations() {
	Class<BareAnnotations> testClass = BareAnnotations.class;
	List<ContextConfigurationAttributes> attributesList = resolveContextConfigurationAttributes(testClass);
	assertNotNull(attributesList);
	assertEquals(1, attributesList.size());
	assertAttributes(attributesList.get(0),
			testClass, EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, ContextLoader.class, true);
}
 
Example 20
@Test
public void resolveConfigAttributesWithMetaAnnotationAndLocations() {
	Class<MetaLocationsFoo> testClass = MetaLocationsFoo.class;
	List<ContextConfigurationAttributes> attributesList = resolveContextConfigurationAttributes(testClass);
	assertNotNull(attributesList);
	assertEquals(1, attributesList.size());
	assertAttributes(attributesList.get(0),
			testClass, new String[] {"/foo.xml"}, EMPTY_CLASS_ARRAY, ContextLoader.class, true);
}
 
Example 21
@Test
public void resolveConfigAttributesWithMetaAnnotationAndLocationsAndOverrides() {
	Class<MetaLocationsFooWithOverrides> testClass = MetaLocationsFooWithOverrides.class;
	List<ContextConfigurationAttributes> attributesList = resolveContextConfigurationAttributes(testClass);
	assertNotNull(attributesList);
	assertEquals(1, attributesList.size());
	assertAttributes(attributesList.get(0),
			testClass, new String[] {"/foo.xml"}, EMPTY_CLASS_ARRAY, ContextLoader.class, true);
}
 
Example 22
@Test
public void resolveConfigAttributesWithMetaAnnotationAndLocationsAndOverriddenAttributes() {
	Class<MetaLocationsFooWithOverriddenAttributes> testClass = MetaLocationsFooWithOverriddenAttributes.class;
	List<ContextConfigurationAttributes> attributesList = resolveContextConfigurationAttributes(testClass);
	assertNotNull(attributesList);
	assertEquals(1, attributesList.size());
	assertAttributes(attributesList.get(0),
			testClass, new String[] {"foo1.xml", "foo2.xml"}, EMPTY_CLASS_ARRAY, ContextLoader.class, true);
}
 
Example 23
@Test
public void resolveConfigAttributesWithMetaAnnotationAndLocationsInClassHierarchy() {
	Class<MetaLocationsBar> testClass = MetaLocationsBar.class;
	List<ContextConfigurationAttributes> attributesList = resolveContextConfigurationAttributes(testClass);
	assertNotNull(attributesList);
	assertEquals(2, attributesList.size());
	assertAttributes(attributesList.get(0),
			testClass, new String[] {"/bar.xml"}, EMPTY_CLASS_ARRAY, ContextLoader.class, true);
	assertAttributes(attributesList.get(1),
			MetaLocationsFoo.class, new String[] {"/foo.xml"}, EMPTY_CLASS_ARRAY, ContextLoader.class, true);
}
 
Example 24
@Test
public void resolveConfigAttributesWithMetaAnnotationAndLocationsInClassHierarchy() {
	Class<MetaLocationsBar> testClass = MetaLocationsBar.class;
	List<ContextConfigurationAttributes> attributesList = resolveContextConfigurationAttributes(testClass);
	assertNotNull(attributesList);
	assertEquals(2, attributesList.size());
	assertAttributes(attributesList.get(0),
			testClass, new String[] {"/bar.xml"}, EMPTY_CLASS_ARRAY, ContextLoader.class, true);
	assertAttributes(attributesList.get(1),
			MetaLocationsFoo.class, new String[] {"/foo.xml"}, EMPTY_CLASS_ARRAY, ContextLoader.class, true);
}
 
Example 25
void assertMergedConfig(MergedContextConfiguration mergedConfig, Class<?> expectedTestClass,
		String[] expectedLocations, Class<?>[] expectedClasses,
		Class<? extends ContextLoader> expectedContextLoaderClass) {

	assertMergedConfig(mergedConfig, expectedTestClass, expectedLocations, expectedClasses,
			EMPTY_INITIALIZER_CLASSES, expectedContextLoaderClass);
}
 
Example 26
@Test
public void buildMergedConfigWithLocalAnnotationAndOverriddenContextLoaderAndLocations() {
	Class<?> testClass = PropertiesLocationsFoo.class;
	Class<? extends ContextLoader> expectedContextLoaderClass = GenericPropertiesContextLoader.class;
	MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass);

	assertMergedConfig(mergedConfig, testClass, array("classpath:/foo.properties"), EMPTY_CLASS_ARRAY,
		expectedContextLoaderClass);
}
 
Example 27
@Test
public void buildMergedConfigWithLocalAnnotationAndOverriddenContextLoaderAndClasses() {
	Class<?> testClass = PropertiesClassesFoo.class;
	Class<? extends ContextLoader> expectedContextLoaderClass = GenericPropertiesContextLoader.class;
	MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass);

	assertMergedConfig(mergedConfig, testClass, EMPTY_STRING_ARRAY, array(FooConfig.class),
		expectedContextLoaderClass);
}
 
Example 28
@Test
public void processContextConfigurationWithDefaultXmlConfigGeneration() {
	ContextConfigurationAttributes configAttributes = new ContextConfigurationAttributes(
			XmlTestCase.class, EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, true, null, true, ContextLoader.class);
	loader.processContextConfiguration(configAttributes);
	assertEquals(1, configAttributes.getLocations().length);
	assertEmpty(configAttributes.getClasses());
}
 
Example 29
@Test
public void processContextConfigurationWithDefaultConfigurationClassGeneration() {
	ContextConfigurationAttributes configAttributes = new ContextConfigurationAttributes(
			ConfigClassTestCase.class, EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, true, null, true, ContextLoader.class);
	loader.processContextConfiguration(configAttributes);
	assertEquals(1, configAttributes.getClasses().length);
	assertEmpty(configAttributes.getLocations());
}
 
Example 30
@Test
public void buildMergedConfigWithLocalAnnotationAndOverriddenContextLoaderAndClasses() {
	Class<?> testClass = PropertiesClassesFoo.class;
	Class<? extends ContextLoader> expectedContextLoaderClass = GenericPropertiesContextLoader.class;
	MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass);

	assertMergedConfig(mergedConfig, testClass, EMPTY_STRING_ARRAY, new Class<?>[] { FooConfig.class },
		expectedContextLoaderClass);
}