[SPR-5713] Added 'value' alias for @ContextConfiguration's 'locations' attribute.
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@1088 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
parent
41b5e5d8b4
commit
545a704833
|
|
@ -45,6 +45,13 @@ public @interface ContextConfiguration {
|
||||||
*/
|
*/
|
||||||
String[] locations() default {};
|
String[] locations() default {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alias for {@link #locations()}.
|
||||||
|
*
|
||||||
|
* @since 3.0
|
||||||
|
*/
|
||||||
|
String[] value() default {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether or not {@link #locations() resource locations} from superclasses
|
* Whether or not {@link #locations() resource locations} from superclasses
|
||||||
* should be <em>inherited</em>.
|
* should be <em>inherited</em>.
|
||||||
|
|
|
||||||
|
|
@ -184,7 +184,25 @@ public class TestContext extends AttributeAccessorSupport {
|
||||||
logger.trace("Retrieved @ContextConfiguration [" + contextConfiguration + "] for declaring class ["
|
logger.trace("Retrieved @ContextConfiguration [" + contextConfiguration + "] for declaring class ["
|
||||||
+ declaringClass + "]");
|
+ declaringClass + "]");
|
||||||
}
|
}
|
||||||
String[] locations = contextLoader.processLocations(declaringClass, contextConfiguration.locations());
|
|
||||||
|
String[] valueLocations = contextConfiguration.value();
|
||||||
|
String[] locations = contextConfiguration.locations();
|
||||||
|
if (!ObjectUtils.isEmpty(valueLocations) && !ObjectUtils.isEmpty(locations)) {
|
||||||
|
String msg = "Test class ["
|
||||||
|
+ declaringClass
|
||||||
|
+ "] has been configured with @ContextConfiguration's 'value' ["
|
||||||
|
+ ObjectUtils.nullSafeToString(valueLocations)
|
||||||
|
+ "] and 'locations' ["
|
||||||
|
+ ObjectUtils.nullSafeToString(locations)
|
||||||
|
+ "] attributes. Only one declaration of resource locations is permitted per @ContextConfiguration annotation.";
|
||||||
|
logger.error(msg);
|
||||||
|
throw new IllegalStateException(msg);
|
||||||
|
}
|
||||||
|
else if (!ObjectUtils.isEmpty(valueLocations)) {
|
||||||
|
locations = valueLocations;
|
||||||
|
}
|
||||||
|
|
||||||
|
locations = contextLoader.processLocations(declaringClass, locations);
|
||||||
locationsList.addAll(0, Arrays.<String> asList(locations));
|
locationsList.addAll(0, Arrays.<String> asList(locations));
|
||||||
declaringClass = contextConfiguration.inheritLocations() ? AnnotationUtils.findAnnotationDeclaringClass(
|
declaringClass = contextConfiguration.inheritLocations() ? AnnotationUtils.findAnnotationDeclaringClass(
|
||||||
annotationType, declaringClass.getSuperclass()) : null;
|
annotationType, declaringClass.getSuperclass()) : null;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2007 the original author or authors.
|
* Copyright 2002-2009 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.
|
||||||
|
|
@ -17,7 +17,6 @@
|
||||||
package org.springframework.test.context.junit4;
|
package org.springframework.test.context.junit4;
|
||||||
|
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.util.ResourceUtils;
|
import org.springframework.util.ResourceUtils;
|
||||||
|
|
||||||
|
|
@ -25,13 +24,19 @@ import org.springframework.util.ResourceUtils;
|
||||||
* Extension of {@link SpringJUnit4ClassRunnerAppCtxTests}, which verifies that
|
* Extension of {@link SpringJUnit4ClassRunnerAppCtxTests}, which verifies that
|
||||||
* we can specify multiple resource locations for our application context, each
|
* we can specify multiple resource locations for our application context, each
|
||||||
* configured differently.
|
* configured differently.
|
||||||
*
|
* <p>
|
||||||
|
* As of Spring 3.0,
|
||||||
|
* <code>MultipleResourcesSpringJUnit4ClassRunnerAppCtxTests</code> is also used
|
||||||
|
* to verify support for the new <code>value</code> attribute alias for
|
||||||
|
* <code>@ContextConfiguration</code>'s <code>locations</code> attribute.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
* @author Sam Brannen
|
* @author Sam Brannen
|
||||||
* @since 2.5
|
* @since 2.5
|
||||||
* @see SpringJUnit4ClassRunnerAppCtxTests
|
* @see SpringJUnit4ClassRunnerAppCtxTests
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(locations = { MultipleResourcesSpringJUnit4ClassRunnerAppCtxTests.CLASSPATH_RESOURCE_PATH,
|
@ContextConfiguration( { MultipleResourcesSpringJUnit4ClassRunnerAppCtxTests.CLASSPATH_RESOURCE_PATH,
|
||||||
MultipleResourcesSpringJUnit4ClassRunnerAppCtxTests.LOCAL_RESOURCE_PATH,
|
MultipleResourcesSpringJUnit4ClassRunnerAppCtxTests.LOCAL_RESOURCE_PATH,
|
||||||
MultipleResourcesSpringJUnit4ClassRunnerAppCtxTests.ABSOLUTE_RESOURCE_PATH })
|
MultipleResourcesSpringJUnit4ClassRunnerAppCtxTests.ABSOLUTE_RESOURCE_PATH })
|
||||||
public class MultipleResourcesSpringJUnit4ClassRunnerAppCtxTests extends SpringJUnit4ClassRunnerAppCtxTests {
|
public class MultipleResourcesSpringJUnit4ClassRunnerAppCtxTests extends SpringJUnit4ClassRunnerAppCtxTests {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue