You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2022/11/25 12:20:57 UTC

[camel] branch main updated: CAMEL-18755: camel-yaml-dsl - Intercept is not added in the route definition.

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 280ec0d4202 CAMEL-18755: camel-yaml-dsl - Intercept is not added in the route definition.
280ec0d4202 is described below

commit 280ec0d4202289195a27012ab55da9b8cbb9d7ea
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Nov 25 13:20:43 2022 +0100

    CAMEL-18755: camel-yaml-dsl - Intercept is not added in the route definition.
---
 .../camel/dsl/yaml/YamlRoutesBuilderLoader.java    | 27 +++++++++++
 .../apache/camel/dsl/yaml/InterceptFromTest.groovy | 52 +++++++++++++++++++++
 .../dsl/yaml/InterceptSendToEndpointTest.groovy    | 53 ++++++++++++++++++++++
 .../org/apache/camel/dsl/yaml/InterceptTest.groovy | 52 +++++++++++++++++++++
 4 files changed, 184 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 2193d538194..26567519789 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
@@ -41,6 +41,9 @@ import org.apache.camel.dsl.yaml.common.YamlDeserializerSupport;
 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.InterceptDefinition;
+import org.apache.camel.model.InterceptFromDefinition;
+import org.apache.camel.model.InterceptSendToEndpointDefinition;
 import org.apache.camel.model.KameletDefinition;
 import org.apache.camel.model.OnCompletionDefinition;
 import org.apache.camel.model.OnExceptionDefinition;
@@ -170,6 +173,30 @@ public class YamlRoutesBuilderLoader extends YamlRoutesBuilderLoaderSupport {
                 } else if (item instanceof CamelContextCustomizer) {
                     ((CamelContextCustomizer) item).configure(getCamelContext());
                     return true;
+                } else if (item instanceof InterceptFromDefinition) {
+                    if (!getRouteCollection().getRoutes().isEmpty()) {
+                        throw new IllegalArgumentException(
+                                "interceptFrom must be defined before any routes in the RouteBuilder");
+                    }
+                    CamelContextAware.trySetCamelContext(getRouteCollection(), getCamelContext());
+                    getRouteCollection().getInterceptFroms().add((InterceptFromDefinition) item);
+                    return true;
+                } else if (item instanceof InterceptDefinition) {
+                    if (!getRouteCollection().getRoutes().isEmpty()) {
+                        throw new IllegalArgumentException(
+                                "intercept must be defined before any routes in the RouteBuilder");
+                    }
+                    CamelContextAware.trySetCamelContext(getRouteCollection(), getCamelContext());
+                    getRouteCollection().getIntercepts().add((InterceptDefinition) item);
+                    return true;
+                } else if (item instanceof InterceptSendToEndpointDefinition) {
+                    if (!getRouteCollection().getRoutes().isEmpty()) {
+                        throw new IllegalArgumentException(
+                                "interceptSendToEndpoint must be defined before any routes in the RouteBuilder");
+                    }
+                    CamelContextAware.trySetCamelContext(getRouteCollection(), getCamelContext());
+                    getRouteCollection().getInterceptSendTos().add((InterceptSendToEndpointDefinition) item);
+                    return true;
                 } else if (item instanceof OnCompletionDefinition) {
                     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/InterceptFromTest.groovy b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/InterceptFromTest.groovy
new file mode 100644
index 00000000000..9de054d1f58
--- /dev/null
+++ b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/InterceptFromTest.groovy
@@ -0,0 +1,52 @@
+/*
+ * 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 InterceptFromTest extends YamlTestSupport {
+    def "interceptFrom"() {
+        setup:
+            loadRoutes """
+                - interceptFrom:
+                    steps:
+                      - to: "mock:intercepted"  
+                - from:
+                    uri: "direct:start"
+                    steps:
+                      - to: "mock:foo"
+                      - set-body:
+                          constant: "Hello Bar"
+                      - to: "mock:bar"
+                      - to: "mock:result"
+            """
+
+            withMock('mock:intercepted') {
+                expectedBodiesReceived("hello")
+            }
+
+        when:
+            context.start()
+
+            withTemplate {
+                to('direct:start').withBody('hello').send()
+            }
+        then:
+            MockEndpoint.assertIsSatisfied(context)
+    }
+}
diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/InterceptSendToEndpointTest.groovy b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/InterceptSendToEndpointTest.groovy
new file mode 100644
index 00000000000..04402b401e2
--- /dev/null
+++ b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/InterceptSendToEndpointTest.groovy
@@ -0,0 +1,53 @@
+/*
+ * 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 InterceptSendToEndpointTest extends YamlTestSupport {
+    def "interceptSendToEndpoint"() {
+        setup:
+            loadRoutes """
+                - interceptSendToEndpoint: 
+                    uri: "mock:bar"
+                    steps:
+                      - to: "mock:intercepted"  
+                - from:
+                    uri: "direct:start"
+                    steps:
+                      - to: "mock:foo"
+                      - set-body:
+                          constant: "Hello Bar"
+                      - to: "mock:bar"
+                      - to: "mock:result"
+            """
+
+            withMock('mock:intercepted') {
+                expectedBodiesReceived("Hello Bar")
+            }
+
+        when:
+            context.start()
+
+            withTemplate {
+                to('direct:start').withBody('hello').send()
+            }
+        then:
+            MockEndpoint.assertIsSatisfied(context)
+    }
+}
diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/InterceptTest.groovy b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/InterceptTest.groovy
new file mode 100644
index 00000000000..477c587cfc9
--- /dev/null
+++ b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/InterceptTest.groovy
@@ -0,0 +1,52 @@
+/*
+ * 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 InterceptTest extends YamlTestSupport {
+    def "intercept"() {
+        setup:
+            loadRoutes """
+                - intercept:
+                    steps:
+                      - to: "mock:intercepted"  
+                - from:
+                    uri: "direct:start"
+                    steps:
+                      - to: "mock:foo"
+                      - set-body:
+                          constant: "Hello Bar"
+                      - to: "mock:bar"
+                      - to: "mock:result"
+            """
+
+            withMock('mock:intercepted') {
+                expectedBodiesReceived("hello", "hello", "Hello Bar", "Hello Bar")
+            }
+
+        when:
+            context.start()
+
+            withTemplate {
+                to('direct:start').withBody('hello').send()
+            }
+        then:
+            MockEndpoint.assertIsSatisfied(context)
+    }
+}