Search in sources :

Example 1 with ObservableRxInvokerProvider

use of org.apache.cxf.jaxrs.rx3.client.ObservableRxInvokerProvider in project cxf by apache.

the class JAXRSRxJava2ObservableTest method testGetHelloWorldJson.

@Test
public void testGetHelloWorldJson() throws Exception {
    String address = "http://localhost:" + PORT + "/rx2/observable/textJson";
    List<Object> providers = new LinkedList<>();
    providers.add(new JacksonJsonProvider());
    providers.add(new ObservableRxInvokerProvider());
    WebClient wc = WebClient.create(address, providers);
    Observable<HelloWorldBean> obs = wc.accept("application/json").rx(ObservableRxInvoker.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(2000);
    assertEquals("Hello", holder.value.getGreeting());
    assertEquals("World", holder.value.getAudience());
}
Also used : Disposable(io.reactivex.disposables.Disposable) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) Holder(javax.xml.ws.Holder) ObservableRxInvoker(org.apache.cxf.jaxrs.rx2.client.ObservableRxInvoker) WebClient(org.apache.cxf.jaxrs.client.WebClient) LinkedList(java.util.LinkedList) ObservableRxInvokerProvider(org.apache.cxf.jaxrs.rx2.client.ObservableRxInvokerProvider) Test(org.junit.Test)

Example 2 with ObservableRxInvokerProvider

use of org.apache.cxf.jaxrs.rx3.client.ObservableRxInvokerProvider in project cxf by apache.

the class JAXRSRxJava2ObservableTest method testObservableImmediateErrorsWithExceptionMapper.

@Test
public void testObservableImmediateErrorsWithExceptionMapper() throws Exception {
    String address = "http://localhost:" + PORT + "/rx2/observable/immediate/mapper/errors";
    final Observable<Response> obs = ClientBuilder.newClient().register(new JacksonJsonProvider()).register(new ObservableRxInvokerProvider()).target(address).request(MediaType.APPLICATION_JSON).rx(ObservableRxInvoker.class).get();
    final TestObserver<Response> subscriber = new TestObserver<>();
    obs.subscribe(subscriber);
    subscriber.await(3, TimeUnit.SECONDS);
    subscriber.assertValue(r -> r.getStatus() == 409 && r.readEntity(String.class).contains("stackTrace")).assertComplete();
}
Also used : Response(javax.ws.rs.core.Response) ObservableRxInvoker(org.apache.cxf.jaxrs.rx2.client.ObservableRxInvoker) BeforeClass(org.junit.BeforeClass) WebClient(org.apache.cxf.jaxrs.client.WebClient) Assert.assertTrue(org.junit.Assert.assertTrue) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) ObservableRxInvokerProvider(org.apache.cxf.jaxrs.rx2.client.ObservableRxInvokerProvider) TimeUnit(java.util.concurrent.TimeUnit) GenericType(javax.ws.rs.core.GenericType) ClientBuilder(javax.ws.rs.client.ClientBuilder) AbstractResourceInfo(org.apache.cxf.jaxrs.model.AbstractResourceInfo) List(java.util.List) MediaType(javax.ws.rs.core.MediaType) Disposable(io.reactivex.disposables.Disposable) Response(javax.ws.rs.core.Response) AbstractBusClientServerTestBase(org.apache.cxf.testutil.common.AbstractBusClientServerTestBase) Holder(javax.xml.ws.Holder) Observable(io.reactivex.Observable) LinkedList(java.util.LinkedList) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) ObservableRxInvokerProvider(org.apache.cxf.jaxrs.rx2.client.ObservableRxInvokerProvider) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) ObservableRxInvoker(org.apache.cxf.jaxrs.rx2.client.ObservableRxInvoker) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test)

Example 3 with ObservableRxInvokerProvider

use of org.apache.cxf.jaxrs.rx3.client.ObservableRxInvokerProvider in project cxf by apache.

the class JAXRSRxJava2ObservableTest method testGetHelloWorldEmpty.

@Test
public void testGetHelloWorldEmpty() throws Exception {
    String address = "http://localhost:" + PORT + "/rx2/observable/empty";
    final Observable<Response> obs = ClientBuilder.newClient().register(new JacksonJsonProvider()).register(new ObservableRxInvokerProvider()).target(address).request(MediaType.APPLICATION_JSON).rx(ObservableRxInvoker.class).get();
    final TestObserver<Response> subscriber = new TestObserver<>();
    obs.subscribe(subscriber);
    subscriber.await(3, TimeUnit.SECONDS);
    subscriber.assertValue(r -> "[]".equals(r.readEntity(String.class))).assertComplete();
}
Also used : Response(javax.ws.rs.core.Response) ObservableRxInvoker(org.apache.cxf.jaxrs.rx2.client.ObservableRxInvoker) BeforeClass(org.junit.BeforeClass) WebClient(org.apache.cxf.jaxrs.client.WebClient) Assert.assertTrue(org.junit.Assert.assertTrue) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) ObservableRxInvokerProvider(org.apache.cxf.jaxrs.rx2.client.ObservableRxInvokerProvider) TimeUnit(java.util.concurrent.TimeUnit) GenericType(javax.ws.rs.core.GenericType) ClientBuilder(javax.ws.rs.client.ClientBuilder) AbstractResourceInfo(org.apache.cxf.jaxrs.model.AbstractResourceInfo) List(java.util.List) MediaType(javax.ws.rs.core.MediaType) Disposable(io.reactivex.disposables.Disposable) Response(javax.ws.rs.core.Response) AbstractBusClientServerTestBase(org.apache.cxf.testutil.common.AbstractBusClientServerTestBase) Holder(javax.xml.ws.Holder) Observable(io.reactivex.Observable) LinkedList(java.util.LinkedList) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) ObservableRxInvokerProvider(org.apache.cxf.jaxrs.rx2.client.ObservableRxInvokerProvider) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) ObservableRxInvoker(org.apache.cxf.jaxrs.rx2.client.ObservableRxInvoker) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test)

Example 4 with ObservableRxInvokerProvider

use of org.apache.cxf.jaxrs.rx3.client.ObservableRxInvokerProvider in project cxf by apache.

the class JAXRSRxJava3ObservableTest method testGetHelloWorldJson.

@Test
public void testGetHelloWorldJson() throws Exception {
    String address = "http://localhost:" + PORT + "/rx3/observable/textJson";
    List<Object> providers = new LinkedList<>();
    providers.add(new JacksonJsonProvider());
    providers.add(new ObservableRxInvokerProvider());
    WebClient wc = WebClient.create(address, providers);
    Observable<HelloWorldBean> obs = wc.accept("application/json").rx(ObservableRxInvoker.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(2000);
    assertEquals("Hello", holder.value.getGreeting());
    assertEquals("World", holder.value.getAudience());
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) Holder(javax.xml.ws.Holder) ObservableRxInvoker(org.apache.cxf.jaxrs.rx3.client.ObservableRxInvoker) WebClient(org.apache.cxf.jaxrs.client.WebClient) LinkedList(java.util.LinkedList) ObservableRxInvokerProvider(org.apache.cxf.jaxrs.rx3.client.ObservableRxInvokerProvider) Test(org.junit.Test)

Example 5 with ObservableRxInvokerProvider

use of org.apache.cxf.jaxrs.rx3.client.ObservableRxInvokerProvider in project cxf by apache.

the class JAXRSRxJava3ObservableTest method testObservableImmediateErrorsWithExceptionMapper.

@Test
public void testObservableImmediateErrorsWithExceptionMapper() throws Exception {
    String address = "http://localhost:" + PORT + "/rx3/observable/immediate/mapper/errors";
    final Observable<Response> obs = ClientBuilder.newClient().register(new JacksonJsonProvider()).register(new ObservableRxInvokerProvider()).target(address).request(MediaType.APPLICATION_JSON).rx(ObservableRxInvoker.class).get();
    final TestObserver<Response> subscriber = new TestObserver<>();
    obs.subscribe(subscriber);
    subscriber.await(3, TimeUnit.SECONDS);
    subscriber.assertValue(r -> r.getStatus() == 409 && r.readEntity(String.class).contains("stackTrace")).assertComplete();
}
Also used : Response(javax.ws.rs.core.Response) BeforeClass(org.junit.BeforeClass) WebClient(org.apache.cxf.jaxrs.client.WebClient) Assert.assertTrue(org.junit.Assert.assertTrue) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) Test(org.junit.Test) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) TimeUnit(java.util.concurrent.TimeUnit) GenericType(javax.ws.rs.core.GenericType) ClientBuilder(javax.ws.rs.client.ClientBuilder) AbstractResourceInfo(org.apache.cxf.jaxrs.model.AbstractResourceInfo) ObservableRxInvokerProvider(org.apache.cxf.jaxrs.rx3.client.ObservableRxInvokerProvider) List(java.util.List) MediaType(javax.ws.rs.core.MediaType) ObservableRxInvoker(org.apache.cxf.jaxrs.rx3.client.ObservableRxInvoker) Response(javax.ws.rs.core.Response) TestObserver(io.reactivex.rxjava3.observers.TestObserver) Observable(io.reactivex.rxjava3.core.Observable) AbstractBusClientServerTestBase(org.apache.cxf.testutil.common.AbstractBusClientServerTestBase) Disposable(io.reactivex.rxjava3.disposables.Disposable) Holder(javax.xml.ws.Holder) LinkedList(java.util.LinkedList) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) ObservableRxInvokerProvider(org.apache.cxf.jaxrs.rx3.client.ObservableRxInvokerProvider) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) ObservableRxInvoker(org.apache.cxf.jaxrs.rx3.client.ObservableRxInvoker) TestObserver(io.reactivex.rxjava3.observers.TestObserver) Test(org.junit.Test)

Aggregations

JacksonJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider)8 Test (org.junit.Test)8 LinkedList (java.util.LinkedList)6 Holder (javax.xml.ws.Holder)6 WebClient (org.apache.cxf.jaxrs.client.WebClient)6 Collections (java.util.Collections)4 List (java.util.List)4 TimeUnit (java.util.concurrent.TimeUnit)4 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)4 ClientBuilder (javax.ws.rs.client.ClientBuilder)4 GenericType (javax.ws.rs.core.GenericType)4 MediaType (javax.ws.rs.core.MediaType)4 Response (javax.ws.rs.core.Response)4 AbstractResourceInfo (org.apache.cxf.jaxrs.model.AbstractResourceInfo)4 ObservableRxInvoker (org.apache.cxf.jaxrs.rx2.client.ObservableRxInvoker)4 ObservableRxInvokerProvider (org.apache.cxf.jaxrs.rx2.client.ObservableRxInvokerProvider)4 ObservableRxInvoker (org.apache.cxf.jaxrs.rx3.client.ObservableRxInvoker)4 ObservableRxInvokerProvider (org.apache.cxf.jaxrs.rx3.client.ObservableRxInvokerProvider)4 AbstractBusClientServerTestBase (org.apache.cxf.testutil.common.AbstractBusClientServerTestBase)4 Assert.assertEquals (org.junit.Assert.assertEquals)4