Skip to content

Commit afda685

Browse files
✅ Add integration tests for BOM POMs
There are two newly added test scenarios. The first one covers a simple dependency that declares a BOM POM. The second one directly imports a BOM POM that has a parent POM. The reason why the second test does not include any effective dependency is to keep the test simple. I could not find any simple dependency that made use of any BOM POM that contained a parent POM, and all the use cases would result in big lockfiles. Assisted-by: Claude Sonnet <noreply@anthropic.com> Signed-off-by: Bruno Pimentel <bpimente@redhat.com>
1 parent 4ac0fba commit afda685

File tree

3 files changed

+154
-0
lines changed

3 files changed

+154
-0
lines changed

maven_plugin/src/test/java/it/IntegrationTestsIT.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,4 +741,50 @@ public void freezePluginDependencies(MavenExecutionResult result) throws Excepti
741741
}
742742
}
743743
}
744+
745+
@MavenTest
746+
public void bomPom(MavenExecutionResult result) throws Exception {
747+
// contract: the lockfile should contain BOM POMs in case any of the dependencies import them
748+
System.out.println("Running 'bomPom' integration test.");
749+
assertThat(result).isSuccessful();
750+
Path lockFilePath = findFile(result, "lockfile.json");
751+
assertThat(lockFilePath).exists();
752+
var lockFile = LockFile.readLockFile(lockFilePath);
753+
754+
var junitDep = lockFile.getDependencies().stream()
755+
.filter(dep -> dep.getGroupId().getValue().equals("org.junit.jupiter")
756+
&& dep.getArtifactId().getValue().equals("junit-jupiter-api"))
757+
.findFirst()
758+
.orElseThrow(() -> new AssertionError("junit-jupiter-api dependency not found"));
759+
760+
junitDep.getBoms().stream()
761+
.filter(bom -> bom.getGroupId().getValue().equals("org.junit")
762+
&& bom.getArtifactId().getValue().equals("junit-bom")
763+
&& bom.getVersion().getValue().equals("5.11.0"))
764+
.findFirst()
765+
.orElseThrow(() -> new AssertionError("junit-bom not found in dependency BOMs"));
766+
}
767+
768+
@MavenTest
769+
public void bomPomWithParent(MavenExecutionResult result) throws Exception {
770+
// contract: if a BOM POM has a parent POM, it should be resolved in the lockfile
771+
System.out.println("Running 'bomPomWithParent' integration test.");
772+
assertThat(result).isSuccessful();
773+
Path lockFilePath = findFile(result, "lockfile.json");
774+
assertThat(lockFilePath).exists();
775+
var lockFile = LockFile.readLockFile(lockFilePath);
776+
777+
var foundBom = lockFile.getBoms().stream()
778+
.filter(bom -> bom.getGroupId().getValue().equals("io.netty")
779+
&& bom.getArtifactId().getValue().equals("netty-bom")
780+
&& bom.getVersion().getValue().equals("4.1.125.Final"))
781+
.findFirst()
782+
.orElseThrow(() -> new AssertionError("junit-jupiter-api dependency not found"));
783+
784+
var parent = foundBom.getParent();
785+
786+
assertThat(parent.getGroupId().equals("org.sonatype.oss"));
787+
assertThat(parent.getArtifactId().equals("oss-parent"));
788+
assertThat(parent.getVersion().equals("7"));
789+
}
744790
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.example.app</groupId>
7+
<artifactId>maven-bom</artifactId>
8+
<version>1.0-SNAPSHOT</version>
9+
10+
<name>maven-bom</name>
11+
12+
<properties>
13+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
14+
<maven.compiler.release>17</maven.compiler.release>
15+
</properties>
16+
17+
<dependencyManagement>
18+
<dependencies>
19+
<dependency>
20+
<groupId>org.junit</groupId>
21+
<artifactId>junit-bom</artifactId>
22+
<version>5.11.0</version>
23+
<type>pom</type>
24+
<scope>import</scope>
25+
</dependency>
26+
</dependencies>
27+
</dependencyManagement>
28+
29+
<dependencies>
30+
<dependency>
31+
<groupId>org.junit.jupiter</groupId>
32+
<artifactId>junit-jupiter-api</artifactId>
33+
<scope>test</scope>
34+
</dependency>
35+
</dependencies>
36+
37+
<build>
38+
<plugins>
39+
<plugin>
40+
<groupId>io.github.chains-project</groupId>
41+
<artifactId>maven-lockfile</artifactId>
42+
<version>@project.version@</version>
43+
<executions>
44+
<execution>
45+
<goals>
46+
<goal>generate</goal>
47+
</goals>
48+
</execution>
49+
</executions>
50+
<configuration>
51+
<checksumMode>local</checksumMode>
52+
<includeMavenPlugins>false</includeMavenPlugins>
53+
</configuration>
54+
</plugin>
55+
</plugins>
56+
</build>
57+
</project>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.example.app</groupId>
7+
<artifactId>maven-bom</artifactId>
8+
<version>1.0-SNAPSHOT</version>
9+
10+
<name>maven-bom-parent</name>
11+
12+
<properties>
13+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
14+
<maven.compiler.release>17</maven.compiler.release>
15+
</properties>
16+
17+
<dependencyManagement>
18+
<dependencies>
19+
<!-- Declares "org.sonatype.oss:oss-parent:7" as parent -->
20+
<dependency>
21+
<groupId>io.netty</groupId>
22+
<artifactId>netty-bom</artifactId>
23+
<version>4.1.125.Final</version>
24+
<type>pom</type>
25+
<scope>import</scope>
26+
</dependency>
27+
</dependencies>
28+
</dependencyManagement>
29+
30+
<build>
31+
<plugins>
32+
<plugin>
33+
<groupId>io.github.chains-project</groupId>
34+
<artifactId>maven-lockfile</artifactId>
35+
<version>@project.version@</version>
36+
<executions>
37+
<execution>
38+
<goals>
39+
<goal>
40+
generate</goal>
41+
</goals>
42+
</execution>
43+
</executions>
44+
<configuration>
45+
<checksumMode>local</checksumMode>
46+
<includeMavenPlugins>false</includeMavenPlugins>
47+
</configuration>
48+
</plugin>
49+
</plugins>
50+
</build>
51+
</project>

0 commit comments

Comments
 (0)