Commit Graph

778 Commits

Author SHA1 Message Date
Rossen Stoyanchev
f4c847b723 MockHttpServletRequestBuilder sets content-length
Closes gh-23978
2019-11-12 17:33:14 +00:00
Rossen Stoyanchev
16c7a40c53 Minor refactoring
See gh-23296
2019-11-12 16:14:02 +00:00
Johannes Teklote
879b2df052 queryParam options for MockMVC requeusts
See gh-23296
2019-11-12 16:13:51 +00:00
Rossen Stoyanchev
347f16c8ac Polishing
See gh-2023
2019-11-11 15:04:36 +00:00
Pat Turner
6db8306e46 XpathResultMatcher supports Hamcrest Matcher NodeList
Use when xpath result is XPathConstants.NODESET
2019-11-11 15:04:36 +00:00
Sam Brannen
cb9d27b9b8 Polish contribution and fix build
See gh-1954
2019-11-09 12:45:02 +01:00
Rob Tompkins
cfb7777a07 Exception response for MockRestServiceServer
Closes gh-1954
2019-11-08 18:09:49 +00:00
Rossen Stoyanchev
5d2fc2fc32 HttpHandlerConnector uses non-blocking thread
Closes gh-23936
2019-11-06 21:58:02 +00:00
Sam Brannen
29599a93a4 Re-enable support for invalid Expires attributes in MockCookie
Changes introduced in commit 9b2087618b
caused a regression for Cookie support in MockHttpServletResponse.
Specifically, an Expires attribute that cannot be parsed using
`ZonedDateTime.parse()` now results in an exception; whereas,
previously an entry such as `Expires=0` was allowed.

This commit fixes this issue in MockCookie by catching and ignoring any
DateTimeException thrown while attempting to parse an Expires attribute.

Closes gh-23911
2019-11-06 18:28:28 +01:00
Sam Brannen
cef4478b7b Treat InvalidPathException like an IOException in MockServletContext
Prior to this commit, if MockServletContext was configured with a
FileSystemResourceLoader, invocations of the following methods on a
Microsoft Windows operating system resulted in an InvalidPathException
if the supplied path contained a colon (such as "C:\\temp"). This is
inconsistent with the behavior on non-Windows operating systems. In
addition, for comparable errors resulting in an IOException, those
methods (except getRealPath()) return null instead of throwing the
exception.

- getResourcePaths()
- getResource()
- getResourceAsStream()
- getRealPath()

This commit makes handling of InvalidPathException and IOException
consistent for these methods: both exceptions now result in null be
returned by these methods.

Closes gh-23717
2019-10-30 15:59:44 +01:00
Sam Brannen
ce0b012f43 Polish contribution
See gh-23769
2019-10-29 13:27:39 +01:00
Vedran Pavic
9b2087618b Preserve expires attribute in MockCookie
At present, MockCookie doesn't preserve expires attribute. This has a
consequence that a cookie value set using
MockHttpServletResponse#addHeader containing an expires attribute will
not match the cookie value obtained from
MockHttpServletResponse#getHeader, since the expires attribute will get
calculated based on current time.

This commit enhances MockCookie to preserve the expires attribute.

Closes gh-23769
2019-10-29 12:56:24 +01:00
Sam Brannen
5b6337b6a9 Clean up warning in spring-test 2019-10-24 13:55:26 +02:00
Sam Brannen
eabf357640 Polish MockMvc result matchers and tests 2019-10-23 14:03:50 +02:00
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
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
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
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
Sebastien Deleuze
7b4b64b8fb Fix UTF-8 handling in ContentResultMatchers
Closes gh-23622
2019-09-13 11:44:10 +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
Phillip Webb
deba2ed1b3 Add blank line between java and javax imports
See gh-23539
2019-09-04 22:05:46 -07:00
Sam Brannen
280a1b8880 Make AbstractWebRequestMatcherTests abstract 2019-09-03 12:13:56 +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
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
Sam Brannen
cf1bf3d98c Polish parameterized tests 2019-08-20 12:43:31 +02: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
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
5e61e33c66 Introduce SpringTestContextFrameworkTestSuite as a convenience in IDE 2019-08-01 18:49:55 +02:00
Juergen Hoeller
27aaad5a89 Add isTooEarly() method to StatusResultMatchers
See gh-23384
2019-07-30 17:37:26 +02:00