diff --git a/src/main/resources/META-INF/rewrite/spring-boot-40-modular-starters.yml b/src/main/resources/META-INF/rewrite/spring-boot-40-modular-starters.yml index 1d51573a8..824ad9291 100644 --- a/src/main/resources/META-INF/rewrite/spring-boot-40-modular-starters.yml +++ b/src/main/resources/META-INF/rewrite/spring-boot-40-modular-starters.yml @@ -102,6 +102,21 @@ recipeList: version: 4.0.x scope: test onlyIfUsing: org.springframework.test.web.servlet.MockMvc + # @WebFluxTest slice; keyed on specific types rather than the package, since the SB3 package's WebTestClient types belong to spring-boot-webtestclient and also serve MockMvc-backed tests + - org.openrewrite.java.dependencies.AddDependency: + groupId: org.springframework.boot + artifactId: spring-boot-starter-webflux-test + acceptTransitive: true + version: 4.0.x + scope: test + onlyIfUsing: org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest + - org.openrewrite.java.dependencies.AddDependency: + groupId: org.springframework.boot + artifactId: spring-boot-starter-webflux-test + acceptTransitive: true + version: 4.0.x + scope: test + onlyIfUsing: org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebFlux - org.openrewrite.java.dependencies.AddDependency: groupId: org.springframework.boot artifactId: spring-boot-starter-restclient @@ -405,6 +420,16 @@ recipeList: oldPackageName: org.springframework.boot.test.autoconfigure.web.servlet newPackageName: org.springframework.boot.webmvc.test.autoconfigure recursive: true + # spring-boot-webflux-test: the @WebFluxTest slice, type-by-type since the WebTestClient types below share the SB3 package but move to spring-boot-webtestclient instead + - org.openrewrite.java.ChangeType: + oldFullyQualifiedTypeName: org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest + newFullyQualifiedTypeName: org.springframework.boot.webflux.test.autoconfigure.WebFluxTest + - org.openrewrite.java.ChangeType: + oldFullyQualifiedTypeName: org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebFlux + newFullyQualifiedTypeName: org.springframework.boot.webflux.test.autoconfigure.AutoConfigureWebFlux + - org.openrewrite.java.ChangeType: + oldFullyQualifiedTypeName: org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTypeExcludeFilter + newFullyQualifiedTypeName: org.springframework.boot.webflux.test.autoconfigure.WebFluxTypeExcludeFilter # spring-boot-webtestclient (originating from spring-boot-test-autoconfigure and spring-boot-test) - org.openrewrite.java.ChangeType: oldFullyQualifiedTypeName: org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient diff --git a/src/test/java/org/openrewrite/java/spring/boot4/MigrateToModularStartersTest.java b/src/test/java/org/openrewrite/java/spring/boot4/MigrateToModularStartersTest.java index b55d49287..3251a9a91 100644 --- a/src/test/java/org/openrewrite/java/spring/boot4/MigrateToModularStartersTest.java +++ b/src/test/java/org/openrewrite/java/spring/boot4/MigrateToModularStartersTest.java @@ -333,6 +333,167 @@ class A { ); } + @Nested + class WebFluxTestSlice { + + @Test + void addWebFluxTestStarterIfWebFluxTestIsUsedForTest() { + rewriteRun( + mavenProject("project", + //language=xml + pomXml( + """ + + 4.0.0 + org.example + example + 1.0-SNAPSHOT + + + + """, + spec -> spec.after(pom -> assertThat(pom) + .contains("spring-boot-starter-webflux-test") + .contains("test") + .containsPattern("4\\.0\\.\\d+") + .actual()) + ), + srcTestJava( + //language=java + java( + """ + import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest; + + @WebFluxTest + class GreetingControllerTest { + } + """, + """ + import org.springframework.boot.webflux.test.autoconfigure.WebFluxTest; + + @WebFluxTest + class GreetingControllerTest { + } + """ + ) + ) + ) + ); + } + + @Test + void addWebFluxTestStarterIfAutoConfigureWebFluxIsUsedForTest() { + rewriteRun( + mavenProject("project", + //language=xml + pomXml( + """ + + 4.0.0 + org.example + example + 1.0-SNAPSHOT + + + + """, + spec -> spec.after(pom -> assertThat(pom) + .contains("spring-boot-starter-webflux-test") + .contains("test") + .containsPattern("4\\.0\\.\\d+") + .actual()) + ), + srcTestJava( + //language=java + java( + """ + import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebFlux; + + @AutoConfigureWebFlux + class GreetingIntegrationTest { + } + """, + """ + import org.springframework.boot.webflux.test.autoconfigure.AutoConfigureWebFlux; + + @AutoConfigureWebFlux + class GreetingIntegrationTest { + } + """ + ) + ) + ) + ); + } + + @Test + void doesNotAddWebFluxTestStarterForAutoConfigureWebTestClientUsage() { + rewriteRun( + mavenProject("project", + //language=xml + pomXml( + """ + + 4.0.0 + org.example + example + 1.0-SNAPSHOT + + + + """ + ), + srcTestJava( + //language=java + java( + """ + import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient; + + @AutoConfigureWebTestClient + class ApiIntegrationTest { + } + """, + """ + import org.springframework.boot.webtestclient.autoconfigure.AutoConfigureWebTestClient; + + @AutoConfigureWebTestClient + class ApiIntegrationTest { + } + """ + ) + ) + ) + ); + } + + @Test + void migrateWebFluxTestSliceTypes() { + rewriteRun( + //language=java + java( + """ + import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebFlux; + import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTypeExcludeFilter; + + @AutoConfigureWebFlux + class GreetingIntegrationTest { + WebFluxTypeExcludeFilter filter; + } + """, + """ + import org.springframework.boot.webflux.test.autoconfigure.AutoConfigureWebFlux; + import org.springframework.boot.webflux.test.autoconfigure.WebFluxTypeExcludeFilter; + + @AutoConfigureWebFlux + class GreetingIntegrationTest { + WebFluxTypeExcludeFilter filter; + } + """ + ) + ); + } + } + @Nested class MigrateActuateHealthPackage implements RewriteTest { @Override