Commit Graph

723 Commits

Author SHA1 Message Date
Sam Brannen
d633cb3ad5 Polish @Sql tests 2019-07-22 18:28:52 +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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Sam Brannen
07e9f802f2 Fix tests
See gh-18490
2019-04-04 12:55:55 +02:00
Brian Clozel
65365d91c8 Fix tests
See gh-18490
2019-04-04 11:19:31 +02:00