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 a696d26  CAMEL-17289: camel-yaml-dsl - Add support for knative kind in 
yaml-dsl loader
a696d26 is described below

commit a696d26139debce15113684158e84cb786d8db31
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Mon Jan 24 13:27:05 2022 +0100

    CAMEL-17289: camel-yaml-dsl - Add support for knative kind in yaml-dsl 
loader
---
 .../camel/dsl/yaml/YamlRoutesBuilderLoader.java    |  8 ++++-
 .../camel/dsl/yaml/KameletBindingLoaderTest.groovy | 39 ++++++++++++++++++++++
 2 files changed, 46 insertions(+), 1 deletion(-)

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 0265a3b..17229f5 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
@@ -72,6 +72,7 @@ public class YamlRoutesBuilderLoader extends 
YamlRoutesBuilderLoaderSupport {
     private static final String INTEGRATION_VERSION = "camel.apache.org/v1";
     private static final String BINDING_VERSION = "camel.apache.org/v1";
     private static final String STRIMZI_VERSION = "kafka.strimzi.io/v1";
+    private static final String KNATIVE_VERSION = "messaging.knative.dev/v1";
 
     public YamlRoutesBuilderLoader() {
         super(EXTENSION);
@@ -390,8 +391,11 @@ public class YamlRoutesBuilderLoader extends 
YamlRoutesBuilderLoaderSupport {
         boolean strimzi
                 = !kamelet && mn != null && anyTupleMatches(mn.getValue(), 
"apiVersion", v -> v.startsWith(STRIMZI_VERSION))
                         && anyTupleMatches(mn.getValue(), "kind", 
"KafkaTopic");
+        boolean knative
+                = !kamelet && !strimzi && mn != null
+                        && anyTupleMatches(mn.getValue(), "apiVersion", v -> 
v.startsWith(KNATIVE_VERSION));
         String uri;
-        if (kamelet || strimzi) {
+        if (kamelet || strimzi || knative) {
             uri = extractTupleValue(mn.getValue(), "name");
         } else {
             uri = extractTupleValue(node.getValue(), "uri");
@@ -409,6 +413,8 @@ public class YamlRoutesBuilderLoader extends 
YamlRoutesBuilderLoaderSupport {
             return "kamelet:" + uri;
         } else if (strimzi) {
             return "kafka:" + uri;
+        } else if (knative) {
+            return "knative:channel/" + uri;
         } else {
             return uri;
         }
diff --git 
a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/KameletBindingLoaderTest.groovy
 
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/KameletBindingLoaderTest.groovy
index b3da18f..177828f 100644
--- 
a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/KameletBindingLoaderTest.groovy
+++ 
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/KameletBindingLoaderTest.groovy
@@ -513,4 +513,43 @@ class KameletBindingLoaderTest extends YamlTestSupport {
         }
     }
 
+    def "kamelet binding from kamelet to knative"() {
+        when:
+
+        // stub knative for testing as it requires to setup connection to a 
real knative broker
+        context.removeComponent("knative")
+        context.addComponent("knative", context.getComponent("stub"))
+
+        loadBindings('''
+                apiVersion: camel.apache.org/v1alpha1
+                kind: KameletBinding
+                metadata:
+                  name: timer-event-source                  
+                spec:
+                  source:
+                    ref:
+                      kind: Kamelet
+                      apiVersion: camel.apache.org/v1
+                      name: timer-source
+                    properties:
+                      message: "Hello world!"
+                  sink:
+                    ref:
+                      kind: InMemoryChannel
+                      apiVersion: messaging.knative.dev/v1
+                      name: my-messages
+            ''')
+        then:
+        context.routeDefinitions.size() == 2
+
+        with (context.routeDefinitions[0]) {
+            routeId == 'timer-event-source'
+            input.endpointUri == 'kamelet:timer-source?message=Hello+world%21'
+            outputs.size() == 1
+            with (outputs[0], ToDefinition) {
+                endpointUri == 'knative:channel/my-messages'
+            }
+        }
+    }
+
 }

Reply via email to