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:04 UTC
[camel-k-runtime] 08/18: YAML: add support for PollEnrich 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 4d8723be22a5b08bfa357057e123a1cf227a6c8d
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Sun Nov 24 15:36:08 2019 +0100
YAML: add support for PollEnrich EIP
---
.../k/loader/yaml/parser/PollEnrichStepParser.java | 54 +++++++++++++++++++
.../k/loader/yaml/parser/PollEnrichTest.groovy | 61 ++++++++++++++++++++++
2 files changed, 115 insertions(+)
diff --git a/camel-k-loader-yaml/src/main/java/org/apache/camel/k/loader/yaml/parser/PollEnrichStepParser.java b/camel-k-loader-yaml/src/main/java/org/apache/camel/k/loader/yaml/parser/PollEnrichStepParser.java
new file mode 100644
index 0000000..4f24db3
--- /dev/null
+++ b/camel-k-loader-yaml/src/main/java/org/apache/camel/k/loader/yaml/parser/PollEnrichStepParser.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.PollEnrichDefinition;
+import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.reifier.PollEnrichReifier;
+import org.apache.camel.reifier.ProcessorReifier;
+
+@YAMLStepParser("poll-enrich")
+public class PollEnrichStepParser implements ProcessorStepParser {
+ static {
+ ProcessorReifier.registerReifier(Definition.class, PollEnrichReifier::new);
+ }
+
+ @Override
+ public ProcessorDefinition<?> toProcessor(Context context) {
+ return context.node(Definition.class);
+ }
+
+ public static final class Definition extends PollEnrichDefinition 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/PollEnrichTest.groovy b/camel-k-loader-yaml/src/test/groovy/org/apache/camel/k/loader/yaml/parser/PollEnrichTest.groovy
new file mode 100644
index 0000000..1e2b3dc
--- /dev/null
+++ b/camel-k-loader-yaml/src/test/groovy/org/apache/camel/k/loader/yaml/parser/PollEnrichTest.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.PollEnrichDefinition
+
+class PollEnrichTest extends TestSupport {
+
+ def "definition with expression"() {
+ given:
+ def stepContext = stepContext('''
+ simple: "${body}"
+ strategy-ref: "myStrategy"
+ ''')
+ when:
+ def processor = new PollEnrichStepParser().toProcessor(stepContext)
+ then:
+ with(processor, PollEnrichDefinition) {
+ 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 PollEnrichStepParser().toProcessor(stepContext)
+ then:
+ with(processor, PollEnrichDefinition) {
+ with(expression) {
+ language == 'simple'
+ expression == '${body}'
+ }
+ aggregationStrategyRef == 'myStrategy'
+ }
+ }
+
+}