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 2010/10/02 18:40:28 UTC
svn commit: r1003830 - in /camel/trunk/components/camel-ftp: ./
src/main/java/org/apache/camel/component/file/remote/
src/test/java/org/apache/camel/component/file/remote/
src/test/java/org/apache/camel/component/file/remote/sftp/
src/test/resources/
Author: davsclaus
Date: Sat Oct 2 16:40:17 2010
New Revision: 1003830
URL: http://svn.apache.org/viewvc?rev=1003830&view=rev
Log:
CAMEL-3191: Added SFTP unit tests using Apache SSHD.
Added:
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/BaseServerTestSupport.java
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/MyPasswordAuthenticator.java
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpConsumeTemplateTest.java
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpServerTestSupport.java
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpSimpleConsumeRecursiveTest.java
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpSimpleConsumeTest.java
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpSimpleProduceTest.java
camel/trunk/components/camel-ftp/src/test/resources/hostkey.pem
Modified:
camel/trunk/components/camel-ftp/pom.xml
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpServerTestSupport.java
Modified: camel/trunk/components/camel-ftp/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/pom.xml?rev=1003830&r1=1003829&r2=1003830&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/pom.xml (original)
+++ camel/trunk/components/camel-ftp/pom.xml Sat Oct 2 16:40:17 2010
@@ -102,11 +102,25 @@
<scope>test</scope>
</dependency>
- <!-- ftpserver using mina 2.0.0-RC1 -->
+ <!-- for testing sftp -->
+ <dependency>
+ <groupId>org.apache.sshd</groupId>
+ <artifactId>sshd-core</artifactId>
+ <version>0.4.0</version>
+ <scope>test</scope>
+ </dependency>
+ <!-- needed for sftp server -->
+ <dependency>
+ <groupId>bouncycastle</groupId>
+ <artifactId>bcprov-jdk15</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <!-- ftpserver using mina 2.0.0 -->
<dependency>
<groupId>org.apache.mina</groupId>
<artifactId>mina-core</artifactId>
- <version>2.0.0-RC1</version>
+ <version>2.0.0</version>
<scope>test</scope>
</dependency>
Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java?rev=1003830&r1=1003829&r2=1003830&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java (original)
+++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java Sat Oct 2 16:40:17 2010
@@ -516,10 +516,13 @@ public class FtpOperations implements Re
}
private void doChangeDirectory(String path) {
+ if (path == null || ".".equals(path)) {
+ return;
+ }
+
if (log.isTraceEnabled()) {
log.trace("Changing directory: " + path);
}
-
boolean success;
try {
success = client.changeWorkingDirectory(path);
Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java?rev=1003830&r1=1003829&r2=1003830&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java (original)
+++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java Sat Oct 2 16:40:17 2010
@@ -363,6 +363,10 @@ public class SftpOperations implements R
}
private void doChangeDirectory(String path) {
+ if (path == null || ".".equals(path)) {
+ return;
+ }
+
if (LOG.isTraceEnabled()) {
LOG.trace("Changing directory: " + path);
}
@@ -429,12 +433,16 @@ public class SftpOperations implements R
}
String onlyName = FileUtil.stripPath(name);
- channel.get(onlyName, os);
+ // use input stream which works with Apache SSHD used for testing
+ InputStream is = channel.get(onlyName);
+ IOHelper.copyAndCloseInput(is, os);
// change back to current directory
changeCurrentDirectory(currentDir);
return true;
+ } catch (IOException e) {
+ throw new GenericFileOperationFailedException("Cannot retrieve file: " + name, e);
} catch (SftpException e) {
throw new GenericFileOperationFailedException("Cannot retrieve file: " + name, e);
} finally {
Added: camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/BaseServerTestSupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/BaseServerTestSupport.java?rev=1003830&view=auto
==============================================================================
--- camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/BaseServerTestSupport.java (added)
+++ camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/BaseServerTestSupport.java Sat Oct 2 16:40:17 2010
@@ -0,0 +1,64 @@
+/**
+ * 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.io.File;
+import java.io.FileOutputStream;
+import java.util.Random;
+
+import org.apache.camel.converter.IOConverter;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+public class BaseServerTestSupport extends CamelTestSupport {
+ protected static int port;
+
+ @BeforeClass
+ public static void initPort() throws Exception {
+ File file = new File("./target/ftpport.txt");
+ file = file.getAbsoluteFile();
+
+ if (!file.exists()) {
+ // start from somewhere in the 21xxx range
+ port = 21000 + new Random().nextInt(900);
+ } else {
+ // read port number from file
+ String s = IOConverter.toString(file, null);
+ port = Integer.parseInt(s);
+ // use next number
+ port++;
+ }
+
+ // save to file, do not append
+ FileOutputStream fos = new FileOutputStream(file, false);
+ try {
+ fos.write(String.valueOf(port).getBytes());
+ } finally {
+ fos.close();
+ }
+ }
+
+ @AfterClass
+ public static void resetPort() throws Exception {
+ port = 0;
+ }
+
+ protected int getPort() {
+ return port;
+ }
+}
\ No newline at end of file
Modified: camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpServerTestSupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpServerTestSupport.java?rev=1003830&r1=1003829&r2=1003830&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpServerTestSupport.java (original)
+++ camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpServerTestSupport.java Sat Oct 2 16:40:17 2010
@@ -17,13 +17,9 @@
package org.apache.camel.component.file.remote;
import java.io.File;
-import java.io.FileOutputStream;
import java.security.NoSuchAlgorithmException;
-import java.util.Random;
import org.apache.camel.Exchange;
-import org.apache.camel.converter.IOConverter;
-import org.apache.camel.test.junit4.CamelTestSupport;
import org.apache.camel.util.ObjectHelper;
import org.apache.ftpserver.ConnectionConfigFactory;
import org.apache.ftpserver.FtpServer;
@@ -34,48 +30,20 @@ import org.apache.ftpserver.listener.Lis
import org.apache.ftpserver.usermanager.ClearTextPasswordEncryptor;
import org.apache.ftpserver.usermanager.PropertiesUserManagerFactory;
import org.junit.After;
-import org.junit.AfterClass;
import org.junit.Before;
-import org.junit.BeforeClass;
/**
* Base class for unit testing using a FTPServer
*/
-public abstract class FtpServerTestSupport extends CamelTestSupport {
+public abstract class FtpServerTestSupport extends BaseServerTestSupport {
protected static final String FTP_ROOT_DIR = "./res/home/";
protected static final File USERS_FILE = new File("./src/test/resources/users.properties");
protected static final String DEFAULT_LISTENER = "default";
- protected static int port;
-
+
protected FtpServer ftpServer;
protected boolean canTest;
- @BeforeClass
- public static void initPort() throws Exception {
- File file = new File("./target/ftpport.txt");
- file = file.getAbsoluteFile();
-
- if (!file.exists()) {
- // start from somewhere in the 21xxx range
- port = 21000 + new Random().nextInt(900);
- } else {
- // read port number from file
- String s = IOConverter.toString(file, null);
- port = Integer.parseInt(s);
- // use next number
- port++;
- }
-
- // save to file, do not append
- FileOutputStream fos = new FileOutputStream(file, false);
- try {
- fos.write(String.valueOf(port).getBytes());
- } finally {
- fos.close();
- }
- }
-
@Override
@Before
public void setUp() throws Exception {
@@ -124,11 +92,6 @@ public abstract class FtpServerTestSuppo
}
}
}
-
- @AfterClass
- public static void resetPort() throws Exception {
- port = 0;
- }
protected boolean canTest() {
return canTest;
@@ -136,7 +99,7 @@ public abstract class FtpServerTestSuppo
protected FtpServerFactory createFtpServerFactory() throws Exception {
assertTrue(USERS_FILE.exists());
- assertTrue("Port number is not initialized in an expected range: " + port, port >= 21000);
+ assertTrue("Port number is not initialized in an expected range: " + BaseServerTestSupport.port, BaseServerTestSupport.port >= 21000);
NativeFileSystemFactory fsf = new NativeFileSystemFactory();
fsf.setCreateHome(true);
@@ -148,7 +111,7 @@ public abstract class FtpServerTestSuppo
UserManager userMgr = pumf.createUserManager();
ListenerFactory factory = new ListenerFactory();
- factory.setPort(port);
+ factory.setPort(BaseServerTestSupport.port);
FtpServerFactory serverFactory = new FtpServerFactory();
serverFactory.setUserManager(userMgr);
@@ -163,7 +126,4 @@ public abstract class FtpServerTestSuppo
template.sendBodyAndHeader(url, body, Exchange.FILE_NAME, fileName);
}
- protected int getPort() {
- return port;
- }
}
Added: camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/MyPasswordAuthenticator.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/MyPasswordAuthenticator.java?rev=1003830&view=auto
==============================================================================
--- camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/MyPasswordAuthenticator.java (added)
+++ camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/MyPasswordAuthenticator.java Sat Oct 2 16:40:17 2010
@@ -0,0 +1,30 @@
+/**
+ * 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.sftp;
+
+import org.apache.sshd.server.PasswordAuthenticator;
+import org.apache.sshd.server.session.ServerSession;
+
+/**
+ * @version $Revision$
+ */
+public class MyPasswordAuthenticator implements PasswordAuthenticator {
+
+ public boolean authenticate(String username, String password, ServerSession session) {
+ return username != null && username.equals(password);
+ }
+}
Added: camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpConsumeTemplateTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpConsumeTemplateTest.java?rev=1003830&view=auto
==============================================================================
--- camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpConsumeTemplateTest.java (added)
+++ camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpConsumeTemplateTest.java Sat Oct 2 16:40:17 2010
@@ -0,0 +1,47 @@
+/**
+ * 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.sftp;
+
+import org.apache.camel.Exchange;
+import org.junit.Test;
+
+/**
+ * @version $Revision$
+ */
+public class SftpConsumeTemplateTest extends SftpServerTestSupport {
+
+ @Override
+ public boolean isUseRouteBuilder() {
+ return false;
+ }
+
+ @Test
+ public void testSftpSimpleConsume() throws Exception {
+ if (!canTest()) {
+ return;
+ }
+
+ // create file using regular file
+ template.sendBodyAndHeader("file://" + FTP_ROOT_DIR, "Hello World", Exchange.FILE_NAME, "hello.txt");
+
+ String out = consumer.receiveBody("sftp://localhost:" + getPort() + "/" + FTP_ROOT_DIR + "?username=admin&password=admin", 5000, String.class);
+ assertNotNull(out);
+ // Apache SSHD appends \u0000 at last byte in retrieved file
+ assertTrue(out.startsWith("Hello World"));
+ }
+
+}
Added: camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpServerTestSupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpServerTestSupport.java?rev=1003830&view=auto
==============================================================================
--- camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpServerTestSupport.java (added)
+++ camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpServerTestSupport.java Sat Oct 2 16:40:17 2010
@@ -0,0 +1,96 @@
+/**
+ * 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.sftp;
+
+import java.security.NoSuchAlgorithmException;
+import java.util.Arrays;
+
+import org.apache.camel.component.file.remote.BaseServerTestSupport;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.sshd.SshServer;
+import org.apache.sshd.common.NamedFactory;
+import org.apache.sshd.common.keyprovider.FileKeyPairProvider;
+import org.apache.sshd.server.Command;
+import org.apache.sshd.server.command.ScpCommandFactory;
+import org.apache.sshd.server.sftp.SftpSubsystem;
+import org.junit.After;
+import org.junit.Before;
+
+/**
+ * @version $Revision$
+ */
+public class SftpServerTestSupport extends BaseServerTestSupport {
+
+ protected static final String FTP_ROOT_DIR = "./res/home/";
+ protected SshServer sshd;
+ protected boolean canTest;
+
+ @Override
+ @Before
+ public void setUp() throws Exception {
+ deleteDirectory(FTP_ROOT_DIR);
+
+ canTest = false;
+ try {
+ super.setUp();
+
+ sshd = SshServer.setUpDefaultServer();
+ sshd.setPort(getPort());
+ sshd.setKeyPairProvider(new FileKeyPairProvider(new String[]{"src/test/resources/hostkey.pem"}));
+ sshd.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(new SftpSubsystem.Factory()));
+ sshd.setCommandFactory(new ScpCommandFactory());
+ sshd.setPasswordAuthenticator(new MyPasswordAuthenticator());
+ sshd.start();
+
+ } catch (Exception e) {
+ // ignore if algorithm is not on the OS
+ NoSuchAlgorithmException nsae = ObjectHelper.getException(NoSuchAlgorithmException.class, e);
+ if (nsae != null) {
+ canTest = false;
+ String name = System.getProperty("os.name");
+ System.out.println("SunX509 is not avail on this platform [" + name + "] Testing is skipped! Real cause: " + nsae.getMessage());
+ } else {
+ // some other error then throw it so the test can fail
+ throw e;
+ }
+ }
+
+ canTest = true;
+ }
+
+ @Override
+ @After
+ public void tearDown() throws Exception {
+ super.tearDown();
+
+ if (sshd != null) {
+ try {
+ sshd.stop();
+ sshd = null;
+ } catch (Exception e) {
+ // ignore while shutting down as we could be polling during shutdown
+ // and get errors when the ftp server is stopping. This is only an issue
+ // since we host the ftp server embedded in the same jvm for unit testing
+ }
+ }
+ }
+
+ protected boolean canTest() {
+ return canTest;
+ }
+
+}
Added: camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpSimpleConsumeRecursiveTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpSimpleConsumeRecursiveTest.java?rev=1003830&view=auto
==============================================================================
--- camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpSimpleConsumeRecursiveTest.java (added)
+++ camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpSimpleConsumeRecursiveTest.java Sat Oct 2 16:40:17 2010
@@ -0,0 +1,60 @@
+/**
+ * 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.sftp;
+
+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 SftpSimpleConsumeRecursiveTest extends SftpServerTestSupport {
+
+ @Test
+ public void testSftpSimpleConsumeRecursive() throws Exception {
+ if (!canTest()) {
+ return;
+ }
+
+ // create files using regular file
+ template.sendBodyAndHeader("file://" + FTP_ROOT_DIR, "A", Exchange.FILE_NAME, "a.txt");
+ template.sendBodyAndHeader("file://" + FTP_ROOT_DIR + "/foo", "B", Exchange.FILE_NAME, "b.txt");
+ template.sendBodyAndHeader("file://" + FTP_ROOT_DIR + "/bar", "C", Exchange.FILE_NAME, "c.txt");
+ template.sendBodyAndHeader("file://" + FTP_ROOT_DIR + "/bar/cake", "D", Exchange.FILE_NAME, "d.txt");
+
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMessageCount(4);
+
+ context.startRoute("foo");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("sftp://localhost:" + getPort() + "/" + FTP_ROOT_DIR + "?username=admin&password=admin&delay=10s&disconnect=true&recursive=true")
+ .routeId("foo").noAutoStartup()
+ .to("log:result", "mock:result");
+ }
+ };
+ }
+}
Added: camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpSimpleConsumeTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpSimpleConsumeTest.java?rev=1003830&view=auto
==============================================================================
--- camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpSimpleConsumeTest.java (added)
+++ camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpSimpleConsumeTest.java Sat Oct 2 16:40:17 2010
@@ -0,0 +1,60 @@
+/**
+ * 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.sftp;
+
+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 SftpSimpleConsumeTest extends SftpServerTestSupport {
+
+ @Test
+ public void testSftpSimpleConsume() throws Exception {
+ if (!canTest()) {
+ return;
+ }
+
+ String expected = "Hello World";
+
+ // create file using regular file
+ template.sendBodyAndHeader("file://" + FTP_ROOT_DIR, expected, Exchange.FILE_NAME, "hello.txt");
+
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMessageCount(1);
+ mock.expectedHeaderReceived(Exchange.FILE_NAME, "hello.txt");
+
+ context.startRoute("foo");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("sftp://localhost:" + getPort() + "/" + FTP_ROOT_DIR + "?username=admin&password=admin&delay=10s&disconnect=true")
+ .routeId("foo").noAutoStartup()
+ .to("mock:result");
+ }
+ };
+ }
+}
Added: camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpSimpleProduceTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpSimpleProduceTest.java?rev=1003830&view=auto
==============================================================================
--- camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpSimpleProduceTest.java (added)
+++ camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpSimpleProduceTest.java Sat Oct 2 16:40:17 2010
@@ -0,0 +1,60 @@
+/**
+ * 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.sftp;
+
+import java.io.File;
+
+import org.apache.camel.Exchange;
+import org.junit.Test;
+
+/**
+ * @version $Revision$
+ */
+public class SftpSimpleProduceTest extends SftpServerTestSupport {
+
+ @Override
+ public boolean isUseRouteBuilder() {
+ return false;
+ }
+
+ @Test
+ public void testSftpSimpleProduce() throws Exception {
+ if (!canTest()) {
+ return;
+ }
+
+ template.sendBodyAndHeader("sftp://localhost:" + getPort() + "/" + FTP_ROOT_DIR + "?username=admin&password=admin", "Hello World", Exchange.FILE_NAME, "hello.txt");
+
+ File file = new File(FTP_ROOT_DIR + "/hello.txt").getAbsoluteFile();
+ assertTrue("File should exist: " + file, file.exists());
+ assertEquals("Hello World", context.getTypeConverter().convertTo(String.class, file));
+ }
+
+ @Test
+ public void testSftpSimpleSubPathProduce() throws Exception {
+ if (!canTest()) {
+ return;
+ }
+
+ template.sendBodyAndHeader("sftp://localhost:" + getPort() + "/" + FTP_ROOT_DIR + "/mysub?username=admin&password=admin", "Bye World", Exchange.FILE_NAME, "bye.txt");
+
+ File file = new File(FTP_ROOT_DIR + "/mysub/bye.txt").getAbsoluteFile();
+ assertTrue("File should exist: " + file, file.exists());
+ assertEquals("Bye World", context.getTypeConverter().convertTo(String.class, file));
+ }
+
+}
Added: camel/trunk/components/camel-ftp/src/test/resources/hostkey.pem
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/test/resources/hostkey.pem?rev=1003830&view=auto
==============================================================================
--- camel/trunk/components/camel-ftp/src/test/resources/hostkey.pem (added)
+++ camel/trunk/components/camel-ftp/src/test/resources/hostkey.pem Sat Oct 2 16:40:17 2010
@@ -0,0 +1,15 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIICXAIBAAKBgQDdfIWeSV4o68dRrKSzFd/Bk51E65UTmmSrmW0O1ohtzi6HzsDP
+jXgCtlTt3FqTcfFfI92IlTr4JWqC9UK1QT1ZTeng0MkPQmv68hDANHbt5CpETZHj
+W5q4OOgWhVvj5IyOC2NZHtKlJBkdsMAa15ouOOJLzBvAvbqOR/yUROsEiQIDAQAB
+AoGBANG3JDW6NoP8rF/zXoeLgLCj+tfVUPSczhGFVrQkAk4mWfyRkhN0WlwHFOec
+K89MpkV1ij/XPVzU4MNbQ2yod1KiDylzvweYv+EaEhASCmYNs6LS03punml42SL9
+97tOmWfVJXxlQoLiY6jHPU97vTc65k8gL+gmmrpchsW0aqmZAkEA/c8zfmKvY37T
+cxcLLwzwsqqH7g2KZGTf9aRmx2ebdW+QKviJJhbdluDgl1TNNFj5vCLznFDRHiqJ
+wq0wkZ39cwJBAN9l5v3kdXj21UrurNPdlV0n2GZBt2vblooQC37XHF97r2zM7Ou+
+Lg6MyfJClyguhWL9dxnGbf3btQ0l3KDstxMCQCRaiEqjAfIjWVATzeNIXDWLHXso
+b1kf5cA+cwY+vdKdTy4IeUR+Y/DXdvPWDqpf0C11aCVMohdLCn5a5ikFUycCQDhV
+K/BuAallJNfmY7JxN87r00fF3ojWMJnT/fIYMFFrkQrwifXQWTDWE76BSDibsosJ
+u1TGksnm8zrDh2UVC/0CQFrHTiSl/3DHvWAbOJawGKg46cnlDcAhSyV8Frs8/dlP
+7YGG3eqkw++lsghqmFO6mRUTKsBmiiB2wgLGhL5pyYY=
+-----END RSA PRIVATE KEY-----
\ No newline at end of file