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

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


The following commit(s) were added to refs/heads/camel-4.18.x by this push:
     new f3104d932ffb CAMEL-23024: Fix yaml-io dumper for resequence
f3104d932ffb is described below

commit f3104d932ffb14275cd04ade327dd7f1b1b1c4c6
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu Feb 26 22:10:47 2026 +0100

    CAMEL-23024: Fix yaml-io dumper for resequence
---
 .../java/org/apache/camel/yaml/io/YamlWriter.java  | 17 +++++++++
 .../org/apache/camel/yaml/out/ModelWriterTest.java | 43 ++++++++++++++++++++++
 core/camel-yaml-io/src/test/resources/route14.yaml | 34 +++++++++++++++++
 core/camel-yaml-io/src/test/resources/route15.yaml | 35 ++++++++++++++++++
 4 files changed, 129 insertions(+)

diff --git 
a/core/camel-yaml-io/src/main/java/org/apache/camel/yaml/io/YamlWriter.java 
b/core/camel-yaml-io/src/main/java/org/apache/camel/yaml/io/YamlWriter.java
index 2f1d38569876..94a772d940c8 100644
--- a/core/camel-yaml-io/src/main/java/org/apache/camel/yaml/io/YamlWriter.java
+++ b/core/camel-yaml-io/src/main/java/org/apache/camel/yaml/io/YamlWriter.java
@@ -216,6 +216,10 @@ public class YamlWriter extends ServiceSupport implements 
CamelContextAware {
                 } else if ("setVariables".equals(parent.getName())) {
                     // special for setVariables
                     setMetadata(parent, "variables", last);
+                } else if ("resequence".equals(parent.getName())
+                        && ("batchConfig".equals(name) || 
"streamConfig".equals(name))) {
+                    // special for resequence
+                    setMetadata(parent, "resequenceConfig", last);
                 } else if (parent.isOutput()) {
                     List<EipModel> list = (List<EipModel>) 
parent.getMetadata().get("_output");
                     if (list == null) {
@@ -336,6 +340,19 @@ public class YamlWriter extends ServiceSupport implements 
CamelContextAware {
                 for (EipModel m : list) {
                     node.addOutput(asNode(m));
                 }
+            } else if ("resequence".equals(node.getName()) && 
"resequenceConfig".equals(key)) {
+                EipModel config = (EipModel) entry.getValue();
+                JsonObject jo = new JsonObject();
+                for (var o : config.getOptions()) {
+                    String n = o.getName();
+                    Object v = config.getMetadata().get(n);
+                    if (v != null) {
+                        jo.put(n, v);
+                    }
+                }
+                if (!jo.isEmpty()) {
+                    node.addProperty(config.getName(), jo);
+                }
             } else if ("choice".equals(node.getName()) && 
"otherwise".equals(key)) {
                 EipModel other = (EipModel) entry.getValue();
                 node.addOutput(asNode(other));
diff --git 
a/core/camel-yaml-io/src/test/java/org/apache/camel/yaml/out/ModelWriterTest.java
 
b/core/camel-yaml-io/src/test/java/org/apache/camel/yaml/out/ModelWriterTest.java
index 8d1968c3d3dc..b54d23e90710 100644
--- 
a/core/camel-yaml-io/src/test/java/org/apache/camel/yaml/out/ModelWriterTest.java
+++ 
b/core/camel-yaml-io/src/test/java/org/apache/camel/yaml/out/ModelWriterTest.java
@@ -30,6 +30,7 @@ import org.apache.camel.model.FromDefinition;
 import org.apache.camel.model.LogDefinition;
 import org.apache.camel.model.MarshalDefinition;
 import org.apache.camel.model.ModelCamelContext;
+import org.apache.camel.model.ResequenceDefinition;
 import org.apache.camel.model.RouteDefinition;
 import org.apache.camel.model.RoutesDefinition;
 import org.apache.camel.model.SetBodyDefinition;
@@ -373,4 +374,46 @@ public class ModelWriterTest {
         Assertions.assertEquals(expected, out);
     }
 
+    @Test
+    public void testResequenceBatch() throws Exception {
+        StringWriter sw = new StringWriter();
+        ModelWriter writer = new ModelWriter(sw);
+
+        RouteDefinition route = new RouteDefinition();
+        route.setId("myRout14");
+        route.setInput(new FromDefinition("timer:foo"));
+        ResequenceDefinition rd = new ResequenceDefinition(new 
SimpleExpression("${body}"));
+        rd.batch().size(300).timeout("4000");
+        route.addOutput(rd);
+        rd.addOutput(new ToDefinition("mock:result"));
+        route.addOutput(new LogDefinition("${body}"));
+
+        writer.writeRouteDefinition(route);
+
+        String out = sw.toString();
+        String expected = 
stripLineComments(Paths.get("src/test/resources/route14.yaml"), "#", true);
+        Assertions.assertEquals(expected, out);
+    }
+
+    @Test
+    public void testResequenceStream() throws Exception {
+        StringWriter sw = new StringWriter();
+        ModelWriter writer = new ModelWriter(sw);
+
+        RouteDefinition route = new RouteDefinition();
+        route.setId("myRout15");
+        route.setInput(new FromDefinition("timer:foo"));
+        ResequenceDefinition rd = new ResequenceDefinition(new 
SimpleExpression("${body}"));
+        rd.stream().capacity(123).timeout("4000").rejectOld();
+        route.addOutput(rd);
+        rd.addOutput(new ToDefinition("mock:result"));
+        route.addOutput(new LogDefinition("${body}"));
+
+        writer.writeRouteDefinition(route);
+
+        String out = sw.toString();
+        String expected = 
stripLineComments(Paths.get("src/test/resources/route15.yaml"), "#", true);
+        Assertions.assertEquals(expected, out);
+    }
+
 }
diff --git a/core/camel-yaml-io/src/test/resources/route14.yaml 
b/core/camel-yaml-io/src/test/resources/route14.yaml
new file mode 100644
index 000000000000..5119fff2818a
--- /dev/null
+++ b/core/camel-yaml-io/src/test/resources/route14.yaml
@@ -0,0 +1,34 @@
+#
+# 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.
+#
+
+- route:
+    id: myRout14
+    from:
+      uri: timer:foo
+      steps:
+        - resequence:
+            batchConfig:
+              batchSize: 300
+              batchTimeout: 4000
+            expression:
+              simple:
+                expression: "${body}"
+            steps:
+              - to:
+                  uri: mock:result
+        - log:
+            message: "${body}"
diff --git a/core/camel-yaml-io/src/test/resources/route15.yaml 
b/core/camel-yaml-io/src/test/resources/route15.yaml
new file mode 100644
index 000000000000..bbf883b17928
--- /dev/null
+++ b/core/camel-yaml-io/src/test/resources/route15.yaml
@@ -0,0 +1,35 @@
+#
+# 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.
+#
+
+- route:
+    id: myRout15
+    from:
+      uri: timer:foo
+      steps:
+        - resequence:
+            streamConfig:
+              capacity: 123
+              timeout: 4000
+              rejectOld: "true"
+            expression:
+              simple:
+                expression: "${body}"
+            steps:
+              - to:
+                  uri: mock:result
+        - log:
+            message: "${body}"

Reply via email to