Spring 3.0 already allows component stereotypes to be used in a
meta-annotation fashion, for example by creating a custom
@TransactionalService stereotype annotation which combines
@Transactional and @Service in a single, reusable, application-specific
annotation. However, the Spring TestContext Framework (TCF) currently
does not provide any support for test-related annotations to be used as
meta-annotations.
This commit overhauls the TCF with regard to how annotations are
retrieved and adds explicit support for the following annotations to be
used as meta-annotations in conjunction with the TCF.
- @ContextConfiguration
- @ContextHierarchy
- @ActiveProfiles
- @DirtiesContext
- @IfProfileValue
- @ProfileValueSourceConfiguration
- @BeforeTransaction
- @AfterTransaction
- @TransactionConfiguration
- @Rollback
- @TestExecutionListeners
- @Repeat
- @Timed
- @WebAppConfiguration
Note that meta-annotation support for @Transactional was already
available prior to this commit.
The following is a summary of the major changes included in this commit.
- Now using AnnotationUtils.getAnnotation() instead of
Class.getAnnotation() where appropriate in the TestContext Framework.
- Now using AnnotationUtils.findAnnotation() instead of
Class.isAnnotationPresent() where appropriate in the TestContext
Framework.
- Introduced findAnnotationPrefersInteracesOverLocalMetaAnnotations() in
AnnotationUtilsTests in order to verify the status quo.
- AnnotationUtils.findAnnotationDeclaringClass() and
AnnotationUtils.findAnnotationDeclaringClassForTypes() now support
meta annotations.
- Introduced MetaAnnotationUtils and AnnotationDescriptor in the
spring-test module.
- Introduced UntypedAnnotationDescriptor in MetaAnnotationUtils.
- Introduced findAnnotationDescriptorForTypes() in MetaAnnotationUtils.
- ContextLoaderUtils now uses MetaAnnotationUtils for looking up
@ActiveProfiles as a potential meta-annotation.
- TestContextManager now uses MetaAnnotationUtils for looking up
@TestExecutionListeners as a potential meta-annotation.
- DirtiesContextTestExecutionListener now uses AnnotationUtils for
looking up @DirtiesContext as a potential meta-annotation.
- Introduced DirtiesContextTestExecutionListenerTests.
- ProfileValueUtils now uses AnnotationUtils for looking up
@IfProfileValue and @ProfileValueSourceConfiguration as potential
meta-annotations.
- @BeforeTransaction and @AfterTransaction now support ANNOTATION_TYPE
as a target, allowing them to be used as meta-annotations.
- TransactionalTestExecutionListener now uses AnnotationUtils for
looking up @BeforeTransaction, @AfterTransaction, @Rollback, and
@TransactionConfiguration as potential meta-annotations.
- Introduced TransactionalTestExecutionListenerTests.
- @Repeat and @Timed now support ANNOTATION_TYPE as a target, allowing
them to be used as meta-annotations.
- SpringJUnit4ClassRunner now uses AnnotationUtils for looking up
@Repeat and @Timed as potential meta-annotations.
- Moved all remaining logic for building the MergedContextConfiguration
from the DefaultTestContext constructor to
ContextLoaderUtils.buildMergedContextConfiguration().
- Verified meta-annotation support for @WebAppConfiguration and
@ContextConfiguration.
Issue: SPR-7827
XML-defined arguments values are initially turned into TypedStringValue wrappers. If we encounter an unresolved argument, we need to unwrap such a TypedStringValue and then try to treat its content as a class name.
Issue: SPR-11034
Also optimized getTypeForFactoryMethod's implementation for non-generic factory methods, and reduced calls to getResolvedFactoryMethod in order to avoid repeated synchronization.
Issue: SPR-11034
Since the Spring TestContext Framework was introduced in Spring
Framework 2.5, the TestContext class has always been a public class
with package private constructors. The visibility of TestContext's
constructor and methods was intentionally limited in order to hide the
implementation details of the context cache, etc. However, this fact
has made it difficult (if not impossible) to unit test custom
TestExecutionListener implementations.
This commit addresses this issue by converting TestContext into a
public interface with a package private DefaultTestContext
implementation. This enables unit testing of any components that depend
on a TestContext (e.g., TestExecutionListeners) while at the same time
preserving the encapsulation of the inner workings of the TestContext
implementation with regard to context loading and caching.
Issue: SPR-7692
Add getSource() method to ResolvableType and TypeDescriptor allowing
access to the underlying source field or method parameter when possible.
Primarily added to provide access to additional type information or
meta-data that alternative JVM languages may provide.
Issue: SPR-10887
Update EvaluationException to expose the toDetailedString() method as
the exception message. The simple message can now be accessed via the
new getSimpleMessage() method.
Issue: SPR-10938
Including ScriptEvaluator implementations for JSR-223, Groovy and BeanShell. BeanShell consistently receives the bean ClassLoader now. Also revised ScriptFactory and its implementations for varargs.
Issue: SPR-11007
DefaultListableBeanFactory performs a fallback check for autowire candidates now, which GenericTypeAwareAutowireCandidateResolver implements to accept raw type matches if the target class has unresolvable type variables. Full generic matches are still preferred; the BeanFactory will only start looking for fallback matches if the first pass led to an empty result.
Issue: SPR-10993
Issue: SPR-11004
Introduce base class AbstractMethodMessageHandler for
HandlerMethod-based message handling.
Add MessageCondition interface for mapping conditions to messages
with support for combining type- and method-level annotation
conditions, the ability to match conditions to messages, and also
comparing matches to select the best match.
Issue: SPR-11024
The testDefaultConfig() method in MvcNamespaceTests creates a new Date()
in its test fixture but then performs an assertion against a hard coded
data string of "2013-10-21". This test therefore only passed yesterday,
on October 21, 2013.
This commit addresses this by changing the hard coded date string to one
based on the current date.
Issue: SPR-10665, SPR-8826
Support repeatable @PropertySource annotations in Java 8 and add
@PropertySources container annotation for Java 6/7. Also add an
ignoreResourceNotFound attribute to @PropertySource allowing missing
property resources to be silently ignored.
This commit also introduces some generally useful methods to
AnnotationUtils for working with @Repeatable annotations.
Issue: SPR-8371
The key contract is MvcUrls. An instance is automatically created with
the Spring MVC namespace and the MVC Java config but can also be easily
created in any configuration.
Some example tests can be found in DefaultMvcUrlsTests.
Issue: SPR-10665, SPR-8826
MvcUriComponentsBuilder allows creating URIs that point to Spring MVC
controller methods annotated with @RequestMapping. It builds them by
exposing a mock method invocation API similar to Mockito, records the
method invocations and thus builds up the URI by inspecting the mapping
annotations and the parameters handed into the method invocations.
Introduced a new SPI UriComponentsContributor that should be implemented
by HandlerMethodArgumentResolvers that actually contribute path segments
or query parameters to a URI. While the newly introduced
MvcUriComponentsBuilder looks up those UriComponentsContributor instances
from the MVC configuration.
The MvcUriComponentsBuilderFactory (name to be discussed - MvcUris maybe?)
prevents the multiple lookups by keeping the UriComponentsBuilder
instances in an instance variable. So an instance of the factory could
be exposed as Spring bean or through a HandlerMethodArgumentResolver to
be injected into Controller methods.
Issue: SPR-10665, SPR-8826