[SPR-6184] Refactored internals of ContextLoaderUtils; @Ignore'd broken test.
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4166 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
parent
d63dba327d
commit
29c33bcd7d
|
|
@ -162,41 +162,31 @@ public abstract class ContextLoaderUtils {
|
|||
Assert.notNull(contextLoader, "ContextLoader must not be null");
|
||||
Assert.notNull(clazz, "Class must not be null");
|
||||
|
||||
List<String> locationsList = new ArrayList<String>();
|
||||
Class<ContextConfiguration> annotationType = ContextConfiguration.class;
|
||||
Class<?> declaringClass = AnnotationUtils.findAnnotationDeclaringClass(annotationType, clazz);
|
||||
Assert.notNull(declaringClass, "Could not find an 'annotation declaring class' for annotation type ["
|
||||
+ annotationType + "] and class [" + clazz + "]");
|
||||
|
||||
// --- configuration class resources ----------------------------
|
||||
boolean processConfigurationClasses = (contextLoader instanceof ResourceTypeAwareContextLoader)
|
||||
&& ((ResourceTypeAwareContextLoader) contextLoader).supportsClassResources();
|
||||
|
||||
// TODO [SPR-6184] Implement recursive search for configuration classes.
|
||||
// This needs to integrate seamlessly (i.e., analogous yet mutually
|
||||
// exclusive) with the existing locations search.
|
||||
if ((contextLoader instanceof ResourceTypeAwareContextLoader)
|
||||
&& ((ResourceTypeAwareContextLoader) contextLoader).supportsClassResources()) {
|
||||
return processConfigurationClasses ? //
|
||||
resolveConfigurationClassNames(contextLoader, annotationType, declaringClass)
|
||||
: resolveStringLocations(contextLoader, annotationType, declaringClass);
|
||||
}
|
||||
|
||||
ContextConfiguration cc = declaringClass.getAnnotation(annotationType);
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace(String.format("Retrieved @ContextConfiguration [%s] for declaring class [%s].", cc,
|
||||
declaringClass));
|
||||
}
|
||||
/**
|
||||
* TODO Document resolveStringLocations().
|
||||
*
|
||||
* @param contextLoader
|
||||
* @param annotationType
|
||||
* @param declaringClass
|
||||
* @return
|
||||
*/
|
||||
private static String[] resolveStringLocations(ContextLoader contextLoader,
|
||||
Class<ContextConfiguration> annotationType, Class<?> declaringClass) {
|
||||
|
||||
String[] classNames = null;
|
||||
|
||||
Class<?>[] configClasses = cc.classes();
|
||||
if (!ObjectUtils.isEmpty(configClasses)) {
|
||||
classNames = new String[configClasses.length];
|
||||
|
||||
for (int i = 0; i < configClasses.length; i++) {
|
||||
classNames[i] = configClasses[i].getName();
|
||||
}
|
||||
}
|
||||
|
||||
return contextLoader.processLocations(declaringClass, classNames);
|
||||
}
|
||||
|
||||
// --- location/value resources ---------------------------------
|
||||
List<String> locationsList = new ArrayList<String>();
|
||||
|
||||
while (declaringClass != null) {
|
||||
ContextConfiguration contextConfiguration = declaringClass.getAnnotation(annotationType);
|
||||
|
|
@ -228,4 +218,37 @@ public abstract class ContextLoaderUtils {
|
|||
return locationsList.toArray(new String[locationsList.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Document resolveConfigClassNames().
|
||||
*
|
||||
* @param contextLoader
|
||||
* @param annotationType
|
||||
* @param declaringClass
|
||||
* @return
|
||||
*/
|
||||
private static String[] resolveConfigurationClassNames(ContextLoader contextLoader,
|
||||
Class<ContextConfiguration> annotationType, Class<?> declaringClass) {
|
||||
|
||||
// TODO [SPR-6184] Implement recursive search for configuration classes.
|
||||
|
||||
ContextConfiguration contextConfiguration = declaringClass.getAnnotation(annotationType);
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace(String.format("Retrieved @ContextConfiguration [%s] for declaring class [%s].",
|
||||
contextConfiguration, declaringClass));
|
||||
}
|
||||
|
||||
String[] classNames = null;
|
||||
|
||||
Class<?>[] configClasses = contextConfiguration.classes();
|
||||
if (!ObjectUtils.isEmpty(configClasses)) {
|
||||
classNames = new String[configClasses.length];
|
||||
|
||||
for (int i = 0; i < configClasses.length; i++) {
|
||||
classNames[i] = configClasses[i].getName();
|
||||
}
|
||||
}
|
||||
|
||||
return contextLoader.processLocations(declaringClass, classNames);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,13 +32,9 @@ import org.junit.runners.Suite.SuiteClasses;
|
|||
|
||||
AnnotationConfigSpringJUnit4ClassRunnerAppCtxTests.class,
|
||||
|
||||
DefaultConfigClassBaseTests.class
|
||||
DefaultConfigClassBaseTests.class,
|
||||
|
||||
// TODO Uncomment once working. Note that JUnit's Suite runner apparently
|
||||
// does not heed the presence of @Ignore on a suite class, at least not
|
||||
// when run within STS 2.6.0.
|
||||
//
|
||||
// DefaultConfigClassInheritedTests.class
|
||||
DefaultConfigClassInheritedTests.class
|
||||
|
||||
})
|
||||
public class AnnotationConfigSuiteTests {
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ package org.springframework.test.context.junit4.annotation;
|
|||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.Employee;
|
||||
|
|
@ -34,7 +33,6 @@ import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
|||
* @author Sam Brannen
|
||||
* @since 3.1
|
||||
*/
|
||||
@Ignore("[SPR-6184] Disabled until ContextLoaderUtils supports recursive search for configuration classes")
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(loader = AnnotationConfigContextLoader.class)
|
||||
public class DefaultConfigClassBaseTests {
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package org.springframework.test.context.junit4.annotation;
|
|||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.Pet;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
|
@ -30,6 +31,7 @@ import org.springframework.test.context.ContextConfiguration;
|
|||
* @author Sam Brannen
|
||||
* @since 3.1
|
||||
*/
|
||||
@Ignore("[SPR-6184] Disabled until ContextLoaderUtils supports recursive search for configuration classes")
|
||||
@ContextConfiguration
|
||||
public class DefaultConfigClassInheritedTests extends DefaultConfigClassBaseTests {
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue