allthingssecurity commented on code in PR #28029:
URL: https://github.com/apache/camel/pull/28029#discussion_r4306582051


##########
core/camel-java-io/src/main/java/org/apache/camel/java/LwModelToJavaDumper.java:
##########
@@ -52,6 +56,17 @@
 @JdkService(ModelToJavaDumper.FACTORY)
 public class LwModelToJavaDumper implements ModelToJavaDumper {
 
+    /**
+     * Options that are written whenever they are set, even with their 
documented default value: when they are not set,
+     * they take the value of a parent level (the rest or the rest 
configuration for a rest or verb, the CamelContext
+     * for a route), and a dump that leaves them out runs differently once 
loaded. The same holds for every option of a
+     * redelivery policy (an onException copies the error handler's policy) 
and of a circuit breaker configuration (it
+     * is layered over the global one).
+     */
+    static final Set<String> INHERITED_OPTIONS = Set.of(
+            "bindingMode", "skipBindingOnErrorCode", 
"clientRequestValidation", "clientResponseValidation", "enableCORS",
+            "enableNoContentResponse", "shutdownRoute", "shutdownRunningTask");

Review Comment:
   Thanks. This is gone now: following Claus's review, 64145639d0f7 moves the 
knowledge into `ModelWriterGeneratorMojo` (the generator that all three writers 
share), which passes no default value for these options. The three dumpers no 
longer have a list or an override, so there is nothing left to keep in sync 
between them.
   
   _Claude Code on behalf of allthingssecurity_
   



##########
core/camel-java-io/src/test/java/org/apache/camel/java/LwModelToJavaDumperTest.java:
##########
@@ -106,4 +107,30 @@ public void configure() {
                     .getExceptionType()).isNull();
         }
     }
+
+    /**
+     * An option set to its documented default value is written: when it is 
not set, the option takes the value of a
+     * parent level (the rest configuration for a verb, the error handler for 
the redelivery of an onException).
+     */
+    @Test
+    public void testDumpOptionsSetToTheirDefaultValue() throws Exception {
+        try (DefaultCamelContext context = new DefaultCamelContext()) {
+            context.addRoutes(new RouteBuilder() {
+                @Override
+                public void configure() {
+                    
rest("/api").get("/raw").bindingMode(RestBindingMode.off).to("direct:raw");
+
+                    from("direct:start").routeId("redelivery")
+                            
.onException(IllegalStateException.class).maximumRedeliveries(1).redeliveryDelay(1000).end()
+                            .to("mock:result");
+                }
+            });
+            Model model = 
context.getCamelContextExtension().getContextPlugin(Model.class);
+            LwModelToJavaDumper dumper = new LwModelToJavaDumper();
+
+            assertThat(dumper.dumpModelAsJava(context, 
model.getRestDefinitions().get(0))).contains(".bindingMode(\"off\")");
+            assertThat(dumper.dumpModelAsJava(context, 
context.getRouteDefinition("redelivery")))
+                    .contains(".redeliveryDelay(\"1000\")");

Review Comment:
   Good point. 64145639d0f7 adds `JavaDumpExplicitDefaultValuesTest`. It dumps 
a route with an onException `redeliveryDelay(1000)` under an error handler with 
a 30 s delay, compiles the dump in memory into a `RouteBuilder`, loads it into 
a new CamelContext and runs it. The reply must come back within 10 s. With the 
writer generated by main the redelivery waits 30 s and the test fails 
(`expected: "handled" but was: "not redelivered within 10 seconds"`); with the 
change it passes. I did not compile the rest verb case: running a rest verb 
needs a rest consumer component, which camel-java-io does not have. The XML and 
YAML tests cover that case, and the string check for `.bindingMode("off")` in 
`LwModelToJavaDumperTest` stays.
   
   _Claude Code on behalf of allthingssecurity_
   



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