Commit Graph

1438 Commits

Author SHA1 Message Date
Stephane Nicoll
3d5003ad63 Introduce TestGenerationContext
This commit polishes DefaultGenerationContext to make the method
that flushes generated classes more explicit. It now throws an
IOException and TestGenerationContext has been updated to handle
that to ease its use in code that can't throw such an exception.

As this use case is likely to happen outside the Spring Framework,
this commit adds such a convenience to spring-test as well.

Closes gh-28877
2022-07-26 17:56:17 +02:00
Sam Brannen
4f8516e2c3 Polishing 2022-07-15 18:24:55 +02:00
Sam Brannen
72e4a5f9fe Fix precondition check in TestClassScanner and improve Javadoc
- remove not-empty precondition check for packageNames so that the core
  scan() method can actually be used.
- document constructor
- document use case for packageNames
- add test that scan's all test classes in the spring-test project
- reduce logging due to the previous action item

See gh-28824
2022-07-15 17:10:47 +02:00
Sam Brannen
3fd72652be Fix @ExtendWith search in TestClassScanner
The search algorithm for @ExtendWith should not be tied to Spring's
@NestedTestConfiguration semantics. Rather, general JUnit annotation
search semantics should be used to find @ExtendWith.

See gh-28824
2022-07-15 16:46:39 +02:00
Sam Brannen
f5503298fb Handle missing dependencies for optional TestExecutionListener again
Commit d1b65f6d3e introduced a regression regarding the handling of
missing dependencies for optional (typically default)
TestExecutionListeners.

Prior to d1b65f6d3e a TestExecutionListener was instantiated using
java.lang.Class.newInstance() which never throws an
InvocationTargetException. With the switch to the new
SpringFactoriesLoader APIs, a TestExecutionListener is now instantiated
using java.lang.reflect.Constructor.newInstance(Object...) which can
throw an InvocationTargetException.

This commit addresses the regression by unwrapping the target exception
in an InvocationTargetException.

See gh-28666
Closes gh-28828
2022-07-15 13:50:32 +02:00
Sam Brannen
9962aa00a0 Introduce TestClassScanner to locate Spring test classes for AOT processing
This commit introduces the TestClassScanner which scans provided
classpath roots for Spring integration test classes using the JUnit
Platform Launcher API which allows all registered TestEngines to
discover tests according to their own rules.

The scanner currently detects the following categories of Spring
integration test classes.

- JUnit Jupiter: classes that register the SpringExtension via
  @ExtendWith.
- JUnit 4: classes that register the SpringJUnit4ClassRunner or
  SpringRunner via @RunWith.
- Generic: classes that are annotated with @ContextConfiguration or
  @BootstrapWith.

The scanner has been tested with the following TestEngine
implementations for the JUnit Platform.

- JUnit Jupiter
- JUnit Vintage
- JUnit Platform Suite Engine
- TestNG Engine for the JUnit Platform

Closes gh-28824
2022-07-15 13:21:22 +02:00
rstoyanchev
bf63309d05 Allow empty path in MockMvc
Closes gh-28823
2022-07-14 12:50:57 +01:00
Sam Brannen
dc0f0c77c9 Merge branch '5.3.x' 2022-07-12 13:05:24 +02:00
Sam Brannen
31a9694fc8 Improve Javadoc for ContextCache#clearStatistics()
See gh-28795
2022-07-12 13:04:34 +02:00
Marc Wrobel
92b8e99cbc Fix and improve Javadoc in spring-test
Closes gh-28795
2022-07-12 12:55:59 +02:00
Sam Brannen
033d9d09e4 Merge branch '5.3.x' 2022-06-30 16:56:43 +02:00
Sam Brannen
9ea45697ac Support cookie comments in MockHttpServletResponse and MockCookie
Prior to this commit, if a cookie was added to MockHttpServletResponse,
the comment attribute was not included in the generated Set-Cookie
header. In addition, MockCookie.parse(String) did not support the
Comment attribute.

This commit addresses both of these issues.

Closes gh-28730
2022-06-30 16:51:43 +02:00
rstoyanchev
b312eca391 Deprecate and set trailingSlash option to false
Closes gh-28552
2022-06-29 16:09:10 +01:00
rstoyanchev
14fd2605a3 Deprecate UrlPathHelper shortcuts on AbstractHandlerMapping
Given the availability of two alternatives mechanisms for URL path
matching, PathPatternParser and AntPathMatcher, and now that
parsed patterns are enabled by default, it makes sense to reduce the
proliferation of options on AbstractHandlerMapping by deprecating
shortcuts related to String path matching. Most applications rely
on Boot and on the MVC config to do all this.

See gh-28607
2022-06-29 13:04:22 +01:00
rstoyanchev
92cf1e13e8 Enable use of parsed patterns by default in Spring MVC
Closes gh-28607
2022-06-29 10:17:27 +01:00
rstoyanchev
8a9b082d8a Improve MappingMatch determination in mock request
MockHttpServletRequest now checks the requestURI and servletPath to
check whether they imply a Servlet path mapping, which is the case
when the requestURI is longer than the contextPath + servletPath.

This is essential when parsed patterns are in use in which case the
request path is parsed taking into account only the requestURI and
the contextPath. However, if the MappingMatch indicates a match by
Servlet path, then the servletPath is also taken into account.

See gh-28607
2022-06-29 10:17:07 +01:00
rstoyanchev
9c2ad4a1b1 Improve forwarded URL support in HtmlUnit integration
Closes gh-28722
2022-06-29 10:16:45 +01:00
Sam Brannen
d1b65f6d3e Stop using SpringFactoriesLoader.loadFactoryNames() in spring-test
Since SpringFactoriesLoader.loadFactoryNames() will be deprecated in
gh-27954, this commit removes the use of it in the spring-test module.

Specifically, this commit removes the protected
getDefaultTestExecutionListenerClasses() and
getDefaultTestExecutionListenerClassNames() methods from
AbstractTestContextBootstrapper and replaces them with a new protected
getDefaultTestExecutionListeners() method that makes use of new APIs
introduced in SpringFactoriesLoader for 6.0.

Third-party subclasses of AbstractTestContextBootstrapper that have
overridden or used getDefaultTestExecutionListenerClasses() or
getDefaultTestExecutionListenerClassNames() will therefore need to
migrate to getDefaultTestExecutionListeners() in Spring Framework 6.0.

Closes gh-28666
2022-06-24 20:03:50 +02:00
Sam Brannen
b5c0c6d53d Merge branch '5.3.x'
# Conflicts:
#	spring-test/src/main/java/org/springframework/test/web/servlet/request/MockMvcRequestBuilders.java
2022-06-15 15:12:34 +02:00
Sam Brannen
fb1fa073a6 Polishing 2022-06-15 15:07:58 +02:00
Sam Brannen
e9806a96dc Polish contribution and introduce test
See gh-28631
2022-06-15 15:07:58 +02:00
Johnny Lim
9b93508374 Add MockMvcRequestBuilders.multipart(HttpMethod, String, Object...)
See gh-28545
Closes gh-28631
2022-06-15 14:09:59 +02:00
rstoyanchev
875ee546e5 Merge branch '5.3.x' 2022-06-08 10:43:36 +01:00
rstoyanchev
7c47b470ff MockMvc allows HttpMethod input for multipart request
Closes gh-28545
2022-06-08 10:07:52 +01:00
Sam Brannen
90e0bd146a Merge branch '5.3.x'
# Conflicts:
#	spring-test/src/main/java/org/springframework/test/context/ContextConfiguration.java
#	spring-test/src/main/java/org/springframework/test/context/TestPropertySource.java
#	spring-test/src/main/java/org/springframework/test/context/jdbc/Sql.java
#	spring-test/src/main/java/org/springframework/test/context/support/AbstractTestContextBootstrapper.java
2022-06-08 10:01:01 +02:00
Sam Brannen
479ef3f3fd Update documentation regarding nested test class support
Closes gh-28579
2022-06-08 09:52:42 +02:00
Sam Brannen
720261db26 Use List.of() and Set.of() where feasible 2022-05-30 18:42:48 +02:00
Sam Brannen
b629487b44 Polish Javadoc for MockFilterChain 2022-05-30 18:41:25 +02:00
Sam Brannen
bf8a54decf Switch focus to JUnit Jupiter in testing examples 2022-05-16 10:05:37 +02:00
Sam Brannen
5220410768 Update copyright date 2022-05-15 19:19:04 +02:00
Eddú Meléndez Gonzales
506b78f469 Use getHost instead of getContainerIpAddress in Redis examples
getContainerIpAddress is deprecated.

Closes gh-28461
2022-05-15 15:12:03 +02:00
Sam Brannen
eb50a6f4a0 Further polishing regarding JDK baseline upgrade
See gh-28440
2022-05-10 17:01:40 +02:00
Sam Brannen
91441ba653 Update copyright date 2022-05-09 20:27:32 +02:00
CharlieYu
432fce9db3 Polish Javadoc and inline comments
Closes gh-28426
2022-05-09 20:26:06 +02:00
rstoyanchev
8378af9e39 Polishing
See gh-28189
2022-05-09 19:01:10 +01:00
Sam Brannen
1fe394f11d Introduce predicate for searching enclosing classes in MergedAnnotations
Due to the deprecation of the TYPE_HIERARCHY_AND_ENCLOSING_CLASSES
search strategy (see gh-28079), this commit introduces a way for users
to provide a Predicate<Class<?>> that is used to decide when the
enclosing class for the class supplied to the predicate should be
searched.

This gives the user complete control over the "enclosing classes"
aspect of the search algorithm in MergedAnnotations.

- To achieve the same behavior as TYPE_HIERARCHY_AND_ENCLOSING_CLASSES,
  a user can provide `clazz -> true` as the predicate.

- To limit the enclosing class search to inner classes, a user can
  provide `ClassUtils::isInnerClass` as the predicate.

- To limit the enclosing class search to static nested classes, a user
  can provide `ClassUtils::isStaticClass` as the predicate.

- For more advanced use cases, the user can provide a custom predicate.

For example, the following performs a search on MyInnerClass within the
entire type hierarchy and enclosing class hierarchy of that class.

MergedAnnotations mergedAnnotations =
   MergedAnnotations.search(TYPE_HIERARCHY)
      .withEnclosingClasses(ClassUtils::isInnerClass)
      .from(MyInnerClass.class);

In addition, TestContextAnnotationUtils in spring-test has been
revised to use this new feature where feasible.

Closes gh-28207
2022-03-24 15:40:44 +01:00
Arjen Poutsma
28ac0d3883 Use HttpStatusCode interface
This commit contains changes made because of the introduction of
HttpStatusCode. In general, methods that used to return a HttpStatus
now return HttpStatusCode instead, and methods that returned raw status
codes are now deprecated.

See gh-28214
2022-03-23 12:49:38 +01:00
rstoyanchev
e7b97f5be7 Merge branch '5.3.x' into main 2022-03-16 09:27:43 +00:00
rstoyanchev
ee7f60000e Polishing contribution
Closes gh-28105
2022-03-16 05:56:47 +00:00
azzureman
f1fdc11fab Support custom HTTP status in MockClientHttpResponse
See gh-28105
2022-03-16 05:56:23 +00:00
Sam Brannen
c249b578b5 Merge branch '5.3.x' 2022-03-12 16:05:39 +01:00
Sam Brannen
d9c22e657f Document the effect of @DirtiesContext on test execution events
See gh-27757
2022-03-12 16:05:14 +01:00
Sam Brannen
0e7c7b444c Merge branch '5.3.x' 2022-03-10 19:28:51 +01:00
Sam Brannen
af977c0891 Improve documentation for @EnabledIf and @DisabledIf test support
Closes gh-28157
2022-03-10 19:27:41 +01:00
Sam Brannen
5119aafe4f Merge branch '5.3.x' 2022-03-06 17:52:21 +01:00
Sam Brannen
a2f02dbfc0 Improve documentation for TestContext events
This commit improves the documentation for test execution events,
especially with regard to the fact that, by default, a
BeforeTestClassEvent is not published for the first test class using a
particular ApplicationContext.

This commit also introduces tests that verify the default behavior and
the ability to change the default behavior with a custom
TestExecutionListener that eagerly loads the context.

Closes gh-27757
2022-03-06 17:51:49 +01:00
Sam Brannen
8c6d59aaaf Polish contribution
See gh-28014
2022-02-19 14:43:26 +01:00
a.yazychyan
c5c926726d Use enhanced switch expressions where feasible
Closes gh-28014
2022-02-19 14:34:05 +01:00
Sam Brannen
c1987e5b8c Merge branch '5.3.x' 2022-02-16 12:12:37 +01:00
Sam Brannen
3ac60147f3 Improve documentation for uri(URI) method in WebTestClient
Prior to this commit, it was not clear that a configured base URI would
not be applied when invoking uri(URI).

This commit adds a note to the Javadoc to clarify that behavior.

Closes gh-28058
2022-02-16 12:11:33 +01:00