Commit Graph

1607 Commits

Author SHA1 Message Date
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
Sam Brannen 69214429df Ensure aggregateTestReports task is UP-TO-DATE
Prior to this commit, the standard Gradle `test` task was configured to
execute all JUnit tests and had a dependency on the `testNG` task. In
addition, the `aggregateTestReports` task depended on the results of
the `test` and `testNG` tasks as input. Consequently, a subsequent
execution of the `aggregateTestReports` task would not be considered
UP-TO-DATE since the JUnit and TestNG results were both written to the
same "test" reports folder.

This commit introduces a new `junit` test task that allows JUnit and
TestNG test output to be completely independent. The standard `test`
task now depends on `junit` and `testNG` but does not execute any tests
itself, and the `aggregateTestReports` task now depends on the
individual `junit` and `testNG` results instead of on the mixed `test`
results.

See also: eec183ef28
2019-07-21 17:21:24 +02:00
Sam Brannen 89571ea236 Introduce @SqlMergeMode for configuring @Sql annotation merging
Closes gh-1835
2019-07-21 14:34:35 +02:00
Sam Brannen ab8876219f Polish contribution
See gh-1835
2019-07-21 13:26:55 +02:00
asympro d77b715d38 Merge class-level and method-level @Sql declarations
See gh-1835
2019-07-21 13:26:48 +02:00
Sebastien Deleuze c006a83584 Upgrade to Coroutines 1.3.0-RC
This commit upgrades Coroutines support to kotlinx.coroutines
1.3.0-RC, leverages the new Coroutines BOM and refine Coroutines
detection to avoid false positives.

Only Coroutines to Mono context interoperability is supported
for now.

CLoses gh-23326
2019-07-21 11:27:43 +02:00
Juergen Hoeller cdeb1fef5f Merge branch '5.1.x' 2019-07-20 18:23:00 +02:00
Juergen Hoeller 92890232df Upgrade to OpenPDF 1.2.21, Rome 1.12.1, XStream 1.4.11.1
Includes updated javadoc links for 5.1.x branch.
2019-07-20 18:20:03 +02:00
Sebastien Deleuze 095fd5bcb3 Use Kotlin BOM
Close gh-23316
2019-07-19 10:43:54 +02:00
Sam Brannen 8db73c80e2 Polish MockRestServiceServer internals regarding "effectively final" 2019-07-18 15:45:44 +02:00
Sam Brannen 42f033e439 Polish MockMvc internals regarding "effectively final" 2019-07-18 15:45:44 +02:00
Juergen Hoeller 94e3210ae7 Fix nullability warnings and javadoc-triggered package cycles 2019-07-17 22:34:07 +02:00
Sam Brannen e92cbe1938 Improve failure messages for redirect/forward in MockMvc 2019-07-17 16:53:47 +02:00
Scheidter,Ryan 84200f3141 Treat null path as non-matching pattern in AntPathMatcher
Prior to this commit, a null path supplied to the isPattern(), match(),
and matchStart() methods in AntPathMatcher resulted in a
NullPointerException.

This commit addresses this by treating a `null` path as a non-matching
pattern.

Closes gh-23297
2019-07-17 16:53:47 +02:00
Sebastien Deleuze b4a0e71ccc Polishing
See gh-23219
2019-07-16 18:46:36 +02:00
Sam Brannen b2b79ae1e6 Polish contribution
See gh-23219
2019-07-16 14:57:32 +02:00
Sebastien Deleuze adadffe0e1 Improve charset handling in MockHttpServletResponse
This commit adds a getContentAsString(Charset fallbackCharset) method
to MockHttpServletResponse in order to make it easier to get the content
in a specific charset like UTF-8 when the response charset has not been
explicitly set (by default ISO-8859-1 is used).

JsonPathResultMatchers leverages this new feature to support UTF-8
content out of the box.

Closes gh-23219
2019-07-16 11:44:16 +02:00
Sam Brannen 0aa5533dea Execute test suite in Gradle using JUnit Platform
Closes gh-23286
2019-07-13 19:13:33 +02:00
Sam Brannen 480b1e0a0d Run JUnit 4 tests in spring-test on the JUnit Platform
This commit simplifies the build for spring-test by running JUnit 4
tests and JUnit Jupiter tests together in the standard Gradle `test`
task.

As an added bonus, the ignored tests in SpringJUnit4ConcurrencyTests
and ClassLevelDisabledSpringRuleTests are now reported in the test
results.

See gh-23286
2019-07-13 18:24:37 +02:00
Sam Brannen 3cf5db6317 Exclude ParallelExecutionSpringExtensionTests.TestCase from build
Prior to this commit, ParallelExecutionSpringExtensionTests.TestCase
was accidentally included in the build which skewed the number of tests
in spring-test by 1000.
2019-07-12 18:21:45 +02:00
Sam Brannen 09c10232a4 Polishing
See gh-23224
2019-07-12 13:08:33 +02:00
Rob Winch fde92793b5 Fix http URLs
See gh-22839
2019-07-11 18:14:20 +02:00
Sam Brannen b5fba14ab8 Fix Checkstyle violation
Eclipse apparently sorts static imports differently.
2019-07-11 18:13:59 +02:00
Sam Brannen fc38bb4fc6 Change @TestConstructor.autowire attribute into an enum
Prior to this commit, @TestConstructor supported a boolean `autowire`
attribute which naturally limited the configuration to two states: on
or off. Since we may need to support additional autowiring modes in the
future, the use of a boolean is limiting.

This commit address this issue by introducing a new AutowireMode enum
in @TestConstructor with ALL and ANNOTATED constants. In addition, the
attribute has been renamed to `autowireMode`, and the system property
has been renamed to `spring.test.constructor.autowire.mode` for greater
clarity of purpose.

Closes gh-23224
2019-07-11 18:00:52 +02:00
Arjen Poutsma 2909de8829 Remove ServerWebExchange::getParts and ServerRequest::parts
Revert to state before DefaultMultipartMessageReader
2019-07-10 16:20:20 +02:00
Sebastien Deleuze ca75c2843a Upgrade to Coroutines 1.3.0-M2 2019-07-09 11:36:26 +02:00
Sebastien Deleuze 08a5196c3a Use elementClass and elementTypeRef consistently 2019-07-08 12:08:40 +02:00
Sebastien Deleuze 2b4d6ce354 Add body methods with Object parameter to WebFlux
The commit deprecates syncBody(Object) in favor of body(Object)
which has the same behavior in ServerResponse, WebClient and
WebTestClient. It also adds body(Object, Class) and
body(Object, ParameterizedTypeReference) methods in order to support
any reactive type that can be adapted to a Publisher via
ReactiveAdapterRegistry. Related BodyInserters#fromProducer
methods are provided as well.

Shadowed Kotlin body<T>() extensions are deprecated in favor of
bodyWithType<T>() ones, including dedicated Publisher<T> and
Flow<T> variants. Coroutines extensions are adapted as well, and
body(Object) can now be used with suspending functions.

Closes gh-23212
2019-07-07 22:27:57 +02:00
Juergen Hoeller e2d01bb783 Merge branch '5.1.x' 2019-06-22 17:11:31 +02:00
Juergen Hoeller 29dcd19971 Upgrade to AspectJ 1.9.4, RxJava 2.2.10, Jetty 9.4.19, Undertow 2.0.22
Includes Hibernate Validator 6.0.17 and renames "withoutJclOverSlf4j".
2019-06-22 16:49:40 +02:00
Arjen Poutsma 92981ac9de Add Flux<Part> ServerRequest.parts()
This commit introduces Flux<Part> ServerRequest.parts() that delegates
to ServerWebExchange.getParts() and offers an alternative,
streaming way of accessing multipart data.

Closes gh-23131
2019-06-21 10:59:13 +02:00
Sam Brannen ef6471fcbf Polish contribution
See gh-23141
2019-06-18 18:59:18 +03:00
RustyTheClone 72adc3d37e Support target type in MockMvcResultMatchers.jsonPath()
This commit introduces an overloaded jsonPath() method to specify a
target type to coerce into for MockMvcResultMatchers.

 - jsonPath(String, Matcher<T>, Class<T>)

Closes gh-23141
2019-06-18 18:57:27 +03:00
Sam Brannen 89ebdc766c Polishing 2019-06-18 18:53:47 +03:00
Sam Brannen 8ceac9c015 Document supported @Transactional attributes in the TCF
This commit documents which attributes in @Transactional are supported
for test-managed transactions in the Spring TestContext Framework (TCF).

Closes gh-23149
2019-06-18 14:34:28 +03:00
Juergen Hoeller 0a77477d32 Merge branch '5.1.x' 2019-06-12 18:16:30 +02:00
Juergen Hoeller fc46abf0b7 Polishing 2019-06-12 18:04:06 +02:00
Juergen Hoeller 7e02358166 Merge branch '5.1.x' 2019-06-12 00:05:01 +02:00
Juergen Hoeller 22aba8bf60 Upgrade to Apache HttpClient 4.5.9 2019-06-11 23:49:57 +02:00
Juergen Hoeller a89bfffd8c Merge branch '5.1.x' 2019-06-11 23:16:03 +02:00
Juergen Hoeller 7dc92aa05d Polishing 2019-06-11 20:57:27 +02:00
Sam Brannen dfbf742547 Polishing 2019-06-11 13:54:11 +03:00
Sam Brannen 59d070e12a Test JUnit Jupiter 5.5 @Timeout support with Spring transactions
See gh-23076
2019-06-10 17:57:56 +03:00
Sam Brannen e903bf440b Polishing 2019-06-06 17:57:14 +03:00
Sam Brannen 61bf45c86f Merge branch '5.1.x' 2019-06-06 17:40:51 +03:00
Ilya Lukyanovich 2ed81be831 Fix MockHttpServletRequest.setCookies to produce single cookie header
Prior to this commit, MockHttpServletRequest.setCookies() produced one
Cookie header per supplied cookie, resulting in multiple Cookie headers
which violates the specification.

This commit fixes this by ensuring that all cookie name-value pairs are
stored under a single Cookie header, separated by a semicolon.

Closes gh-23074
2019-06-06 17:13:21 +03:00
Sebastien Deleuze 098ac0bbb8 Annotate Object#equals parameter with @Nullable
Closes gh-23093
2019-06-06 14:18:30 +02:00
Сергей Цыпанов aaeabc3c85 Simplify iteration over maps
Closes gh-23053
2019-05-29 18:00:34 +02:00
Sam Brannen 4b9f5a35a6 Polish contribution 2019-05-27 11:22:11 +02:00
Сергей Цыпанов 6964ed33bf Allocate objects only when it's necessary
Closes gh-23036
2019-05-27 11:14:25 +02:00
Sam Brannen 4f4427f550 Migrate TestNG assertions to AssertJ
Migrate all existing TestNG based assertions to AssertJ and add
Checkstyle rules to ensure they don't return.

See gh-23022
2019-05-26 18:29:39 +02:00
Sam Brannen 50cc23ca55 Use the JUnit Platform Test Kit in spring-test 2019-05-26 14:28:09 +02:00
Phillip Webb 6b9160b3ae Restore transaction specific assertions
Revert 82d0e49d and instead create a `TransactionAssert` class.

Closes gh-23022
2019-05-24 11:09:44 -07:00
Sam Brannen 5a1217cafe Migrate JUnit Jupiter assertions to AssertJ
Migrate all existing JUnit Jupiter based assertions to AssertJ and add
Checkstyle rules to ensure they don't return.

See gh-23022
2019-05-24 18:50:01 +02:00
Phillip Webb 82d0e49de9 Inline methods from TransactionTestUtils
Delete `TransactionTestUtils` and inline AssertJ assertions
instead.

Closes gh-23022
2019-05-23 16:38:39 -07:00
Phillip Webb 9d74da006c Migrate JUnit 4 assertions to AssertJ
Migrate all existing JUnit 4 `assert...` based assertions to AssertJ
and add a checkstyle rule to ensure they don't return.

See gh-23022
2019-05-23 15:52:49 -07:00
Phillip Webb 95a9d46a87 Migrate Hamcrest assertions to AssertJ
Migrate all existing `assertThat(..., Matcher)` assertions to AssertJ
and add checkstyle rules to ensure they don't return.

See gh-23022
2019-05-23 15:49:59 -07:00
Phillip Webb 02850f357f Migrate exception checking tests to use AssertJ
Migrate tests that use `@Test(expectedException=...)` or
`try...fail...catch` to use AssertJ's `assertThatException`
instead.
2019-05-20 10:47:53 -07:00
Juergen Hoeller 9755b59197 Merge branch '5.1.x' 2019-05-13 18:05:07 +02:00
Juergen Hoeller 5910d2d4dc Add missing Nullable annotation to assertNotNull
See gh-22932
2019-05-13 18:03:01 +02:00
stsypanov 9ca8681f79 Iteration over a map using EntrySet 2019-05-13 15:38:13 +02:00
Sam Brannen 73dbd06361 Enforces static imports for JUnit 4 assertions and assumptions
This commit configures Checkstyle to enforces static imports for JUnit 4
assertions and assumptions.

See gh-22932
2019-05-12 15:13:07 +02:00
Sam Brannen da1b004254 Merge branch '5.1.x' 2019-05-11 18:21:44 +02:00
Sam Brannen e1b0bf22bf Polish Javadoc for AssertionErrors
See gh-22932
2019-05-11 18:21:06 +02:00
Sam Brannen 33fcde4c3e Merge branch '5.1.x' 2019-05-11 18:04:48 +02:00
Sam Brannen 233b225b4f Remove JUnit dependency from HeaderResultMatchers
Prior to this commit, HeaderResultMatchers had a direct dependency on
org.junit.Assert which forces JUnit 4 to be present on the classpath.

This commit fixes this by introducing assertNotNull() in
org.springframework.test.util.AssertionErrors and delegating to that
instead.

Fixes gh-22932
2019-05-11 18:03:42 +02:00
Sam Brannen 0cff7eb32c Fix Javadoc links 2019-05-10 17:40:03 +02:00
Phillip Webb 798b51f4a3 Migrate to BDD Mockito
Migrate all tests to consistently use BDD Mockito. Also add
checksyle rule to enforce going forwards.
2019-05-08 13:46:13 -07:00
Phillip Webb 816bbee8de Remove '.*' imports from tests
Organize test imports to expand all '.*' static imports into
fully qualified imports.

This update will allow us to use additional checkstyle rules in
the future, and will also help if we migrate fully to AssertJ.
2019-05-08 09:55:09 -07:00
Juergen Hoeller d3b713d5f0 Upgrade to Protobuf 3.7.1 and HtmlUnit 2.35 2019-05-08 17:52:56 +02:00
Sam Brannen 6a05b97df3 Log identity hash for ApplicationContext for context cache hits/misses
DefaultCacheAwareContextLoaderDelegate now logs the identity hash code
for an application context instance that was stored in or retrieved from
the context cache in the Spring TestContext Framework.

Closes gh-22925
2019-05-08 16:39:23 +02:00
Phil Webb d7320de871 Migrate away from ExpectedException (#22922)
* Add limited checkstyles to test code

Add a limited set of checkstyle rules to the test codebase to improve
code consistency.

* Fix checksyle violations in test code

* Organize imports to fix checkstyle for test code

* Migrate to assertThatExceptionOfType

Migrate aware from ExpectedException rules to AssertJ exception
assertions. Also include a checkstyle rules to ensure that the
the ExpectedException is not accidentally used in the future.

See gh-22894
2019-05-08 16:25:52 +02:00
Sam Brannen 77eef47483 Support automatic constructor injection in JUnit Jupiter
Prior to this commit, dependency injection of all arguments in a test
class constructor invoked by JUnit Jupiter was only possible if the
constructor was explicitly annotated with @Autowired.

This commit introduces support for a configurable "test constructor
autowire" mode which defaults to false in order to remain backwards
compatible.

Specifically, this mode can be configured globally for an entire test
suite via a new "spring.test.constructor.autowire" JVM system property
that can alternatively be configured via the SpringProperties
mechanism. In addition, the global "test constructor autowire" mode can
be overridden locally on a per-class basis via the new @TestConstructor
annotation.

Closes gh-22286
2019-05-08 14:51:43 +02:00
Sam Brannen d4379630e2 Use assertThat from Hamcrest instead of JUnit 4
org.junit.Assert.assertThat() is deprecated as of JUnit 4.13.

See gh-22894
2019-05-05 17:31:31 +02:00
Sam Brannen 772ef40920 Upgrade to JUnit 4.13-beta-3
See gh-22894
2019-05-05 16:56:48 +02:00
Juergen Hoeller ec8689d1fc Merge branch '5.1.x' 2019-05-03 14:23:59 +02:00
Juergen Hoeller 4e10735e8f MockHttpServletRequest restores default locale for empty accept header
Closes gh-22877
2019-05-03 14:08:12 +02:00
Juergen Hoeller 0be610b0ee Support for reactive transactions in TransactionInterceptor
Introduces TransactionManager marker interface for PlatformTransactionManager as well as ReactiveTransactionManager, allowing for a common configuration type in TransactionAspectSupport and TransactionManagementConfigurer.

Closes gh-22590
2019-05-02 16:23:48 +02:00
Sebastien Deleuze 89454e69c3 Deprecate MediaType.APPLICATION_JSON_UTF8
This commit deprecates MediaType.APPLICATION_JSON_UTF8 and
MediaType.APPLICATION_PROBLEM_JSON_UTF8 in favor of
MediaType.APPLICATION_JSON and MediaType.APPLICATION_PROBLEM_JSON since
UTF-8 encoding is now handled correctly by most browsers
(related bug has been fixed in Chrome since September 2017).

MediaType.APPLICATION_JSON is now used as the default JSON content type.

Closes gh-22788
2019-04-30 16:11:50 +02:00
Juergen Hoeller 55418b256d Merge branch '5.1.x' 2019-04-26 16:56:04 +02:00
Juergen Hoeller e5e2d2d661 Polishing (includes minor performance refinements from master) 2019-04-26 16:51:18 +02:00
Johnny Lim 33ac14f099 Add missing fail() calls in MockRestServiceServerTests
Closes gh-22836
2019-04-25 17:34:50 +03:00
Sam Brannen 4a090922d7 Polish Javadoc 2019-04-21 15:33:53 +02:00
Rossen Stoyanchev de3238dbea Merge branch '5.1.x' 2019-04-16 21:08:54 -04:00
Rossen Stoyanchev 5b711a964b Pass Mono to Reactor Netty when feasible
Closes gh-22800
2019-04-16 20:52:19 -04:00
Juergen Hoeller 44df98c82d Merge branch '5.1.x' 2019-04-12 11:37:07 +02:00
Juergen Hoeller b07d46da99 MockCookie compares attributes in case-insensitive manner
Closes gh-22786
2019-04-12 11:10:02 +02:00
Sam Brannen 7f58e395d3 Remove @Deprecated from org.springframework.mock.jndi package
This commit removes the @Deprecated declaration on the
org.springframework.mock.jndi package, since such usage results in a
compiler warning on JDK 9+ which breaks Spring's JDK 9 and JDK 11 CI
builds.

https://bugs.openjdk.java.net/browse/JDK-6481080

See gh-22779
2019-04-11 16:17:58 +02:00
Sam Brannen 88e3b84164 Deprecate mock JNDI support in the spring-test module
Closes gh-22779
2019-04-10 16:00:05 +02:00
Rossen Stoyanchev d1f888a7a9 Empty path mapping behaves consistently
An empty path mapping in an @RequestMapping now consistently matches to
empty paths regardless of whether there are both type and method level,
annotations, or method-level only.

Closes gh-22543
2019-04-09 15:03:43 -04:00
Sam Brannen cf5d0e6aa9 Introduce publishEvent() convenience method in TestContext
This commit introduces a publishEvent() method in the TestContext API
as a convenience for publishing an ApplicationEvent to the test's
ApplicationContext but only if the ApplicationContext is currently
available and with lazy creation of the ApplicationEvent.

For example, the beforeTestClass() method in
EventPublishingTestExecutionListener is now implemented as follows.

  public void beforeTestClass(TestContext testContext) {
      testContext.publishEvent(BeforeTestClassEvent::new);
  }

Closes gh-22765
2019-04-08 15:14:39 +02:00
Sam Brannen 353e092bf6 Register EventPublishingTestExecutionListener by default (round 2)
This commit registers the EventPublishingTestExecutionListener as a
default TestExecutionListener with an order of 10,000. This registers
the EventPublishingTestExecutionListener as the last listener provided
by the Spring Framework.

With EventPublishingTestExecutionListener registered with an order of
10,000, it is effectively wrapped by all other Spring listeners,
including support for @DirtiesContext and test-managed transactions.

Furthermore, this commit revises the implementation of
EventPublishingTestExecutionListener to take advantage of the new
TestContext#hasApplicationContext() support which allows the
EventPublishingTestExecutionListener to publish events only if the
test's ApplicationContext is currently available. This avoids
undesirable side-effects such as eager loading of the
ApplicationContext before it is needed or re-loading of the
ApplicationContext after it has been intentionally closed.

Closes gh-18490
2019-04-06 16:39:26 +02:00
Sam Brannen c3d0459a4e Add support to query if ApplicationContext is available in the TCF
This commit introduces support in the Spring TestContext Framework
(TCF) to query whether the test's ApplicationContext is available.

Specifically, this commit introduces the following two `default`
methods along with corresponding implementations in DefaultTestContext
and DefaultCacheAwareContextLoaderDelegate.

- `boolean hasApplicationContext()` in the TestContext API

- `boolean isContextLoaded(MergedContextConfiguration)` in the
  CacheAwareContextLoaderDelegate API

Closes gh-22756
2019-04-06 16:00:33 +02:00
Rossen Stoyanchev ed70978071 verify() fails if there are failed requests
Normally failed requests fail the test but they're suppressed for some
reason (e.g. in async callback) then verify should still correctly
report the failures.

Closes gh-21799
2019-04-04 16:49:46 -04:00
Sam Brannen 4be605eb1e Revert "Fix tests"
This reverts commit 07e9f802f2.
2019-04-04 19:10:58 +02:00
Sam Brannen d6ba5259d8 Revert "Register EventPublishingTestExecutionListener by default"
This reverts commit 86fb7362b1.
2019-04-04 19:10:58 +02:00
Sam Brannen a66e6d3231 Revert "Fix tests"
This reverts commit 65365d91c8.
2019-04-04 19:10:58 +02:00
Sam Brannen f7a5b3013e Revert "Register EventPublishingTestExecutionListener by default"
This reverts commit 13543f5e0f.
2019-04-04 19:10:58 +02:00
Juergen Hoeller 1741b6dcd9 Merge branch '5.1.x' 2019-04-04 16:12:07 +02:00
Juergen Hoeller 95232d5bf8 Upgrade to Apache HttpClient 4.5.8 and Jetty Reactive HttpClient 1.0.3 2019-04-04 16:10:16 +02:00
Sam Brannen 07e9f802f2 Fix tests
See gh-18490
2019-04-04 12:55:55 +02:00
Sam Brannen 86fb7362b1 Register EventPublishingTestExecutionListener by default
See gh-18490
2019-04-04 12:55:06 +02:00
Brian Clozel 65365d91c8 Fix tests
See gh-18490
2019-04-04 11:19:31 +02:00
Sam Brannen 13543f5e0f Register EventPublishingTestExecutionListener by default
Closes gh-18490
2019-04-03 18:31:16 +02:00
Sam Brannen d6173512fe Document test execution event support in the Reference Manual
Closes gh-18490
2019-04-03 18:18:39 +02:00
Brian Clozel 47c8d1de7b Avoid calling other bean methods in web config
This commit changes the main configuration classes for Spring MVC and
Spring WebFlux to not call other bean methods when setting up the web
infrastructure. This allows configuration classes extending
`DelegatingWebFluxConfiguration` and `DelegatingWebMvcConfiguration`
to opt-in the lite-mode, as introduced in gh-22461.
2019-04-03 10:16:41 +02:00
Brian Clozel 83ce8ad79a Fix checkstyle 2019-04-03 10:16:11 +02:00
Sam Brannen 5922642333 Document exception handling and async support for test events
This commit updates the class-level Javadoc for
EventPublishingTestExecutionListener in order to provide explicit
documentation for exception handling and async support.

See gh-18490
2019-04-02 20:31:58 +02:00
Sam Brannen f9d59570de URL Cleanup - polishing 2019-03-28 14:05:21 +01:00