You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ja...@apache.org on 2019/08/14 20:00:14 UTC

[camel] branch CAMEL-13853 updated: CAMEL-13853: fix tests

This is an automated email from the ASF dual-hosted git repository.

janbednar pushed a commit to branch CAMEL-13853
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/CAMEL-13853 by this push:
     new 7c7efa0  CAMEL-13853: fix tests
7c7efa0 is described below

commit 7c7efa04c8edad385dd9a62f074c81c2886d54a6
Author: Jan Bednář <ma...@janbednar.eu>
AuthorDate: Wed Aug 14 21:59:08 2019 +0200

    CAMEL-13853: fix tests
---
 .../ElasticsearchClusterIndexTest.java             |  4 ++--
 .../file/remote/BaseServerTestSupport.java         | 10 +++++----
 .../file/remote/FtpServerTestSupport.java          | 24 ++++++++++++----------
 .../remote/sftp/SftpKeyPairRSAConsumeTest.java     |  2 +-
 .../file/remote/sftp/SftpServerTestSupport.java    | 11 ++++++++--
 .../http/NettyHttpGetWithInvalidMessageTest.java   |  6 +++---
 .../camel/component/stomp/StompConsumerTest.java   |  2 +-
 .../camel/component/stomp/StompProducerTest.java   |  2 +-
 8 files changed, 36 insertions(+), 25 deletions(-)

diff --git a/components/camel-elasticsearch-rest/src/test/java/org/apache/camel/component/elasticsearch/ElasticsearchClusterIndexTest.java b/components/camel-elasticsearch-rest/src/test/java/org/apache/camel/component/elasticsearch/ElasticsearchClusterIndexTest.java
index c350330..41a4d0e 100644
--- a/components/camel-elasticsearch-rest/src/test/java/org/apache/camel/component/elasticsearch/ElasticsearchClusterIndexTest.java
+++ b/components/camel-elasticsearch-rest/src/test/java/org/apache/camel/component/elasticsearch/ElasticsearchClusterIndexTest.java
@@ -73,9 +73,9 @@ public class ElasticsearchClusterIndexTest extends ElasticsearchClusterBaseTest
             @Override
             public void configure() {
                 from("direct:indexWithIpAndPort")
-                    .to("elasticsearch-rest://" + clusterName + "?operation=Index&indexName=twitter&hostAddresses=localhost:" + ES_FIRST_NODE_TRANSPORT_PORT);
+                    .to("elasticsearch-rest://" + clusterName + "?operation=Index&indexName=twitter&hostAddresses=localhost:" + ES_BASE_HTTP_PORT);
                 from("direct:indexWithSniffer")
-                    .to("elasticsearch-rest://" + clusterName + "?operation=Index&indexName=twitter&enableSniffer=true&hostAddresses=localhost:" + ES_FIRST_NODE_TRANSPORT_PORT);
+                    .to("elasticsearch-rest://" + clusterName + "?operation=Index&indexName=twitter&enableSniffer=true&hostAddresses=localhost:" + ES_BASE_HTTP_PORT);
             }
         };
     }
diff --git a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/BaseServerTestSupport.java b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/BaseServerTestSupport.java
index a1ebc04..cfb6525 100644
--- a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/BaseServerTestSupport.java
+++ b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/BaseServerTestSupport.java
@@ -18,14 +18,16 @@ package org.apache.camel.component.file.remote;
 
 import org.apache.camel.test.AvailablePortFinder;
 import org.apache.camel.test.junit4.CamelTestSupport;
-import org.junit.BeforeClass;
+import org.junit.Before;
 
 public class BaseServerTestSupport extends CamelTestSupport {
-    protected static int port;
+    protected int port;
 
-    @BeforeClass
-    public static void initPort() throws Exception {
+    @Before
+    @Override
+    public void setUp() throws Exception {
         port = AvailablePortFinder.getNextAvailable();
+        super.setUp();
     }
 
     protected int getPort() {
diff --git a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpServerTestSupport.java b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpServerTestSupport.java
index 488616a..2fd2c30 100644
--- a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpServerTestSupport.java
+++ b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpServerTestSupport.java
@@ -53,15 +53,6 @@ public abstract class FtpServerTestSupport extends BaseServerTestSupport {
 
         canTest = false;
 
-        FtpServerFactory factory = createFtpServerFactory();
-        if (factory != null) {
-            ftpServer = factory.createServer();
-            if (ftpServer != null) {
-                ftpServer.start();
-                canTest = true;
-            }
-        }
-
         try {
             super.setUp();
         } catch (Exception e) {
@@ -78,6 +69,17 @@ public abstract class FtpServerTestSupport extends BaseServerTestSupport {
                 throw e;
             }
         }
+
+        FtpServerFactory factory = createFtpServerFactory();
+        if (factory != null) {
+            ftpServer = factory.createServer();
+            if (ftpServer != null) {
+                ftpServer.start();
+                canTest = true;
+            }
+        }
+
+
     }
 
     @Override
@@ -103,7 +105,7 @@ public abstract class FtpServerTestSupport extends BaseServerTestSupport {
 
     protected FtpServerFactory createFtpServerFactory() throws Exception {
         assertTrue(USERS_FILE.exists());
-        assertTrue("Port number is not initialized in an expected range: " + BaseServerTestSupport.port, BaseServerTestSupport.port >= 21000);
+        assertTrue("Port number is not initialized in an expected range: " + getPort(), getPort() > 0);
 
         NativeFileSystemFactory fsf = new NativeFileSystemFactory();
         fsf.setCreateHome(true);
@@ -115,7 +117,7 @@ public abstract class FtpServerTestSupport extends BaseServerTestSupport {
         UserManager userMgr = pumf.createUserManager();
         
         ListenerFactory factory = new ListenerFactory();
-        factory.setPort(BaseServerTestSupport.port);
+        factory.setPort(getPort());
         
         FtpServerFactory serverFactory = new FtpServerFactory();
         serverFactory.setUserManager(userMgr);
diff --git a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpKeyPairRSAConsumeTest.java b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpKeyPairRSAConsumeTest.java
index f8b584a..3e93ae2 100644
--- a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpKeyPairRSAConsumeTest.java
+++ b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpKeyPairRSAConsumeTest.java
@@ -80,7 +80,7 @@ public class SftpKeyPairRSAConsumeTest extends SftpServerTestSupport {
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
         context.getRegistry().bind("keyPair", keyPair);
-        context.getRegistry().bind("knownHosts", getBytesFromFile("./src/test/resources/known_hosts"));
+        context.getRegistry().bind("knownHosts", buildKnownHosts());
 
         return new RouteBuilder() {
             @Override
diff --git a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpServerTestSupport.java b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpServerTestSupport.java
index 2fd292d..b621397 100644
--- a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpServerTestSupport.java
+++ b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpServerTestSupport.java
@@ -40,6 +40,9 @@ import org.junit.Before;
 public class SftpServerTestSupport extends BaseServerTestSupport {
 
     protected static final String FTP_ROOT_DIR = "target/res/home";
+    private static final String KNOWN_HOSTS = "[localhost]:%d ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDdfIWeSV4o68dRrKS" +
+            "zFd/Bk51E65UTmmSrmW0O1ohtzi6HzsDPjXgCtlTt3FqTcfFfI92IlTr4JWqC9UK1QT1ZTeng0MkPQmv68hDANHbt5CpETZHjW5q4OOgWhV" +
+            "vj5IyOC2NZHtKlJBkdsMAa15ouOOJLzBvAvbqOR/yUROsEiQ==";
     protected SshServer sshd;
     protected boolean canTest;
     protected String oldUserHome;
@@ -60,10 +63,10 @@ public class SftpServerTestSupport extends BaseServerTestSupport {
         createDirectory(simulatedUserHome);
         createDirectory(simulatedUserSsh);
 
-        FileUtils.copyInputStreamToFile(getClass().getClassLoader().getResourceAsStream("known_hosts"), new File(simulatedUserSsh + "/known_hosts"));
-
         super.setUp();
 
+        FileUtils.writeByteArrayToFile(new File(simulatedUserSsh + "/known_hosts"), buildKnownHosts());
+
         setUpServer();
     }
 
@@ -140,4 +143,8 @@ public class SftpServerTestSupport extends BaseServerTestSupport {
             session.disconnect(4, "dummy");
         }
     }
+
+    protected byte[] buildKnownHosts() {
+        return String.format(KNOWN_HOSTS, port).getBytes();
+    }
 }
diff --git a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpGetWithInvalidMessageTest.java b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpGetWithInvalidMessageTest.java
index 135d0bf..30035ff 100644
--- a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpGetWithInvalidMessageTest.java
+++ b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpGetWithInvalidMessageTest.java
@@ -33,7 +33,7 @@ import org.junit.Test;
 
 public class NettyHttpGetWithInvalidMessageTest extends CamelTestSupport {
     private static final String REQUEST_STRING = "user: Willem\n" 
-        + "GET http://localhost:8101/test HTTP/1.1\n" + "another: value\n Host: localhost\n";
+        + "GET http://localhost:%s/test HTTP/1.1\n" + "another: value\n Host: localhost\n";
     private int port1;
     
     @BindToRegistry("string-decoder")
@@ -62,7 +62,7 @@ public class NettyHttpGetWithInvalidMessageTest extends CamelTestSupport {
     
     @Test
     public void testNettyHttpServer() throws Exception {
-        invokeService(8100);
+        invokeService(port1);
     }
     
     //@Test
@@ -74,7 +74,7 @@ public class NettyHttpGetWithInvalidMessageTest extends CamelTestSupport {
         Exchange out = template.request("netty:tcp://localhost:" + port + "?encoders=#encoders&decoders=#decoders&sync=true", new Processor() {
             @Override
             public void process(Exchange exchange) throws Exception {
-                exchange.getIn().setBody(REQUEST_STRING);
+                exchange.getIn().setBody(String.format(REQUEST_STRING, port));
             }
         });
 
diff --git a/components/camel-stomp/src/test/java/org/apache/camel/component/stomp/StompConsumerTest.java b/components/camel-stomp/src/test/java/org/apache/camel/component/stomp/StompConsumerTest.java
index 788a41e..7d19a20 100644
--- a/components/camel-stomp/src/test/java/org/apache/camel/component/stomp/StompConsumerTest.java
+++ b/components/camel-stomp/src/test/java/org/apache/camel/component/stomp/StompConsumerTest.java
@@ -63,7 +63,7 @@ public class StompConsumerTest extends StompBaseTest {
     protected RouteBuilder createRouteBuilder() {
         return new RouteBuilder() {
             public void configure() {
-                from("stomp:test")
+                fromF("stomp:test?brokerURL=tcp://localhost:%s", getPort())
                         .transform(body().convertToString())
                         .to("mock:result");
             }
diff --git a/components/camel-stomp/src/test/java/org/apache/camel/component/stomp/StompProducerTest.java b/components/camel-stomp/src/test/java/org/apache/camel/component/stomp/StompProducerTest.java
index 0703caf..92b9173 100644
--- a/components/camel-stomp/src/test/java/org/apache/camel/component/stomp/StompProducerTest.java
+++ b/components/camel-stomp/src/test/java/org/apache/camel/component/stomp/StompProducerTest.java
@@ -92,7 +92,7 @@ public class StompProducerTest extends StompBaseTest {
     protected RouteBuilder createRouteBuilder() {
         return new RouteBuilder() {
             public void configure() {
-                from("direct:foo").to("stomp:test");
+                from("direct:foo").toF("stomp:test?brokerURL=tcp://localhost:%s", getPort());
             }
         };
     }