Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,167 @@ class A {
);
}

@Nested
class WebFluxTestSlice {

@Test
void addWebFluxTestStarterIfWebFluxTestIsUsedForTest() {
rewriteRun(
mavenProject("project",
//language=xml
pomXml(
"""
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>example</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
</dependencies>
</project>
""",
spec -> spec.after(pom -> assertThat(pom)
.contains("<artifactId>spring-boot-starter-webflux-test</artifactId>")
.contains("<scope>test</scope>")
.containsPattern("<version>4\\.0\\.\\d+</version>")
.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(
"""
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>example</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
</dependencies>
</project>
""",
spec -> spec.after(pom -> assertThat(pom)
.contains("<artifactId>spring-boot-starter-webflux-test</artifactId>")
.contains("<scope>test</scope>")
.containsPattern("<version>4\\.0\\.\\d+</version>")
.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(
"""
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>example</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
</dependencies>
</project>
"""
),
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
Expand Down
Loading