16
16
17
17
package org .springframework .sbm ;
18
18
19
+ import org .jetbrains .annotations .NotNull ;
19
20
import org .junit .jupiter .api .Tag ;
20
21
import org .junit .jupiter .api .Test ;
22
+ import org .openrewrite .maven .MavenParser ;
23
+ import org .openrewrite .maven .tree .Dependency ;
24
+ import org .openrewrite .maven .tree .MavenResolutionResult ;
25
+ import org .openrewrite .xml .tree .Xml ;
26
+
27
+ import java .nio .file .Path ;
28
+ import java .util .List ;
29
+ import java .util .Optional ;
30
+
31
+ import static org .assertj .core .api .AssertionsForClassTypes .assertThat ;
21
32
22
33
public class BootUpgrade_27_30_MultiModule_IntegrationTest extends IntegrationTestBaseClass {
23
34
@ Override
@@ -35,6 +46,81 @@ void migrateMultiModuleApplication() {
35
46
applyRecipe ("boot-2.7-3.0-dependency-version-update" );
36
47
37
48
buildProject ();
49
+
50
+ verifyParentPomVersion ();
51
+ verifyEhCacheVersionIsUpgraded ();
52
+ }
53
+
54
+ private void verifyEhCacheVersionIsUpgraded () {
55
+ Optional <Dependency > ehcacheResult = getDependencyByArtifactId ("ehcache" , "spring-app/" );
56
+
57
+ assertThat (ehcacheResult ).isPresent ();
58
+
59
+ Dependency ehcacheDependency = ehcacheResult .get ();
60
+
61
+ assertThat (ehcacheDependency .getArtifactId ()).isEqualTo ("ehcache" );
62
+ assertThat (ehcacheDependency .getGav ().getGroupId ()).isEqualTo ("org.ehcache" );
63
+ assertThat (ehcacheDependency .getGav ().getVersion ()).isNull ();
64
+ assertThat (ehcacheDependency .getClassifier ()).isEqualTo ("jakarta" );
65
+ }
66
+
67
+ private Optional <Dependency > getDependencyByArtifactId (String artifactId , String module ) {
68
+ Xml .Document mavenAsXMLDocument = getBuildFileByModule (module );
69
+ List <Dependency > dependencies = getDependencies (mavenAsXMLDocument );
70
+ return dependencies
71
+ .stream ()
72
+ .filter (dependency -> dependency .getArtifactId ().equals (artifactId ))
73
+ .findFirst ();
74
+ }
75
+
76
+ private List <Dependency > getDependencies (Xml .Document mavenAsXMLDocument ) {
77
+ return mavenAsXMLDocument
78
+ .getMarkers ()
79
+ .findFirst (MavenResolutionResult .class )
80
+ .get ()
81
+ .getPom ()
82
+ .getRequestedDependencies ();
83
+ }
84
+
85
+ private void verifyParentPomVersion () {
86
+ Xml .Document mavenAsXMLDocument = getRootBuildFile ();
87
+
88
+ Xml .Tag parentTag = mavenAsXMLDocument
89
+ .getRoot ()
90
+ .getChildren ("parent" ).get (0 );
91
+
92
+ String version = parentTag .getChildValue ("version" ).get ();
93
+
94
+ String groupId = parentTag .getChildValue ("groupId" ).get ();
95
+ String artifactId = parentTag .getChildValue ("artifactId" ).get ();
96
+
97
+ assertThat (version ).isEqualTo ("3.0.0-M3" );
98
+ assertThat (groupId ).isEqualTo ("org.springframework.boot" );
99
+ assertThat (artifactId ).isEqualTo ("spring-boot-starter-parent" );
100
+ }
101
+
102
+ @ NotNull
103
+ private Xml .Document getRootBuildFile () {
104
+ return parsePom (loadFile (Path .of ("pom.xml" )));
105
+ }
106
+
107
+ @ NotNull
108
+ private Xml .Document getBuildFileByModule (String app ) {
109
+
110
+ return parseSubmodulePom (loadFile (Path .of ("pom.xml" )), loadFile (Path .of (app + "pom.xml" )));
111
+ }
112
+
113
+
114
+ @ NotNull
115
+ private Xml .Document parsePom (String pomContent ) {
116
+ MavenParser mavenParser = new MavenParser .Builder ().build ();
117
+ return mavenParser .parse (pomContent ).get (0 );
118
+ }
119
+
120
+ @ NotNull
121
+ private Xml .Document parseSubmodulePom (String parentPom , String pomContent ) {
122
+ MavenParser mavenParser = new MavenParser .Builder ().build ();
123
+ return mavenParser .parse (parentPom , pomContent ).get (1 );
38
124
}
39
125
40
126
private void buildProject () {
0 commit comments