This is an automated email from the ASF dual-hosted git repository.

fmariani pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-spring-boot.git

commit a7288d7200d03385fe77acdf198a5d1c071bbba0
Author: Croway <federico.mariani.1...@gmail.com>
AuthorDate: Wed Apr 16 18:26:29 2025 +0200

    Run itests using Spring Boot JUnit version in case of clash with the 
version declared by Camel
---
 pom.xml                                            |  2 +-
 tests/camel-itest-spring-boot/pom.xml              |  1 -
 .../itest/springboot/util/ArquillianPackager.java  | 43 ++++++++++++++++++++++
 .../src/test/resources/application-pom-sb3.xml     | 12 +++---
 4 files changed, 50 insertions(+), 8 deletions(-)

diff --git a/pom.xml b/pom.xml
index 5ed40518b4f..b04dc3d0922 100644
--- a/pom.xml
+++ b/pom.xml
@@ -116,7 +116,7 @@
         <!-- versions -->
         <aether-version>1.0.2.v20150114</aether-version>
         
<arquillian-container-se-managed-version>1.0.2.Final</arquillian-container-se-managed-version>
-        <arquillian-version>1.7.0.Alpha10</arquillian-version>
+        <arquillian-version>1.9.4.Final</arquillian-version>
         <avro-version>1.12.0</avro-version>
         <graal-sdk-version>22.3.2</graal-sdk-version>
         <jakarta-jaxb-version>4.0.2</jakarta-jaxb-version>
diff --git a/tests/camel-itest-spring-boot/pom.xml 
b/tests/camel-itest-spring-boot/pom.xml
index 7af88306795..deca95c6065 100644
--- a/tests/camel-itest-spring-boot/pom.xml
+++ b/tests/camel-itest-spring-boot/pom.xml
@@ -38,7 +38,6 @@
         <shrinkwrap-plexus-version>3.2.1</shrinkwrap-plexus-version>
     </properties>
 
-
     <dependencies>
 
         <dependency>
diff --git 
a/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/util/ArquillianPackager.java
 
b/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/util/ArquillianPackager.java
index 0c07cd202a9..43f71ccc106 100644
--- 
a/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/util/ArquillianPackager.java
+++ 
b/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/util/ArquillianPackager.java
@@ -37,6 +37,7 @@ import java.util.TreeMap;
 import java.util.TreeSet;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
+import java.util.stream.Collectors;
 
 import org.apache.camel.itest.springboot.ITestConfig;
 import org.apache.camel.itest.springboot.ITestConfigBuilder;
@@ -216,10 +217,16 @@ public final class ArquillianPackager {
         }
 
         // Remove duplicates between test and runtime dependencies
+        Set<MavenResolvedArtifact> jUnitDependenciesDuplicates =
+                getJUnitDependenciesDuplicates(runtimeDependencies, 
testProvidedDependenciesPom);
+
         runtimeDependencies.addAll(testProvidedDependenciesPom);
         List<MavenResolvedArtifact> dependencyArtifacts = new 
LinkedList<>(runtimeDependencies);
         lookForVersionMismatch(config, dependencyArtifacts);
 
+        // Remove duplicates after the version mismatch analysis
+        dependencyArtifacts.removeAll(jUnitDependenciesDuplicates);
+
         List<File> dependencies = new LinkedList<>();
         for (MavenResolvedArtifact a : dependencyArtifacts) {
             dependencies.add(a.asFile());
@@ -275,6 +282,42 @@ public final class ArquillianPackager {
         return external.build();
     }
 
+    /**
+     * In case Camel and Camel Spring Boot declare different JUnit versions, 
use the Spring Boot one to prevent issues
+     *
+     * @param runtimeDependencies
+     * @param testProvidedDependencies
+     * @return
+     */
+    private static Set<MavenResolvedArtifact> 
getJUnitDependenciesDuplicates(Set<MavenResolvedArtifact> runtimeDependencies, 
Set<MavenResolvedArtifact> testProvidedDependencies) {
+        Set<MavenResolvedArtifact> junitRuntimeDependencies =
+                runtimeDependencies.stream()
+                        .filter(d -> 
d.getCoordinate().getArtifactId().startsWith("junit"))
+                        .collect(Collectors.toSet());
+
+        // For each JUnit runtime (Spring Boot) dependency, find test 
dependencies with same artifactId and groupId but different version
+        return junitRuntimeDependencies.stream()
+                .flatMap(junitDep -> testProvidedDependencies.stream()
+                        .filter(testDep -> 
isSameArtifactWithDifferentVersion(junitDep, testDep)))
+                .collect(Collectors.toSet());
+    }
+
+    /**
+     * Checks if two artifacts have the same artifactId and groupId but 
different versions.
+     *
+     * @param artifact1 First artifact to compare
+     * @param artifact2 Second artifact to compare
+     * @return true if artifacts have same artifactId and groupId but 
different versions
+     */
+    private static boolean isSameArtifactWithDifferentVersion(
+            MavenResolvedArtifact artifact1,
+            MavenResolvedArtifact artifact2) {
+
+        return 
artifact1.getCoordinate().getArtifactId().equals(artifact2.getCoordinate().getArtifactId())
 &&
+                
artifact1.getCoordinate().getGroupId().equals(artifact2.getCoordinate().getGroupId())
 &&
+                
!artifact1.getCoordinate().getVersion().equals(artifact2.getCoordinate().getVersion());
+    }
+
     private static void lookForVersionMismatch(ITestConfig config, 
List<MavenResolvedArtifact> dependencyArtifacts) {
         Set<String> ignore = new HashSet<>(config.getIgnoreLibraryMismatch());
 
diff --git 
a/tests/camel-itest-spring-boot/src/test/resources/application-pom-sb3.xml 
b/tests/camel-itest-spring-boot/src/test/resources/application-pom-sb3.xml
index 4cde6afebc5..f6126da1d8b 100644
--- a/tests/camel-itest-spring-boot/src/test/resources/application-pom-sb3.xml
+++ b/tests/camel-itest-spring-boot/src/test/resources/application-pom-sb3.xml
@@ -67,17 +67,17 @@
             <artifactId>#{module}-starter</artifactId>
         </dependency>
 
-        <!-- Required by the integration tests to run in Junit5 -->
+           <!-- Required by the integration tests to run in Junit5 -->
         <dependency>
-               <groupId>org.junit.jupiter</groupId>
-               <artifactId>junit-jupiter</artifactId>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter</artifactId>
             <scope>test</scope>
         </dependency>
         <!--  Required for UnitTestCommand -->
         <dependency>
-               <groupId>org.junit.platform</groupId>
-               <artifactId>junit-platform-launcher</artifactId>
-             <scope>test</scope>
+            <groupId>org.junit.platform</groupId>
+            <artifactId>junit-platform-launcher</artifactId>
+            <scope>test</scope>
         </dependency>
 
         <!-- DEPENDENCIES -->

Reply via email to