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

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


The following commit(s) were added to refs/heads/master by this push:
     new 0d9cf7f  Add more EIPS to YAML DSL (#303)
0d9cf7f is described below

commit 0d9cf7f78caaa26ce9668571bc44d702bf784f26
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu Apr 16 13:41:30 2020 +0200

    Add more EIPS to YAML DSL (#303)
---
 camel-k-loader-yaml/README.adoc                    |  7 +++
 .../k/loader/yaml/parser/RollbackStepParser.java   | 30 ++++++++++++
 .../k/loader/yaml/parser/ScriptStepParser.java     | 36 +++++++++++++++
 .../yaml/parser/SetExchangePatternStepParser.java  | 30 ++++++++++++
 .../camel/k/loader/yaml/parser/StepStepParser.java | 48 ++++++++++++++++++++
 .../yaml/parser/ThrowExceptionStepParser.java      | 30 ++++++++++++
 .../camel/k/loader/yaml/parser/RollbackTest.groovy | 41 +++++++++++++++++
 .../camel/k/loader/yaml/parser/ScriptTest.groovy   | 53 ++++++++++++++++++++++
 .../yaml/parser/SetExchangePatternTest.groovy      | 38 ++++++++++++++++
 .../camel/k/loader/yaml/parser/StepTest.groovy     | 52 +++++++++++++++++++++
 .../k/loader/yaml/parser/ThrowExceptionTest.groovy | 39 ++++++++++++++++
 11 files changed, 404 insertions(+)

diff --git a/camel-k-loader-yaml/README.adoc b/camel-k-loader-yaml/README.adoc
index 90df923..8566e7c 100644
--- a/camel-k-loader-yaml/README.adoc
+++ b/camel-k-loader-yaml/README.adoc
@@ -128,6 +128,7 @@ In case you want to use the data-format's default settings, 
you need to place an
 - Filter
 - From
 - Idempotent Consumer
+- Load Balance
 - Log
 - Loop
 - Marshal
@@ -142,15 +143,21 @@ In case you want to use the data-format's default 
settings, you need to place an
 - Remove Properties
 - Resequence
 - Rest DSL
+- Rollback
 - Routing Slip
 - Sample
+- Script
 - Set Body
+- Set Exchange Pattern
 - Set Header
 - Set Property
 - Sort
 - Split
+- Step
+- Stop
 - Threads
 - Throttle
+- Throw Exception
 - To
 - To Dynamic
 - Transform
diff --git 
a/camel-k-loader-yaml/camel-k-loader-yaml-common/src/main/java/org/apache/camel/k/loader/yaml/parser/RollbackStepParser.java
 
b/camel-k-loader-yaml/camel-k-loader-yaml-common/src/main/java/org/apache/camel/k/loader/yaml/parser/RollbackStepParser.java
new file mode 100644
index 0000000..4931752
--- /dev/null
+++ 
b/camel-k-loader-yaml/camel-k-loader-yaml-common/src/main/java/org/apache/camel/k/loader/yaml/parser/RollbackStepParser.java
@@ -0,0 +1,30 @@
+/*
+ * 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.k.loader.yaml.parser;
+
+import org.apache.camel.k.annotation.yaml.YAMLStepParser;
+import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.model.RollbackDefinition;
+
+@YAMLStepParser("rollback")
+public class RollbackStepParser implements ProcessorStepParser {
+    @Override
+    public ProcessorDefinition<?> toProcessor(Context context) {
+        return context.node(RollbackDefinition.class);
+    }
+}
+
diff --git 
a/camel-k-loader-yaml/camel-k-loader-yaml-common/src/main/java/org/apache/camel/k/loader/yaml/parser/ScriptStepParser.java
 
b/camel-k-loader-yaml/camel-k-loader-yaml-common/src/main/java/org/apache/camel/k/loader/yaml/parser/ScriptStepParser.java
new file mode 100644
index 0000000..105a1c5
--- /dev/null
+++ 
b/camel-k-loader-yaml/camel-k-loader-yaml-common/src/main/java/org/apache/camel/k/loader/yaml/parser/ScriptStepParser.java
@@ -0,0 +1,36 @@
+/*
+ * 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.k.loader.yaml.parser;
+
+import org.apache.camel.k.annotation.yaml.YAMLNodeDefinition;
+import org.apache.camel.k.annotation.yaml.YAMLStepParser;
+import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.model.ScriptDefinition;
+import org.apache.camel.reifier.ScriptReifier;
+
+@YAMLStepParser("script")
+public class ScriptStepParser implements ProcessorStepParser {
+    @Override
+    public ProcessorDefinition<?> toProcessor(Context context) {
+        return context.node(Definition.class);
+    }
+
+    @YAMLNodeDefinition(reifiers = ScriptReifier.class)
+    public static final class Definition extends ScriptDefinition implements 
HasExpression {
+    }
+}
+
diff --git 
a/camel-k-loader-yaml/camel-k-loader-yaml-common/src/main/java/org/apache/camel/k/loader/yaml/parser/SetExchangePatternStepParser.java
 
b/camel-k-loader-yaml/camel-k-loader-yaml-common/src/main/java/org/apache/camel/k/loader/yaml/parser/SetExchangePatternStepParser.java
new file mode 100644
index 0000000..3ad2ad5
--- /dev/null
+++ 
b/camel-k-loader-yaml/camel-k-loader-yaml-common/src/main/java/org/apache/camel/k/loader/yaml/parser/SetExchangePatternStepParser.java
@@ -0,0 +1,30 @@
+/*
+ * 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.k.loader.yaml.parser;
+
+import org.apache.camel.k.annotation.yaml.YAMLStepParser;
+import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.model.SetExchangePatternDefinition;
+
+@YAMLStepParser("set-exchange-pattern")
+public class SetExchangePatternStepParser implements ProcessorStepParser {
+    @Override
+    public ProcessorDefinition<?> toProcessor(Context context) {
+        return context.node(SetExchangePatternDefinition.class);
+    }
+}
+
diff --git 
a/camel-k-loader-yaml/camel-k-loader-yaml-common/src/main/java/org/apache/camel/k/loader/yaml/parser/StepStepParser.java
 
b/camel-k-loader-yaml/camel-k-loader-yaml-common/src/main/java/org/apache/camel/k/loader/yaml/parser/StepStepParser.java
new file mode 100644
index 0000000..26450ff
--- /dev/null
+++ 
b/camel-k-loader-yaml/camel-k-loader-yaml-common/src/main/java/org/apache/camel/k/loader/yaml/parser/StepStepParser.java
@@ -0,0 +1,48 @@
+/*
+ * 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.k.loader.yaml.parser;
+
+import java.util.List;
+
+import org.apache.camel.k.annotation.yaml.YAMLNodeDefinition;
+import org.apache.camel.k.annotation.yaml.YAMLStepParser;
+import org.apache.camel.k.loader.yaml.model.Step;
+import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.model.StepDefinition;
+
+@YAMLStepParser("step")
+public class StepStepParser implements ProcessorStepParser {
+    @Override
+    public ProcessorDefinition<?> toProcessor(Context context) {
+        final Definition definition = context.node(Definition.class);
+        final StepDefinition answer = new StepDefinition();
+
+        StepParserSupport.notNull(definition.steps, "steps");
+
+        return StepParserSupport.convertSteps(
+            context,
+            answer,
+            definition.steps
+        );
+    }
+
+    @YAMLNodeDefinition
+    public static final class Definition {
+        public List<Step> steps;
+    }
+}
+
diff --git 
a/camel-k-loader-yaml/camel-k-loader-yaml-common/src/main/java/org/apache/camel/k/loader/yaml/parser/ThrowExceptionStepParser.java
 
b/camel-k-loader-yaml/camel-k-loader-yaml-common/src/main/java/org/apache/camel/k/loader/yaml/parser/ThrowExceptionStepParser.java
new file mode 100644
index 0000000..455e565
--- /dev/null
+++ 
b/camel-k-loader-yaml/camel-k-loader-yaml-common/src/main/java/org/apache/camel/k/loader/yaml/parser/ThrowExceptionStepParser.java
@@ -0,0 +1,30 @@
+/*
+ * 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.k.loader.yaml.parser;
+
+import org.apache.camel.k.annotation.yaml.YAMLStepParser;
+import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.model.ThrowExceptionDefinition;
+
+@YAMLStepParser("throw-exception")
+public class ThrowExceptionStepParser implements ProcessorStepParser {
+    @Override
+    public ProcessorDefinition<?> toProcessor(Context context) {
+        return context.node(ThrowExceptionDefinition.class);
+    }
+}
+
diff --git 
a/camel-k-loader-yaml/camel-k-loader-yaml/src/test/groovy/org/apache/camel/k/loader/yaml/parser/RollbackTest.groovy
 
b/camel-k-loader-yaml/camel-k-loader-yaml/src/test/groovy/org/apache/camel/k/loader/yaml/parser/RollbackTest.groovy
new file mode 100644
index 0000000..3ba76f6
--- /dev/null
+++ 
b/camel-k-loader-yaml/camel-k-loader-yaml/src/test/groovy/org/apache/camel/k/loader/yaml/parser/RollbackTest.groovy
@@ -0,0 +1,41 @@
+/*
+ * 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.k.loader.yaml.parser
+
+import org.apache.camel.k.loader.yaml.TestSupport
+import org.apache.camel.model.IdempotentConsumerDefinition
+import org.apache.camel.model.LogDefinition
+import org.apache.camel.model.RollbackDefinition
+
+class RollbackTest extends TestSupport {
+
+    def "definition"() {
+        given:
+        def stepContext = stepContext('''
+                 mark-rollback-only: "true"
+                 message: "test"
+            ''')
+        when:
+        def processor = new RollbackStepParser().toProcessor(stepContext)
+        then:
+        with(processor, RollbackDefinition) {
+            markRollbackOnly == "true"
+            message == 'test'
+        }
+    }
+
+}
diff --git 
a/camel-k-loader-yaml/camel-k-loader-yaml/src/test/groovy/org/apache/camel/k/loader/yaml/parser/ScriptTest.groovy
 
b/camel-k-loader-yaml/camel-k-loader-yaml/src/test/groovy/org/apache/camel/k/loader/yaml/parser/ScriptTest.groovy
new file mode 100644
index 0000000..2dfdcfb
--- /dev/null
+++ 
b/camel-k-loader-yaml/camel-k-loader-yaml/src/test/groovy/org/apache/camel/k/loader/yaml/parser/ScriptTest.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.k.loader.yaml.parser
+
+import org.apache.camel.k.loader.yaml.TestSupport
+import org.apache.camel.model.ScriptDefinition
+
+class ScriptTest extends TestSupport {
+
+    def "definition with expression"() {
+        given:
+            def stepContext = stepContext('''
+                 simple: "Hello ${body}"
+            ''')
+        when:
+            def processor = new ScriptStepParser().toProcessor(stepContext)
+        then:
+            with(processor, ScriptDefinition) {
+                expression.language == 'simple'
+                expression.expression == 'Hello ${body}'
+            }
+    }
+
+    def "definition with expression block"() {
+        given:
+            def stepContext = stepContext('''
+                 expression:
+                   simple: "Bye ${body}"
+            ''')
+        when:
+            def processor = new ScriptStepParser().toProcessor(stepContext)
+        then:
+            with(processor, ScriptDefinition) {
+                expression.language == 'simple'
+                expression.expression == 'Bye ${body}'
+            }
+    }
+
+}
diff --git 
a/camel-k-loader-yaml/camel-k-loader-yaml/src/test/groovy/org/apache/camel/k/loader/yaml/parser/SetExchangePatternTest.groovy
 
b/camel-k-loader-yaml/camel-k-loader-yaml/src/test/groovy/org/apache/camel/k/loader/yaml/parser/SetExchangePatternTest.groovy
new file mode 100644
index 0000000..a7d3531
--- /dev/null
+++ 
b/camel-k-loader-yaml/camel-k-loader-yaml/src/test/groovy/org/apache/camel/k/loader/yaml/parser/SetExchangePatternTest.groovy
@@ -0,0 +1,38 @@
+/*
+ * 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.k.loader.yaml.parser
+
+import org.apache.camel.ExchangePattern
+import org.apache.camel.k.loader.yaml.TestSupport
+import org.apache.camel.model.SetExchangePatternDefinition
+
+class SetExchangePatternTest extends TestSupport {
+
+    def "definition"() {
+        given:
+            def stepContext = stepContext('''
+                 pattern: "InOut"
+            ''')
+        when:
+            def processor = new 
SetExchangePatternStepParser().toProcessor(stepContext)
+        then:
+            with(processor, SetExchangePatternDefinition) {
+                pattern == ExchangePattern.InOut.name()
+            }
+    }
+
+}
diff --git 
a/camel-k-loader-yaml/camel-k-loader-yaml/src/test/groovy/org/apache/camel/k/loader/yaml/parser/StepTest.groovy
 
b/camel-k-loader-yaml/camel-k-loader-yaml/src/test/groovy/org/apache/camel/k/loader/yaml/parser/StepTest.groovy
new file mode 100644
index 0000000..a25b269
--- /dev/null
+++ 
b/camel-k-loader-yaml/camel-k-loader-yaml/src/test/groovy/org/apache/camel/k/loader/yaml/parser/StepTest.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.k.loader.yaml.parser
+
+import org.apache.camel.k.loader.yaml.TestSupport
+import org.apache.camel.model.StepDefinition
+
+class StepTest extends TestSupport {
+
+    def "definition"() {
+        given:
+            def stepContext = stepContext('''
+                 steps:
+                   - log:
+                       message: "test"
+                   - to:
+                       uri: "seda:foo"    
+            ''')
+        when:
+            def processor = new StepStepParser().toProcessor(stepContext)
+        then:
+            with(processor, StepDefinition) {
+                !outputs.empty
+            }
+    }
+
+    def "should fail without steps"() {
+        given:
+            def stepContext = 
stepContext(TestSupport.MAPPER.createObjectNode());
+        when:
+            new StepStepParser().toProcessor(stepContext)
+        then:
+            def ex = thrown(StepParserException)
+
+            ex.properties.contains('steps')
+    }
+
+}
diff --git 
a/camel-k-loader-yaml/camel-k-loader-yaml/src/test/groovy/org/apache/camel/k/loader/yaml/parser/ThrowExceptionTest.groovy
 
b/camel-k-loader-yaml/camel-k-loader-yaml/src/test/groovy/org/apache/camel/k/loader/yaml/parser/ThrowExceptionTest.groovy
new file mode 100644
index 0000000..d592d14
--- /dev/null
+++ 
b/camel-k-loader-yaml/camel-k-loader-yaml/src/test/groovy/org/apache/camel/k/loader/yaml/parser/ThrowExceptionTest.groovy
@@ -0,0 +1,39 @@
+/*
+ * 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.k.loader.yaml.parser
+
+import org.apache.camel.k.loader.yaml.TestSupport
+import org.apache.camel.model.ThrowExceptionDefinition
+
+class ThrowExceptionTest extends TestSupport {
+
+    def "definition"() {
+        given:
+            def stepContext = stepContext('''
+                     exception-type: "java.lang.IllegalArgumentException"
+                     message: "test"
+                ''')
+        when:
+            def processor = new 
ThrowExceptionStepParser().toProcessor(stepContext)
+        then:
+            with(processor, ThrowExceptionDefinition) {
+                message == 'test'
+                exceptionType == "java.lang.IllegalArgumentException"
+            }
+    }
+
+}

Reply via email to