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/08/26 10:37:04 UTC
[camel] 02/04: CAMEL-18430: Added unit test
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 463899970d7baa92549bf83c03f25182bf89588a
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Aug 26 09:45:24 2022 +0200
CAMEL-18430: Added unit test
---
.../enricher/EnricherLambdaAggregateTest.java | 52 +++++++++++++++++++++
.../enricher/EnricherLambdaPojoAggregateTest.java | 53 ++++++++++++++++++++++
2 files changed, 105 insertions(+)
diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/enricher/EnricherLambdaAggregateTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/enricher/EnricherLambdaAggregateTest.java
new file mode 100644
index 00000000000..7ed69ce435d
--- /dev/null
+++ b/core/camel-core/src/test/java/org/apache/camel/processor/enricher/EnricherLambdaAggregateTest.java
@@ -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.processor.enricher;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.jupiter.api.Test;
+
+public class EnricherLambdaAggregateTest extends ContextTestSupport {
+
+ @Test
+ public void testEnrich() throws Exception {
+ getMockEndpoint("mock:result").expectedBodiesReceived("A+B");
+
+ template.sendBody("direct:start", "A");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .enrich("direct:b", (e1, e2) -> {
+ String b = e1.getMessage().getBody(String.class) + "+" + e2.getMessage().getBody(String.class);
+ e1.getMessage().setBody(b);
+ return e1;
+ })
+ .to("mock:result");
+
+ from("direct:b").setBody(constant("B"));
+ }
+ };
+ }
+
+}
diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/enricher/EnricherLambdaPojoAggregateTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/enricher/EnricherLambdaPojoAggregateTest.java
new file mode 100644
index 00000000000..b558940d7ce
--- /dev/null
+++ b/core/camel-core/src/test/java/org/apache/camel/processor/enricher/EnricherLambdaPojoAggregateTest.java
@@ -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.processor.enricher;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.AggregationStrategies;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.jupiter.api.Test;
+
+public class EnricherLambdaPojoAggregateTest extends ContextTestSupport {
+
+ @Test
+ public void testEnrich() throws Exception {
+ getMockEndpoint("mock:result").expectedBodiesReceived("A+B");
+
+ template.sendBody("direct:start", "A");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .enrich("direct:b", AggregationStrategies.bean(EnricherLambdaPojoAggregateTest.class, "merge"))
+ .to("mock:result");
+
+ from("direct:b").setBody(constant("B"));
+ }
+ };
+ }
+
+ public String merge(String a, String b) {
+ return a + "+" + b;
+ }
+
+}