Search in sources :

Example 31 with Maybe

use of io.reactivex.rxjava3.core.Maybe in project RxJava by ReactiveX.

the class FlowableFirstTest method firstWithPredicateAndEmpty.

@Test
public void firstWithPredicateAndEmpty() {
    Maybe<Integer> maybe = Flowable.just(1).filter(new Predicate<Integer>() {

        @Override
        public boolean test(Integer t1) {
            return t1 % 2 == 0;
        }
    }).firstElement();
    maybe.subscribe(wm);
    InOrder inOrder = inOrder(wm);
    inOrder.verify(wm).onComplete();
    inOrder.verify(wm, never()).onError(any(Throwable.class));
    inOrder.verifyNoMoreInteractions();
}
Also used : InOrder(org.mockito.InOrder) Predicate(io.reactivex.rxjava3.functions.Predicate)

Example 32 with Maybe

use of io.reactivex.rxjava3.core.Maybe in project cxf by apache.

the class ReactiveIOInvoker method handleMaybe.

protected AsyncResponseImpl handleMaybe(Message inMessage, Maybe<?> maybe) {
    final AsyncResponseImpl asyncResponse = new AsyncResponseImpl(inMessage);
    Disposable d = subscribe(maybe, asyncResponse);
    if (d == null) {
        throw new IllegalStateException("Subscribe did not return a Disposable");
    }
    return asyncResponse;
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) AsyncResponseImpl(org.apache.cxf.jaxrs.impl.AsyncResponseImpl)

Example 33 with Maybe

use of io.reactivex.rxjava3.core.Maybe in project cxf by apache.

the class JAXRSRxJava3MaybeTest method testGetString.

@Test
public void testGetString() throws Exception {
    String address = "http://localhost:" + PORT + "/rx3/maybe/textAsync";
    final Flowable<String> obs = ClientBuilder.newClient().register(new FlowableRxInvokerProvider()).target(address).request(MediaType.TEXT_PLAIN).rx(FlowableRxInvoker.class).get(String.class);
    final TestSubscriber<String> subscriber = new TestSubscriber<>();
    obs.subscribe(subscriber);
    subscriber.await(3, TimeUnit.SECONDS);
    subscriber.assertValue(r -> "Hello, world!".equals(r)).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) Assert.assertTrue(org.junit.Assert.assertTrue) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) Test(org.junit.Test) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) TimeUnit(java.util.concurrent.TimeUnit) ClientBuilder(javax.ws.rs.client.ClientBuilder) AbstractResourceInfo(org.apache.cxf.jaxrs.model.AbstractResourceInfo) MediaType(javax.ws.rs.core.MediaType) Response(javax.ws.rs.core.Response) AbstractBusClientServerTestBase(org.apache.cxf.testutil.common.AbstractBusClientServerTestBase) FlowableRxInvokerProvider(org.apache.cxf.jaxrs.rx3.client.FlowableRxInvokerProvider) FlowableRxInvoker(org.apache.cxf.jaxrs.rx3.client.FlowableRxInvoker) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) Test(org.junit.Test)

Example 34 with Maybe

use of io.reactivex.rxjava3.core.Maybe in project cxf by apache.

the class JAXRSRxJava3MaybeTest method testGetError.

@Test
public void testGetError() throws Exception {
    String address = "http://localhost:" + PORT + "/rx3/maybe/error";
    final Flowable<String> obs = ClientBuilder.newClient().register(new FlowableRxInvokerProvider()).target(address).request(MediaType.APPLICATION_JSON).rx(FlowableRxInvoker.class).get(String.class);
    final TestSubscriber<String> 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) FlowableRxInvoker(org.apache.cxf.jaxrs.rx3.client.FlowableRxInvoker) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) Test(org.junit.Test)

Example 35 with Maybe

use of io.reactivex.rxjava3.core.Maybe in project retrofit by square.

the class RxJava3CallAdapterFactoryTest method rawResponseTypeThrows.

@Test
public void rawResponseTypeThrows() {
    Type observableType = new TypeToken<Observable<Response>>() {
    }.getType();
    try {
        factory.get(observableType, NO_ANNOTATIONS, retrofit);
        fail();
    } catch (IllegalStateException e) {
        assertThat(e).hasMessage("Response must be parameterized as Response<Foo> or Response<? extends Foo>");
    }
    Type singleType = new TypeToken<Single<Response>>() {
    }.getType();
    try {
        factory.get(singleType, NO_ANNOTATIONS, retrofit);
        fail();
    } catch (IllegalStateException e) {
        assertThat(e).hasMessage("Response must be parameterized as Response<Foo> or Response<? extends Foo>");
    }
    Type maybeType = new TypeToken<Maybe<Response>>() {
    }.getType();
    try {
        factory.get(maybeType, NO_ANNOTATIONS, retrofit);
        fail();
    } catch (IllegalStateException e) {
        assertThat(e).hasMessage("Response must be parameterized as Response<Foo> or Response<? extends Foo>");
    }
    Type flowableType = new TypeToken<Flowable<Response>>() {
    }.getType();
    try {
        factory.get(flowableType, NO_ANNOTATIONS, retrofit);
        fail();
    } catch (IllegalStateException e) {
        assertThat(e).hasMessage("Response must be parameterized as Response<Foo> or Response<? extends Foo>");
    }
}
Also used : Type(java.lang.reflect.Type) Maybe(io.reactivex.rxjava3.core.Maybe) Single(io.reactivex.rxjava3.core.Single) Observable(io.reactivex.rxjava3.core.Observable) Flowable(io.reactivex.rxjava3.core.Flowable) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)55 TestException (io.reactivex.rxjava3.exceptions.TestException)38 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)13 Maybe (io.reactivex.rxjava3.core.Maybe)12 InOrder (org.mockito.InOrder)12 Flowable (io.reactivex.rxjava3.core.Flowable)10 Observable (io.reactivex.rxjava3.core.Observable)10 Disposable (io.reactivex.rxjava3.disposables.Disposable)10 Single (io.reactivex.rxjava3.core.Single)8 IOException (java.io.IOException)8 Predicate (io.reactivex.rxjava3.functions.Predicate)6 RxMethod (io.reactivex.rxjava3.validators.BaseTypeParser.RxMethod)6 Type (java.lang.reflect.Type)6 Test (org.junit.jupiter.api.Test)6 TestObserver (io.reactivex.rxjava3.observers.TestObserver)5 Completable (io.reactivex.rxjava3.core.Completable)4 Action (io.reactivex.rxjava3.functions.Action)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 FlowableRxInvoker (org.apache.cxf.jaxrs.rx3.client.FlowableRxInvoker)4 FlowableRxInvokerProvider (org.apache.cxf.jaxrs.rx3.client.FlowableRxInvokerProvider)4