Commit Graph

1615 Commits

Author SHA1 Message Date
Sam Brannen 82f64f6a8d Polish contribution
See gh-23756
2019-10-23 12:34:51 +02:00
Drummond Dawson e73344fc71 Introduce sessionAttributeDoesNotExist in RequestResultMatchers
Analogous to the attributeDoesNotExist() method in ModelResultMatchers,
this commit introduces a new sessionAttributeDoesNotExist() method in
RequestResultMatchers which asserts that the given attributes are null
in the HttpSession.

Closes gh-23756
2019-10-23 12:28:08 +02:00
Sam Brannen 6fd50d7d17 Register EventPublishingTEL in JUnit 4 & TestNG base classes
Spring Framework 5.2 introduced an EventPublishingTestExecutionListener
in the Spring TestContext Framework. This listener is automatically
registered via the spring.factories mechanism; however, this listener is
not registered in the abstract JUnit 4 and TestNG base classes.

This commit addresses this oversight by explicitly registering the
EventPublishingTestExecutionListener in the following classes.

- AbstractJUnit4SpringContextTests
- AbstractTransactionalJUnit4SpringContextTests
- AbstractTestNGSpringContextTests
- AbstractTransactionalTestNGSpringContextTests

Closes gh-23748
2019-10-02 15:04:03 +02:00
Sam Brannen fc74c43718 Polishing 2019-10-02 14:49:23 +02:00
Sam Brannen 3a59b01be8 Polish Javadoc for abstract JUnit 4 and TestNG base classes 2019-10-02 14:26:50 +02:00
Sebastien Deleuze b24ac74106 Restore TransactionOperations Kotlin API compatibilty
This commit renames the Runnable variant to executeWithoutResult
and uses a Consumer<TransactionStatus> parameter for better
consistency with TransactionCallbackWithoutResult.

Closes gh-23724
2019-09-29 19:31:12 +02:00
Sam Brannen 06563d8b4b Add headerDoesNotExist() to MockRestRequestMatchers
Prior to this commit, one could not test for the absence of a specific
HTTP header in a request.

This commit adds a headerDoesNotExist() method in MockRestRequestMatchers.

Closes gh-23721
2019-09-27 17:38:11 +02:00
Sam Brannen 6186239287 Remove obsolete references to specific release versions in testing docs 2019-09-26 15:02:30 +02:00
Sam Brannen f05b4625de Merge branch '5.1.x' 2019-09-26 10:55:55 +02:00
Sam Brannen 7d126d3288 Improve documentation regarding "annotated classes"
See gh-23638
2019-09-26 10:26:36 +02:00
Juergen Hoeller 3616e96792 Upgrade to SLF4J 1.7.28, Groovy 2.5.8, RxJava 2.2.12, Joda-Time 2.10.4, Rome 1.12.2, OkHttp 3.14.3, Apache HttpClient 4.5.10, Apache Johnzon 1.1.13 2019-09-25 22:27:41 +02:00
Sebastien Deleuze 091c512f0d Upgrade to Coroutines 1.3.2
Closes gh-23663
2019-09-25 21:51:04 +02:00
Rossen Stoyanchev 2995b6f224 Merge branch '5.1.x' 2019-09-25 17:28:24 +01:00
Rossen Stoyanchev 17c423f5af Support for sameSite attribute in WebFlux
Bypass server cookie and write Set-Cookie header directly for Reactor
Netty, and Servlet API which do not provide options.

For Undertow use the sameSite attribute.

Closes gh-23693
2019-09-25 17:16:48 +01:00
Sebastien Deleuze a4b278a269 Polishing 2019-09-25 17:02:05 +02:00
Juergen Hoeller bd70f10d2b Merge branch '5.1.x'
# Conflicts:
#	build.gradle
#	spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java
#	spring-aspects/spring-aspects.gradle
#	spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java
#	spring-beans/src/main/java/org/springframework/beans/factory/support/GenericBeanDefinition.java
#	spring-beans/src/test/java/org/springframework/beans/factory/DefaultListableBeanFactoryTests.java
#	spring-orm/spring-orm.gradle
#	spring-test/spring-test.gradle
2019-09-25 12:43:24 +02:00
Juergen Hoeller b1ed0511f7 Upgrade to Tomcat 9.0.26, Undertow 2.0.26, Hibernate ORM 5.3.12
Includes Netty 4.1.39 (aligned with Reactor) and Checkstyle 8.24.
2019-09-25 12:15:02 +02:00
Juergen Hoeller bb6f9bb6d4 Polishing 2019-09-25 12:14:48 +02:00
Rossen Stoyanchev 30e1257dda Merge branch '5.1.x' 2019-09-24 13:39:42 +01:00
Rossen Stoyanchev 955000699a Add getRawStatusCode() to ExchangeResult
Closes gh-23630
2019-09-24 12:58:52 +01:00
Sam Brannen 4acd180fa3 Document that setting static final fields is unsupported
This commit updates the documentation for ReflectionUtils and
ReflectionTestUtils to point out that setting static final fields is
not supported.
2019-09-21 15:42:09 +02:00
Sam Brannen e1e072b75c Fix memory leak regression involving @Async methods
Spring Framework 5.2 M1 introduced a memory leak for applications using
@Async methods. Specifically, in a large test suite with multiple
ApplicationContexts that were closed (e.g., via @DirtiesContext,
@MockBean, or context cache eviction), the JVM process could run out of
memory.

Underlying cause: Due to a missing equals() implementation in Spring's
new AnnotationCandidateClassFilter, CGLIB's static cache of generated
classes indirectly retained references to BeanFactory instances for the
closed ApplicationContexts for the duration of the test suite.

This commit fixes this regression by introducing a proper equals()
implementation in AnnotationCandidateClassFilter. This commit also
introduces corresponding hashCode() and toString() implementations.

Closes gh-23571
2019-09-18 14:28:54 +02:00
Phillip Webb d945ae9191 Add blank line between java and javax imports
See gh-23539

Co-authored-by: Sam Brannen <sbrannen@pivotal.io>
2019-09-16 13:41:59 +02:00
Arjen Poutsma a65fd34801 Change raw status code range check in MockClientHttpResponse
This commit changes the raw status code check to allow for all three
digit numbers, not just those between 100 and 600.

See gh-23599
2019-09-16 09:52:03 +02:00
Sebastien Deleuze 7b4b64b8fb Fix UTF-8 handling in ContentResultMatchers
Closes gh-23622
2019-09-13 11:44:10 +02:00
Sam Brannen 8f38f5c17a Polishing 2019-09-12 11:35:30 +02:00
Sam Brannen d759ae772b Rename Spr3896SuiteTests to Spr3896TestSuite
This commit renames Spr3896SuiteTests to comply with our naming
convention for test classes that should be executed via the Gradle
build.

The effect of this commit is that test classes included in that "suite"
are no longer executed twice in the build. Consequently, Gradle and
Bamboo will now report the same number of executed tests for the
spring-test project.
2019-09-11 13:21:19 +02:00
Arjen Poutsma 13ba7ef701 Merge branch '5.1.x' 2019-09-11 10:43:43 +02:00
Arjen Poutsma b159ef6019 Make MockClientHttpResponse uses raw status code
This commit make sure that MockClientHttpResponse does not use
HttpStatus, but the raw status code.

Closes gh-23599
2019-09-11 10:41:01 +02:00
Sebastien Deleuze 5bb8c47b14 Rename fromObject to fromValue in BodyInserters
Closes gh-23587
2019-09-09 00:08:55 +02:00
Sam Brannen a7aecbb4dc Ensure spring-test test tasks are UP-TO-DATE
See also: 69214429df and eec183ef28
2019-09-05 15:06:12 +02:00
Phillip Webb deba2ed1b3 Add blank line between java and javax imports
See gh-23539
2019-09-04 22:05:46 -07:00
Juergen Hoeller f26866e4d4 Introduce getType variant with allowFactoryBeanInit flag
Closes gh-23374
2019-09-04 00:06:23 +02:00
Sam Brannen 670cbb9aed Simplify Gradle test task configuration
As an added bonus, AbstractViewTests is now executed in the build.
2019-09-03 12:40:59 +02:00
Sam Brannen 280a1b8880 Make AbstractWebRequestMatcherTests abstract 2019-09-03 12:13:56 +02:00
Sam Brannen 2c44eabe41 Remove unnecessary dependency declarations in spring-test 2019-09-03 12:13:56 +02:00
Brian Clozel d4089747b8 Use dependency management in Framework build
Prior to this commit, the Spring Framework build would partially use the
dependency management plugin to import and enforce BOMs.

This commit applies the dependency management plugin to all Java
projects and regroups all version management declaration in the root
`build.gradle` file (versions and exclusions).

Some versions are overridden in specific modules for
backwards-compatibility reasons or extended support.

This commit also adds the Gradle versions plugin that checks for
dependency upgrades in artifact repositories and produces a report; you
can use the following:

    ./gradlew dependencyUpdates
2019-09-02 18:01:09 +02:00
Sebastien Deleuze a2e740c896 Polishing 2019-09-02 16:37:42 +02:00
Sebastien Deleuze ca02cc1194 Migrate to AssertJ in Kotlin tests
Closes gh-23475
2019-09-02 15:59:26 +02:00
Sam Brannen 0f4dcb52ca Polishing 2019-09-02 12:34:06 +02:00
Sebastien Deleuze 57f0c2b7df Remove bodyWithType extension from WebTestClient
Since there is no more clash with the new bodyValue
method name.

See gh-23523
2019-08-31 11:40:44 +02:00
Sam Brannen ab779eb431 Preserve placeholders in @TestPropertySource locations
Prior to this commit, it was impossible to include a placeholder (i.e.,
${placeholder.name}) in a Properties file location configured via
@TestPropertySource if the placeholder was immediately followed by a
relative path (i.e., "../"). This was due to the fact that the location
was always cleaned using StringUtils.cleanPath(), which removed the
placeholder and the relative path syntax.

This commit fixes this by preserving all placeholders in
@TestPropertySource locations by simply not cleaning the locations if
they contain placeholders.

Closes gh-23544
2019-08-30 18:57:20 +02:00
Sam Brannen 9fa9a09007 Polishing 2019-08-30 18:56:03 +02:00
Sam Brannen 22494ba231 Ensure @ContextConfiguration & @TestPropertySource locations are cleaned
This commit ensures that locations to resources configured via
@ContextConfiguration & @TestPropertySource are consistently cleaned
using StringUtils.clean().

See gh-23544
2019-08-30 17:55:13 +02:00
Sam Brannen 793f9e3d29 Ensure SpringExtensionContextCacheTests are robust
... by explicitly ordering the test methods.
2019-08-30 16:22:54 +02:00
Sam Brannen 1ea6ce72bb Test status quo for relative paths & placeholders in @TestPropertySource
This commit introduces a collection of @Nested integration tests that
verify proper support for @TestPropertySource with explicit properties
files declared with absolute paths, relative paths, and placeholders in
the classpath and in the file system.

See gh-23544
2019-08-30 15:51:45 +02:00
Sam Brannen 7738e778fa Polishing 2019-08-30 15:51:44 +02:00
Sam Brannen c004ef888c Configure index in @ParameterizedTest display names
This commit prepends "[{index}] " to all custom display names
configured via @ParameterizedTest.

This provides better diagnostics between the "technical names" reported
on the CI server vs. the "display names" reported within a developer's
IDE.

See gh-23451
2019-08-28 17:06:23 +02:00
Sam Brannen aef67ea6bd Polishing 2019-08-27 17:42:00 +02:00
Sam Brannen b2ad16aaa7 Merge branch '5.1.x' 2019-08-27 17:37:25 +02:00
Sam Brannen 8189c90741 Allow Set-Cookie header to be overwritten in MockHttpServletResponse
Prior to this commit, there was no way to replace the Set-Cookie header
via MockHttpServletResponse. Specifically, an invocation of setHeader()
for the Set-Cookie header resulted in an additional Set-Cookie header
instead of replacing the existing one, which is in violation of the
contract for javax.servlet.http.HttpServletResponse.setHeader(...).

This commit refactors the internals of MockHttpServletResponse to ensure
that an existing Set-Cookie header is overwritten when set via an
invocation of setHeader(). This commit also verifies the expected
behavior for addHeader() and addCookie() with regard to multiple cookies.

Closes gh-23512
2019-08-27 17:20:38 +02:00
Sam Brannen ac760c8d4b Polish Javadoc for ReflectionTestUtils
Closes gh-23504
2019-08-23 16:38:35 +02:00
Sam Brannen 5ce75f3d08 Support static methods with ReflectionTestUtils.invokeMethod()
Prior to this commit, the invokeMethod() utility method in
ReflectionTestUtils only supported instance methods.

This commit brings the invokeMethod() support on par with the getField()
support by supporting the invocation of static methods via two new
invokeMethod() variants.

Closes gh-23504
2019-08-23 16:27:27 +02:00
Sam Brannen d4360db497 Polish ReflectionTestUtilsTests 2019-08-23 15:03:41 +02:00
Sam Brannen ad6231ad29 Add missing @Override annotations 2019-08-23 13:50:58 +02:00
Sam Brannen 05c270d916 Ensure TransactionalSqlScriptsSpringRuleTests is purely JUnit 4 2019-08-23 13:50:33 +02:00
John Lin 74de495574 Fix unmatched parentheses in @ContextHierarchy Javadoc
Closes gh-23487
2019-08-21 13:53:32 +02:00
Rossen Stoyanchev 274eab7c5d Merge branch '5.1.x' 2019-08-21 13:36:11 +03:00
Rossen Stoyanchev a7bb5ca473 Remove unnecessary iteration over headers
The use of LinkedCaseInsensitiveMap, going back to 3.0, makes it
unnecessary to iterate over keys which can cause
ConcurrentModificationException.

Closes gh-23460
2019-08-21 13:34:17 +03:00
Brian Clozel e9523161f0 Revert "Revert "Refactor Gradle tasks in Spring Framework build""
This reverts commit fb0d618751.
2019-08-20 20:26:43 +02:00
Stephane Nicoll fb0d618751 Revert "Refactor Gradle tasks in Spring Framework build"
This reverts commit 1539ba8991.
2019-08-20 20:07:11 +02:00
Brian Clozel 1539ba8991 Refactor Gradle tasks in Spring Framework build
This commit reorganizes tasks and scripts in the build to only apply
them where they're needed. We're considering here 3 "types" of projects
in our build:
* the root project, handling documentation, publishing, etc
* framework modules (a project that's published as a spring artifact)
* internal modules, such as the BOM, our coroutines support and our
integration-tests

With this change, we're strealining the project configuration for all
spring modules and only applying plugins when needed (typically our
kotlin support).

See gh-23282
2019-08-20 18:17:02 +02:00
Sam Brannen cf1bf3d98c Polish parameterized tests 2019-08-20 12:43:31 +02:00
Rossen Stoyanchev 26dc93d0f6 Polish body methods
WebClient, WebTestClient, and ServerResponse
2019-08-20 10:27:06 +03:00
Rossen Stoyanchev b75674f5e9 Polish method order 2019-08-20 10:27:05 +03:00
Rossen Stoyanchev 008687d5ae Rename body(Object) to bodyValue
The recently added body(Object) variant can be confused easily with
body(Publisher, Class) forgetting to provide the element type and
only running into the IllegalArgumentException at runtime.

See gh-23212
2019-08-20 10:27:05 +03:00
Sam Brannen 74ccfe3533 Polish Spring's internal TestGroup support 2019-08-19 15:21:16 +02:00
Sam Brannen 19ed439e4b Avoid Hamcrest 2.x deprecation warnings
See gh-23467
2019-08-18 09:30:50 +02:00
Sam Brannen 303fc3211c Upgrade to Hamcrest 2.1
Closes gh-23467
2019-08-17 18:44:54 +02:00
Sam Brannen 288461a541 Introduce @EnabledForTestGroups in Spring's test suite
Closes gh-23476
2019-08-17 14:47:24 +02:00
Sam Brannen 163b97f1ff Polish MockMvcWebClientBuilderTests
Inspired by the fact that example.com is currently not reachable from
my network.
2019-08-17 12:36:45 +02:00
Sam Brannen 5c1f93d9a6 Migrate spring-test test suite from JUnit 4 to JUnit Jupiter
This commit migrates the spring-test test suite from JUnit 4 to JUnit
Jupiter where applicable.

Tests specific to our JUnit 4 and TestNG support remain written using
those frameworks. In addition, some tests are still written in JUnit 4
if they extend a test class that should not be migrated to JUnit
Jupiter.

See gh-23451
2019-08-17 11:37:33 +02:00
Sam Brannen 979508a7f3 Remove JUnit 4 dependency from all modules except spring-test
This commit removes the JUnit 4 dependency from all modules except
spring-test which provides explicit JUnit 4 support.

This commit also includes the following.

- migration from JUnit 4 assertions to JUnit Jupiter assertions in all
  Kotlin tests
- migration from JUnit 4 assumptions in Spring's TestGroup support to
  JUnit Jupiter assumptions, based on org.opentest4j.TestAbortedException
- introduction of a new TestGroups utility class than can be used from
  existing JUnit 4 tests in the spring-test module in order to perform
  assumptions using JUnit 4's Assume class

See gh-23451
2019-08-17 11:37:21 +02:00
Sam Brannen 3f3e41923f Migrate rest of test suite from JUnit 4 to JUnit Jupiter
This commit migrates the rest of Spring's test suite to JUnit Jupiter,
except spring-test which will be migrated in a separate commit.

See gh-23451
2019-08-17 11:36:58 +02:00
Sam Brannen fabdb07e53 Redeclare default methods in AbstractTestExecutionListener
This commit redeclares default methods in AbstractTestExecutionListener
in order to make them inlinable.
2019-08-09 16:39:35 +02:00
Sam Brannen 50e5334378 Simplify assertions within MockMvc internals 2019-08-07 17:32:19 +02:00
Sam Brannen 5e61e33c66 Introduce SpringTestContextFrameworkTestSuite as a convenience in IDE 2019-08-01 18:49:55 +02:00
Phillip Webb a6021cc968 Rename SearchStrategy.EXHAUSTIVE to TYPE_HIERARCHY
Rename `SearchStrategy.EXHAUSTIVE` from `MergedAnnotations` to
`SearchStrategy.TYPE_HIERARCHY`

See gh-23378
2019-07-31 13:52:53 +01:00
Juergen Hoeller e6f86c5c75 Nullability refinements and related polishing 2019-07-31 13:45:48 +02:00
Phillip Webb 2ee1ce61c0 Add missing variants of getBeanNamesForType
Update `ListableBeanFactory` and `BeanFactoryUtils` to add the missing
`getBeanNamesForType` methods that accept a `ResolvableType` rather
than a `Class`.

This completes the work started in 778a01943b.

Closes gh-23335
2019-07-31 12:22:03 +02:00
Juergen Hoeller 3b235a098f Merge branch '5.1.x' 2019-07-30 22:52:20 +02:00
Juergen Hoeller 960079e5f5 Retain non-null HttpStatus return value in Client(Http)Response
See gh-23366
2019-07-30 22:26:46 +02:00
Arjen Poutsma ac9a11a581 Merge branch '5.1.x' 2019-07-30 18:03:01 +02:00
Arjen Poutsma 29ef985411 Add support for non-standard status codes
Added support for status codes that do not occur in HttpStatus in
DefaultClientResponseBuilder and made ClientResponse::statusCode
ClientHttpResponse::getStatusCode @Nullable.

Closed gh-23366
2019-07-30 17:44:47 +02:00
Juergen Hoeller 27aaad5a89 Add isTooEarly() method to StatusResultMatchers
See gh-23384
2019-07-30 17:37:26 +02:00
Juergen Hoeller 8ef557df2f Merge branch '5.1.x' 2019-07-30 17:34:29 +02:00
Juergen Hoeller c4622dbebc Polishing 2019-07-30 16:59:01 +02:00
Sam Brannen 027fd78306 Further refine @TestPropertySource merged annotation calls
See gh-23320
2019-07-29 22:53:15 +02:00
Phillip Webb c9479ff20f Refine @TestPropertySource merged annotation calls
See gh-23320
2019-07-29 22:53:00 +02:00
Sam Brannen c72bf10eb9 Polish MergedSqlConfig 2019-07-28 18:41:26 +02:00
Sam Brannen bfbe8f8780 Polish MergedTestPropertySources 2019-07-28 15:40:39 +02:00
Sam Brannen a37eaf75c4 Verify meta @TestPropertySource overrides meta-meta declaration
This commit introduces tests which verify that properties configured via
@TestPropertySource used as a meta-annotation override those configured
via @TestPropertySource used as a meta-meta-annotation.

See gh-23320
2019-07-28 12:35:57 +02:00
Sam Brannen 1954861844 Update @TestPropertySource Javadoc regarding "local" semantics
See gh-23320
2019-07-28 12:12:28 +02:00
Sam Brannen 136af0b164 Overhaul repeatable @TestPropertySource support
Prior to this commit, if multiple, directly present
`@TestPropertySource` annotations declared the same property, the
precedence ordering was top-down instead of bottom-up, in contrast to
the semantics for class hierarchies. In other words, a subsequent
`@TestPropertySource` annotation could not override a property in a
previous `@TestPropertySource` annotation.

This commit overhauls the internals of `TestPropertySourceUtils` in
order to provide proper support for property overrides within local,
directly present `@TestPropertySource` declarations.

Specifically, the `locations` and `properties` attributes from all
`@TestPropertySource` declarations that are directly present or
meta-present on a given class are now merged into a single instance of
`TestPropertySourceAttributes` internally, with assertions in place to
ensure that such "same level" `@TestPropertySource` declarations do not
configure different values for the `inheritLocations` and
`inheritProperties` flags. Effectively, all "same level"
`@TestPropertySource` declarations are treated internally as if there
were only one such annotation declared by the user.

See gh-23320
2019-07-27 22:30:34 +02:00
Anatoliy Korovin 2e476ca14f Support @TestPropertySource as a repeatable annotation
Prior to this commit, @TestPropertySource could not be declared as a
repeatable annotation. In addition, a local declaration of
@TestPropertySource would silently override a meta-present
@TestPropertySource.

This commit addresses this issue by introducing @TestPropertySources as
a container for @TestPropertySource. This commit also updates the
search and algorithms within TestPropertySourceUtils.

Closes gh-23320
2019-07-27 22:27:30 +02:00
Sam Brannen c3c152f806 Add multi-prefix comment support for @SqlConfig
gh-23289 introduced support for multiple single-line comment prefixes
for ScriptUtils, ResourceDatabasePopulator, and EmbeddedDatabaseBuilder.

This commit adds the same support for @SqlConfig in the TestContext
Framework. Specifically, @SqlConfig has a new `commentPrefixes`
attribute for setting multiple single-line comment prefixes.

Closes gh-23331
2019-07-24 12:01:14 +02:00
Sam Brannen d633cb3ad5 Polish @Sql tests 2019-07-22 18:28:52 +02:00
Sam Brannen d1570fd05b Fix copy-n-paste error in WebTestClient Javadoc 2019-07-22 18:16:46 +02:00
Sam Brannen fbe697061c Remove duplicate junit-bom configuration from spring-test.gradle
The junit-bom is already configured in build.gradle via "allprojects".
2019-07-21 20:40:53 +02:00
Sam Brannen 8ccf4a9072 Set testGroups system property for spring-test Gradle test tasks 2019-07-21 20:21:58 +02:00