Fix remaining Java compiler warnings, mainly around missing
generics or deprecated code.
Also add the `-Werror` compiler option to ensure that any future
warnings will fail the build.
Issue: SPR-11064
Commit deba32cad9 upgraded the Servlet API mocks to Servlet 3.0;
however, not all of the Javadoc was updated accordingly.
This commit updates the remaining Javadoc with regard to Servlet 3.0 as
the baseline for mocks in the spring-test module.
In addition, this commit syncs up the mocks used for internal testing in
the spring-web module with the most current versions from spring-test.
Issue: SPR-11049
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
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
Prior to this commit, the uniqueness check for @ContextConfiguration
attributes within a @ContextHierarchy was performed at a single test
class level instead of against the merged configuration for all test
class levels in the test class hierarchy.
This commit addresses this issue by moving the uniqueness check
algorithm from resolveContextHierarchyAttributes() to
buildContextHierarchyMap() within ContextLoaderUtils.
Issue: SPR-10997
Prior to this commit, one could call the setStatus method on
this Mock object and update the response's status,
even though the sendError method had already been called.
According to the HttpServletResponse Javadoc, sendError() methods
commit the response; so the response can't be written after that.
This commit fixes MockHttpServletResponse's behavior; setStatus
methods do not update the status once the response has been
committed.
Issue: SPR-10414
This commit undoes the changes made in ec5d81e78e and ensures that the
getRequestURL() method in MockHttpServletRequest does not include the
String "null" for a null requestURI by first checking if the requestURI
contains text before including it in the composed URL.
Issue: SPR-10643
A getCookies method is now available on ServerHttpRequest with one
ServletServerCookie implementation that wraps a Servlet cookie.
The SockJS service makes use of this to check for an existing session
cookie in the request.
This commit refactors ContextLoaderUtilsTests into
AbstractContextLoaderUtilsTests and several specialized subclasses in
order to reduce to the growing complexity of ContextLoaderUtilsTests.
Prior to this commit, the active bean definition profiles to use when
loading an ApplicationContext for tests could only be configured
declaratively (i.e., via hard-coded values supplied to the 'value' or
'profiles' attribute of @ActiveProfiles).
This commit makes it possible to programmatically configure active bean
definition profiles in tests via a new ActiveProfileResolver interface.
Custom resolvers can be registered via a new 'resolver' attribute
introduced in @ActiveProfiles.
Overview of changes:
- Introduced a new ActiveProfilesResolver API.
- Added a 'resolver' attribute to @ActiveProfiles.
- Updated ContextLoaderUtils.resolveActiveProfiles() to support
ActiveProfilesResolvers.
- Documented these new features in the reference manual.
- Added new content to the reference manual regarding the
'inheritProfiles' attribute of @ActiveProfiles
- Removed the use of <lineannotation> Docbook markup in the testing
chapter of the reference manual for Java code examples in order to
allow comments to have proper syntax highlighting in the generated
HTML and PDF.
Issue: SPR-10338
The Javadoc for several methods in HttpSession specifies that an
IllegalStateException must be thrown if the method is called on an
invalidated session; however, Spring's MockHttpSession did not implement
this behavior consistently prior to this commit.
This commit therefore ensures that the following methods in
MockHttpSession properly throw an IllegalStateException as defined in
the Servlet specification.
- long getCreationTime()
- long getLastAccessedTime()
- Object getAttribute(String)
- Object getValue(String)
- Enumeration<String> getAttributeNames()
- String[] getValueNames()
- void setAttribute(String, Object)
- void putValue(String , Object)
- void removeAttribute(String)
- void removeValue(String)
- void invalidate()
- boolean isNew()
Issue: SPR-7659
Prior to this commit it was possible for the method and requestURI
fields in MockHttpServletRequest to be set to null.
This commit ensures that the method and requestURI fields are internally
stored as empty strings if the user sets them to a null value.
Issue: SPR-10643
Prior to this commit, MockHttpServletRequest.getRequestURL() always
included the server port number in the reconstructed request URL, even
for implicit ports (i.e., 80 and 443) and negative ports.
MockHttpServletRequest.getRequestURL() now omits the port number when
reconstructing a URL that has an implicit or negative port.
Issue: SPR-9726
This commit introduces a deleteFromTableWhere() convenience method in
AbstractTransactionalJUnit4SpringContextTests and
AbstractTransactionalTestNGSpringContextTests that delegates to the
recently introduced method of the same name in JdbcTestUtils.
Issue: SPR-10639
Change ContextHierarchyDirtiesContextTests to obtain beans whilst the
ApplicationContext is still open, rather than trying to obtain them
after the context has been closed.
This commit removes the use of @SuppressWarnings("deprecation") for
code in the spring-test module that no longer references deprecated code.
Issue: SPR-10499
This commit deletes the deprecated SimpleJdbcTestUtils class as well as
remaining usage of SimpleJdbcTemplate within the TestContext framework
and its test suite.
Issue: SPR-10499
This commit deletes the deprecated @ExpectedException and
@NotTransactional annotations, supporting code, and related Javadoc and
reference documentation.
Issue: SPR-10499
This commit removes the suppression of warnings in Servlet and Portlet
mocks since such suppression is no longer necessary with the upgrade to
version 3.0 of the Servlet specification.
MockServletContext.getMimeTypes now returns null if the Java Activation
Framework returns "application/octet-stream", which is the default
media type it returns if the mime type is unknown. This enforces the
contract for ServletContext.getMimeTypes (return null for uknown mime
types) but does mean "application/octet-stream" cannot be returned.
Issue: SPR-10334
Prior to this commit the Spring TestContext Framework supported creating
only flat, non-hierarchical contexts. There was no easy way to create
contexts with parent-child relationships.
This commit addresses this issue by introducing a new @ContextHierarchy
annotation that can be used in conjunction with @ContextConfiguration
for declaring hierarchies of application contexts, either within a
single test class or within a test class hierarchy. In addition,
@DirtiesContext now supports a new 'hierarchyMode' attribute for
controlling context cache clearing for context hierarchies.
- Introduced a new @ContextHierarchy annotation.
- Introduced 'name' attribute in @ContextConfiguration.
- Introduced 'name' property in ContextConfigurationAttributes.
- TestContext is now aware of @ContextHierarchy in addition to
@ContextConfiguration.
- Introduced findAnnotationDeclaringClassForTypes() in AnnotationUtils.
- Introduced resolveContextHierarchyAttributes() in ContextLoaderUtils.
- Introduced buildContextHierarchyMap() in ContextLoaderUtils.
- @ContextConfiguration and @ContextHierarchy may not be used as
top-level, class-level annotations simultaneously.
- Introduced reference to the parent configuration in
MergedContextConfiguration and WebMergedContextConfiguration.
- Introduced overloaded buildMergedContextConfiguration() methods in
ContextLoaderUtils in order to handle context hierarchies separately
from conventional, non-hierarchical contexts.
- Introduced hashCode() and equals() in ContextConfigurationAttributes.
- ContextLoaderUtils ensures uniqueness of @ContextConfiguration
elements within a single @ContextHierarchy declaration.
- Introduced CacheAwareContextLoaderDelegate that can be used for
loading contexts with transparent support for interacting with the
context cache -- for example, for retrieving the parent application
context in a context hierarchy.
- TestContext now delegates to CacheAwareContextLoaderDelegate for
loading contexts.
- Introduced getParentApplicationContext() in MergedContextConfiguration
- The loadContext(MergedContextConfiguration) methods in
AbstractGenericContextLoader and AbstractGenericWebContextLoader now
set the parent context as appropriate.
- Introduced 'hierarchyMode' attribute in @DirtiesContext with a
corresponding HierarchyMode enum that defines EXHAUSTIVE and
CURRENT_LEVEL cache removal modes.
- ContextCache now internally tracks the relationships between contexts
that make up a context hierarchy. Furthermore, when a context is
removed, if it is part of a context hierarchy all corresponding
contexts will be removed from the cache according to the supplied
HierarchyMode.
- AbstractGenericWebContextLoader will set a loaded context as the
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE in the MockServletContext when
context hierarchies are used if the context has no parent or if the
context has a parent that is not a WAC.
- Where appropriate, updated Javadoc to refer to the
ServletTestExecutionListener, which was introduced in 3.2.0.
- Updated Javadoc to avoid and/or suppress warnings in spring-test.
- Suppressed remaining warnings in code in spring-test.
Issue: SPR-5613, SPR-9863