gnodet-bot commented on code in PR #27293:
URL: https://github.com/apache/camel/pull/27293#discussion_r4170438688
##########
dsl/camel-kamelet-main/src/test/java/org/apache/camel/main/download/KnownDependenciesResolverTest.java:
##########
@@ -22,6 +22,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
Review Comment:
🔴 **Compilation error:** `assertGav()` (called at lines 74 and 80) uses
`assertFalse`, but the import is missing. Add it here:
```suggestion
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertFalse;
```
##########
dsl/camel-kamelet-main/src/test/java/org/apache/camel/main/download/KnownDependenciesResolverTest.java:
##########
@@ -53,4 +54,37 @@ void mavenGavForClass_returnsPackageScopedDependency() {
public static class SomeClass {
}
+
+ @Test
+ void anImportResolvesAnyClassOfAComponent() {
+ // CAMEL-25239: any class of a component a source imports, not only
the component class itself, such as the
+ // constants of the headers of a component that a kamelet uses
+ KnownDependenciesResolver resolver = new KnownDependenciesResolver(new
SimpleCamelContext(), null, null);
+ resolver.loadKnownDependencies();
+
+ assertImport(resolver,
"org.apache.camel.component.aws2.s3.AWS2S3Component", "camel-aws2-s3");
+ assertImport(resolver,
"org.apache.camel.component.aws2.s3.AWS2S3Constants", "camel-aws2-s3");
+ assertImport(resolver,
"org.apache.camel.component.aws2.s3.utils.AWS2S3Utils", "camel-aws2-s3");
+ // a sibling package of another component is not mistaken for it
+ assertImport(resolver,
"org.apache.camel.component.aws2.s3vectors.AWS2S3VectorsConstants",
"camel-aws2-s3-vectors");
+ // a sub package of another component's package wins for its own
classes
+ assertImport(resolver,
"org.apache.camel.component.file.remote.SftpConstants", "camel-ftp");
+ assertImport(resolver, "org.apache.camel.component.file.GenericFile",
"camel-file");
+ // the libraries still resolve as before
+ assertGav(resolver, "com.fasterxml.jackson.databind.ObjectMapper",
"com.fasterxml.jackson.core", "jackson-databind");
+ // a component in a base package does not claim every class in it
+ assertNull(resolver.mavenGavForImport("org.apache.camel.Exchange"));
+
assertNull(resolver.mavenGavForImport("org.apache.camel.component.Anything"));
+ // a class looked up at runtime (often only probed for) still needs
the component class itself
+
assertNull(resolver.mavenGavForClass("org.apache.camel.component.aws2.s3.AWS2S3Constants"));
+ assertGav(resolver,
"org.apache.camel.component.aws2.s3.AWS2S3Component", "org.apache.camel",
"camel-aws2-s3");
+ }
+
+ private static void assertImport(KnownDependenciesResolver resolver,
String className, String artifactId) {
+ MavenGav gav = resolver.mavenGavForImport(className);
+ assertNotNull(gav, className);
+ assertEquals("org.apache.camel", gav.getGroupId(), className);
+ assertEquals(artifactId, gav.getArtifactId(), className);
+ assertNotNull(gav.getVersion(), className + " version is null");
+ }
}
Review Comment:
🔴 **Compilation error:** `assertGav()` is called at lines 74 and 80 but the
method was removed along with
`theShippedMappingResolvesThirdPartyClassesByPackage`. The helper needs to be
added back (it exists on `main` at line 146):
```suggestion
}
private static void assertGav(KnownDependenciesResolver resolver, String
className, String groupId, String artifactId) {
MavenGav gav = resolver.mavenGavForClass(className);
assertNotNull(gav, className);
assertEquals(groupId, gav.getGroupId(), className);
assertEquals(artifactId, gav.getArtifactId(), className);
String version = gav.getVersion();
assertNotNull(version, className + " version is null");
assertFalse(version.startsWith("${"), className + " version is an
unresolved placeholder: " + version);
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]