diff --git a/applications/spring-shell/src/test/java/org/springframework/sbm/BootUpgrade_27_30_IntegrationTest.java b/applications/spring-shell/src/test/java/org/springframework/sbm/BootUpgrade_27_30_IntegrationTest.java index 26cb3cfb8..271a7313c 100644 --- a/applications/spring-shell/src/test/java/org/springframework/sbm/BootUpgrade_27_30_IntegrationTest.java +++ b/applications/spring-shell/src/test/java/org/springframework/sbm/BootUpgrade_27_30_IntegrationTest.java @@ -19,9 +19,13 @@ import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.openrewrite.maven.MavenParser; +import org.openrewrite.maven.tree.Dependency; +import org.openrewrite.maven.tree.MavenResolutionResult; import org.openrewrite.xml.tree.Xml; import java.nio.file.Path; +import java.util.List; +import java.util.Optional; import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; @@ -48,6 +52,34 @@ void migrateSimpleApplication() { verifyConstructorBindingRemoval(); verifyCrudRepoAddition(); verifyAutoConfigurationIsRefactored(); + verifyEhCacheVersionIsUpgraded(); + } + + private void verifyEhCacheVersionIsUpgraded() { + String pomContent = loadFile(Path.of("pom.xml")); + + Xml.Document mavenAsXMLDocument = parsePom(pomContent); + + List dependencies = mavenAsXMLDocument + .getMarkers() + .findFirst(MavenResolutionResult.class) + .get() + .getPom() + .getRequestedDependencies(); + + Optional ehcacheResult = dependencies + .stream() + .filter(dependency -> dependency.getArtifactId().equals("ehcache")) + .findFirst(); + + assertThat(ehcacheResult).isPresent(); + + Dependency ehcacheDependency = ehcacheResult.get(); + + assertThat(ehcacheDependency.getArtifactId()).isEqualTo("ehcache"); + assertThat(ehcacheDependency.getGav().getGroupId()).isEqualTo("org.ehcache"); + assertThat(ehcacheDependency.getGav().getVersion()).isNull(); + assertThat(ehcacheDependency.getClassifier()).isEqualTo("jakarta"); } private void verifyAutoConfigurationIsRefactored() { diff --git a/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30/README.md b/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30/README.md new file mode 100644 index 000000000..500c74c90 --- /dev/null +++ b/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30/README.md @@ -0,0 +1,8 @@ +**Features used in the current project** + +* ehcache in pom is mentioned this helps validate our migration to spring 3 where ehcache classifier has to be used to resolve version. +* Uses Constructor binding on classes which will be removed when migrating to Spring 3 +* Uses PagingAndSortingRepo interface where CrudRepo has been removed. +* Uses properties that will be removed/moved on spring 3 migration +* Uses micrometer packages which are moved to a new structure. + diff --git a/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30/pom.xml b/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30/pom.xml index ae435e540..3a1f59d30 100644 --- a/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30/pom.xml +++ b/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30/pom.xml @@ -26,6 +26,10 @@ io.micrometer micrometer-registry-prometheus + + org.ehcache + ehcache + org.springframework.boot spring-boot-starter-data-jpa diff --git a/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30/src/main/java/org/springboot/example/ehcache/EventLogger.java b/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30/src/main/java/org/springboot/example/ehcache/EventLogger.java new file mode 100644 index 000000000..883e58b7f --- /dev/null +++ b/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30/src/main/java/org/springboot/example/ehcache/EventLogger.java @@ -0,0 +1,11 @@ +package org.springboot.example.ehcache; + +import org.ehcache.event.CacheEvent; +import org.ehcache.event.CacheEventListener; + +public class EventLogger implements CacheEventListener { + @Override + public void onEvent(CacheEvent cacheEvent) { + System.out.println("My ehcache event listener is called"); + } +} diff --git a/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30/src/main/java/org/springboot/example/upgrade/StudentRepoReactiveSorting.java b/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30/src/main/java/org/springboot/example/upgrade/StudentRepoReactiveSorting.java index bcf258179..5ea9eee45 100644 --- a/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30/src/main/java/org/springboot/example/upgrade/StudentRepoReactiveSorting.java +++ b/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30/src/main/java/org/springboot/example/upgrade/StudentRepoReactiveSorting.java @@ -1,6 +1,5 @@ package org.springboot.example.upgrade; -import org.springframework.data.repository.reactive.ReactiveCrudRepository; import org.springframework.data.repository.reactive.ReactiveSortingRepository; public interface StudentRepoReactiveSorting extends ReactiveSortingRepository { diff --git a/components/sbm-recipes-boot-upgrade/src/main/resources/recipes/boot-2.7-3.0-dependency-version-update.yaml b/components/sbm-recipes-boot-upgrade/src/main/resources/recipes/boot-2.7-3.0-dependency-version-update.yaml index 76ef74370..ae17856f1 100644 --- a/components/sbm-recipes-boot-upgrade/src/main/resources/recipes/boot-2.7-3.0-dependency-version-update.yaml +++ b/components/sbm-recipes-boot-upgrade/src/main/resources/recipes/boot-2.7-3.0-dependency-version-update.yaml @@ -40,6 +40,13 @@ displayName: Upgrade to Spring Data 3.0 description: 'Upgrade to Spring Data to 3.0 from any prior version.' recipeList: + - org.openrewrite.maven.ChangeDependencyClassifier: + groupId: org.ehcache + artifactId: ehcache + newClassifier: jakarta + - org.openrewrite.maven.ChangeDependencyVersion: + dependencyPattern: org.ehcache:ehcache + newVersion: 3.10.0 - org.openrewrite.maven.UpgradeParentVersion: groupId: org.springframework.boot artifactId: spring-boot-starter-parent