Return-Path: Delivered-To: apmail-camel-commits-archive@www.apache.org Received: (qmail 9293 invoked from network); 20 Dec 2010 14:23:42 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 20 Dec 2010 14:23:42 -0000 Received: (qmail 80242 invoked by uid 500); 20 Dec 2010 14:23:42 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 80217 invoked by uid 500); 20 Dec 2010 14:23:42 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 80210 invoked by uid 99); 20 Dec 2010 14:23:41 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 20 Dec 2010 14:23:41 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 20 Dec 2010 14:23:39 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 08EA623888CE; Mon, 20 Dec 2010 14:23:19 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1051127 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/component/file/ camel-core/src/main/java/org/apache/camel/component/file/strategy/ camel-core/src/test/java/org/apache/camel/component/file/ components/camel-ftp/src/test... Date: Mon, 20 Dec 2010 14:23:18 -0000 To: commits@camel.apache.org From: davsclaus@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20101220142319.08EA623888CE@eris.apache.org> Author: davsclaus Date: Mon Dec 20 14:23:18 2010 New Revision: 1051127 URL: http://svn.apache.org/viewvc?rev=1051127&view=rev Log: CAMEL-3163: File/FTP consumer now support doneFileName option to only consume a file if a done file exists as well. Added: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerDoneFileNamePrefixTest.java camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerDoneFileNameSimplePrefixTest.java camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerDoneFileNameSuffixTest.java camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerDoneFileNameTest.java - copied, changed from r1050776, camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FilerProducerDoneFileNameTest.java camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerDualDoneFileNameTest.java camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerPreMoveDoneFileNameTest.java camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerShouldSkipDoneFilePrefixTest.java camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerShouldSkipDoneFileSuffixTest.java camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerShouldSkipDoneFileTest.java camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDoneFileNameTest.java - copied, changed from r1051031, camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpRecursiveNoopTest.java camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDualDoneFileNameTest.java Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileOnCompletion.java camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileProcessStrategyFactory.java Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java?rev=1051127&r1=1051126&r2=1051127&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java Mon Dec 20 14:23:18 2010 @@ -426,6 +426,29 @@ public abstract class GenericFileConsume } } + // if done file name is enabled, then the file is only valid if a done file exists + if (endpoint.getDoneFileName() != null) { + // done file must be in same path as the file + String doneFileName = endpoint.createDoneFileName(file.getAbsoluteFilePath()); + ObjectHelper.notEmpty(doneFileName, "doneFileName", endpoint); + + // is it a done file name? + if (endpoint.isDoneFile(file.getFileNameOnly())) { + if (log.isTraceEnabled()) { + log.trace("Skipping done file: " + file); + } + return false; + } + + // the file is only valid if the done file exist + if (!operations.existsFile(doneFileName)) { + if (log.isTraceEnabled()) { + log.trace("Done file: " + doneFileName + " does not exist"); + } + return false; + } + } + return true; } Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java?rev=1051127&r1=1051126&r2=1051127&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java Mon Dec 20 14:23:18 2010 @@ -27,6 +27,7 @@ import org.apache.camel.CamelContext; import org.apache.camel.Component; import org.apache.camel.Exchange; import org.apache.camel.Expression; +import org.apache.camel.ExpressionIllegalSyntaxException; import org.apache.camel.Message; import org.apache.camel.Processor; import org.apache.camel.converter.IOConverter; @@ -613,4 +614,84 @@ public abstract class GenericFileEndpoin } return language.createExpression(expression); } + + /** + * Creates the associated name of the done file based on the given file name. + *

+ * This method should only be invoked if a done filename property has been set on this endpoint. + * + * @param fileName the file name + * @return name of the associated done file name + */ + protected String createDoneFileName(String fileName) { + String pattern = getDoneFileName(); + ObjectHelper.notEmpty(pattern, "doneFileName", pattern); + + // we only support ${file:name} or ${file:name.noext} as dynamic placeholders for done files + String path = FileUtil.onlyPath(fileName); + String onlyName = FileUtil.stripPath(fileName); + + pattern = pattern.replaceFirst("\\$\\{file:name\\}", onlyName); + pattern = pattern.replaceFirst("\\$simple\\{file:name\\}", onlyName); + pattern = pattern.replaceFirst("\\$\\{file:name.noext\\}", FileUtil.stripExt(onlyName)); + pattern = pattern.replaceFirst("\\$simple\\{file:name.noext\\}", FileUtil.stripExt(onlyName)); + + // must be able to resolve all placeholders supported + if (SimpleLanguage.hasStartToken(pattern)) { + throw new ExpressionIllegalSyntaxException(fileName + ". Cannot resolve reminder: " + pattern); + } + + String answer = pattern; + if (ObjectHelper.isNotEmpty(path) && ObjectHelper.isNotEmpty(pattern)) { + // done file must always be in same directory as the real file name + answer = path + File.separator + pattern; + } + + if (getConfiguration().needToNormalize()) { + // must normalize path to cater for Windows and other OS + answer = FileUtil.normalizePath(answer); + } + + return answer; + } + + /** + * Is the given file a done file? + *

+ * This method should only be invoked if a done filename property has been set on this endpoint. + * + * @param fileName the file name + * @return true if its a done file, false otherwise + */ + protected boolean isDoneFile(String fileName) { + String pattern = getDoneFileName(); + ObjectHelper.notEmpty(pattern, "doneFileName", pattern); + + if (!SimpleLanguage.hasStartToken(pattern)) { + // no tokens, so just match names directly + return pattern.equals(fileName); + } + + // the static part of the pattern, is that a prefix or suffix? + // its a prefix if ${ start token is not at the start of the pattern + boolean prefix = pattern.indexOf("${") > 0; + + // remove dynamic parts of the pattern so we only got the static part left + pattern = pattern.replaceFirst("\\$\\{file:name\\}", ""); + pattern = pattern.replaceFirst("\\$simple\\{file:name\\}", ""); + pattern = pattern.replaceFirst("\\$\\{file:name.noext\\}", ""); + pattern = pattern.replaceFirst("\\$simple\\{file:name.noext\\}", ""); + + // must be able to resolve all placeholders supported + if (SimpleLanguage.hasStartToken(pattern)) { + throw new ExpressionIllegalSyntaxException(fileName + ". Cannot resolve reminder: " + pattern); + } + + if (prefix) { + return fileName.startsWith(pattern); + } else { + return fileName.endsWith(pattern); + } + } + } Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileOnCompletion.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileOnCompletion.java?rev=1051127&r1=1051126&r2=1051127&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileOnCompletion.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileOnCompletion.java Mon Dec 20 14:23:18 2010 @@ -20,6 +20,7 @@ import org.apache.camel.Exchange; import org.apache.camel.impl.LoggingExceptionHandler; import org.apache.camel.spi.ExceptionHandler; import org.apache.camel.spi.Synchronization; +import org.apache.camel.util.ObjectHelper; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -114,6 +115,26 @@ public class GenericFileOnCompletion endpoint.getIdempotentRepository().add(absoluteFileName); } + // delete done file if used + if (endpoint.getDoneFileName() != null) { + // done file must be in same path as the original input file + String doneFileName = endpoint.createDoneFileName(absoluteFileName); + ObjectHelper.notEmpty(doneFileName, "doneFileName", endpoint); + + try { + // delete done file + boolean deleted = operations.deleteFile(doneFileName); + if (log.isTraceEnabled()) { + log.trace("Done file: " + doneFileName + " was deleted: " + deleted); + } + if (!deleted) { + log.warn("Done file: " + doneFileName + " could not be deleted"); + } + } catch (Exception e) { + handleException(e); + } + } + try { if (log.isTraceEnabled()) { log.trace("Commit file strategy: " + processStrategy + " for file: " + file); @@ -122,6 +143,8 @@ public class GenericFileOnCompletion } catch (Exception e) { handleException(e); } + + } /** Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java?rev=1051127&r1=1051126&r2=1051127&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java Mon Dec 20 14:23:18 2010 @@ -166,7 +166,7 @@ public class GenericFileProducer exte // any done file to write? if (endpoint.getDoneFileName() != null) { - String doneFileName = createDoneName(target); + String doneFileName = endpoint.createDoneFileName(target); ObjectHelper.notEmpty(doneFileName, "doneFileName", endpoint); // create empty exchange with empty body to write as the done file @@ -335,28 +335,4 @@ public class GenericFileProducer exte } } - public String createDoneName(String fileName) { - String pattern = endpoint.getDoneFileName(); - ObjectHelper.notEmpty(pattern, "doneFileName", endpoint); - - // we only support ${file:name} or ${file:name.noext} as dynamic placeholders for done files - String path = FileUtil.onlyPath(fileName); - String onlyName = FileUtil.stripPath(fileName); - - pattern = pattern.replaceFirst("\\$\\{file:name\\}", onlyName); - pattern = pattern.replaceFirst("\\$\\{file:name.noext\\}", FileUtil.stripExt(onlyName)); - - // must be able to resolve all placeholders supported - if (SimpleLanguage.hasStartToken(pattern)) { - throw new ExpressionIllegalSyntaxException(fileName + ". Cannot resolve reminder: " + pattern); - } - - // done file must always be in same directory as the real file name - if (ObjectHelper.isNotEmpty(pattern)) { - return path + File.separator + pattern; - } else { - return pattern; - } - } - } Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileProcessStrategyFactory.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileProcessStrategyFactory.java?rev=1051127&r1=1051126&r2=1051127&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileProcessStrategyFactory.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileProcessStrategyFactory.java Mon Dec 20 14:23:18 2010 @@ -91,7 +91,7 @@ public final class GenericFileProcessStr return strategy; } - // no explicit stategy set then fallback to readLock option + // no explicit strategy set then fallback to readLock option String readLock = (String) params.get("readLock"); if (ObjectHelper.isNotEmpty(readLock)) { if ("none".equals(readLock) || "false".equals(readLock)) { Added: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerDoneFileNamePrefixTest.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerDoneFileNamePrefixTest.java?rev=1051127&view=auto ============================================================================== --- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerDoneFileNamePrefixTest.java (added) +++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerDoneFileNamePrefixTest.java Mon Dec 20 14:23:18 2010 @@ -0,0 +1,71 @@ +/** + * 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; + +import java.io.File; + +import org.apache.camel.ContextTestSupport; +import org.apache.camel.Exchange; +import org.apache.camel.builder.RouteBuilder; + +/** + * Unit test for writing done files + */ +public class FilerConsumerDoneFileNamePrefixTest extends ContextTestSupport { + + @Override + protected void setUp() throws Exception { + deleteDirectory("target/done"); + super.setUp(); + } + + public void testDoneFile() throws Exception { + getMockEndpoint("mock:result").expectedMessageCount(0); + + template.sendBodyAndHeader("file:target/done", "Hello World", Exchange.FILE_NAME, "hello.txt"); + + // wait a bit and it should not pickup the written file as there are no done file + Thread.sleep(250); + + assertMockEndpointsSatisfied(); + resetMocks(); + oneExchangeDone.reset(); + + getMockEndpoint("mock:result").expectedBodiesReceived("Hello World"); + + // write the done file + template.sendBodyAndHeader("file:target/done", "", Exchange.FILE_NAME, "done-hello.txt"); + + assertMockEndpointsSatisfied(); + oneExchangeDone.matchesMockWaitTime(); + + // done file should be deleted now + File file = new File("target/done/done-hello.txt").getAbsoluteFile(); + assertFalse("Done file should be deleted: " + file, file.exists()); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("file:target/done?doneFileName=done-${file:name}&initialDelay=0&delay=10").to("mock:result"); + } + }; + } + +} Added: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerDoneFileNameSimplePrefixTest.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerDoneFileNameSimplePrefixTest.java?rev=1051127&view=auto ============================================================================== --- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerDoneFileNameSimplePrefixTest.java (added) +++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerDoneFileNameSimplePrefixTest.java Mon Dec 20 14:23:18 2010 @@ -0,0 +1,72 @@ +/** + * 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; + +import java.io.File; + +import org.apache.camel.ContextTestSupport; +import org.apache.camel.Exchange; +import org.apache.camel.builder.RouteBuilder; + +/** + * Unit test for writing done files + */ +public class FilerConsumerDoneFileNameSimplePrefixTest extends ContextTestSupport { + + @Override + protected void setUp() throws Exception { + deleteDirectory("target/done"); + super.setUp(); + } + + public void testDoneFile() throws Exception { + getMockEndpoint("mock:result").expectedMessageCount(0); + + template.sendBodyAndHeader("file:target/done", "Hello World", Exchange.FILE_NAME, "hello.txt"); + + // wait a bit and it should not pickup the written file as there are no done file + Thread.sleep(250); + + assertMockEndpointsSatisfied(); + resetMocks(); + oneExchangeDone.reset(); + + getMockEndpoint("mock:result").expectedBodiesReceived("Hello World"); + + // write the done file + template.sendBodyAndHeader("file:target/done", "", Exchange.FILE_NAME, "done-hello.txt"); + + assertMockEndpointsSatisfied(); + oneExchangeDone.matchesMockWaitTime(); + + // done file should be deleted now + File file = new File("target/done/done-hello.txt").getAbsoluteFile(); + assertFalse("Done file should be deleted: " + file, file.exists()); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + // using $simple{ to avoid clash with spring property placeholder + from("file:target/done?doneFileName=done-$simple{file:name}&initialDelay=0&delay=10").to("mock:result"); + } + }; + } + +} Added: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerDoneFileNameSuffixTest.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerDoneFileNameSuffixTest.java?rev=1051127&view=auto ============================================================================== --- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerDoneFileNameSuffixTest.java (added) +++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerDoneFileNameSuffixTest.java Mon Dec 20 14:23:18 2010 @@ -0,0 +1,71 @@ +/** + * 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; + +import java.io.File; + +import org.apache.camel.ContextTestSupport; +import org.apache.camel.Exchange; +import org.apache.camel.builder.RouteBuilder; + +/** + * Unit test for writing done files + */ +public class FilerConsumerDoneFileNameSuffixTest extends ContextTestSupport { + + @Override + protected void setUp() throws Exception { + deleteDirectory("target/done"); + super.setUp(); + } + + public void testDoneFile() throws Exception { + getMockEndpoint("mock:result").expectedMessageCount(0); + + template.sendBodyAndHeader("file:target/done", "Hello World", Exchange.FILE_NAME, "hello.txt"); + + // wait a bit and it should not pickup the written file as there are no done file + Thread.sleep(250); + + assertMockEndpointsSatisfied(); + resetMocks(); + oneExchangeDone.reset(); + + getMockEndpoint("mock:result").expectedBodiesReceived("Hello World"); + + // write the done file + template.sendBodyAndHeader("file:target/done", "", Exchange.FILE_NAME, "hello.txt.ready"); + + assertMockEndpointsSatisfied(); + oneExchangeDone.matchesMockWaitTime(); + + // done file should be deleted now + File file = new File("target/done/hello.txt.ready").getAbsoluteFile(); + assertFalse("Done file should be deleted: " + file, file.exists()); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("file:target/done?doneFileName=${file:name}.ready&initialDelay=0&delay=10").to("mock:result"); + } + }; + } + +} Copied: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerDoneFileNameTest.java (from r1050776, camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FilerProducerDoneFileNameTest.java) URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerDoneFileNameTest.java?p2=camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerDoneFileNameTest.java&p1=camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FilerProducerDoneFileNameTest.java&r1=1050776&r2=1051127&rev=1051127&view=diff ============================================================================== --- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FilerProducerDoneFileNameTest.java (original) +++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerDoneFileNameTest.java Mon Dec 20 14:23:18 2010 @@ -18,15 +18,14 @@ package org.apache.camel.component.file; import java.io.File; -import org.apache.camel.CamelExecutionException; import org.apache.camel.ContextTestSupport; import org.apache.camel.Exchange; -import org.apache.camel.ExpressionIllegalSyntaxException; +import org.apache.camel.builder.RouteBuilder; /** * Unit test for writing done files */ -public class FilerProducerDoneFileNameTest extends ContextTestSupport { +public class FilerConsumerDoneFileNameTest extends ContextTestSupport { @Override protected void setUp() throws Exception { @@ -34,68 +33,39 @@ public class FilerProducerDoneFileNameTe super.setUp(); } - public void testProducerConstantDoneFileName() throws Exception { - template.sendBodyAndHeader("file:target/done?doneFileName=done", "Hello World", Exchange.FILE_NAME, "hello.txt"); + public void testDoneFile() throws Exception { + getMockEndpoint("mock:result").expectedMessageCount(0); - File file = new File("target/done/hello.txt").getAbsoluteFile(); - assertEquals("File should exists", true, file.exists()); + template.sendBodyAndHeader("file:target/done", "Hello World", Exchange.FILE_NAME, "hello.txt"); - File done = new File("target/done/done").getAbsoluteFile(); - assertEquals("Done file should exists", true, done.exists()); - } - - public void testProducerPrefixDoneFileName() throws Exception { - template.sendBodyAndHeader("file:target/done?doneFileName=done-${file:name}", "Hello World", Exchange.FILE_NAME, "hello.txt"); - - File file = new File("target/done/hello.txt").getAbsoluteFile(); - assertEquals("File should exists", true, file.exists()); - - File done = new File("target/done/done-hello.txt").getAbsoluteFile(); - assertEquals("Done file should exists", true, done.exists()); - } - - public void testProducerExtDoneFileName() throws Exception { - template.sendBodyAndHeader("file:target/done?doneFileName=${file:name}.done", "Hello World", Exchange.FILE_NAME, "hello.txt"); + // wait a bit and it should not pickup the written file as there are no done file + Thread.sleep(250); - File file = new File("target/done/hello.txt").getAbsoluteFile(); - assertEquals("File should exists", true, file.exists()); + assertMockEndpointsSatisfied(); + resetMocks(); + oneExchangeDone.reset(); - File done = new File("target/done/hello.txt.done").getAbsoluteFile(); - assertEquals("Done file should exists", true, done.exists()); - } - - public void testProducerReplaceExtDoneFileName() throws Exception { - template.sendBodyAndHeader("file:target/done?doneFileName=${file:name.noext}.done", "Hello World", Exchange.FILE_NAME, "hello.txt"); - - File file = new File("target/done/hello.txt").getAbsoluteFile(); - assertEquals("File should exists", true, file.exists()); + getMockEndpoint("mock:result").expectedBodiesReceived("Hello World"); - File done = new File("target/done/hello.done").getAbsoluteFile(); - assertEquals("Done file should exists", true, done.exists()); - } + // write the done file + template.sendBodyAndHeader("file:target/done", "", Exchange.FILE_NAME, "done"); - public void testProducerInvalidDoneFileName() throws Exception { - try { - template.sendBodyAndHeader("file:target/done?doneFileName=${file:parent}/foo", "Hello World", Exchange.FILE_NAME, "hello.txt"); - fail("Should have thrown exception"); - } catch (CamelExecutionException e) { - ExpressionIllegalSyntaxException cause = assertIsInstanceOf(ExpressionIllegalSyntaxException.class, e.getCause()); - assertTrue(cause.getMessage(), cause.getMessage().endsWith("Cannot resolve reminder: ${file:parent}/foo")); - } - } + assertMockEndpointsSatisfied(); + oneExchangeDone.matchesMockWaitTime(); - public void testProducerEmptyDoneFileName() throws Exception { - try { - template.sendBodyAndHeader("file:target/done?doneFileName=", "Hello World", Exchange.FILE_NAME, "hello.txt"); - fail("Should have thrown exception"); - } catch (CamelExecutionException e) { - IllegalArgumentException cause = assertIsInstanceOf(IllegalArgumentException.class, e.getCause()); - assertTrue(cause.getMessage(), cause.getMessage().startsWith("doneFileName must be specified and not empty")); - } + // done file should be deleted now + File file = new File("target/done/done").getAbsoluteFile(); + assertFalse("Done file should be deleted: " + file, file.exists()); } @Override - public boolean isUseRouteBuilder() { - return false; + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("file:target/done?doneFileName=done&initialDelay=0&delay=10").to("mock:result"); + } + }; } + } Added: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerDualDoneFileNameTest.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerDualDoneFileNameTest.java?rev=1051127&view=auto ============================================================================== --- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerDualDoneFileNameTest.java (added) +++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerDualDoneFileNameTest.java Mon Dec 20 14:23:18 2010 @@ -0,0 +1,65 @@ +/** + * 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; + +import org.apache.camel.ContextTestSupport; +import org.apache.camel.Exchange; +import org.apache.camel.builder.RouteBuilder; + +/** + * Unit test for writing done files + */ +public class FilerConsumerDualDoneFileNameTest extends ContextTestSupport { + + @Override + protected void setUp() throws Exception { + deleteDirectory("target/done"); + super.setUp(); + } + + public void testTwoDoneFile() throws Exception { + getMockEndpoint("mock:result").expectedBodiesReceivedInAnyOrder("Hello World", "Bye World"); + + template.sendBodyAndHeader("file:target/done?doneFileName=${file:name}.ready", "Hello World", Exchange.FILE_NAME, "hello.txt"); + template.sendBodyAndHeader("file:target/done?doneFileName=${file:name}.ready", "Bye World", Exchange.FILE_NAME, "bye.txt"); + + assertMockEndpointsSatisfied(); + } + + public void testOneDoneFileMissing() throws Exception { + getMockEndpoint("mock:result").expectedBodiesReceived("Hello World"); + + template.sendBodyAndHeader("file:target/done?doneFileName=${file:name}.ready", "Hello World", Exchange.FILE_NAME, "hello.txt"); + template.sendBodyAndHeader("file:target/done", "Bye World", Exchange.FILE_NAME, "bye.txt"); + + // give chance to poll 2nd file but it lacks the done file + Thread.sleep(250); + + assertMockEndpointsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("file:target/done?doneFileName=${file:name}.ready&initialDelay=0&delay=10").to("mock:result"); + } + }; + } + +} Added: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerPreMoveDoneFileNameTest.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerPreMoveDoneFileNameTest.java?rev=1051127&view=auto ============================================================================== --- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerPreMoveDoneFileNameTest.java (added) +++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerPreMoveDoneFileNameTest.java Mon Dec 20 14:23:18 2010 @@ -0,0 +1,71 @@ +/** + * 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; + +import java.io.File; + +import org.apache.camel.ContextTestSupport; +import org.apache.camel.Exchange; +import org.apache.camel.builder.RouteBuilder; + +/** + * Unit test for writing done files + */ +public class FilerConsumerPreMoveDoneFileNameTest extends ContextTestSupport { + + @Override + protected void setUp() throws Exception { + deleteDirectory("target/done"); + super.setUp(); + } + + public void testDoneFile() throws Exception { + getMockEndpoint("mock:result").expectedMessageCount(0); + + template.sendBodyAndHeader("file:target/done", "Hello World", Exchange.FILE_NAME, "hello.txt"); + + // wait a bit and it should not pickup the written file as there are no done file + Thread.sleep(250); + + assertMockEndpointsSatisfied(); + resetMocks(); + oneExchangeDone.reset(); + + getMockEndpoint("mock:result").expectedBodiesReceived("Hello World"); + + // write the done file + template.sendBodyAndHeader("file:target/done", "", Exchange.FILE_NAME, "ready"); + + assertMockEndpointsSatisfied(); + oneExchangeDone.matchesMockWaitTime(); + + // done file should be deleted now + File file = new File("target/done/ready").getAbsoluteFile(); + assertFalse("Done file should be deleted: " + file, file.exists()); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("file:target/done?preMove=work/work-${file:name}&doneFileName=ready&initialDelay=0&delay=10").to("mock:result"); + } + }; + } + +} Added: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerShouldSkipDoneFilePrefixTest.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerShouldSkipDoneFilePrefixTest.java?rev=1051127&view=auto ============================================================================== --- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerShouldSkipDoneFilePrefixTest.java (added) +++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerShouldSkipDoneFilePrefixTest.java Mon Dec 20 14:23:18 2010 @@ -0,0 +1,75 @@ +/** + * 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; + +import java.io.File; + +import org.apache.camel.ContextTestSupport; +import org.apache.camel.Exchange; +import org.apache.camel.builder.RouteBuilder; + +/** + * Unit test for writing done files + */ +public class FilerConsumerShouldSkipDoneFilePrefixTest extends ContextTestSupport { + + @Override + protected void setUp() throws Exception { + deleteDirectory("target/done"); + super.setUp(); + } + + public void testDoneFile() throws Exception { + getMockEndpoint("mock:result").expectedMessageCount(0); + + // write the done file + template.sendBodyAndHeader("file:target/done", "", Exchange.FILE_NAME, "done-hello.txt"); + + // wait a bit and it should not pickup the written file as there are no target file + Thread.sleep(250); + + assertMockEndpointsSatisfied(); + resetMocks(); + oneExchangeDone.reset(); + + // done file should exist + File file = new File("target/done/done-hello.txt").getAbsoluteFile(); + assertTrue("Done file should exist: " + file, file.exists()); + + getMockEndpoint("mock:result").expectedBodiesReceived("Hello World"); + + // write the target file + template.sendBodyAndHeader("file:target/done", "Hello World", Exchange.FILE_NAME, "hello.txt"); + + assertMockEndpointsSatisfied(); + oneExchangeDone.matchesMockWaitTime(); + + // done file should be deleted now + assertFalse("Done file should be deleted: " + file, file.exists()); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("file:target/done?doneFileName=done-${file:name}&initialDelay=0&delay=10").to("mock:result"); + } + }; + } + +} Added: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerShouldSkipDoneFileSuffixTest.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerShouldSkipDoneFileSuffixTest.java?rev=1051127&view=auto ============================================================================== --- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerShouldSkipDoneFileSuffixTest.java (added) +++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerShouldSkipDoneFileSuffixTest.java Mon Dec 20 14:23:18 2010 @@ -0,0 +1,75 @@ +/** + * 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; + +import java.io.File; + +import org.apache.camel.ContextTestSupport; +import org.apache.camel.Exchange; +import org.apache.camel.builder.RouteBuilder; + +/** + * Unit test for writing done files + */ +public class FilerConsumerShouldSkipDoneFileSuffixTest extends ContextTestSupport { + + @Override + protected void setUp() throws Exception { + deleteDirectory("target/done"); + super.setUp(); + } + + public void testDoneFile() throws Exception { + getMockEndpoint("mock:result").expectedMessageCount(0); + + // write the done file + template.sendBodyAndHeader("file:target/done", "", Exchange.FILE_NAME, "hello.txt.ready"); + + // wait a bit and it should not pickup the written file as there are no target file + Thread.sleep(250); + + assertMockEndpointsSatisfied(); + resetMocks(); + oneExchangeDone.reset(); + + // done file should exist + File file = new File("target/done/hello.txt.ready").getAbsoluteFile(); + assertTrue("Done file should exist: " + file, file.exists()); + + getMockEndpoint("mock:result").expectedBodiesReceived("Hello World"); + + // write the target file + template.sendBodyAndHeader("file:target/done", "Hello World", Exchange.FILE_NAME, "hello.txt"); + + assertMockEndpointsSatisfied(); + oneExchangeDone.matchesMockWaitTime(); + + // done file should be deleted now + assertFalse("Done file should be deleted: " + file, file.exists()); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("file:target/done?doneFileName=${file:name}.ready&initialDelay=0&delay=10").to("mock:result"); + } + }; + } + +} Added: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerShouldSkipDoneFileTest.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerShouldSkipDoneFileTest.java?rev=1051127&view=auto ============================================================================== --- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerShouldSkipDoneFileTest.java (added) +++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerShouldSkipDoneFileTest.java Mon Dec 20 14:23:18 2010 @@ -0,0 +1,75 @@ +/** + * 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; + +import java.io.File; + +import org.apache.camel.ContextTestSupport; +import org.apache.camel.Exchange; +import org.apache.camel.builder.RouteBuilder; + +/** + * Unit test for writing done files + */ +public class FilerConsumerShouldSkipDoneFileTest extends ContextTestSupport { + + @Override + protected void setUp() throws Exception { + deleteDirectory("target/done"); + super.setUp(); + } + + public void testDoneFile() throws Exception { + getMockEndpoint("mock:result").expectedMessageCount(0); + + // write the done file + template.sendBodyAndHeader("file:target/done", "", Exchange.FILE_NAME, "done"); + + // wait a bit and it should not pickup the written file as there are no target file + Thread.sleep(250); + + assertMockEndpointsSatisfied(); + resetMocks(); + oneExchangeDone.reset(); + + // done file should exist + File file = new File("target/done/done").getAbsoluteFile(); + assertTrue("Done file should exist: " + file, file.exists()); + + getMockEndpoint("mock:result").expectedBodiesReceived("Hello World"); + + // write the target file + template.sendBodyAndHeader("file:target/done", "Hello World", Exchange.FILE_NAME, "hello.txt"); + + assertMockEndpointsSatisfied(); + oneExchangeDone.matchesMockWaitTime(); + + // done file should be deleted now + assertFalse("Done file should be deleted: " + file, file.exists()); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("file:target/done?doneFileName=done&initialDelay=0&delay=10").to("mock:result"); + } + }; + } + +} Copied: camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDoneFileNameTest.java (from r1051031, camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpRecursiveNoopTest.java) URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDoneFileNameTest.java?p2=camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDoneFileNameTest.java&p1=camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpRecursiveNoopTest.java&r1=1051031&r2=1051127&rev=1051127&view=diff ============================================================================== --- camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpRecursiveNoopTest.java (original) +++ camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDoneFileNameTest.java Mon Dec 20 14:23:18 2010 @@ -16,46 +16,47 @@ */ package org.apache.camel.component.file.remote; +import java.io.File; + import org.apache.camel.Exchange; import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; import org.junit.Test; /** * @version $Revision$ */ -public class FromFtpRecursiveNoopTest extends FtpServerTestSupport { +public class FtpConsumerDoneFileNameTest extends FtpServerTestSupport { protected String getFtpUrl() { - return "ftp://admin@localhost:" + getPort() + "/noop?password=admin&binary=false&initialDelay=3000" - + "&recursive=true&noop=true"; + return "ftp://admin@localhost:" + getPort() + "/done?password=admin&initialDelay=0&delay=100&stepwise=false"; } - @Override - public void setUp() throws Exception { - super.setUp(); + @Test + public void testDoneFileName() throws Exception { + getMockEndpoint("mock:result").expectedMessageCount(0); - template.sendBodyAndHeader(getFtpUrl(), "a", Exchange.FILE_NAME, "a.txt"); - template.sendBodyAndHeader(getFtpUrl(), "b", Exchange.FILE_NAME, "b.txt"); - template.sendBodyAndHeader(getFtpUrl(), "a2", Exchange.FILE_NAME, "foo/a.txt"); - template.sendBodyAndHeader(getFtpUrl(), "c", Exchange.FILE_NAME, "bar/c.txt"); - template.sendBodyAndHeader(getFtpUrl(), "b2", Exchange.FILE_NAME, "bar/b.txt"); - } + template.sendBodyAndHeader(getFtpUrl(), "Hello World", Exchange.FILE_NAME, "hello.txt"); - @Test - public void testRecursiveNoop() throws Exception { - MockEndpoint mock = getMockEndpoint("mock:result"); - mock.expectedBodiesReceivedInAnyOrder("a", "b", "a2", "c", "b2"); + // wait a bit and it should not pickup the written file as there are no done file + Thread.sleep(1000); assertMockEndpointsSatisfied(); - // reset mock and send in a new file to be picked up only - mock.reset(); - mock.expectedBodiesReceived("c2"); + resetMocks(); + + getMockEndpoint("mock:result").expectedBodiesReceived("Hello World"); - template.sendBodyAndHeader(getFtpUrl(), "c2", Exchange.FILE_NAME, "c.txt"); + // write the done file + template.sendBodyAndHeader(getFtpUrl(), "", Exchange.FILE_NAME, "done"); assertMockEndpointsSatisfied(); + + // give time for done file to be deleted + Thread.sleep(1000); + + // done file should be deleted now + File file = new File(FTP_ROOT_DIR + "done/done").getAbsoluteFile(); + assertFalse("Done file should be deleted: " + file, file.exists()); } @Override @@ -63,9 +64,8 @@ public class FromFtpRecursiveNoopTest ex return new RouteBuilder() { @Override public void configure() throws Exception { - from(getFtpUrl()) + from(getFtpUrl() + "&doneFileName=done") .convertBodyTo(String.class) - .to("log:ftp") .to("mock:result"); } }; Added: camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDualDoneFileNameTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDualDoneFileNameTest.java?rev=1051127&view=auto ============================================================================== --- camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDualDoneFileNameTest.java (added) +++ camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDualDoneFileNameTest.java Mon Dec 20 14:23:18 2010 @@ -0,0 +1,67 @@ +/** + * 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.builder.RouteBuilder; +import org.junit.Test; + +/** + * @version $Revision: 1032261 $ + */ +public class FtpConsumerDualDoneFileNameTest extends FtpServerTestSupport { + + protected String getFtpUrl() { + return "ftp://admin@localhost:" + getPort() + "/done?password=admin&initialDelay=0&delay=100&stepwise=false"; + } + + @Test + public void testTwoDoneFile() throws Exception { + getMockEndpoint("mock:result").expectedBodiesReceivedInAnyOrder("Hello World", "Bye World"); + + template.sendBodyAndHeader(getFtpUrl() + "&doneFileName=${file:name}.ready", "Hello World", Exchange.FILE_NAME, "hello.txt"); + template.sendBodyAndHeader(getFtpUrl() + "&doneFileName=${file:name}.ready", "Bye World", Exchange.FILE_NAME, "bye.txt"); + + assertMockEndpointsSatisfied(); + } + + @Test + public void testOneDoneFileMissing() throws Exception { + getMockEndpoint("mock:result").expectedBodiesReceived("Hello World"); + + template.sendBodyAndHeader(getFtpUrl() + "&doneFileName=${file:name}.ready", "Hello World", Exchange.FILE_NAME, "hello.txt"); + template.sendBodyAndHeader(getFtpUrl(), "Bye World", Exchange.FILE_NAME, "bye.txt"); + + // give chance to poll 2nd file but it lacks the done file + Thread.sleep(1000); + + assertMockEndpointsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from(getFtpUrl() + "&doneFileName=${file:name}.ready") + .convertBodyTo(String.class) + .to("mock:result"); + } + }; + } + +}