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 2015/03/28 17:22:28 UTC

camel git commit: CAMEL-8557: Added unit test

Repository: camel
Updated Branches:
  refs/heads/master 7b76c6eba -> b1d482888


CAMEL-8557: 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/b1d48288
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b1d48288
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b1d48288

Branch: refs/heads/master
Commit: b1d48288856bfe5fb69a992ca9b5043e3e049211
Parents: 7b76c6e
Author: Claus Ibsen <da...@apache.org>
Authored: Sat Mar 28 17:19:30 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Mar 28 17:24:39 2015 +0100

----------------------------------------------------------------------
 .../FtpConsumerIdempotentMemoryRefTest.java     | 102 +++++++++++++++++++
 1 file changed, 102 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/b1d48288/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerIdempotentMemoryRefTest.java
----------------------------------------------------------------------
diff --git a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerIdempotentMemoryRefTest.java b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerIdempotentMemoryRefTest.java
new file mode 100644
index 0000000..8de66c9
--- /dev/null
+++ b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerIdempotentMemoryRefTest.java
@@ -0,0 +1,102 @@
+/**
+ * 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 java.util.concurrent.TimeUnit;
+
+import org.apache.camel.builder.NotifyBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.processor.idempotent.MemoryIdempotentRepository;
+import org.junit.Test;
+
+/**
+ * Memory repo test
+ */
+public class FtpConsumerIdempotentMemoryRefTest extends FtpServerTestSupport {
+
+    private MemoryIdempotentRepository repo;
+
+    private String getFtpUrl() {
+        return "ftp://admin@localhost:" + getPort()
+                + "/idempotent?password=admin&binary=false&idempotent=true&idempotentRepository=#myRepo&idempotentKey=${file:onlyname}&delete=true";
+    }
+
+    @Override
+    protected JndiRegistry createRegistry() throws Exception {
+        JndiRegistry jndi = super.createRegistry();
+        repo = new MemoryIdempotentRepository();
+        repo.setCacheSize(5);
+        jndi.bind("myRepo", repo);
+        return jndi;
+    }
+
+    @Test
+    public void testIdempotent() throws Exception {
+        NotifyBuilder notify = new NotifyBuilder(context).whenDone(5).create();
+        getMockEndpoint("mock:result").expectedMessageCount(5);
+
+        sendFile(getFtpUrl(), "Hello A", "a.txt");
+        sendFile(getFtpUrl(), "Hello B", "b.txt");
+        sendFile(getFtpUrl(), "Hello C", "c.txt");
+        sendFile(getFtpUrl(), "Hello D", "d.txt");
+        sendFile(getFtpUrl(), "Hello E", "e.txt");
+
+        assertMockEndpointsSatisfied();
+        assertTrue(notify.matches(5, TimeUnit.SECONDS));
+
+        assertEquals(5, repo.getCache().size());
+        assertTrue(repo.contains("a.txt"));
+        assertTrue(repo.contains("b.txt"));
+        assertTrue(repo.contains("c.txt"));
+        assertTrue(repo.contains("d.txt"));
+        assertTrue(repo.contains("e.txt"));
+
+        resetMocks();
+        notify = new NotifyBuilder(context).whenDone(4).create();
+
+        getMockEndpoint("mock:result").expectedMessageCount(2);
+
+        // duplicate
+        sendFile(getFtpUrl(), "Hello A", "a.txt");
+        sendFile(getFtpUrl(), "Hello B", "b.txt");
+        // new files
+        sendFile(getFtpUrl(), "Hello E", "f.txt");
+        sendFile(getFtpUrl(), "Hello E", "g.txt");
+
+        assertMockEndpointsSatisfied();
+        assertTrue(notify.matches(5, TimeUnit.SECONDS));
+
+        assertEquals(5, repo.getCache().size());
+        assertTrue(repo.contains("a.txt"));
+        assertTrue(repo.contains("b.txt"));
+        assertFalse(repo.contains("c.txt"));
+        assertFalse(repo.contains("d.txt"));
+        assertTrue(repo.contains("e.txt"));
+        assertTrue(repo.contains("f.txt"));
+        assertTrue(repo.contains("g.txt"));
+    }
+    
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                from(getFtpUrl()).to("mock:result");
+            }
+        };
+    }
+}
\ No newline at end of file