gnodet-bot commented on code in PR #26634:
URL: https://github.com/apache/camel/pull/26634#discussion_r4057466073


##########
dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ai/SourceValidatorEndpointTest.java:
##########
@@ -560,4 +560,24 @@ void aProducerOnlyComponentInFromIsNamed() {
         assertThat(msgs).hasSize(1);
         assertThat(msgs.get(0)).contains("mock is a producer-only component: 
it cannot be a from:").contains("direct:name");
     }
+
+    /** CAMEL-24852: the directory of a file endpoint on a to: cannot be 
dynamic; toD: evaluates the uri first. */
+    @Test
+    void aDynamicDirectoryOnAFileEndpointSaysToUseFileNameOrToD() {
+        String yaml = """
+                - route:
+                    from:
+                      uri: timer:tick
+                      steps:
+                        - to:
+                            uri: 
"file://archived/${header.monthDir}?fileName=${header.CamelFileName}"
+                """;
+        List<String> errors = SourceValidator.validateYamlEndpoints(yaml, 
catalog);
+        assertThat(errors)
+                .anyMatch(e -> e.startsWith("Line 6: file: the directory 
archived/${header.monthDir} cannot be dynamic")
+                        && e.contains("fileName 
(file:archived?fileName=${...})") && e.contains("use toD:"));
+
+        List<String> dynamic = 
SourceValidator.validateYamlEndpoints(yaml.replace("- to:", "- toD:"), catalog);
+        assertThat(dynamic).noneMatch(e -> e.contains("cannot be dynamic"));
+    }
 }

Review Comment:
   💡 **Missing test for `from:`** — `checkDynamicDirectory` explicitly 
documents that it checks both `to:` and `from:` (a file consumer also fails at 
startup with a dynamic directory). The test currently only covers `to:` → 
`toD:`. Consider adding a `from: file://archived/${header.monthDir}` case to 
verify the same error is reported (and that a `from:` is not silently skipped).
   
   ```suggestion
       /** CAMEL-24852: the directory of a file endpoint on a to: cannot be 
dynamic; toD: evaluates the uri first. */
       @Test
       void aDynamicDirectoryOnAFileEndpointSaysToUseFileNameOrToD() {
           String yaml = """
                   - route:
                       from:
                         uri: timer:tick
                         steps:
                           - to:
                               uri: 
"file://archived/${header.monthDir}?fileName=${header.CamelFileName}"
                   """;
           List<String> errors = SourceValidator.validateYamlEndpoints(yaml, 
catalog);
           assertThat(errors)
                   .anyMatch(e -> e.startsWith("Line 6: file: the directory 
archived/${header.monthDir} cannot be dynamic")
                           && e.contains("fileName 
(file:archived?fileName=${...})") && e.contains("use toD:"));
   
           List<String> dynamic = 
SourceValidator.validateYamlEndpoints(yaml.replace("- to:", "- toD:"), catalog);
           assertThat(dynamic).noneMatch(e -> e.contains("cannot be dynamic"));
   
           // from: with a dynamic directory also fails at startup
           String fromYaml = """
                   - route:
                       from:
                         uri: "file://archived/${header.monthDir}"
                       steps:
                         - to:
                             uri: log:done
                   """;
           List<String> fromErrors = 
SourceValidator.validateYamlEndpoints(fromYaml, catalog);
           assertThat(fromErrors)
                   .anyMatch(e -> e.contains("file:") && e.contains("cannot be 
dynamic"));
       }
   ```



-- 
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]

Reply via email to