diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/anchor-rewrite.properties b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/anchor-rewrite.properties index ecede55509..4d5b3dc9ac 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/anchor-rewrite.properties +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/anchor-rewrite.properties @@ -2527,7 +2527,7 @@ howto.spring-mvc.customize-view-resolvers # 2 == Testing With Spring Security howto-use-test-with-spring-security=\ -howto.testing-with-spring-security +howto.spring-mvc.testing.with-spring-security # 2 == Jersey howto-jersey=\ @@ -2845,11 +2845,11 @@ howto.traditional-deployment.weblogic # 2 == 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 howto-testcontainers=\ -howto.testcontainers +howto.testing.testcontainers diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/testing.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/testing.adoc index 5b5f928d25..2679586f50 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/testing.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/testing.adoc @@ -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. 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 _<>_ how-to section. +More details on how to use Spring Security's `MockMvc` support can be found in this _<>_ how-to section. TIP: Sometimes writing Spring MVC tests is not enough; Spring Boot can help you run <>. diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto.adoc index 24deb2d22a..76523555c9 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto.adoc @@ -23,8 +23,6 @@ include::howto/webserver.adoc[] include::howto/spring-mvc.adoc[] -include::howto/testing-with-spring-security.adoc[] - include::howto/jersey.adoc[] include::howto/http-clients.adoc[] @@ -45,10 +43,8 @@ include::howto/security.adoc[] include::howto/hotswapping.adoc[] +include::howto/testing.adoc[] + include::howto/build.adoc[] include::howto/traditional-deployment.adoc[] - -include::howto/jedis-instead-of-lettuce.adoc[] - -include::howto/testcontainers.adoc[] diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/jedis-instead-of-lettuce.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/nosql.adoc similarity index 81% rename from spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/jedis-instead-of-lettuce.adoc rename to spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/nosql.adoc index 7cea12e54e..c7be21231a 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/jedis-instead-of-lettuce.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/nosql.adoc @@ -1,5 +1,12 @@ -[[howto.jedis-instead-of-lettuce]] -== Use Jedis Instead of Lettuce +[[howto.nosql]] +== 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]. 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. diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/testcontainers.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/testcontainers.adoc deleted file mode 100644 index 03176988e8..0000000000 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/testcontainers.adoc +++ /dev/null @@ -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. diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/testing-with-spring-security.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/testing-with-spring-security.adoc deleted file mode 100644 index 74687f51b8..0000000000 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/testing-with-spring-security.adoc +++ /dev/null @@ -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]). diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/testing.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/testing.adoc new file mode 100644 index 0000000000..ab606af1fc --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/testing.adoc @@ -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. diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/testcontainers/dynamicproperties/MyIntegrationTests.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/testing/testcontainers/dynamicproperties/MyIntegrationTests.java similarity index 93% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/testcontainers/dynamicproperties/MyIntegrationTests.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/testing/testcontainers/dynamicproperties/MyIntegrationTests.java index 55ee89faa3..d49df7c750 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/testcontainers/dynamicproperties/MyIntegrationTests.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/testing/testcontainers/dynamicproperties/MyIntegrationTests.java @@ -14,7 +14,7 @@ * 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.testcontainers.containers.Neo4jContainer; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/testcontainers/vanilla/MyIntegrationTests.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/testing/testcontainers/vanilla/MyIntegrationTests.java similarity index 93% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/testcontainers/vanilla/MyIntegrationTests.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/testing/testcontainers/vanilla/MyIntegrationTests.java index 454b2f0cb1..30f4a5f719 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/testcontainers/vanilla/MyIntegrationTests.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/testing/testcontainers/vanilla/MyIntegrationTests.java @@ -14,7 +14,7 @@ * 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.testcontainers.containers.Neo4jContainer; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/testingwithspringsecurity/MySecurityTests.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/testing/withspringsecurity/MySecurityTests.java similarity index 94% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/testingwithspringsecurity/MySecurityTests.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/testing/withspringsecurity/MySecurityTests.java index d322bb7369..b932490b8a 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/testingwithspringsecurity/MySecurityTests.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/testing/withspringsecurity/MySecurityTests.java @@ -14,7 +14,7 @@ * 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; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/testingwithspringsecurity/UserController.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/testing/withspringsecurity/UserController.java similarity index 90% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/testingwithspringsecurity/UserController.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/testing/withspringsecurity/UserController.java index 19e24c032b..96fa823791 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/testingwithspringsecurity/UserController.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/testing/withspringsecurity/UserController.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.docs.howto.testingwithspringsecurity; +package org.springframework.boot.docs.howto.testing.withspringsecurity; class UserController {