[camel] branch CAMEL-13826 updated: CAMEL-13826: Migrated camel-ahc-ws tests to camel-test-junit5

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[camel] branch CAMEL-13826 updated: CAMEL-13826: Migrated camel-ahc-ws tests to camel-test-junit5

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

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


The following commit(s) were added to refs/heads/CAMEL-13826 by this push:
     new 2b1b52c  CAMEL-13826: Migrated camel-ahc-ws tests to camel-test-junit5
2b1b52c is described below

commit 2b1b52c137c74cdcab7a82e40c1a21cb6b4a9b07
Author: aldettinger <[hidden email]>
AuthorDate: Tue Aug 13 19:35:58 2019 +0200

    CAMEL-13826: Migrated camel-ahc-ws tests to camel-test-junit5
---
 components/camel-ahc-ws/pom.xml                    |  7 +-----
 .../component/ahc/ws/WsProducerConsumerTest.java   | 28 ++++++++++++++--------
 .../camel/component/ahc/ws/WsProducerTestBase.java | 26 +++++++++++---------
 .../camel/component/ahc/ws/WssProducerTest.java    |  4 ++--
 .../src/main/docs/test-junit5.adoc                 |  1 +
 5 files changed, 37 insertions(+), 29 deletions(-)

diff --git a/components/camel-ahc-ws/pom.xml b/components/camel-ahc-ws/pom.xml
index f38b7e8..a680c8c 100644
--- a/components/camel-ahc-ws/pom.xml
+++ b/components/camel-ahc-ws/pom.xml
@@ -62,12 +62,7 @@
         <!-- testing -->
         <dependency>
             <groupId>org.apache.camel</groupId>
-            <artifactId>camel-test</artifactId>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
+            <artifactId>camel-test-junit5</artifactId>
             <scope>test</scope>
         </dependency>
         <dependency>
diff --git a/components/camel-ahc-ws/src/test/java/org/apache/camel/component/ahc/ws/WsProducerConsumerTest.java b/components/camel-ahc-ws/src/test/java/org/apache/camel/component/ahc/ws/WsProducerConsumerTest.java
index 3f4f539..e556130 100644
--- a/components/camel-ahc-ws/src/test/java/org/apache/camel/component/ahc/ws/WsProducerConsumerTest.java
+++ b/components/camel-ahc-ws/src/test/java/org/apache/camel/component/ahc/ws/WsProducerConsumerTest.java
@@ -20,21 +20,29 @@ import java.util.List;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.test.AvailablePortFinder;
-import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.test.junit5.CamelTestSupport;
 import org.eclipse.jetty.server.Connector;
 import org.eclipse.jetty.server.Server;
 import org.eclipse.jetty.server.ServerConnector;
 import org.eclipse.jetty.servlet.ServletContextHandler;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 /**
  *
  */
 public class WsProducerConsumerTest extends CamelTestSupport {
+    
     protected static final String TEST_MESSAGE = "Hello World!";
     protected static final int PORT = AvailablePortFinder.getNextAvailable();
+    
+    private static final Logger LOG = LoggerFactory.getLogger(WsProducerConsumerTest.class);
+    
     protected Server server;
   
     protected List<Object> messages;
@@ -52,23 +60,23 @@ public class WsProducerConsumerTest extends CamelTestSupport {
         server.setHandler(ctx);
         
         server.start();
-        assertTrue(server.isStarted());      
+        assertTrue(server.isStarted());
     }
-    
+
     public void stopTestServer() throws Exception {
         server.stop();
         server.destroy();
     }
 
     @Override
-    @Before
+    @BeforeEach
     public void setUp() throws Exception {
         startTestServer();
         super.setUp();
     }
 
     @Override
-    @After
+    @AfterEach
     public void tearDown() throws Exception {
         super.tearDown();
         stopTestServer();
@@ -95,7 +103,7 @@ public class WsProducerConsumerTest extends CamelTestSupport {
 
         resetMocks();
 
-        log.info("Restarting bar route");
+        LOG.info("Restarting bar route");
         context.getRouteController().stopRoute("bar");
         Thread.sleep(500);
         context.getRouteController().startRoute("bar");
@@ -118,7 +126,7 @@ public class WsProducerConsumerTest extends CamelTestSupport {
 
         resetMocks();
 
-        log.info("Restarting foo route");
+        LOG.info("Restarting foo route");
         context.getRouteController().stopRoute("foo");
         Thread.sleep(500);
         context.getRouteController().startRoute("foo");
diff --git a/components/camel-ahc-ws/src/test/java/org/apache/camel/component/ahc/ws/WsProducerTestBase.java b/components/camel-ahc-ws/src/test/java/org/apache/camel/component/ahc/ws/WsProducerTestBase.java
index e8f3c26..7f6186a 100644
--- a/components/camel-ahc-ws/src/test/java/org/apache/camel/component/ahc/ws/WsProducerTestBase.java
+++ b/components/camel-ahc-ws/src/test/java/org/apache/camel/component/ahc/ws/WsProducerTestBase.java
@@ -31,16 +31,20 @@ import org.apache.camel.test.AvailablePortFinder;
 import org.eclipse.jetty.server.Connector;
 import org.eclipse.jetty.server.Server;
 import org.eclipse.jetty.servlet.ServletContextHandler;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
 
 /**
  *
  */
-public abstract class WsProducerTestBase extends Assert {
+public abstract class WsProducerTestBase {
     
     protected static final String TEST_MESSAGE = "Hello World!";
     protected static final int PORT = AvailablePortFinder.getNextAvailable();
@@ -54,7 +58,7 @@ public abstract class WsProducerTestBase extends Assert {
         server = new Server(PORT);
         Connector connector = getConnector();
         server.addConnector(connector);
-        
+
         ServletContextHandler ctx = new ServletContextHandler();
         ctx.setContextPath("/");
         ctx.addServlet(TestServletFactory.class.getName(), "/*");
@@ -70,7 +74,7 @@ public abstract class WsProducerTestBase extends Assert {
         server.destroy();
     }
     
-    @Before
+    @BeforeEach
     public void setUp() throws Exception {
         TestMessages.getInstance().getMessages().clear();
 
@@ -83,7 +87,7 @@ public abstract class WsProducerTestBase extends Assert {
         template = camelContext.createProducerTemplate();
     }
 
-    @After
+    @AfterEach
     public void tearDown() throws Exception {
         template.stop();
         camelContext.stop();
@@ -113,7 +117,7 @@ public abstract class WsProducerTestBase extends Assert {
         verifyMessage(testMessage, TestMessages.getInstance().getMessages().get(0));
     }
 
-    @Ignore
+    @Disabled
     @Test
     public void testWriteBytesToWebsocket() throws Exception {
         byte[] testMessageBytes = getByteTestMessage();
@@ -122,7 +126,7 @@ public abstract class WsProducerTestBase extends Assert {
         verifyMessage(testMessageBytes, TestMessages.getInstance().getMessages().get(0));
     }
 
-    @Ignore
+    @Disabled
     @Test
     public void testWriteStreamToWebsocket() throws Exception {
         byte[] testMessageBytes = createLongByteTestMessage();
diff --git a/components/camel-ahc-ws/src/test/java/org/apache/camel/component/ahc/ws/WssProducerTest.java b/components/camel-ahc-ws/src/test/java/org/apache/camel/component/ahc/ws/WssProducerTest.java
index 2d41f01..11c2511 100644
--- a/components/camel-ahc-ws/src/test/java/org/apache/camel/component/ahc/ws/WssProducerTest.java
+++ b/components/camel-ahc-ws/src/test/java/org/apache/camel/component/ahc/ws/WssProducerTest.java
@@ -26,9 +26,9 @@ import org.eclipse.jetty.server.Connector;
 import org.eclipse.jetty.server.ServerConnector;
 import org.eclipse.jetty.server.SslConnectionFactory;
 import org.eclipse.jetty.util.ssl.SslContextFactory;
-import org.junit.Ignore;
+import org.junit.jupiter.api.Disabled;
 
-@Ignore("Not yet migrated to work with Jetty 9")
+@Disabled("Not yet migrated to work with Jetty 9")
 public class WssProducerTest extends WsProducerTestBase {
     protected static final String PW = "changeit";
     
diff --git a/components/camel-test-junit5/src/main/docs/test-junit5.adoc b/components/camel-test-junit5/src/main/docs/test-junit5.adoc
index d9a4d5c..eb74435 100644
--- a/components/camel-test-junit5/src/main/docs/test-junit5.adoc
+++ b/components/camel-test-junit5/src/main/docs/test-junit5.adoc
@@ -60,6 +60,7 @@ Projects using `camel-test` would need to use `camel-test-junit5`. For instance,
 === Typical migration steps linked to JUnit 5 support in Camel Test
 * Imports of `org.apache.camel.test.junit4.\*` should be replaced with `org.apache.camel.test.junit5.*`
 * `TestSupport` static methods should be imported where needed, for instance `import static org.apache.camel.test.junit5.TestSupport.assertIsInstanceOf`
+* Usage of the field `CamelTestSupport.log` should be replaced by another logger, for instance `org.slf4j.LoggerFactory.getLogger(MyCamelTest.class);`
 
 === Typical migration steps linked to JUnit 5 itself
 Once Camel related steps have been performed, there are still typical JUnit 5 migration steps to remember: