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

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


The following commit(s) were added to refs/heads/main by this push:
     new a444ac88dbb [CAMEL-18753] camel-yaml-dsl - OnCompletion is not added 
in the route… (#8771)
a444ac88dbb is described below

commit a444ac88dbbe2631f671298ef1b110b7363e2283
Author: Marc Boulanger <hellh...@gmail.com>
AuthorDate: Thu Nov 24 16:40:24 2022 +0100

    [CAMEL-18753] camel-yaml-dsl - OnCompletion is not added in the route… 
(#8771)
    
    * [CAMEL-18753] camel-yaml-dsl - OnCompletion is not added in the route 
definition.
    
    * [CAMEL-18753] camel-yaml-dsl - OnCompletion is not added in the route 
definition.
    
    Co-authored-by: Boulanger M <m...@adeops.be>
---
 .../camel/dsl/yaml/YamlRoutesBuilderLoader.java    |  9 ++++
 .../apache/camel/dsl/yaml/OnCompletionTest.groovy  | 50 ++++++++++++++++++++++
 2 files changed, 59 insertions(+)

diff --git 
a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/java/org/apache/camel/dsl/yaml/YamlRoutesBuilderLoader.java
 
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/java/org/apache/camel/dsl/yaml/YamlRoutesBuilderLoader.java
index 406a221fc03..2193d538194 100644
--- 
a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/java/org/apache/camel/dsl/yaml/YamlRoutesBuilderLoader.java
+++ 
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/java/org/apache/camel/dsl/yaml/YamlRoutesBuilderLoader.java
@@ -42,6 +42,7 @@ import 
org.apache.camel.dsl.yaml.common.exception.InvalidEndpointException;
 import org.apache.camel.dsl.yaml.common.exception.InvalidNodeTypeException;
 import org.apache.camel.dsl.yaml.deserializers.OutputAwareFromDefinition;
 import org.apache.camel.model.KameletDefinition;
+import org.apache.camel.model.OnCompletionDefinition;
 import org.apache.camel.model.OnExceptionDefinition;
 import org.apache.camel.model.ProcessorDefinition;
 import org.apache.camel.model.RouteConfigurationDefinition;
@@ -169,6 +170,14 @@ public class YamlRoutesBuilderLoader extends 
YamlRoutesBuilderLoaderSupport {
                 } else if (item instanceof CamelContextCustomizer) {
                     ((CamelContextCustomizer) 
item).configure(getCamelContext());
                     return true;
+                } else if (item instanceof OnCompletionDefinition) {
+                    if (!getRouteCollection().getRoutes().isEmpty()) {
+                        throw new IllegalArgumentException(
+                                "onCompletion must be defined before any 
routes in the RouteBuilder");
+                    }
+                    CamelContextAware.trySetCamelContext(getRouteCollection(), 
getCamelContext());
+                    
getRouteCollection().getOnCompletions().add((OnCompletionDefinition) item);
+                    return true;
                 } else if (item instanceof OnExceptionDefinition) {
                     if (!getRouteCollection().getRoutes().isEmpty()) {
                         throw new IllegalArgumentException(
diff --git 
a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/OnCompletionTest.groovy
 
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/OnCompletionTest.groovy
new file mode 100644
index 00000000000..2c072db4e80
--- /dev/null
+++ 
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/OnCompletionTest.groovy
@@ -0,0 +1,50 @@
+/*
+ * 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.yaml
+
+import org.apache.camel.component.mock.MockEndpoint
+import org.apache.camel.dsl.yaml.support.YamlTestSupport
+
+class OnCompletionTest extends YamlTestSupport {
+    def "on-completion"() {
+        setup:
+            loadRoutes """
+                - on-completion:
+                    steps:
+                      - transform:
+                          constant: "Processed"
+                      - to: "mock:on-success"  
+                - from:
+                    uri: "direct:start"
+                    steps:
+                      - to: "mock:end"
+            """
+
+            withMock('mock:on-success') {
+                expectedBodiesReceived 'Processed'
+            }
+
+        when:
+            context.start()
+
+            withTemplate {
+                to('direct:start').withBody('hello').send()
+            }
+        then:
+            MockEndpoint.assertIsSatisfied(context)
+    }
+}

Reply via email to