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

davsclaus pushed a commit to branch fix/CAMEL-24921
in repository https://gitbox.apache.org/repos/asf/camel.git

commit ccfe9ada903097f151939c0e03cbecee6c4d5d77
Author: Claus Ibsen <[email protected]>
AuthorDate: Wed Sep 23 11:55:10 2026 +0200

    CAMEL-24921: simple - read a predicate inside ${ }
    
    ${body != null && body.size() > 0} was refused with "Operators go outside 
the
    function", and it is what a model writes and what a person writes who last
    wrote JSP: the braces hold a full expression in Jakarta EL, Groovy and a
    JavaScript template. Simple looks like those and was not, so the wrong guess
    was the natural one.
    
    The braces now answer the predicate when they hold one. The form with the
    operators outside (${body} != null && ${body.size()} > 0) means the same 
and is
    unchanged, and the ternary keeps working. Inside the braces the answer is a
    value, so a template can hold it too: "Over three: ${header.n > 3}".
    
    An operator counts only when whitespace surrounds it outside quotes, which 
is
    what keeps ${header.Content-Length} a name and ${date:now:yyyy-MM-dd} a
    pattern. Every one of the 804 distinct simple expressions in camel,
    camel-kamelets, camel-examples and camel-jbang-examples parses to exactly 
what
    it parsed to before.
    
    The wrapping is shared with the ternary condition (CAMEL-24920) so the two
    cannot drift apart.
    
    Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
    Claude-Session: https://claude.ai/code/session_01Bp3538HRBPMQkb5ta9xRaj
---
 .../ai/PredicateInBracesValidatorTest.java         | 57 ++++++++++++++++++++++
 1 file changed, 57 insertions(+)

diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ai/PredicateInBracesValidatorTest.java
 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ai/PredicateInBracesValidatorTest.java
new file mode 100644
index 000000000000..dae26c73370c
--- /dev/null
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ai/PredicateInBracesValidatorTest.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.dsl.jbang.core.commands.ai;
+
+import java.util.List;
+
+import org.apache.camel.catalog.CamelCatalog;
+import org.apache.camel.catalog.DefaultCamelCatalog;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * CAMEL-24921: what the runtime accepts, the tools that write files must 
accept too - a route with a predicate inside
+ * the braces is not refused before it ever runs.
+ */
+class PredicateInBracesValidatorTest {
+
+    private static final String ROUTE = """
+            - route:
+                from:
+                  uri: direct:start
+                  steps:
+                    - choice:
+                        when:
+                          - expression:
+                              simple: "${body != null && body.size() > 0}"
+                            steps:
+                              - log:
+                                  message: "some"
+                        otherwise:
+                          steps:
+                            - log:
+                                message: "none"
+            """;
+
+    @Test
+    void aPredicateInsideTheBracesValidates() {
+        CamelCatalog catalog = new DefaultCamelCatalog();
+        List<String> problems = SourceValidator.validateCamelYaml(ROUTE, 
catalog);
+        assertThat(problems).as("the runtime accepts this route, so the 
validator must too").isEmpty();
+    }
+}

Reply via email to