You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by lb...@apache.org on 2019/11/26 10:43:01 UTC
[camel-k-runtime] 05/18: YAML: add support for Enrich EIP
This is an automated email from the ASF dual-hosted git repository.
lburgazzoli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k-runtime.git
commit 1689b7c0b71bade8135e35953692856c8fe9ade1
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Sun Nov 24 15:16:26 2019 +0100
YAML: add support for Enrich EIP
---
.../k/loader/yaml/parser/EnrichStepParser.java | 54 +++++++++++++++++++
.../camel/k/loader/yaml/parser/EnrichTest.groovy | 61 ++++++++++++++++++++++
2 files changed, 115 insertions(+)
diff --git a/camel-k-loader-yaml/src/main/java/org/apache/camel/k/loader/yaml/parser/EnrichStepParser.java b/camel-k-loader-yaml/src/main/java/org/apache/camel/k/loader/yaml/parser/EnrichStepParser.java
new file mode 100644
index 0000000..6108a8c
--- /dev/null
+++ b/camel-k-loader-yaml/src/main/java/org/apache/camel/k/loader/yaml/parser/EnrichStepParser.java
@@ -0,0 +1,54 @@
+/*
+ * 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 com.fasterxml.jackson.annotation.JsonIgnore;
+import org.apache.camel.Expression;
+import org.apache.camel.k.annotation.yaml.YAMLStepParser;
+import org.apache.camel.k.loader.yaml.model.Step;
+import org.apache.camel.model.EnrichDefinition;
+import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.reifier.EnrichReifier;
+import org.apache.camel.reifier.ProcessorReifier;
+
+@YAMLStepParser("enrich")
+public class EnrichStepParser implements ProcessorStepParser {
+ static {
+ ProcessorReifier.registerReifier(Definition.class, EnrichReifier::new);
+ }
+
+ @Override
+ public ProcessorDefinition<?> toProcessor(Context context) {
+ return context.node(Definition.class);
+ }
+
+ public static final class Definition extends EnrichDefinition implements HasExpression, Step.Definition {
+ @JsonIgnore
+ public void setExpression(Expression expression) {
+ super.setExpression(expression);
+ }
+
+ public void setStrategyRef(String aggregationStrategyRef) {
+ super.setAggregationStrategyRef(aggregationStrategyRef);
+ }
+
+ public String getStrategyMethodName() {
+ return super.getAggregationStrategyRef();
+ }
+ }
+}
+
diff --git a/camel-k-loader-yaml/src/test/groovy/org/apache/camel/k/loader/yaml/parser/EnrichTest.groovy b/camel-k-loader-yaml/src/test/groovy/org/apache/camel/k/loader/yaml/parser/EnrichTest.groovy
new file mode 100644
index 0000000..c6f87b2
--- /dev/null
+++ b/camel-k-loader-yaml/src/test/groovy/org/apache/camel/k/loader/yaml/parser/EnrichTest.groovy
@@ -0,0 +1,61 @@
+/*
+ * 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.EnrichDefinition
+
+class EnrichTest extends TestSupport {
+
+ def "definition with expression"() {
+ given:
+ def stepContext = stepContext('''
+ simple: "${body}"
+ strategy-ref: "myStrategy"
+ ''')
+ when:
+ def processor = new EnrichStepParser().toProcessor(stepContext)
+ then:
+ with(processor, EnrichDefinition) {
+ with(expression) {
+ language == 'simple'
+ expression == '${body}'
+ }
+ aggregationStrategyRef == 'myStrategy'
+ }
+ }
+
+ def "definition with expression block"() {
+ given:
+ def stepContext = stepContext('''
+ expression:
+ simple: "${body}"
+ strategy-ref: "myStrategy"
+ ''')
+ when:
+ def processor = new EnrichStepParser().toProcessor(stepContext)
+ then:
+ with(processor, EnrichDefinition) {
+ with(expression) {
+ language == 'simple'
+ expression == '${body}'
+ }
+ aggregationStrategyRef == 'myStrategy'
+ }
+ }
+
+}