camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/2] camel git commit: CAMEL-10004: Added unit test
Date Tue, 31 May 2016 13:43:45 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.17.x f276b5fbe -> 0be02b861
  refs/heads/master 02fa6a655 -> 3584f0905


CAMEL-10004: Added unit test


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/3584f090
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/3584f090
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/3584f090

Branch: refs/heads/master
Commit: 3584f090556c6f4d2860fda5f4eb48405c4a7a99
Parents: 02fa6a6
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Tue May 31 15:41:32 2016 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Tue May 31 15:42:27 2016 +0200

----------------------------------------------------------------------
 .../FtpPollEnrichBridgeErrorHandlerTest.java    | 90 ++++++++++++++++++++
 1 file changed, 90 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/3584f090/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpPollEnrichBridgeErrorHandlerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpPollEnrichBridgeErrorHandlerTest.java
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpPollEnrichBridgeErrorHandlerTest.java
new file mode 100644
index 0000000..c550a50
--- /dev/null
+++ b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpPollEnrichBridgeErrorHandlerTest.java
@@ -0,0 +1,90 @@
+/**
+ * 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.component.file.remote;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.processor.aggregate.AggregationStrategy;
+import org.junit.Test;
+
+import static org.apache.camel.util.ExchangeHelper.copyResultsPreservePattern;
+
+public class FtpPollEnrichBridgeErrorHandlerTest extends BaseServerTestSupport {
+
+    // we want to poll enrich from FTP and therefore want to fail fast if something is wrong
+    // and then bridge that error to the Camel routing error handler
+    // so we need to turn of reconnection attempts
+    // and turn of auto create as that will pre-login to check if the directory exists
+    // and in case of connection error then throw that as an exception
+    private String uri = "ftp://admin@localhost:" + getPort() + "/unknown/?password=admin"
+            + "&maximumReconnectAttempts=0&autoCreate=false&throwExceptionOnConnectFailed=true&consumer.bridgeErrorHandler=true";
+
+    @Test
+    public void testPollEnrich() throws Exception {
+        getMockEndpoint("mock:result").expectedMessageCount(0);
+        getMockEndpoint("mock:dead").expectedMessageCount(1);
+
+        template.sendBody("seda:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+
+        Exchange out = getMockEndpoint("mock:dead").getExchanges().get(0);
+        assertNotNull(out);
+
+        Exception caught = out.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class);
+        assertNotNull("Should store caught exception", caught);
+    }
+
+    @Override
+    protected RoutesBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                errorHandler(deadLetterChannel("mock:dead"));
+
+                from("seda:start")
+                    // the FTP server is not running and therefore we should get an exception
+                    // and use 60s timeout
+                    // and turn on aggregation on exception as we have turned on bridge error
handler,
+                    // so we want to run out custom aggregation strategy for exceptions as
well
+                    .pollEnrich(uri, 60000, new MyAggregationStrategy(), true)
+                    .to("mock:result");
+            }
+        };
+    }
+
+    private class MyAggregationStrategy implements AggregationStrategy {
+
+        @Override
+        public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
+            if (newExchange != null) {
+                copyResultsPreservePattern(oldExchange, newExchange);
+            } else {
+                // if no newExchange then there was no message from the external resource
+                // and therefore we should set an empty body to indicate this fact
+                // but keep headers/attachments as we want to propagate those
+                oldExchange.getIn().setBody(null);
+                oldExchange.setOut(null);
+            }
+            // in case of exception we are bridged then we want to perform redeliveries etc.
+            // so we need to turn of exhausted redelivery
+            oldExchange.removeProperties(Exchange.REDELIVERY_EXHAUSTED);
+            return oldExchange;
+        }
+    }
+}
\ No newline at end of file


Mime
View raw message