You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by re...@apache.org on 2019/01/08 03:27:58 UTC

[cxf] branch master updated: Refactored JAXRSRxJava2FlowableTest to use dedicated test scaffolding

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 86c4b89  Refactored JAXRSRxJava2FlowableTest to use dedicated test scaffolding
86c4b89 is described below

commit 86c4b897ac2e4fe50a3fe8068408a2afbc259fb4
Author: reta <dr...@gmail.com>
AuthorDate: Mon Jan 7 22:27:13 2019 -0500

    Refactored JAXRSRxJava2FlowableTest to use dedicated test scaffolding
---
 .../cxf/systest/jaxrs/reactive/HelloWorldBean.java | 41 +++++++++++++++
 .../jaxrs/reactive/JAXRSRxJava2FlowableTest.java   | 59 ++++++++--------------
 2 files changed, 61 insertions(+), 39 deletions(-)

diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/reactive/HelloWorldBean.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/reactive/HelloWorldBean.java
index 799403c..bdbf2a3 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/reactive/HelloWorldBean.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/reactive/HelloWorldBean.java
@@ -25,7 +25,12 @@ public class HelloWorldBean {
         this("Hello");
     }
     public HelloWorldBean(String greeting) {
+        this(greeting, "World");
+    }
+    
+    public HelloWorldBean(String greeting, String audience) {
         this.greeting = greeting;
+        this.audience = audience;
     }
 
     public String getGreeting() {
@@ -40,4 +45,40 @@ public class HelloWorldBean {
     public void setAudience(String audience) {
         this.audience = audience;
     }
+    @Override
+    public int hashCode() {
+        int result = 31 + ((audience == null) ? 0 : audience.hashCode());
+        result = 31 * result + ((greeting == null) ? 0 : greeting.hashCode());
+        return result;
+    }
+    
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        
+        if (obj == null) {
+            return false;
+        }
+        
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        
+        final HelloWorldBean other = (HelloWorldBean) obj;
+        if (audience == null && other.audience != null) {
+            return false;
+        } else if (!audience.equals(other.audience)) {
+            return false;
+        }
+        
+        if (greeting == null && other.greeting != null) {
+            return false;
+        } else if (!greeting.equals(other.greeting)) {
+            return false;
+        }
+        
+        return true;
+    }
 }
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/reactive/JAXRSRxJava2FlowableTest.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/reactive/JAXRSRxJava2FlowableTest.java
index 403610b..ca1e658 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/reactive/JAXRSRxJava2FlowableTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/reactive/JAXRSRxJava2FlowableTest.java
@@ -22,13 +22,12 @@ package org.apache.cxf.systest.jaxrs.reactive;
 import java.util.Collections;
 import java.util.LinkedList;
 import java.util.List;
-import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
 
 import javax.ws.rs.NotFoundException;
 import javax.ws.rs.client.ClientBuilder;
 import javax.ws.rs.client.Invocation;
 import javax.ws.rs.core.GenericType;
-import javax.xml.ws.Holder;
 
 import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
 
@@ -39,14 +38,13 @@ import org.apache.cxf.jaxrs.rx2.client.FlowableRxInvokerProvider;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
 
 import io.reactivex.Flowable;
-import io.reactivex.disposables.Disposable;
+import io.reactivex.subscribers.TestSubscriber;
 
 import org.junit.BeforeClass;
 import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
 
 public class JAXRSRxJava2FlowableTest extends AbstractBusClientServerTestBase {
     public static final String PORT = RxJava2FlowableServer.PORT;
@@ -76,16 +74,11 @@ public class JAXRSRxJava2FlowableTest extends AbstractBusClientServerTestBase {
             .rx(FlowableRxInvoker.class)
             .get(HelloWorldBean.class);
 
-        Holder<HelloWorldBean> holder = new Holder<>();
-        Disposable d = obs.subscribe(v -> {
-            holder.value = v;
-        });
-        if (d == null) {
-            throw new IllegalStateException("Subscribe did not return a Disposable");
-        }
-        Thread.sleep(3000);
-        assertEquals("Hello", holder.value.getGreeting());
-        assertEquals("World", holder.value.getAudience());
+        final TestSubscriber<HelloWorldBean> subscriber = new TestSubscriber<>();
+        obs.subscribe(subscriber);
+
+        subscriber.await(3, TimeUnit.SECONDS);
+        subscriber.assertResult(new HelloWorldBean("Hello", "World"));
     }
 
     @Test
@@ -138,37 +131,25 @@ public class JAXRSRxJava2FlowableTest extends AbstractBusClientServerTestBase {
             .rx(FlowableRxInvoker.class)
             .get(String.class);
 
-        Thread.sleep(2000);
-
-        Disposable d = obs.map(
-            s -> {
-                return s + s;
-            })
-            .subscribe(s -> assertDuplicateResponse(s));
-        if (d == null) {
-            throw new IllegalStateException("Subscribe did not return a Disposable");
-        }
+        final TestSubscriber<String> subscriber = new TestSubscriber<>();
+        obs.map(s -> s + s).subscribe(subscriber);
+        
+        subscriber.await(2, TimeUnit.SECONDS);
+        subscriber.assertResult("Hello, world!Hello, world!");
     }
+    
     @Test
     public void testGetHelloWorldAsyncObservable404() throws Exception {
         String address = "http://localhost:" + PORT + "/rx2/flowable/textAsync404";
         Invocation.Builder b = ClientBuilder.newClient().register(new FlowableRxInvokerProvider())
             .target(address).request();
-        Disposable d = b.rx(FlowableRxInvoker.class).get(String.class).subscribe(
-            s -> {
-                fail("Exception expected");
-            },
-            t -> validateT((ExecutionException)t));
-        if (d == null) {
-            throw new IllegalStateException("Subscribe did not return a Disposable");
-        }
 
-    }
-
-    private void validateT(ExecutionException t) {
-        assertTrue(t.getCause() instanceof NotFoundException);
-    }
-    private void assertDuplicateResponse(String s) {
-        assertEquals("Hello, world!Hello, world!", s);
+        final TestSubscriber<String> subscriber = new TestSubscriber<>();
+        b.rx(FlowableRxInvoker.class)
+            .get(String.class)
+            .subscribe(subscriber);
+        
+        subscriber.await(1, TimeUnit.SECONDS);
+        subscriber.assertError(NotFoundException.class);
     }
 }