Search in sources :

Example 31 with FlowableRxInvokerProvider

use of org.apache.cxf.jaxrs.rx2.client.FlowableRxInvokerProvider in project cxf by apache.

the class JAXRSRxJava3FlowableTest method testFlowableErrorWithExceptionMapperReturnsNoExceptionPayload.

@Test
public void testFlowableErrorWithExceptionMapperReturnsNoExceptionPayload() throws Exception {
    String address = "http://localhost:" + PORT + "/rx33/flowable/mixed/error";
    final Flowable<Response> obs = ClientBuilder.newClient().register(new JacksonJsonProvider()).register(new FlowableRxInvokerProvider()).target(address).request(MediaType.APPLICATION_JSON).rx(FlowableRxInvoker.class).get();
    final TestSubscriber<Response> subscriber = new TestSubscriber<>();
    obs.subscribe(subscriber);
    // The response should not include the exception payload (injected by exception mapper)
    // if some elements have been emitted before
    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) Flowable(io.reactivex.rxjava3.core.Flowable) BeforeClass(org.junit.BeforeClass) FlowableRxInvoker(org.apache.cxf.jaxrs.rx3.client.FlowableRxInvoker) FlowableRxInvokerProvider(org.apache.cxf.jaxrs.rx3.client.FlowableRxInvokerProvider) WebClient(org.apache.cxf.jaxrs.client.WebClient) Assert.assertTrue(org.junit.Assert.assertTrue) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) Test(org.junit.Test) Invocation(javax.ws.rs.client.Invocation) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) NotFoundException(javax.ws.rs.NotFoundException) 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) Response(javax.ws.rs.core.Response) AbstractBusClientServerTestBase(org.apache.cxf.testutil.common.AbstractBusClientServerTestBase) LinkedList(java.util.LinkedList) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) FlowableRxInvokerProvider(org.apache.cxf.jaxrs.rx3.client.FlowableRxInvokerProvider) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) FlowableRxInvoker(org.apache.cxf.jaxrs.rx3.client.FlowableRxInvoker) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) Test(org.junit.Test)

Example 32 with FlowableRxInvokerProvider

use of org.apache.cxf.jaxrs.rx2.client.FlowableRxInvokerProvider in project cxf by apache.

the class JAXRSRxJava3FlowableTest method testFlowableErrorWithExceptionMapperReturnsContentPayload.

@Test
public void testFlowableErrorWithExceptionMapperReturnsContentPayload() throws Exception {
    GenericType<List<HelloWorldBean>> helloWorldBeanListType = new GenericType<List<HelloWorldBean>>() {
    };
    String address = "http://localhost:" + PORT + "/rx33/flowable/mixed/error";
    final Flowable<Response> obs = ClientBuilder.newClient().register(new JacksonJsonProvider()).register(new FlowableRxInvokerProvider()).target(address).request(MediaType.APPLICATION_JSON).rx(FlowableRxInvoker.class).get();
    final TestSubscriber<Response> subscriber = new TestSubscriber<>();
    obs.subscribe(subscriber);
    // The response should include the emitted elements prior the error
    subscriber.await(3, TimeUnit.SECONDS);
    subscriber.assertValue(r -> r.getStatus() == 409 && r.readEntity(helloWorldBeanListType).size() == 4).assertComplete();
}
Also used : Flowable(io.reactivex.rxjava3.core.Flowable) BeforeClass(org.junit.BeforeClass) FlowableRxInvoker(org.apache.cxf.jaxrs.rx3.client.FlowableRxInvoker) FlowableRxInvokerProvider(org.apache.cxf.jaxrs.rx3.client.FlowableRxInvokerProvider) WebClient(org.apache.cxf.jaxrs.client.WebClient) Assert.assertTrue(org.junit.Assert.assertTrue) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) Test(org.junit.Test) Invocation(javax.ws.rs.client.Invocation) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) NotFoundException(javax.ws.rs.NotFoundException) 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) Response(javax.ws.rs.core.Response) AbstractBusClientServerTestBase(org.apache.cxf.testutil.common.AbstractBusClientServerTestBase) LinkedList(java.util.LinkedList) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) FlowableRxInvokerProvider(org.apache.cxf.jaxrs.rx3.client.FlowableRxInvokerProvider) GenericType(javax.ws.rs.core.GenericType) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) Response(javax.ws.rs.core.Response) FlowableRxInvoker(org.apache.cxf.jaxrs.rx3.client.FlowableRxInvoker) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) List(java.util.List) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 33 with FlowableRxInvokerProvider

use of org.apache.cxf.jaxrs.rx2.client.FlowableRxInvokerProvider in project cxf by apache.

the class JAXRSRxJava3FlowableTest method testFlowableErrorWithWebException.

@Test
public void testFlowableErrorWithWebException() throws Exception {
    String address = "http://localhost:" + PORT + "/rx33/flowable/web/errors";
    final Flowable<Response> obs = ClientBuilder.newClient().register(new JacksonJsonProvider()).register(new FlowableRxInvokerProvider()).target(address).request(MediaType.APPLICATION_JSON).rx(FlowableRxInvoker.class).get();
    final TestSubscriber<Response> subscriber = new TestSubscriber<>();
    obs.subscribe(subscriber);
    // The response should not include the exception payload (injected by exception mapper)
    // if some elements have been emitted before
    subscriber.await(3, TimeUnit.SECONDS);
    subscriber.assertValue(r -> r.getStatus() == 403 && !r.readEntity(String.class).contains("stackTrace")).assertComplete();
}
Also used : Response(javax.ws.rs.core.Response) Flowable(io.reactivex.rxjava3.core.Flowable) BeforeClass(org.junit.BeforeClass) FlowableRxInvoker(org.apache.cxf.jaxrs.rx3.client.FlowableRxInvoker) FlowableRxInvokerProvider(org.apache.cxf.jaxrs.rx3.client.FlowableRxInvokerProvider) WebClient(org.apache.cxf.jaxrs.client.WebClient) Assert.assertTrue(org.junit.Assert.assertTrue) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) Test(org.junit.Test) Invocation(javax.ws.rs.client.Invocation) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) NotFoundException(javax.ws.rs.NotFoundException) 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) Response(javax.ws.rs.core.Response) AbstractBusClientServerTestBase(org.apache.cxf.testutil.common.AbstractBusClientServerTestBase) LinkedList(java.util.LinkedList) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) FlowableRxInvokerProvider(org.apache.cxf.jaxrs.rx3.client.FlowableRxInvokerProvider) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) FlowableRxInvoker(org.apache.cxf.jaxrs.rx3.client.FlowableRxInvoker) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) Test(org.junit.Test)

Example 34 with FlowableRxInvokerProvider

use of org.apache.cxf.jaxrs.rx2.client.FlowableRxInvokerProvider in project cxf by apache.

the class JAXRSRxJava3FlowableTest method testFlowableImmediateErrors.

@Test
public void testFlowableImmediateErrors() throws Exception {
    String address = "http://localhost:" + PORT + "/rx33/flowable/immediate/errors";
    final Flowable<HelloWorldBean> obs = ClientBuilder.newClient().register(new JacksonJsonProvider()).register(new FlowableRxInvokerProvider()).target(address).request(MediaType.APPLICATION_JSON).rx(FlowableRxInvoker.class).get(HelloWorldBean.class);
    final TestSubscriber<HelloWorldBean> subscriber = new TestSubscriber<>();
    obs.subscribe(subscriber);
    subscriber.await(3, TimeUnit.SECONDS);
    subscriber.assertError(InternalServerErrorException.class);
}
Also used : FlowableRxInvokerProvider(org.apache.cxf.jaxrs.rx3.client.FlowableRxInvokerProvider) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) FlowableRxInvoker(org.apache.cxf.jaxrs.rx3.client.FlowableRxInvoker) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) Test(org.junit.Test)

Example 35 with FlowableRxInvokerProvider

use of org.apache.cxf.jaxrs.rx2.client.FlowableRxInvokerProvider in project cxf by apache.

the class JAXRSRxJava3FlowableTest method testGetHelloWorldAsyncObservable.

@Test
public void testGetHelloWorldAsyncObservable() throws Exception {
    String address = "http://localhost:" + PORT + "/rx3/flowable/textAsync";
    WebClient wc = WebClient.create(address, Collections.singletonList(new FlowableRxInvokerProvider()));
    Flowable<String> obs = wc.accept("text/plain").rx(FlowableRxInvoker.class).get(String.class);
    final TestSubscriber<String> subscriber = new TestSubscriber<>();
    obs.map(s -> s + s).subscribe(subscriber);
    subscriber.await(2, TimeUnit.SECONDS);
    subscriber.assertResult("Hello, world!Hello, world!");
}
Also used : Flowable(io.reactivex.rxjava3.core.Flowable) BeforeClass(org.junit.BeforeClass) FlowableRxInvoker(org.apache.cxf.jaxrs.rx3.client.FlowableRxInvoker) FlowableRxInvokerProvider(org.apache.cxf.jaxrs.rx3.client.FlowableRxInvokerProvider) WebClient(org.apache.cxf.jaxrs.client.WebClient) Assert.assertTrue(org.junit.Assert.assertTrue) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) Test(org.junit.Test) Invocation(javax.ws.rs.client.Invocation) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) NotFoundException(javax.ws.rs.NotFoundException) 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) Response(javax.ws.rs.core.Response) AbstractBusClientServerTestBase(org.apache.cxf.testutil.common.AbstractBusClientServerTestBase) LinkedList(java.util.LinkedList) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) FlowableRxInvokerProvider(org.apache.cxf.jaxrs.rx3.client.FlowableRxInvokerProvider) FlowableRxInvoker(org.apache.cxf.jaxrs.rx3.client.FlowableRxInvoker) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)36 JacksonJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider)30 TimeUnit (java.util.concurrent.TimeUnit)26 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)26 ClientBuilder (javax.ws.rs.client.ClientBuilder)26 MediaType (javax.ws.rs.core.MediaType)26 AbstractResourceInfo (org.apache.cxf.jaxrs.model.AbstractResourceInfo)26 AbstractBusClientServerTestBase (org.apache.cxf.testutil.common.AbstractBusClientServerTestBase)26 Assert.assertTrue (org.junit.Assert.assertTrue)26 BeforeClass (org.junit.BeforeClass)26 Response (javax.ws.rs.core.Response)22 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)18 TestSubscriber (io.reactivex.subscribers.TestSubscriber)18 LinkedList (java.util.LinkedList)18 Invocation (javax.ws.rs.client.Invocation)18 WebClient (org.apache.cxf.jaxrs.client.WebClient)18 FlowableRxInvokerProvider (org.apache.cxf.jaxrs.rx2.client.FlowableRxInvokerProvider)18 FlowableRxInvokerProvider (org.apache.cxf.jaxrs.rx3.client.FlowableRxInvokerProvider)18 FlowableRxInvoker (org.apache.cxf.jaxrs.rx2.client.FlowableRxInvoker)17 FlowableRxInvoker (org.apache.cxf.jaxrs.rx3.client.FlowableRxInvoker)17