mimeType is not a valid method on ContentResultMatche.
I have signed and agree to the terms of the SpringSource Individual
Contributor License Agreement.
- Consistent importing of org.junit.Assert.*;
- Proper declaration of expected exceptions via @Test(expected).
- Renamed SpEL ExpressionTestCase to AbstractExpressionTests.
- Formatting and test method naming conventions.
Prior to this commit several test classes named "*Test" were not
recognized as tests by the Gradle build. This is due to the configured
inclusion of '**/*Tests.*' which follows Spring's naming convention for
test classes.
This commit addresses this issue by:
- Renaming real test classes consistently to "*Tests".
- Renaming internal test classes to "*TestCase".
- Renaming @WebTest to @WebTestStereotype.
- Disabling broken tests in AnnoDrivenStaticEntityMockingControlTest.
- Modifying the Gradle build configuration so that classes ending in
either "*Tests" or "*Test" are considered test classes.
Issue: SPR-11384
SPR-11145 claims that ServletContextAware beans declared in an
ApplicationContext loaded for an integration test by the TestContext
framework (TCF) do not have their setServletContext() methods invoked
if the tests are executed manually using JUnit 4.11.
This commit verifies that such ServletContextAware beans are processed
properly regardless of how the test was launched. Specifically:
- A ServletContextAwareBean has been introduced.
- BasicAnnotationConfigWacTests has been retrofitted with a
ServletContextAwareBean in its context.
- ServletContextAwareBeanWacTests has been introduced to execute
BasicAnnotationConfigWacTests manually via JUnitCore.
Issue: SPR-11145
equalTo is not a valid method on JsonPathResultMatchers
I have signed and agree to the terms of the SpringSource Individual Contributor License Agreement.
Prior to this commit, a NoClassDefFoundError caught in
TestContextManager's retrieveTestExecutionListeners() method would be
handled differently for implicit default listeners (i.e., listeners not
declared via @TestExecutionListeners) and listeners explicitly declared
via @TestExecutionListeners. Specifically, a NoClassDefFoundError would
cause a test to fail for an explicitly declared TestExecutionListener
but not for an implicitly declared one.
This commit addresses this issue by:
- Always swallowing a NoClassDefFoundError for both implicitly and
explicitly declared TestExecutionListeners.
- Changing the log level from DEBUG to INFO to make such situations
more visible to the average end user.
Issue: SPR-11347
This commit deletes methods in RollbackForRequiredEjbTxDaoTestNGTests
that were unnecessarily redeclared. The redeclaration is required for
JUnit's @FixMethodOrder support but not for TestNG's built-in support
for dependent methods.
Issue: SPR-6132
This commit introduces transactional integration tests executing
against both JUnit and TestNG in the TestContext framework (TCF) using
@TransactionAttribute in EJBs instead of Spring’s @Transactional
annotation.
These tests disprove the claims raised in SPR-6132 by demonstrating that
transaction support in the TCF works as expected when a transactional
EJB method that is configured with TransactionAttribute.REQUIRES_NEW is
invoked. Specifically:
- The transaction managed by the TCF is suspended while such an EJB
method is invoked.
- Any work performed within the new transaction for the EJB method is
committed after the method invocation completes.
- The transaction managed by the TCF is resumed and subsequently
either rolled back or committed as necessary based on the
configuration of @Rollback and @TransactionConfiguration.
The configuration for the JUnit-based tests is straightforward and self
explanatory; however, the configuration for the TestNG tests is less
intuitive.
In order for the TCF to function properly, the developer must ensure
that test methods within a given TestNG test (whether defined locally,
in a superclass, or somewhere else in the suite) are executed in the
proper order. In a stand-alone test class this is straightforward;
however, in a test class hierarchy (or test suite) with dependent
methods, it is necessary to configure TestNG so that all methods within
an individual test are executed in isolation from test methods in other
tests. This can be achieved by configuring a test class to run in its
own uniquely identified suite (e.g., by annotating each concrete
TestNG-based test class with @Test(suiteName = "< Some Unique Suite
Name >")).
For example, without specifying a unique suite name for the TestNG
tests introduced in this commit, test methods will be executed in the
following (incorrect) order:
- CommitForRequiredEjbTxDaoTestNGTests.test1InitialState()
- CommitForRequiresNewEjbTxDaoTestNGTests.test1InitialState()
- RollbackForRequiresNewEjbTxDaoTestNGTests.test1InitialState()
- RollbackForRequiredEjbTxDaoTestNGTests.test1InitialState()
- CommitForRequiredEjbTxDaoTestNGTests.test2IncrementCount1()
The reason for this ordering is that test2IncrementCount1() depends on
test1InitialState(); however, the intention of the developer is that
the tests for an individual test class are independent of those in
other test classes. So by specifying unique suite names for each test
class, the following (correct) ordering is achieved:
- RollbackForRequiresNewEjbTxDaoTestNGTests.test1InitialState()
- RollbackForRequiresNewEjbTxDaoTestNGTests.test2IncrementCount1()
- RollbackForRequiresNewEjbTxDaoTestNGTests.test3IncrementCount2()
- CommitForRequiredEjbTxDaoTestNGTests.test1InitialState()
- CommitForRequiredEjbTxDaoTestNGTests.test2IncrementCount1()
- CommitForRequiredEjbTxDaoTestNGTests.test3IncrementCount2()
- RollbackForRequiredEjbTxDaoTestNGTests.test1InitialState()
- RollbackForRequiredEjbTxDaoTestNGTests.test2IncrementCount1()
- RollbackForRequiredEjbTxDaoTestNGTests.test3IncrementCount2()
- CommitForRequiresNewEjbTxDaoTestNGTests.test1InitialState()
- CommitForRequiresNewEjbTxDaoTestNGTests.test2IncrementCount1()
- CommitForRequiresNewEjbTxDaoTestNGTests.test3IncrementCount2()
See the JIRA issue for more detailed log output.
Furthermore, @DirtiesContext(classMode = ClassMode.AFTER_CLASS) has
been used in both the JUnit and TestNG tests introduced in this commit
in order to ensure that the in-memory database is reinitialized between
each test class.
Issue: SPR-6132
The ServletTestExecutionListener is now prepended to the set of default
listeners in AbstractJUnit4SpringContextTests and
AbstractTestNGSpringContextTests.
Issue: SPR-11340
This commit makes the logging in TransactionalTestExecutionListener
consistent for both starting and ending transactions. Specifically,
the current TestContext is now included in the informational log
statement when starting a new transaction.
Issue: SPR-11323
When adding headers generically, MockHttpServletRequestBuilder now
recognizes Content-Type and updates the contentType field accordingly.
Issue: SPR-11308
Prior to this commit, some unit tests were using
Spring's Jackson 1.x implementations. Now Jackson
2.x implementations are the default ones used in
unit tests.
Even if Jackson 1.x support is deprecated, Jackson 1.x
unit tests are kept.
Issue: SPR-11121
This change splits out an abstract base class from DefaultMockMvcBuilder
with StandaloneMockMvcBuilder switching to extend the new abstract class
(rather than DefaultMockMvcBuilder).
Issue: SPR-11238
- Completed Javadoc for MetaAnnotationUtils.
- Added Javadoc notes to multiple annotations in the TCF, pointing out
which annotations can be used as meta-annotations.
Issue: SPR-11109
This commit fixes a bug introduced in the last commit.
ServletTestExecutionListener (STEL) now tracks whether it has already
populated the RequestContextHolder.
Issue: SPR-11144
The previous commit for issue SPR-11144 revealed a bug in
ServletTestExecutionListener (STEL). Specifically, STEL acted on the
fact that the ApplicationContext for a given TestContext was an
instance of WebApplicationContext. This behavior could potentially
break test code from previous releases of the Spring Framework that
relied on a custom setup of the RequestAttributes in the
RequestContextHolder with a custom WebApplicationContext ContextLoader.
This commit addresses this issue by ensuring that STEL only comes into
play if the test class is annotated with @WebAppConfiguration (for
prepareTestInstance() and beforeTestMethod()) or if the TestContext
attribute named RESET_REQUEST_CONTEXT_HOLDER_ATTRIBUTE is set to
Boolean.TRUE (for afterTestMethod()).
Issue: SPR-11144
Prior to this commit, the ServletTestExecutionListener did not
overwrite RequestAttributes in the RequestContextHolder if the
ApplicationContext associated with the given TestContext was not a
WebApplicationContext; however, the ServletTestExecutionListener would
clear the RequestAttributes after every test method execution,
regardless of whether the context was a WebApplicationContext or not.
This behavior breaks backwards compatibility with integration tests
that managed the RequestAttributes in RequestContextHolder themselves.
This commit addresses this issue by introducing a TestContext attribute
named RESET_REQUEST_CONTEXT_HOLDER_ATTRIBUTE in
ServletTestExecutionListener. This attribute is used internally within
ServletTestExecutionListener to ensure that the RequestContextHolder is
only cleared (i.e., reset) if the ServletTestExecutionListener actually
populated the RequestContextHolder.
Issue: SPR-11144
Apply consistent styling to new classes introduced in Spring 4.0.
- Javadoc line wrapping, whitespace and formatting
- General code whitespace
- Consistent Assert.notNull messages
Prior to this commit, the Spring TestContext Framework (TCF) supported
the use of test-related annotations as meta-annotations for composing
custom test stereotype annotations; however, attributes in custom
stereotypes could not be used to override meta-annotation attributes.
This commit addresses this by allowing attributes from the following
annotations (when used as meta-annotations) to be overridden in custom
stereotypes.
- @ContextConfiguration
- @ActiveProfiles
- @DirtiesContext
- @TransactionConfiguration
- @Timed
- @TestExecutionListeners
This support depends on functionality provided by
AnnotatedElementUtils. See the 'Notes' below for further details and
ramifications.
Notes:
- AnnotatedElementUtils does not support overrides for the 'value'
attribute of an annotation. It is therefore not possible or not
feasible to support meta-annotation attribute overrides for some
test-related annotations.
- @ContextHierarchy, @WebAppConfiguration, @Rollback, @Repeat, and
@ProfileValueSourceConfiguration define single 'value' attributes
which cannot be overridden via Spring's meta-annotation attribute
support.
- Although @IfProfileValue has 'values' and 'name' attributes, the
typical usage scenario involves the 'value' attribute which is not
supported for meta-annotation attribute overrides. Furthermore,
'name' and 'values' are so generic that it is deemed unfeasible to
provide meta-annotation attribute override support for these.
- @BeforeTransaction and @AfterTransaction do not define any attributes
that can be overridden.
- Support for meta-annotation attribute overrides for @Transactional is
provided indirectly via SpringTransactionAnnotationParser.
Implementation Details:
- MetaAnnotationUtils.AnnotationDescriptor now provides access to the
AnnotationAttributes for the described annotation.
- MetaAnnotationUtils.AnnotationDescriptor now provides access to the
root declaring class as well as the declaring class.
- ContextLoaderUtils now retrieves AnnotationAttributes from
AnnotationDescriptor to look up annotation attributes for
@ContextConfiguration and @ActiveProfiles.
- ContextConfigurationAttributes now provides a constructor to have its
attributes sourced from an instance of AnnotationAttributes.
- ContextLoaderUtils.resolveContextHierarchyAttributes() now throws an
IllegalStateException if no class in the class hierarchy declares
@ContextHierarchy.
- TransactionalTestExecutionListener now uses AnnotatedElementUtils to
look up annotation attributes for @TransactionConfiguration.
- Implemented missing unit tests for @Rollback resolution in
TransactionalTestExecutionListener.
- SpringJUnit4ClassRunner now uses AnnotatedElementUtils to look up
annotation attributes for @Timed.
- TestContextManager now retrieves AnnotationAttributes from
AnnotationDescriptor to look up annotation attributes for
@TestExecutionListeners.
- DirtiesContextTestExecutionListener now uses AnnotatedElementUtils to
look up annotation attributes for @DirtiesContext.
Issue: SPR-11038
This change fixes a timing issue in tests using Spring MVC Tests where
assertions on an async result may not wait long enough.
The fix involves the use of a new callback in MockAsyncContext that
allows tests to detect when an async dispatch has been invoked.
Issue: SPR-10838
@Rollback now supports ANNOTATION_TYPE as a target, allowing it to be
used as meta-annotation.
Note: this change was accidentally omitted from the original commit for
SPR-7827.
Issue: SPR-7827
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