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/10/20 10:43:41 UTC
[camel] 01/02: CAMEL-18622: camel-yaml-dsl - Add support for camel.yaml/camelk.yaml file extension
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-3.18.x
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 876f882307b2c54d37d8b476f90d485b609362d7
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Oct 20 12:39:39 2022 +0200
CAMEL-18622: camel-yaml-dsl - Add support for camel.yaml/camelk.yaml file extension
---
.../org/apache/camel/routes-loader/camel.yaml | 2 +
.../org/apache/camel/routes-loader/camelk.yaml | 2 +
.../dsl/yaml/CamelKYamlRoutesBuilderLoader.java | 31 ++++++
.../dsl/yaml/CamelYamlRoutesBuilderLoader.java | 31 ++++++
.../camel/dsl/yaml/YamlRoutesBuilderLoader.java | 4 +
.../camel/dsl/yaml/ChoiceCamelExtTest.groovy | 111 +++++++++++++++++++++
.../camel/dsl/yaml/ChoiceCamelKExtTest.groovy | 111 +++++++++++++++++++++
.../camel/dsl/yaml/support/YamlTestSupport.groovy | 10 +-
8 files changed, 299 insertions(+), 3 deletions(-)
diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/META-INF/services/org/apache/camel/routes-loader/camel.yaml b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/META-INF/services/org/apache/camel/routes-loader/camel.yaml
new file mode 100644
index 00000000000..99b1490d923
--- /dev/null
+++ b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/META-INF/services/org/apache/camel/routes-loader/camel.yaml
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.dsl.yaml.CamelYamlRoutesBuilderLoader
diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/META-INF/services/org/apache/camel/routes-loader/camelk.yaml b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/META-INF/services/org/apache/camel/routes-loader/camelk.yaml
new file mode 100644
index 00000000000..aa182116b9f
--- /dev/null
+++ b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/META-INF/services/org/apache/camel/routes-loader/camelk.yaml
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.dsl.yaml.CamelKYamlRoutesBuilderLoader
diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/java/org/apache/camel/dsl/yaml/CamelKYamlRoutesBuilderLoader.java b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/java/org/apache/camel/dsl/yaml/CamelKYamlRoutesBuilderLoader.java
new file mode 100644
index 00000000000..9155acefa09
--- /dev/null
+++ b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/java/org/apache/camel/dsl/yaml/CamelKYamlRoutesBuilderLoader.java
@@ -0,0 +1,31 @@
+/*
+ * 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.api.management.ManagedResource;
+import org.apache.camel.spi.annotations.RoutesLoader;
+
+@ManagedResource(description = "Managed CamelK YAML RoutesBuilderLoader")
+@RoutesLoader(CamelKYamlRoutesBuilderLoader.EXTENSION)
+public class CamelKYamlRoutesBuilderLoader extends YamlRoutesBuilderLoader {
+
+ public static final String EXTENSION = "camelk.yaml";
+
+ public CamelKYamlRoutesBuilderLoader() {
+ super(EXTENSION);
+ }
+}
diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/java/org/apache/camel/dsl/yaml/CamelYamlRoutesBuilderLoader.java b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/java/org/apache/camel/dsl/yaml/CamelYamlRoutesBuilderLoader.java
new file mode 100644
index 00000000000..fd6d754926e
--- /dev/null
+++ b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/java/org/apache/camel/dsl/yaml/CamelYamlRoutesBuilderLoader.java
@@ -0,0 +1,31 @@
+/*
+ * 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.api.management.ManagedResource;
+import org.apache.camel.spi.annotations.RoutesLoader;
+
+@ManagedResource(description = "Managed Camel YAML RoutesBuilderLoader")
+@RoutesLoader(CamelYamlRoutesBuilderLoader.EXTENSION)
+public class CamelYamlRoutesBuilderLoader extends YamlRoutesBuilderLoader {
+
+ public static final String EXTENSION = "camel.yaml";
+
+ public CamelYamlRoutesBuilderLoader() {
+ super(EXTENSION);
+ }
+}
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 a6f8cea52ef..406a221fc03 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
@@ -108,6 +108,10 @@ public class YamlRoutesBuilderLoader extends YamlRoutesBuilderLoaderSupport {
super(EXTENSION);
}
+ YamlRoutesBuilderLoader(String extension) {
+ super(extension);
+ }
+
protected RouteBuilder builder(final YamlDeserializationContext ctx, final Node root) {
// we need to keep track of already configured items as the yaml-dsl returns a
diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/ChoiceCamelExtTest.groovy b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/ChoiceCamelExtTest.groovy
new file mode 100644
index 00000000000..8a1a08d5319
--- /dev/null
+++ b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/ChoiceCamelExtTest.groovy
@@ -0,0 +1,111 @@
+/*
+ * 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.dsl.yaml.support.YamlTestSupport
+import org.apache.camel.model.ChoiceDefinition
+import org.apache.camel.model.ToDefinition
+import org.apache.camel.model.WhenDefinition
+
+class ChoiceCamelExtTest extends YamlTestSupport {
+
+ def "choice definition"() {
+ when:
+ loadRoutesExt("camel.yaml", '''
+ - from:
+ uri: "direct:start"
+ steps:
+ - choice:
+ when:
+ - simple: "${body.size()} == 1"
+ steps:
+ - to: "log:when-a"
+ - expression:
+ simple: "${body.size()} == 2"
+ steps:
+ - to: "log:when-b"
+ otherwise:
+ steps:
+ - to: "log:otherwise"
+ ''')
+ then:
+ context.routeDefinitions.size() == 1
+
+ with(context.routeDefinitions[0].outputs[0], ChoiceDefinition) {
+ with(whenClauses[0], WhenDefinition) {
+ expression.language == 'simple'
+ expression.expression == '${body.size()} == 1'
+ with(outputs[0], ToDefinition) {
+ endpointUri == 'log:when-a'
+ }
+ }
+ with(whenClauses[1], WhenDefinition) {
+ expression.language == 'simple'
+ expression.expression == '${body.size()} == 2'
+ with(outputs[0], ToDefinition) {
+ endpointUri == 'log:when-b'
+ }
+ }
+ with(otherwise.outputs[0], ToDefinition) {
+ endpointUri == 'log:otherwise'
+ }
+ }
+ }
+
+ def "choice in precondition mode"() {
+ when:
+ loadRoutesExt("camel.yaml", '''
+ - from:
+ uri: "direct:start"
+ steps:
+ - choice:
+ precondition: true
+ when:
+ - simple: "{{?red}}"
+ steps:
+ - to: "mock:red"
+ - simple: "{{?blue}}"
+ steps:
+ - to: "mock:blue"
+ otherwise:
+ steps:
+ - to: "mock:other"
+ ''')
+ then:
+ context.routeDefinitions.size() == 1
+
+ with(context.routeDefinitions[0].outputs[0], ChoiceDefinition) {
+ with(whenClauses[0], WhenDefinition) {
+ expression.language == 'simple'
+ expression.expression == '{{?red}}'
+ with(outputs[0], ToDefinition) {
+ endpointUri == 'mock:red'
+ }
+ }
+ with(whenClauses[1], WhenDefinition) {
+ expression.language == 'simple'
+ expression.expression == '{{?blue}}'
+ with(outputs[0], ToDefinition) {
+ endpointUri == 'mock:blue'
+ }
+ }
+ with(otherwise.outputs[0], ToDefinition) {
+ endpointUri == 'mock:other'
+ }
+ }
+ }
+}
diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/ChoiceCamelKExtTest.groovy b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/ChoiceCamelKExtTest.groovy
new file mode 100644
index 00000000000..fdee6ef02e2
--- /dev/null
+++ b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/ChoiceCamelKExtTest.groovy
@@ -0,0 +1,111 @@
+/*
+ * 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.dsl.yaml.support.YamlTestSupport
+import org.apache.camel.model.ChoiceDefinition
+import org.apache.camel.model.ToDefinition
+import org.apache.camel.model.WhenDefinition
+
+class ChoiceCamelKExtTest extends YamlTestSupport {
+
+ def "choice definition"() {
+ when:
+ loadRoutesExt("camelk.yaml", '''
+ - from:
+ uri: "direct:start"
+ steps:
+ - choice:
+ when:
+ - simple: "${body.size()} == 1"
+ steps:
+ - to: "log:when-a"
+ - expression:
+ simple: "${body.size()} == 2"
+ steps:
+ - to: "log:when-b"
+ otherwise:
+ steps:
+ - to: "log:otherwise"
+ ''')
+ then:
+ context.routeDefinitions.size() == 1
+
+ with(context.routeDefinitions[0].outputs[0], ChoiceDefinition) {
+ with(whenClauses[0], WhenDefinition) {
+ expression.language == 'simple'
+ expression.expression == '${body.size()} == 1'
+ with(outputs[0], ToDefinition) {
+ endpointUri == 'log:when-a'
+ }
+ }
+ with(whenClauses[1], WhenDefinition) {
+ expression.language == 'simple'
+ expression.expression == '${body.size()} == 2'
+ with(outputs[0], ToDefinition) {
+ endpointUri == 'log:when-b'
+ }
+ }
+ with(otherwise.outputs[0], ToDefinition) {
+ endpointUri == 'log:otherwise'
+ }
+ }
+ }
+
+ def "choice in precondition mode"() {
+ when:
+ loadRoutesExt("camelk.yaml", '''
+ - from:
+ uri: "direct:start"
+ steps:
+ - choice:
+ precondition: true
+ when:
+ - simple: "{{?red}}"
+ steps:
+ - to: "mock:red"
+ - simple: "{{?blue}}"
+ steps:
+ - to: "mock:blue"
+ otherwise:
+ steps:
+ - to: "mock:other"
+ ''')
+ then:
+ context.routeDefinitions.size() == 1
+
+ with(context.routeDefinitions[0].outputs[0], ChoiceDefinition) {
+ with(whenClauses[0], WhenDefinition) {
+ expression.language == 'simple'
+ expression.expression == '{{?red}}'
+ with(outputs[0], ToDefinition) {
+ endpointUri == 'mock:red'
+ }
+ }
+ with(whenClauses[1], WhenDefinition) {
+ expression.language == 'simple'
+ expression.expression == '{{?blue}}'
+ with(outputs[0], ToDefinition) {
+ endpointUri == 'mock:blue'
+ }
+ }
+ with(otherwise.outputs[0], ToDefinition) {
+ endpointUri == 'mock:other'
+ }
+ }
+ }
+}
diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/support/YamlTestSupport.groovy b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/support/YamlTestSupport.groovy
index 692d9ab7c00..6091f7674c4 100644
--- a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/support/YamlTestSupport.groovy
+++ b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/support/YamlTestSupport.groovy
@@ -78,12 +78,16 @@ class YamlTestSupport extends Specification implements HasCamelContext {
}
def loadRoutes(String... resources) {
+ loadRoutesExt("yaml", resources)
+ }
+
+ def loadRoutesExt(String ext, String... resources) {
int index = 0
loadRoutes(
- resources.collect {
- it -> ResourceHelper.fromString("route-${index++}.yaml", it.stripIndent())
- }
+ resources.collect {
+ it -> ResourceHelper.fromString("route-${index++}." + ext, it.stripIndent())
+ }
)
}