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

acosentino pushed a commit to branch aggregate-attempt
in repository https://gitbox.apache.org/repos/asf/camel-kafka-connector.git

commit 712917ea9274feaf13bb5f4eeb2971b4f0c6e234
Author: Andrea Cosentino <[email protected]>
AuthorDate: Mon Jun 22 18:33:22 2020 +0200

    Added a StringAggregator basic
---
 .../aggregator/StringAggregator.java               | 44 ++++++++++++++++++++++
 .../camel/kafkaconnector/DataFormatTest.java       |  3 +-
 2 files changed, 46 insertions(+), 1 deletion(-)

diff --git 
a/core/src/main/java/org/apache/camel/kafkaconnector/aggregator/StringAggregator.java
 
b/core/src/main/java/org/apache/camel/kafkaconnector/aggregator/StringAggregator.java
new file mode 100644
index 0000000..61f8fb9
--- /dev/null
+++ 
b/core/src/main/java/org/apache/camel/kafkaconnector/aggregator/StringAggregator.java
@@ -0,0 +1,44 @@
+/*
+ * 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.kafkaconnector.aggregator;
+
+import org.apache.camel.AggregationStrategy;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+
+public class StringAggregator implements AggregationStrategy {
+
+    @Override
+    public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
+        // lets append the old body to the new body
+        if (oldExchange == null) {
+            return newExchange;
+        }
+
+        String body = oldExchange.getIn().getBody(String.class);
+        if (body != null) {
+            Message newIn = newExchange.getIn();
+            String newBody = newIn.getBody(String.class);
+            if (newBody != null) {
+                body += System.lineSeparator() + newBody;
+            }
+
+            newIn.setBody(body);
+        }
+        return newExchange;
+    }
+}
diff --git 
a/core/src/test/java/org/apache/camel/kafkaconnector/DataFormatTest.java 
b/core/src/test/java/org/apache/camel/kafkaconnector/DataFormatTest.java
index 9f18e28..fb76939 100644
--- a/core/src/test/java/org/apache/camel/kafkaconnector/DataFormatTest.java
+++ b/core/src/test/java/org/apache/camel/kafkaconnector/DataFormatTest.java
@@ -27,6 +27,7 @@ import org.junit.jupiter.api.Test;
 
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 public class DataFormatTest {
 
@@ -109,7 +110,7 @@ public class DataFormatTest {
 
         cms.start();
         HL7DataFormat hl7dfLoaded = 
dcc.getRegistry().lookupByNameAndType("hl7", HL7DataFormat.class);
-        assertFalse(hl7dfLoaded.isValidate());
+        assertTrue(hl7dfLoaded.isValidate());
         cms.stop();
     }
 }

Reply via email to