You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by gn...@apache.org on 2020/07/22 16:59:12 UTC

[camel] 06/18: [CAMEL-11807] Upgrade camel-reactor to junit5

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

gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 967c507602cb9b7723cc293440e5a81d5ff7a3b8
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Wed Jul 22 13:58:13 2020 +0200

    [CAMEL-11807] Upgrade camel-reactor to junit5
---
 components/camel-reactor/pom.xml                   |  6 +--
 .../ReactorStreamsServiceBackpressureTest.java     | 32 +++++++------
 .../engine/ReactorStreamsServiceEventTypeTest.java |  9 ++--
 .../ReactorStreamsServiceSubscriberTest.java       | 11 +++--
 .../reactor/engine/ReactorStreamsServiceTest.java  | 55 ++++++++++++----------
 .../engine/ReactorStreamsServiceTestSupport.java   |  2 +-
 6 files changed, 62 insertions(+), 53 deletions(-)

diff --git a/components/camel-reactor/pom.xml b/components/camel-reactor/pom.xml
index 4e5650d..1bc4496 100644
--- a/components/camel-reactor/pom.xml
+++ b/components/camel-reactor/pom.xml
@@ -62,7 +62,7 @@
         <!-- test dependencies -->
         <dependency>
             <groupId>org.apache.camel</groupId>
-            <artifactId>camel-test</artifactId>
+            <artifactId>camel-test-junit5</artifactId>
             <scope>test</scope>
         </dependency>
         <dependency>
@@ -71,8 +71,8 @@
             <scope>test</scope>
         </dependency>
         <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter</artifactId>
             <scope>test</scope>
         </dependency>
     </dependencies>
diff --git a/components/camel-reactor/src/test/java/org/apache/camel/component/reactor/engine/ReactorStreamsServiceBackpressureTest.java b/components/camel-reactor/src/test/java/org/apache/camel/component/reactor/engine/ReactorStreamsServiceBackpressureTest.java
index ad0e128..9b689f9 100644
--- a/components/camel-reactor/src/test/java/org/apache/camel/component/reactor/engine/ReactorStreamsServiceBackpressureTest.java
+++ b/components/camel-reactor/src/test/java/org/apache/camel/component/reactor/engine/ReactorStreamsServiceBackpressureTest.java
@@ -25,10 +25,12 @@ import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.reactive.streams.ReactiveStreamsBackpressureStrategy;
 import org.apache.camel.component.reactor.engine.suport.TestSubscriber;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 import reactor.core.publisher.Flux;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
 public class ReactorStreamsServiceBackpressureTest extends ReactorStreamsServiceTestSupport {
 
     @Test
@@ -57,12 +59,12 @@ public class ReactorStreamsServiceBackpressureTest extends ReactorStreamsService
 
         context.start();
 
-        Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
-        Assert.assertEquals(20, queue.size());
+        assertTrue(latch.await(5, TimeUnit.SECONDS));
+        assertEquals(20, queue.size());
 
         int num = 1;
         for (int i : queue) {
-            Assert.assertEquals(num++, i);
+            assertEquals(num++, i);
         }
     }
 
@@ -99,17 +101,17 @@ public class ReactorStreamsServiceBackpressureTest extends ReactorStreamsService
         crs.fromStream("integers", Integer.class).subscribe(subscriber);
         context.start();
 
-        Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
+        assertTrue(latch.await(5, TimeUnit.SECONDS));
         Thread.sleep(1000); // wait for all numbers to be generated
 
         subscriber.request(19);
-        Assert.assertTrue(latch2.await(1, TimeUnit.SECONDS));
+        assertTrue(latch2.await(1, TimeUnit.SECONDS));
 
         Thread.sleep(200); // add other time to ensure no other items arrive
-        Assert.assertEquals(2, queue.size());
+        assertEquals(2, queue.size());
 
         int sum = queue.stream().reduce(Integer::sum).get();
-        Assert.assertEquals(3, sum); // 1 + 2 = 3
+        assertEquals(3, sum); // 1 + 2 = 3
 
         subscriber.cancel();
     }
@@ -146,21 +148,21 @@ public class ReactorStreamsServiceBackpressureTest extends ReactorStreamsService
         crs.fromStream("integers", Integer.class).subscribe(subscriber);
         context.start();
 
-        Assert.assertTrue(latch1.await(5, TimeUnit.SECONDS));
+        assertTrue(latch1.await(5, TimeUnit.SECONDS));
         Thread.sleep(1000); // wait for all numbers to be generated
 
         subscriber.request(19);
-        Assert.assertTrue(latch2.await(1, TimeUnit.SECONDS));
+        assertTrue(latch2.await(1, TimeUnit.SECONDS));
 
         Thread.sleep(200); // add other time to ensure no other items arrive
 
         // TODO: the chain caches two elements instead of one: change it if you find an EmitterProcessor without prefetch
-        // Assert.assertEquals(2, queue.size());
-        Assert.assertEquals(3, queue.size());
+        // assertEquals(2, queue.size());
+        assertEquals(3, queue.size());
 
         int sum = queue.stream().reduce(Integer::sum).get();
-        // Assert.assertEquals(21, sum); // 1 + 20 = 21
-        Assert.assertEquals(23, sum); // 1 + 2 + 20 = 23
+        // assertEquals(21, sum); // 1 + 20 = 21
+        assertEquals(23, sum); // 1 + 2 + 20 = 23
 
         subscriber.cancel();
     }
diff --git a/components/camel-reactor/src/test/java/org/apache/camel/component/reactor/engine/ReactorStreamsServiceEventTypeTest.java b/components/camel-reactor/src/test/java/org/apache/camel/component/reactor/engine/ReactorStreamsServiceEventTypeTest.java
index 9a7d5f3..0892526 100644
--- a/components/camel-reactor/src/test/java/org/apache/camel/component/reactor/engine/ReactorStreamsServiceEventTypeTest.java
+++ b/components/camel-reactor/src/test/java/org/apache/camel/component/reactor/engine/ReactorStreamsServiceEventTypeTest.java
@@ -20,11 +20,12 @@ import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.component.reactive.streams.ReactiveStreamsConstants;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 import org.reactivestreams.Subscriber;
 import reactor.core.publisher.Flux;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
 public class ReactorStreamsServiceEventTypeTest extends ReactorStreamsServiceTestSupport {
 
     @Test
@@ -93,7 +94,7 @@ public class ReactorStreamsServiceEventTypeTest extends ReactorStreamsServiceTes
         endpoint.assertIsSatisfied();
 
         Exchange ex = endpoint.getExchanges().get(0);
-        Assert.assertEquals(1, ex.getIn().getBody());
+        assertEquals(1, ex.getIn().getBody());
     }
 
     @Test
@@ -128,7 +129,7 @@ public class ReactorStreamsServiceEventTypeTest extends ReactorStreamsServiceTes
         endpoint.assertIsSatisfied();
 
         Exchange exch = endpoint.getExchanges().get(0);
-        Assert.assertEquals(ex, exch.getIn().getBody());
+        assertEquals(ex, exch.getIn().getBody());
     }
 
     @Test
diff --git a/components/camel-reactor/src/test/java/org/apache/camel/component/reactor/engine/ReactorStreamsServiceSubscriberTest.java b/components/camel-reactor/src/test/java/org/apache/camel/component/reactor/engine/ReactorStreamsServiceSubscriberTest.java
index eb237ac..e102c4b 100644
--- a/components/camel-reactor/src/test/java/org/apache/camel/component/reactor/engine/ReactorStreamsServiceSubscriberTest.java
+++ b/components/camel-reactor/src/test/java/org/apache/camel/component/reactor/engine/ReactorStreamsServiceSubscriberTest.java
@@ -21,12 +21,13 @@ import java.util.concurrent.atomic.AtomicLong;
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 import org.reactivestreams.Publisher;
 import org.reactivestreams.Subscriber;
 import reactor.core.publisher.Flux;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
 public class ReactorStreamsServiceSubscriberTest extends ReactorStreamsServiceTestSupport {
     @Test
     public void testSubscriber() throws Exception {
@@ -100,7 +101,7 @@ public class ReactorStreamsServiceSubscriberTest extends ReactorStreamsServiceTe
         endpoint.expectedMessageCount(1000);
         endpoint.assertIsSatisfied();
 
-        Assert.assertEquals(
+        assertEquals(
             1,
             endpoint.getExchanges().stream()
                 .map(x -> x.getIn().getHeader("thread", String.class))
@@ -113,7 +114,7 @@ public class ReactorStreamsServiceSubscriberTest extends ReactorStreamsServiceTe
 
         endpoint.getExchanges().stream()
             .map(x -> x.getIn().getBody(Long.class))
-            .forEach(n -> Assert.assertEquals(num.getAndIncrement(), n.longValue()));
+            .forEach(n -> assertEquals(num.getAndIncrement(), n.longValue()));
     }
 
     @Test
@@ -138,7 +139,7 @@ public class ReactorStreamsServiceSubscriberTest extends ReactorStreamsServiceTe
         endpoint.expectedMessageCount(1000);
         endpoint.assertIsSatisfied();
 
-        Assert.assertEquals(
+        assertEquals(
             3,
             endpoint.getExchanges().stream()
                 .map(x -> x.getIn().getHeader("thread", String.class))
diff --git a/components/camel-reactor/src/test/java/org/apache/camel/component/reactor/engine/ReactorStreamsServiceTest.java b/components/camel-reactor/src/test/java/org/apache/camel/component/reactor/engine/ReactorStreamsServiceTest.java
index 6ef2a2f..ab58fdc 100644
--- a/components/camel-reactor/src/test/java/org/apache/camel/component/reactor/engine/ReactorStreamsServiceTest.java
+++ b/components/camel-reactor/src/test/java/org/apache/camel/component/reactor/engine/ReactorStreamsServiceTest.java
@@ -33,12 +33,16 @@ import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.support.DefaultExchange;
 import org.apache.camel.support.ExchangeHelper;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 import org.reactivestreams.Publisher;
 import reactor.core.Disposable;
 import reactor.core.publisher.Flux;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
 public class ReactorStreamsServiceTest extends ReactorStreamsServiceTestSupport {
 
     // ************************************************
@@ -72,7 +76,7 @@ public class ReactorStreamsServiceTest extends ReactorStreamsServiceTestSupport
         AtomicInteger value = new AtomicInteger(0);
 
         Flux.from(crs.fromStream("numbers", Integer.class))
-            .doOnNext(res -> Assert.assertEquals(value.incrementAndGet(), res.intValue()))
+            .doOnNext(res -> assertEquals(value.incrementAndGet(), res.intValue()))
             .subscribe();
 
         template.sendBody("direct:reactive", 1);
@@ -97,7 +101,7 @@ public class ReactorStreamsServiceTest extends ReactorStreamsServiceTestSupport
         final AtomicInteger value = new AtomicInteger(0);
 
         Flux.from(crs.fromStream("tick", Integer.class))
-            .doOnNext(res -> Assert.assertEquals(value.incrementAndGet(), res.intValue()))
+            .doOnNext(res -> assertEquals(value.incrementAndGet(), res.intValue()))
             .doOnNext(n -> latch.countDown())
             .subscribe();
 
@@ -105,7 +109,7 @@ public class ReactorStreamsServiceTest extends ReactorStreamsServiceTestSupport
 
         latch.await(5, TimeUnit.SECONDS);
 
-        Assert.assertEquals(num, value.get());
+        assertEquals(num, value.get());
     }
 
     @Test
@@ -132,8 +136,8 @@ public class ReactorStreamsServiceTest extends ReactorStreamsServiceTestSupport
         template.sendBody("direct:reactive", 1);
         template.sendBody("direct:reactive", 2);
 
-        Assert.assertTrue(latch1.await(5, TimeUnit.SECONDS));
-        Assert.assertTrue(latch2.await(5, TimeUnit.SECONDS));
+        assertTrue(latch1.await(5, TimeUnit.SECONDS));
+        assertTrue(latch2.await(5, TimeUnit.SECONDS));
     }
 
     @Test
@@ -185,11 +189,11 @@ public class ReactorStreamsServiceTest extends ReactorStreamsServiceTestSupport
 
         Flux.from(timer)
             .map(exchange -> ExchangeHelper.getHeaderOrProperty(exchange, Exchange.TIMER_COUNTER, Integer.class))
-            .doOnNext(res -> Assert.assertEquals(value.incrementAndGet(), res.intValue()))
+            .doOnNext(res -> assertEquals(value.incrementAndGet(), res.intValue()))
             .doOnNext(res -> latch.countDown())
             .subscribe();
 
-        Assert.assertTrue(latch.await(2, TimeUnit.SECONDS));
+        assertTrue(latch.await(2, TimeUnit.SECONDS));
     }
 
     // ************************************************
@@ -222,7 +226,7 @@ public class ReactorStreamsServiceTest extends ReactorStreamsServiceTestSupport
         );
 
         for (int i = 1; i <= 3; i++) {
-            Assert.assertEquals(
+            assertEquals(
                 "after stream: " + (-i),
                 template.requestBody("direct:source", i, String.class)
             );
@@ -249,7 +253,7 @@ public class ReactorStreamsServiceTest extends ReactorStreamsServiceTestSupport
         );
 
         for (int i = 1; i <= 3; i++) {
-            Assert.assertEquals(
+            assertEquals(
                 "after stream: " + (-i),
                 template.requestBody("direct:source", i, String.class)
             );
@@ -274,12 +278,12 @@ public class ReactorStreamsServiceTest extends ReactorStreamsServiceTestSupport
         Publisher<Exchange> publisher = crs.toStream("reactive", new DefaultExchange(context));
         Exchange res = Flux.from(publisher).blockFirst();
 
-        Assert.assertNotNull(res);
+        assertNotNull(res);
 
         String content = res.getIn().getBody(String.class);
 
-        Assert.assertNotNull(content);
-        Assert.assertEquals("123", content);
+        assertNotNull(content);
+        assertEquals("123", content);
     }
 
     @Test
@@ -295,8 +299,8 @@ public class ReactorStreamsServiceTest extends ReactorStreamsServiceTestSupport
             .doOnNext(res -> latch.countDown())
             .subscribe();
 
-        Assert.assertTrue(latch.await(2, TimeUnit.SECONDS));
-        Assert.assertEquals(new TreeSet<>(Arrays.asList("Hello 1", "Hello 2", "Hello 3")), values);
+        assertTrue(latch.await(2, TimeUnit.SECONDS));
+        assertEquals(new TreeSet<>(Arrays.asList("Hello 1", "Hello 2", "Hello 3")), values);
     }
 
     @Test
@@ -314,8 +318,8 @@ public class ReactorStreamsServiceTest extends ReactorStreamsServiceTestSupport
             .doOnNext(res -> latch.countDown())
             .subscribe();
 
-        Assert.assertTrue(latch.await(2, TimeUnit.SECONDS));
-        Assert.assertEquals(new TreeSet<>(Arrays.asList("Hello 1", "Hello 2", "Hello 3")), values);
+        assertTrue(latch.await(2, TimeUnit.SECONDS));
+        assertEquals(new TreeSet<>(Arrays.asList("Hello 1", "Hello 2", "Hello 3")), values);
     }
 
     @Test
@@ -332,8 +336,8 @@ public class ReactorStreamsServiceTest extends ReactorStreamsServiceTestSupport
             .doOnNext(res -> latch.countDown())
             .subscribe();
 
-        Assert.assertTrue(latch.await(2, TimeUnit.SECONDS));
-        Assert.assertEquals(new TreeSet<>(Arrays.asList("Hello 1", "Hello 2", "Hello 3")), values);
+        assertTrue(latch.await(2, TimeUnit.SECONDS));
+        assertEquals(new TreeSet<>(Arrays.asList("Hello 1", "Hello 2", "Hello 3")), values);
     }
 
     @Test
@@ -352,8 +356,8 @@ public class ReactorStreamsServiceTest extends ReactorStreamsServiceTestSupport
             .doOnNext(res -> latch.countDown())
             .subscribe();
 
-        Assert.assertTrue(latch.await(2, TimeUnit.SECONDS));
-        Assert.assertEquals(new TreeSet<>(Arrays.asList("Hello 1", "Hello 2", "Hello 3")), values);
+        assertTrue(latch.await(2, TimeUnit.SECONDS));
+        assertEquals(new TreeSet<>(Arrays.asList("Hello 1", "Hello 2", "Hello 3")), values);
     }
 
     // ************************************************
@@ -380,7 +384,7 @@ public class ReactorStreamsServiceTest extends ReactorStreamsServiceTestSupport
 
         int idx = 1;
         for (Exchange ex : mock.getExchanges()) {
-            Assert.assertEquals(Integer.valueOf(idx++), ex.getIn().getBody(Integer.class));
+            assertEquals(Integer.valueOf(idx++), ex.getIn().getBody(Integer.class));
         }
     }
 
@@ -388,7 +392,7 @@ public class ReactorStreamsServiceTest extends ReactorStreamsServiceTestSupport
     // misc
     // ************************************************
 
-    @Test(expected = FailedToStartRouteException.class)
+    @Test
     public void testOnlyOneCamelProducerPerPublisher() throws Exception {
         context.addRoutes(new RouteBuilder() {
             @Override
@@ -400,6 +404,7 @@ public class ReactorStreamsServiceTest extends ReactorStreamsServiceTestSupport
             }
         });
 
-        context.start();
+        assertThrows(FailedToStartRouteException.class,
+            () -> context.start());
     }
 }
diff --git a/components/camel-reactor/src/test/java/org/apache/camel/component/reactor/engine/ReactorStreamsServiceTestSupport.java b/components/camel-reactor/src/test/java/org/apache/camel/component/reactor/engine/ReactorStreamsServiceTestSupport.java
index f3065d7..8f2b488 100644
--- a/components/camel-reactor/src/test/java/org/apache/camel/component/reactor/engine/ReactorStreamsServiceTestSupport.java
+++ b/components/camel-reactor/src/test/java/org/apache/camel/component/reactor/engine/ReactorStreamsServiceTestSupport.java
@@ -21,7 +21,7 @@ import org.apache.camel.component.reactive.streams.ReactiveStreamsComponent;
 import org.apache.camel.component.reactive.streams.ReactiveStreamsConstants;
 import org.apache.camel.component.reactive.streams.api.CamelReactiveStreams;
 import org.apache.camel.component.reactive.streams.api.CamelReactiveStreamsService;
-import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.test.junit5.CamelTestSupport;
 import org.apache.camel.util.ObjectHelper;
 
 class ReactorStreamsServiceTestSupport extends CamelTestSupport {