Fixed test on CI servers
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/45222fdd Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/45222fdd Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/45222fdd Branch: refs/heads/camel-2.12.x Commit: 45222fdd603fd96b7884b8457aec9453f8fee52e Parents: 2e7aafd Author: Claus Ibsen <davscl...@apache.org> Authored: Mon Oct 7 09:15:56 2013 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Mon Oct 7 09:16:36 2013 +0200 ---------------------------------------------------------------------- .../component/jsch/ScpServerTestSupport.java | 6 +-- .../component/jsch/ScpSimpleProduceTest.java | 55 +++++++++----------- 2 files changed, 29 insertions(+), 32 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/45222fdd/components/camel-jsch/src/test/java/org/apache/camel/component/jsch/ScpServerTestSupport.java ---------------------------------------------------------------------- diff --git a/components/camel-jsch/src/test/java/org/apache/camel/component/jsch/ScpServerTestSupport.java b/components/camel-jsch/src/test/java/org/apache/camel/component/jsch/ScpServerTestSupport.java index f31dfa7..c207742 100644 --- a/components/camel-jsch/src/test/java/org/apache/camel/component/jsch/ScpServerTestSupport.java +++ b/components/camel-jsch/src/test/java/org/apache/camel/component/jsch/ScpServerTestSupport.java @@ -86,8 +86,8 @@ public abstract class ScpServerTestSupport extends CamelTestSupport { @Override @Before public void setUp() throws Exception { - File root = new File(getScpPath()); - root.mkdirs(); // implicitly create sshd home dir + deleteDirectory(getScpPath()); + createDirectory(getScpPath()); setupComplete = startSshd(); setupKnownHosts(); @@ -109,6 +109,7 @@ public abstract class ScpServerTestSupport extends CamelTestSupport { } } FileUtil.deleteFile(new File(knownHostsFile)); + deleteDirectory(getScpPath()); } protected final String getScpPath() { @@ -121,7 +122,6 @@ public abstract class ScpServerTestSupport extends CamelTestSupport { return "scp://localhost:" + getPort() + "/" + getScpPath(); } - @SuppressWarnings("unchecked") protected boolean startSshd() { sshd = SshServer.setUpDefaultServer(); http://git-wip-us.apache.org/repos/asf/camel/blob/45222fdd/components/camel-jsch/src/test/java/org/apache/camel/component/jsch/ScpSimpleProduceTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jsch/src/test/java/org/apache/camel/component/jsch/ScpSimpleProduceTest.java b/components/camel-jsch/src/test/java/org/apache/camel/component/jsch/ScpSimpleProduceTest.java index 524ca8e..27c58e5 100644 --- a/components/camel-jsch/src/test/java/org/apache/camel/component/jsch/ScpSimpleProduceTest.java +++ b/components/camel-jsch/src/test/java/org/apache/camel/component/jsch/ScpSimpleProduceTest.java @@ -16,72 +16,72 @@ */ package org.apache.camel.component.jsch; -import java.io.File; - import org.apache.camel.Exchange; +import org.apache.camel.builder.RouteBuilder; import org.junit.Assume; import org.junit.Ignore; import org.junit.Test; public class ScpSimpleProduceTest extends ScpServerTestSupport { - + @Override - public boolean isUseRouteBuilder() { - return false; + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("file:" + getScpPath() + "?recursive=true&delete=true") + .convertBodyTo(String.class) + .to("mock:result"); + } + }; } @Test public void testScpSimpleProduce() throws Exception { Assume.assumeTrue(this.isSetupComplete()); + getMockEndpoint("mock:result").expectedBodiesReceived("Hello World"); + String uri = getScpUri() + "?username=admin&password=admin&knownHostsFile=" + getKnownHostsFile(); template.sendBodyAndHeader(uri, "Hello World", Exchange.FILE_NAME, "hello.txt"); - Thread.sleep(1000); - File file = new File(getScpPath() + "/hello.txt"); - assertFileExists(file.getAbsolutePath()); - assertEquals("Hello World", context.getTypeConverter().convertTo(String.class, file)); + assertMockEndpointsSatisfied(); } @Test public void testScpSimpleSubPathProduce() throws Exception { Assume.assumeTrue(this.isSetupComplete()); + getMockEndpoint("mock:result").expectedBodiesReceived("Bye World"); + String uri = getScpUri() + "?username=admin&password=admin&knownHostsFile=" + getKnownHostsFile(); template.sendBodyAndHeader(uri, "Bye World", Exchange.FILE_NAME, "mysub/bye.txt"); - Thread.sleep(1000); - File file = new File(getScpPath() + "/mysub/bye.txt"); - assertFileExists(file.getAbsolutePath()); - assertEquals("Bye World", context.getTypeConverter().convertTo(String.class, file)); + assertMockEndpointsSatisfied(); } @Test public void testScpSimpleTwoSubPathProduce() throws Exception { Assume.assumeTrue(this.isSetupComplete()); + getMockEndpoint("mock:result").expectedBodiesReceived("Farewell World"); + String uri = getScpUri() + "?username=admin&password=admin&knownHostsFile=" + getKnownHostsFile(); template.sendBodyAndHeader(uri, "Farewell World", Exchange.FILE_NAME, "mysub/mysubsub/farewell.txt"); - Thread.sleep(1000); - File file = new File(getScpPath() + "/mysub/mysubsub/farewell.txt"); - assertFileExists(file.getAbsolutePath()); - assertEquals("Farewell World", context.getTypeConverter().convertTo(String.class, file)); + assertMockEndpointsSatisfied(); } @Test public void testScpProduceChmod() throws Exception { Assume.assumeTrue(this.isSetupComplete()); + getMockEndpoint("mock:result").expectedBodiesReceived("Bonjour Monde"); + String uri = getScpUri() + "?username=admin&password=admin&chmod=640&knownHostsFile=" + getKnownHostsFile(); template.sendBodyAndHeader(uri, "Bonjour Monde", Exchange.FILE_NAME, "monde.txt"); - Thread.sleep(1000); - File file = new File(getScpPath() + "/monde.txt"); - assertFileExists(file.getAbsolutePath()); - // Mina sshd we use for testing ignores file perms; - // assertFalse("File should not have execute rights: " + file, file.canExecute()); - assertEquals("Bonjour Monde", context.getTypeConverter().convertTo(String.class, file)); + assertMockEndpointsSatisfied(); } @Test @@ -89,14 +89,11 @@ public class ScpSimpleProduceTest extends ScpServerTestSupport { public void testScpProducePrivateKey() throws Exception { Assume.assumeTrue(this.isSetupComplete()); + getMockEndpoint("mock:result").expectedMessageCount(1); + String uri = getScpUri() + "?username=admin&privateKeyFile=src/test/resources/camel-key.priv&privateKeyFilePassphrase=password&knownHostsFile=" + getKnownHostsFile(); template.sendBodyAndHeader(uri, "Hallo Welt", Exchange.FILE_NAME, "welt.txt"); - Thread.sleep(1000); - File file = new File(getScpPath() + "/welt.txt"); - assertFileExists(file.getAbsolutePath()); - // Mina sshd we use for testing ignores file perms; - // assertFalse("File should not have execute rights: " + file, file.canExecute()); - assertEquals("Hallo Welt", context.getTypeConverter().convertTo(String.class, file)); + assertMockEndpointsSatisfied(); } }