Browse Source

[SPR-6184] Introduced ResourceType enum for context loaders; documented tests.

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4199 50f2f4bb-b051-0410-bef5-90022cba6387
pull/1/merge
Sam Brannen 15 years ago
parent
commit
5d0c5f7698
  1. 8
      org.springframework.test/src/main/java/org/springframework/test/context/ContextConfiguration.java
  2. 15
      org.springframework.test/src/main/java/org/springframework/test/context/ContextLoaderUtils.java
  3. 34
      org.springframework.test/src/main/java/org/springframework/test/context/ResourceTypeAwareContextLoader.java
  4. 20
      org.springframework.test/src/main/java/org/springframework/test/context/support/AbstractContextLoader.java
  5. 14
      org.springframework.test/src/main/java/org/springframework/test/context/support/AnnotationConfigContextLoader.java
  6. 10
      org.springframework.test/src/test/java/org/springframework/test/context/junit4/annotation/AnnotationConfigSpringJUnit4ClassRunnerAppCtxTests.java
  7. 5
      org.springframework.test/src/test/java/org/springframework/test/context/junit4/annotation/AnnotationConfigTestSuite.java
  8. 5
      org.springframework.test/src/test/java/org/springframework/test/context/junit4/annotation/DefaultConfigClassBaseTests.java
  9. 2
      org.springframework.test/src/test/java/org/springframework/test/context/junit4/annotation/DefaultConfigClassBaseTestsConfig.java
  10. 6
      org.springframework.test/src/test/java/org/springframework/test/context/junit4/annotation/DefaultConfigClassInheritedTests.java
  11. 2
      org.springframework.test/src/test/java/org/springframework/test/context/junit4/annotation/DefaultConfigClassInheritedTestsConfig.java
  12. 7
      org.springframework.test/src/test/java/org/springframework/test/context/junit4/annotation/PojoAndStringConfig.java

8
org.springframework.test/src/main/java/org/springframework/test/context/ContextConfiguration.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -79,7 +79,7 @@ public @interface ContextConfiguration { @@ -79,7 +79,7 @@ public @interface ContextConfiguration {
* defined by an annotated superclass. Thus, subclasses have the option of
* <em>extending</em> the list of resource locations. In the following
* example, the {@link org.springframework.context.ApplicationContext ApplicationContext}
* for <code>ExtendedTest</code> will be loaded from
* for <code>ExtendedTest</code> will be loaded from
* &quot;base-context.xml&quot; <strong>and</strong>
* &quot;extended-context.xml&quot;, in that order. Beans defined in
* &quot;extended-context.xml&quot; may therefore override those defined in
@ -106,8 +106,8 @@ public @interface ContextConfiguration { @@ -106,8 +106,8 @@ public @interface ContextConfiguration {
* {@link org.springframework.context.ApplicationContext ApplicationContext}.
* <p>If not specified, the loader will be inherited from the first superclass
* which is annotated with <code>&#064;ContextConfiguration</code> and specifies
* an explicit loader. If no class in the hierarchy specifies an explicit
* loader, a default loader will be used instead.
* an explicit loader. If no class in the hierarchy specifies an explicit
* loader, a default loader will be used instead.
* <p>The default concrete implementation chosen at runtime will be
* {@link org.springframework.test.context.support.GenericXmlContextLoader GenericXmlContextLoader}.
* Also check out {@link org.springframework.test.context.support.AbstractContextLoader AbstractContextLoader}'s

15
org.springframework.test/src/main/java/org/springframework/test/context/ContextLoaderUtils.java

@ -25,6 +25,7 @@ import org.apache.commons.logging.LogFactory; @@ -25,6 +25,7 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.test.context.ResourceTypeAwareContextLoader.ResourceType;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
@ -101,8 +102,9 @@ public abstract class ContextLoaderUtils { @@ -101,8 +102,9 @@ public abstract class ContextLoaderUtils {
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 + "]");
Assert.notNull(declaringClass, String.format(
"Could not find an 'annotation declaring class' for annotation type [%s] and class [%s]", annotationType,
clazz));
while (declaringClass != null) {
ContextConfiguration contextConfiguration = declaringClass.getAnnotation(annotationType);
@ -166,7 +168,7 @@ public abstract class ContextLoaderUtils { @@ -166,7 +168,7 @@ public abstract class ContextLoaderUtils {
Assert.notNull(clazz, "Class must not be null");
boolean processConfigurationClasses = (contextLoader instanceof ResourceTypeAwareContextLoader)
&& ((ResourceTypeAwareContextLoader) contextLoader).supportsClassResources();
&& ResourceType.CLASSES == ((ResourceTypeAwareContextLoader) contextLoader).getResourceType();
LocationsResolver locationsResolver = processConfigurationClasses ? classNameLocationsResolver
: resourcePathLocationsResolver;
@ -212,9 +214,10 @@ public abstract class ContextLoaderUtils { @@ -212,9 +214,10 @@ public abstract class ContextLoaderUtils {
if (!ObjectUtils.isEmpty(valueLocations) && !ObjectUtils.isEmpty(locations)) {
String msg = String.format(
"Test class [%s] has been configured with @ContextConfiguration's 'value' [%s] and 'locations' [%s] attributes. Only one declaration of resource locations is permitted per @ContextConfiguration annotation.",
declaringClass, ObjectUtils.nullSafeToString(valueLocations),
ObjectUtils.nullSafeToString(locations));
"Test class [%s] has been configured with @ContextConfiguration's 'value' [%s] "
+ "and 'locations' [%s] attributes. Only one declaration of resource "
+ "locations is permitted per @ContextConfiguration annotation.", declaringClass,
ObjectUtils.nullSafeToString(valueLocations), ObjectUtils.nullSafeToString(locations));
ContextLoaderUtils.logger.error(msg);
throw new IllegalStateException(msg);
}

34
org.springframework.test/src/main/java/org/springframework/test/context/ResourceTypeAwareContextLoader.java

@ -25,18 +25,34 @@ package org.springframework.test.context; @@ -25,18 +25,34 @@ package org.springframework.test.context;
public interface ResourceTypeAwareContextLoader extends ContextLoader {
/**
* @return <code>true</code> if this <code>ContextLoader</code> supports
* String-based resource locations
* @see ContextConfiguration#locations()
* @see ContextConfiguration#value()
* TODO Document ResourceType.
*/
boolean supportsStringResources();
public static enum ResourceType {
/**
* String-based resource locations.
*
* @see ContextConfiguration#locations()
* @see ContextConfiguration#value()
*/
LOCATIONS,
/**
* Configuration classes.
*
* @see ContextConfiguration#classes()
*/
CLASSES;
};
/**
* @return <code>true</code> if this <code>ContextLoader</code> supports
* Class-based resource locations
* @see ContextConfiguration#classes()
* Get the application context {@link ResourceType} supported by this
* <code>ContextLoader</code>.
*
* @return the context resource type supported by this ContextLoader
*/
boolean supportsClassResources();
ResourceType getResourceType();
}

20
org.springframework.test/src/main/java/org/springframework/test/context/support/AbstractContextLoader.java

@ -64,7 +64,7 @@ public abstract class AbstractContextLoader implements ResourceTypeAwareContextL @@ -64,7 +64,7 @@ public abstract class AbstractContextLoader implements ResourceTypeAwareContextL
}
/**
* Generates the default classpath resource locations array based on the
* Generate the default classpath resource locations array based on the
* supplied class.
* <p>For example, if the supplied class is <code>com.example.MyTest</code>,
* the generated locations will contain a single string with a value of
@ -142,21 +142,11 @@ public abstract class AbstractContextLoader implements ResourceTypeAwareContextL @@ -142,21 +142,11 @@ public abstract class AbstractContextLoader implements ResourceTypeAwareContextL
protected abstract String getResourceSuffix();
/**
* TODO Document supportsStringResources() implementation.
*
* @return <code>true</code>
* The default implementation returns {@link ResourceType#LOCATIONS}.
* <p>Can be overridden by subclasses.
*/
public boolean supportsStringResources() {
return true;
}
/**
* TODO Document supportsClassResources() implementations.
*
* @return <code>false</code>
*/
public boolean supportsClassResources() {
return false;
public ResourceType getResourceType() {
return ResourceType.LOCATIONS;
}
}

14
org.springframework.test/src/main/java/org/springframework/test/context/support/AnnotationConfigContextLoader.java

@ -128,19 +128,11 @@ public class AnnotationConfigContextLoader extends AbstractGenericContextLoader @@ -128,19 +128,11 @@ public class AnnotationConfigContextLoader extends AbstractGenericContextLoader
}
/**
* @return <code>true</code>
* Returns {@link ResourceType#CLASSES}.
*/
@Override
public boolean supportsClassResources() {
return true;
}
/**
* @return <code>false</code>
*/
@Override
public boolean supportsStringResources() {
return false;
public ResourceType getResourceType() {
return ResourceType.CLASSES;
}
}

10
org.springframework.test/src/test/java/org/springframework/test/context/junit4/annotation/AnnotationConfigSpringJUnit4ClassRunnerAppCtxTests.java

@ -21,7 +21,15 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunnerAppCtxTest @@ -21,7 +21,15 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunnerAppCtxTest
import org.springframework.test.context.support.AnnotationConfigContextLoader;
/**
* TODO [SPR-6184] Document tests.
* Integration tests that verify support for configuration classes in
* the Spring TestContext Framework.
*
* <p>Furthermore, by extending {@link SpringJUnit4ClassRunnerAppCtxTests},
* this class also verifies support for several basic features of the
* Spring TestContext Framework. See JavaDoc in
* <code>SpringJUnit4ClassRunnerAppCtxTests</code> for details.
*
* <p>Configuration will be loaded from {@link PojoAndStringConfig}.
*
* @author Sam Brannen
* @since 3.1

5
org.springframework.test/src/test/java/org/springframework/test/context/junit4/annotation/AnnotationConfigSuiteTests.java → org.springframework.test/src/test/java/org/springframework/test/context/junit4/annotation/AnnotationConfigTestSuite.java

@ -21,7 +21,8 @@ import org.junit.runners.Suite; @@ -21,7 +21,8 @@ import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
/**
* TODO [SPR-6184] Document tests.
* JUnit test suite for annotation-driven <em>configuration class</em>
* support in the Spring TestContext Framework.
*
* @author Sam Brannen
* @since 3.1
@ -33,5 +34,5 @@ AnnotationConfigSpringJUnit4ClassRunnerAppCtxTests.class,// @@ -33,5 +34,5 @@ AnnotationConfigSpringJUnit4ClassRunnerAppCtxTests.class,//
DefaultConfigClassBaseTests.class,//
DefaultConfigClassInheritedTests.class //
})
public class AnnotationConfigSuiteTests {
public class AnnotationConfigTestSuite {
}

5
org.springframework.test/src/test/java/org/springframework/test/context/junit4/annotation/DefaultConfigClassBaseTests.java

@ -28,7 +28,10 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -28,7 +28,10 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;
/**
* TODO [SPR-6184] Document tests.
* Integration tests that verify support for configuration classes in
* the Spring TestContext Framework.
*
* <p>Configuration will be loaded from {@link DefaultConfigClassBaseTestsConfig}.
*
* @author Sam Brannen
* @since 3.1

2
org.springframework.test/src/test/java/org/springframework/test/context/junit4/annotation/DefaultConfigClassBaseTestsConfig.java

@ -21,7 +21,7 @@ import org.springframework.context.annotation.Bean; @@ -21,7 +21,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* TODO [SPR-6184] Document configuration class.
* ApplicationContext configuration class for {@link DefaultConfigClassBaseTests}.
*
* @author Sam Brannen
* @since 3.1

6
org.springframework.test/src/test/java/org/springframework/test/context/junit4/annotation/DefaultConfigClassInheritedTests.java

@ -25,7 +25,11 @@ import org.springframework.beans.factory.annotation.Autowired; @@ -25,7 +25,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
/**
* TODO [SPR-6184] Document tests.
* Integration tests that verify support for configuration classes in
* the Spring TestContext Framework.
*
* <p>Configuration will be loaded from {@link DefaultConfigClassBaseTestsConfig}
* and {@link DefaultConfigClassInheritedTestsConfig}.
*
* @author Sam Brannen
* @since 3.1

2
org.springframework.test/src/test/java/org/springframework/test/context/junit4/annotation/DefaultConfigClassInheritedTestsConfig.java

@ -21,7 +21,7 @@ import org.springframework.context.annotation.Bean; @@ -21,7 +21,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* TODO [SPR-6184] Document configuration class.
* ApplicationContext configuration class for {@link DefaultConfigClassInheritedTests}.
*
* @author Sam Brannen
* @since 3.1

7
org.springframework.test/src/test/java/org/springframework/test/context/junit4/annotation/PojoAndStringConfig.java

@ -22,7 +22,12 @@ import org.springframework.context.annotation.Bean; @@ -22,7 +22,12 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* TODO [SPR-6184] Document configuration class.
* ApplicationContext configuration class for various integration tests.
*
* <p>The beans defined in this configuration class map directly to the
* beans defined in <code>SpringJUnit4ClassRunnerAppCtxTests-context.xml</code>.
* Consequently, the application contexts loaded from these two sources
* should be identical with regard to bean definitions.
*
* @author Sam Brannen
* @since 3.1

Loading…
Cancel
Save