16
16
package org .springframework .sbm .parsers ;
17
17
18
18
import org .apache .maven .project .MavenProject ;
19
+ import org .intellij .lang .annotations .Language ;
19
20
import org .junit .jupiter .api .DisplayName ;
20
21
import org .junit .jupiter .api .Test ;
21
22
import org .junit .jupiter .api .io .TempDir ;
22
23
23
24
import java .nio .file .Files ;
24
25
import java .nio .file .Path ;
26
+ import java .util .ArrayList ;
27
+ import java .util .List ;
28
+
29
+ import static org .assertj .core .api .Assertions .assertThat ;
25
30
26
31
/**
27
32
* @author Fabian Krüger
@@ -31,23 +36,19 @@ class MavenProjectFactoryTest {
31
36
@ Test
32
37
@ DisplayName ("Factory should create fully initialized MavenProject" )
33
38
void factoryShouldCreateFullyInitializedMavenProject (@ TempDir Path tempDir ) throws Exception {
39
+ @ Language ("xml" )
34
40
String pomXml = """
35
41
<?xml version="1.0" encoding="UTF-8"?>
36
42
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
37
43
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
38
44
<modelVersion>4.0.0</modelVersion>
39
- <parent>
40
- <groupId>org.springframework.boot</groupId>
41
- <artifactId>spring-boot-starter-parent</artifactId>
42
- <version>2.7.1</version>
43
- <relativePath/> <!-- lookup parent from repository -->
44
- </parent>
45
45
<groupId>com.example</groupId>
46
- <artifactId>demo-spring-song-app </artifactId>
46
+ <artifactId>the-example </artifactId>
47
47
<version>0.0.1-SNAPSHOT</version>
48
+ <name>the-name</name>
48
49
<properties>
49
50
<java.version>11</java.version>
50
- <spring-cloud .version>2021.0.4 </spring-cloud .version>
51
+ <spring-boot .version>3.1.2 </spring-boot .version>
51
52
</properties>
52
53
<repositories>
53
54
<repository>
@@ -64,55 +65,24 @@ void factoryShouldCreateFullyInitializedMavenProject(@TempDir Path tempDir) thro
64
65
<dependencies>
65
66
<dependency>
66
67
<groupId>org.springframework.boot</groupId>
67
- <artifactId>spring-boot-starter-web</artifactId>
68
- </dependency>
69
- <dependency>
70
- <groupId>org.ehcache</groupId>
71
- <artifactId>ehcache</artifactId>
68
+ <artifactId>spring-boot-starter</artifactId>
72
69
</dependency>
73
70
<dependency>
74
- <groupId>org.springframework.boot</groupId>
75
- <artifactId>spring-boot-starter-data-jpa</artifactId>
76
- </dependency>
77
- <dependency>
78
- <groupId>com.h2database</groupId>
79
- <artifactId>h2</artifactId>
80
- <scope>runtime</scope>
81
- </dependency>
82
- <dependency>
83
- <groupId>org.hibernate.validator</groupId>
84
- <artifactId>hibernate-validator</artifactId>
85
- </dependency>
86
-
87
-
88
- <dependency>
89
- <groupId>com.github.tomakehurst</groupId>
90
- <artifactId>wiremock-jre8</artifactId>
91
- <version>2.35.0</version>
92
- </dependency>
93
- <dependency>
94
- <groupId>org.apache.johnzon</groupId>
95
- <artifactId>johnzon-core</artifactId>
96
- </dependency>
97
- <dependency>
98
- <groupId>org.projectlombok</groupId>
99
- <artifactId>lombok</artifactId>
100
- </dependency>
101
- <dependency>
102
- <groupId>org.springframework.boot</groupId>
103
- <artifactId>spring-boot-starter-test</artifactId>
71
+ <groupId>javax.validation</groupId>
72
+ <artifactId>validation-api</artifactId>
73
+ <version>2.0.1.Final</version>
104
74
<scope>test</scope>
105
75
</dependency>
106
76
</dependencies>
107
77
<dependencyManagement>
108
78
<dependencies>
109
79
<dependency>
110
- <groupId>org.springframework.cloud </groupId>
111
- <artifactId>spring-cloud -dependencies</artifactId>
112
- <version>${spring-cloud .version}</version>
80
+ <groupId>org.springframework.boot </groupId>
81
+ <artifactId>spring-boot -dependencies</artifactId>
82
+ <version>${spring-boot .version}</version>
113
83
<type>pom</type>
114
84
<scope>import</scope>
115
- </dependency>
85
+ </dependency>
116
86
</dependencies>
117
87
</dependencyManagement>
118
88
<build>
@@ -123,25 +93,56 @@ void factoryShouldCreateFullyInitializedMavenProject(@TempDir Path tempDir) thro
123
93
</plugin>
124
94
</plugins>
125
95
</build>
126
-
127
96
</project>
128
97
""" ;
129
98
130
99
MavenPlexusContainerFactory plexusContainerFactory = new MavenPlexusContainerFactory ();
131
- MavenExecutionRequestFactory requestFactory = new MavenExecutionRequestFactory (
132
- new MavenConfigFileParser ()
133
- );
100
+ MavenExecutionRequestFactory requestFactory = new MavenExecutionRequestFactory (new MavenConfigFileParser ());
101
+ MavenExecutor mavenExecutor = new MavenExecutor (requestFactory , plexusContainerFactory );
134
102
MavenProjectFactory sut = new MavenProjectFactory (
135
- plexusContainerFactory ,
136
- new MavenExecutor (
137
- requestFactory ,
138
- plexusContainerFactory
139
- ),
140
- requestFactory
103
+ mavenExecutor
141
104
);
105
+
142
106
Path pomFile = tempDir .resolve ("pom.xml" );
143
107
Files .writeString (pomFile , pomXml );
144
108
MavenProject mavenProject = sut .createMavenProject (pomFile .toFile ());
109
+ assertThat (mavenProject .getName ()).isEqualTo ("the-name" );
110
+ assertThat (mavenProject .getArtifactId ()).isEqualTo ("the-example" );
111
+ assertThat (mavenProject .getGroupId ()).isEqualTo ("com.example" );
112
+
113
+ List <String > mainDeps = List .of (
114
+ tempDir .resolve ("target/classes" ).toString (),
115
+ dep ("org/springframework/boot/spring-boot-starter/3.1.2/spring-boot-starter-3.1.2.jar" ),
116
+ dep ("org/springframework/boot/spring-boot/3.1.2/spring-boot-3.1.2.jar" ),
117
+ dep ("org/springframework/spring-context/6.0.11/spring-context-6.0.11.jar" ),
118
+ dep ("org/springframework/spring-aop/6.0.11/spring-aop-6.0.11.jar" ),
119
+ dep ("org/springframework/spring-beans/6.0.11/spring-beans-6.0.11.jar" ),
120
+ dep ("org/springframework/spring-expression/6.0.11/spring-expression-6.0.11.jar" ),
121
+ dep ("org/springframework/boot/spring-boot-autoconfigure/3.1.2/spring-boot-autoconfigure-3.1.2.jar" ),
122
+ dep ("org/springframework/boot/spring-boot-starter-logging/3.1.2/spring-boot-starter-logging-3.1.2.jar" ),
123
+ dep ("ch/qos/logback/logback-classic/1.4.8/logback-classic-1.4.8.jar" ),
124
+ dep ("ch/qos/logback/logback-core/1.4.8/logback-core-1.4.8.jar" ),
125
+ dep ("org/slf4j/slf4j-api/2.0.7/slf4j-api-2.0.7.jar" ),
126
+ dep ("org/apache/logging/log4j/log4j-to-slf4j/2.20.0/log4j-to-slf4j-2.20.0.jar" ),
127
+ dep ("org/apache/logging/log4j/log4j-api/2.20.0/log4j-api-2.20.0.jar" ),
128
+ dep ("org/slf4j/jul-to-slf4j/2.0.7/jul-to-slf4j-2.0.7.jar" ),
129
+ dep ("jakarta/annotation/jakarta.annotation-api/2.1.1/jakarta.annotation-api-2.1.1.jar" ),
130
+ dep ("org/springframework/spring-core/6.0.11/spring-core-6.0.11.jar" ),
131
+ dep ("org/springframework/spring-jcl/6.0.11/spring-jcl-6.0.11.jar" ),
132
+ dep ("org/yaml/snakeyaml/1.33/snakeyaml-1.33.jar" )
133
+ );
134
+ assertThat (mavenProject .getCompileClasspathElements ()).containsExactlyInAnyOrder (mainDeps .toArray (new String []{}));
135
+
136
+ List <String > testDeps = new ArrayList <>();
137
+ testDeps .addAll (mainDeps );
138
+ testDeps .add (tempDir .resolve ("target/test-classes" ).toString ());
139
+ testDeps .add (dep ("javax/validation/validation-api/2.0.1.Final/validation-api-2.0.1.Final.jar" ));
140
+ assertThat (mavenProject .getTestClasspathElements ()).containsExactlyInAnyOrder (testDeps .toArray (new String []{}));
141
+ }
142
+
143
+ private String dep (String s ) {
144
+ Path m2Repo = Path .of (System .getProperty ("user.home" )).resolve (".m2/repository/" ).resolve (s );
145
+ return m2Repo .toString ();
145
146
}
146
147
147
148
0 commit comments