Author: davsclaus
Date: Fri Oct 16 09:18:17 2009
New Revision: 825820
URL: http://svn.apache.org/viewvc?rev=825820&view=rev
Log:
MR-193: Added more unit tests. Fixed use with RemoteFile and GenericFile
copying.
Removed:
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/DefaultRemoteFileSorter.java
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpEndpoint.java
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFile.java
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/UriConfigurationTest.java
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java?rev=825820&r1=825819&r2=825820&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java
Fri Oct 16 09:18:17 2009
@@ -74,10 +74,24 @@
result.setFile(source.getFile());
result.setBody(source.getBody());
result.setBinding(source.getBinding());
+
+ copyFromPopulateAdditional(source, result);
return result;
}
/**
+ * Copies additional information from the source to the result.
+ * <p/>
+ * Inherited classes can override this method and copy their specific data.
+ *
+ * @param source the source
+ * @param result the result
+ */
+ public void copyFromPopulateAdditional(GenericFile source, GenericFile
result) {
+ // noop
+ }
+
+ /**
* Bind this GenericFile to an Exchange
*/
public void bindToExchange(Exchange exchange) {
Modified:
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpEndpoint.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpEndpoint.java?rev=825820&r1=825819&r2=825820&view=diff
==============================================================================
---
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpEndpoint.java
(original)
+++
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpEndpoint.java
Fri Oct 16 09:18:17 2009
@@ -17,6 +17,7 @@
package org.apache.camel.component.file.remote;
import org.apache.camel.Processor;
+import org.apache.camel.component.file.GenericFileConfiguration;
import org.apache.camel.component.file.GenericFileProducer;
import org.apache.commons.net.ftp.FTPFile;
Modified:
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFile.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFile.java?rev=825820&r1=825819&r2=825820&view=diff
==============================================================================
---
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFile.java
(original)
+++
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFile.java
Fri Oct 16 09:18:17 2009
@@ -19,7 +19,6 @@
import org.apache.camel.component.file.GenericFile;
import org.apache.camel.component.file.GenericFileMessage;
import org.apache.camel.util.FileUtil;
-import org.apache.camel.util.ObjectHelper;
/**
* Represents a remote file of some sort of backing object
@@ -65,34 +64,16 @@
protected String normalizePath(String name) {
return name;
}
-
- @SuppressWarnings("unchecked")
- public RemoteFile<T> copyFrom(RemoteFile<T> source) {
- RemoteFile<T> result;
- try {
- result = source.getClass().newInstance();
- } catch (Exception e) {
- throw ObjectHelper.wrapRuntimeCamelException(e);
- }
- // align these setters with GenericFile
- result.setEndpointPath(source.getEndpointPath());
- result.setAbsolute(source.isAbsolute());
- result.setAbsoluteFilePath(source.getAbsoluteFilePath());
- result.setRelativeFilePath(source.getRelativeFilePath());
- result.setFileName(source.getFileName());
- result.setFileNameOnly(source.getFileNameOnly());
- result.setFileLength(source.getFileLength());
- result.setLastModified(source.getLastModified());
- result.setFile(source.getFile());
- result.setBody(source.getBody());
- result.setBinding(source.getBinding());
+ @Override
+ public void copyFromPopulateAdditional(GenericFile source, GenericFile
result) {
+ RemoteFile remoteSource = (RemoteFile) source;
+ RemoteFile remoteResult = (RemoteFile) result;
- result.setHostname(source.getHostname());
- return result;
+ remoteResult.setHostname(remoteSource.getHostname());
}
- protected String normalizePathToProtocol(String path) {
+ protected String normalizePathToProtocol(String path) {
path = super.normalizePathToProtocol(path);
// strip leading / for FTP protocol to avoid files with absolute paths
return FileUtil.stripLeadingSeparator(path);
Modified:
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java?rev=825820&r1=825819&r2=825820&view=diff
==============================================================================
---
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java
(original)
+++
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java
Fri Oct 16 09:18:17 2009
@@ -100,9 +100,6 @@
RemoteFileConfiguration config = (RemoteFileConfiguration)
getConfiguration();
ObjectHelper.notEmpty(config.getHost(), "host");
ObjectHelper.notEmpty(config.getProtocol(), "protocol");
- if (config.getPort() <= 0) {
- throw new IllegalArgumentException("port is not assigned to a
positive value");
- }
}
/**
Modified:
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/UriConfigurationTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/UriConfigurationTest.java?rev=825820&r1=825819&r2=825820&view=diff
==============================================================================
---
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/UriConfigurationTest.java
(original)
+++
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/UriConfigurationTest.java
Fri Oct 16 09:18:17 2009
@@ -18,6 +18,8 @@
import org.apache.camel.CamelContext;
import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;
@@ -136,4 +138,24 @@
assertEquals(true, config.isBinary());
assertEquals("/home/janstey/.ssh/known_hosts",
config.getKnownHostsFile());
}
+
+ @Test
+ public void testInvalidStartingDirectory() throws Exception {
+ Endpoint endpoint =
context.getEndpoint("ftp://u...@hostname?password=secret");
+ FtpEndpoint ftpEndpoint = assertIsInstanceOf(FtpEndpoint.class,
endpoint);
+ FtpConfiguration config = (FtpConfiguration)
ftpEndpoint.getConfiguration();
+ config.setHost("somewhere");
+ config.setDirectory("some/file.txt");
+ try {
+ ftpEndpoint.createConsumer(new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ // do nothing
+ }
+ });
+ fail("Should have thrown exception");
+ } catch (IllegalArgumentException e) {
+ assertEquals("Only directory is supported. Endpoint must be
configured with a valid directory: some/file.txt", e.getMessage());
+ }
+ }
+
}