Reorder a few how-to sections

Closes gh-26262
This commit is contained in:
Phillip Webb 2021-05-18 11:54:04 -07:00
commit 1411cc3df7
11 changed files with 66 additions and 52 deletions

View File

@ -2527,7 +2527,7 @@ howto.spring-mvc.customize-view-resolvers
# 2 == Testing With Spring Security # 2 == Testing With Spring Security
howto-use-test-with-spring-security=\ howto-use-test-with-spring-security=\
howto.testing-with-spring-security howto.spring-mvc.testing.with-spring-security
# 2 == Jersey # 2 == Jersey
howto-jersey=\ howto-jersey=\
@ -2845,11 +2845,11 @@ howto.traditional-deployment.weblogic
# 2 == Use Jedis Instead of Lettuce # 2 == Use Jedis Instead of Lettuce
howto-use-jedis-instead-of-lettuce=\ howto-use-jedis-instead-of-lettuce=\
howto.jedis-instead-of-lettuce howto.nosql.jedis-instead-of-lettuce
# 2 == Use Testcontainers for integration testing # 2 == Use Testcontainers for integration testing
howto-testcontainers=\ howto-testcontainers=\
howto.testcontainers howto.testing.testcontainers

View File

@ -404,7 +404,7 @@ If you define your own `webDriver` scope you may find it stops working when you
If you have Spring Security on the classpath, `@WebMvcTest` will also scan `WebSecurityConfigurer` beans. If you have Spring Security on the classpath, `@WebMvcTest` will also scan `WebSecurityConfigurer` beans.
Instead of disabling security completely for such tests, you can use Spring Security's test support. Instead of disabling security completely for such tests, you can use Spring Security's test support.
More details on how to use Spring Security's `MockMvc` support can be found in this _<<howto#howto.testing-with-spring-security>>_ how-to section. More details on how to use Spring Security's `MockMvc` support can be found in this _<<howto#howto.testing.with-spring-security>>_ how-to section.
TIP: Sometimes writing Spring MVC tests is not enough; Spring Boot can help you run <<features#features.testing.spring-boot-applications.with-running-server, full end-to-end tests with an actual server>>. TIP: Sometimes writing Spring MVC tests is not enough; Spring Boot can help you run <<features#features.testing.spring-boot-applications.with-running-server, full end-to-end tests with an actual server>>.

View File

@ -23,8 +23,6 @@ include::howto/webserver.adoc[]
include::howto/spring-mvc.adoc[] include::howto/spring-mvc.adoc[]
include::howto/testing-with-spring-security.adoc[]
include::howto/jersey.adoc[] include::howto/jersey.adoc[]
include::howto/http-clients.adoc[] include::howto/http-clients.adoc[]
@ -45,10 +43,8 @@ include::howto/security.adoc[]
include::howto/hotswapping.adoc[] include::howto/hotswapping.adoc[]
include::howto/testing.adoc[]
include::howto/build.adoc[] include::howto/build.adoc[]
include::howto/traditional-deployment.adoc[] include::howto/traditional-deployment.adoc[]
include::howto/jedis-instead-of-lettuce.adoc[]
include::howto/testcontainers.adoc[]

View File

@ -1,5 +1,12 @@
[[howto.jedis-instead-of-lettuce]] [[howto.nosql]]
== Use Jedis Instead of Lettuce == NoSQL
Spring Boot offers a number of starters that support NoSQL technologies.
This section answers questions that arise from using NoSQL with Spring Boot.
[[howto.nosql.jedis-instead-of-lettuce]]
=== Use Jedis Instead of Lettuce
By default, the Spring Boot starter (`spring-boot-starter-data-redis`) uses https://github.com/lettuce-io/lettuce-core/[Lettuce]. By default, the Spring Boot starter (`spring-boot-starter-data-redis`) uses https://github.com/lettuce-io/lettuce-core/[Lettuce].
You need to exclude that dependency and include the https://github.com/xetorthio/jedis/[Jedis] one instead. You need to exclude that dependency and include the https://github.com/xetorthio/jedis/[Jedis] one instead.
Spring Boot manages both of these dependencies so you can switch to Jedis without specifying a version. Spring Boot manages both of these dependencies so you can switch to Jedis without specifying a version.

View File

@ -1,23 +0,0 @@
[[howto.testcontainers]]
== Use Testcontainers for integration testing
The https://www.testcontainers.org/[Testcontainers] library provides a way to manage services running inside Docker containers.
It integrates with JUnit, allowing you to write a test class that can start up a container before any of the tests run.
Testcontainers is especially useful for writing integration tests that talk to a real backend service such as MySQL, MongoDB, Cassandra etc.
Testcontainers can be used in a Spring Boot test as follows:
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/howto/testcontainers/vanilla/MyIntegrationTests.java[]
----
This will start up a docker container running Neo4j (if Docker is running locally) before any of the tests are run.
In most cases, you will need to configure the application using details from the running container, such as container IP or port.
This can be done with a static `@DynamicPropertySource` method that allows adding dynamic property values to the Spring Environment.
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/howto/testcontainers/dynamicproperties/MyIntegrationTests.java[]
----
The above configuration allows Neo4j-related beans in the application to communicate with Neo4j running inside the Testcontainers-managed Docker container.

View File

@ -1,13 +0,0 @@
[[howto.testing-with-spring-security]]
== Testing With Spring Security
Spring Security provides support for running tests as a specific user.
For example, the test in the snippet below will run with an authenticated user that has the `ADMIN` role.
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/howto/testingwithspringsecurity/MySecurityTests.java[]
----
Spring Security provides comprehensive integration with Spring MVC Test and this can also be used when testing controllers using the `@WebMvcTest` slice and `MockMvc`.
For additional details on Spring Security's testing support, refer to Spring Security's {spring-security-docs}#test[reference documentation]).

View File

@ -0,0 +1,47 @@
[[howto.testing]]
== Testing
Spring Boot includes a number of testing utilities and support classes as well as a dedicated starter that provides common test dependencies.
This section answers common questions about testing.
[[howto.testing.with-spring-security]]
=== Testing With Spring Security
Spring Security provides support for running tests as a specific user.
For example, the test in the snippet below will run with an authenticated user that has the `ADMIN` role.
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/howto/testing/withspringsecurity/MySecurityTests.java[]
----
Spring Security provides comprehensive integration with Spring MVC Test and this can also be used when testing controllers using the `@WebMvcTest` slice and `MockMvc`.
For additional details on Spring Security's testing support, refer to Spring Security's {spring-security-docs}#test[reference documentation]).
[[howto.testing.testcontainers]]
=== Use Testcontainers for Integration Testing
The https://www.testcontainers.org/[Testcontainers] library provides a way to manage services running inside Docker containers.
It integrates with JUnit, allowing you to write a test class that can start up a container before any of the tests run.
Testcontainers is especially useful for writing integration tests that talk to a real backend service such as MySQL, MongoDB, Cassandra etc.
Testcontainers can be used in a Spring Boot test as follows:
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/howto/testing/testcontainers/vanilla/MyIntegrationTests.java[]
----
This will start up a docker container running Neo4j (if Docker is running locally) before any of the tests are run.
In most cases, you will need to configure the application using details from the running container, such as container IP or port.
This can be done with a static `@DynamicPropertySource` method that allows adding dynamic property values to the Spring Environment.
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/howto/testing/testcontainers/dynamicproperties/MyIntegrationTests.java[]
----
The above configuration allows Neo4j-related beans in the application to communicate with Neo4j running inside the Testcontainers-managed Docker container.

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.docs.howto.testcontainers.dynamicproperties; package org.springframework.boot.docs.howto.testing.testcontainers.dynamicproperties;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.testcontainers.containers.Neo4jContainer; import org.testcontainers.containers.Neo4jContainer;

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.docs.howto.testcontainers.vanilla; package org.springframework.boot.docs.howto.testing.testcontainers.vanilla;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.testcontainers.containers.Neo4jContainer; import org.testcontainers.containers.Neo4jContainer;

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.docs.howto.testingwithspringsecurity; package org.springframework.boot.docs.howto.testing.withspringsecurity;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.docs.howto.testingwithspringsecurity; package org.springframework.boot.docs.howto.testing.withspringsecurity;
class UserController { class UserController {