Search in sources :

Example 51 with Action1

use of rx.functions.Action1 in project jocean-http by isdom.

the class MessageUtil method toRequest.

public static Action1<Object> toRequest(final Object... beans) {
    return new Action1<Object>() {

        @Override
        public void call(final Object obj) {
            if (obj instanceof HttpRequest) {
                final HttpRequest request = (HttpRequest) obj;
                for (Object bean : beans) {
                    setUriToRequest(request, bean);
                    addQueryParams(request, bean);
                    addHeaderParams(request, bean);
                }
            }
        }
    };
}
Also used : DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) HttpRequest(io.netty.handler.codec.http.HttpRequest) Action1(rx.functions.Action1) HttpObject(io.netty.handler.codec.http.HttpObject)

Example 52 with Action1

use of rx.functions.Action1 in project photon-model by vmware.

the class AzureUtils method injectOperationContext.

public static <T> Action1<T> injectOperationContext(Action1<T> original) {
    OperationContext operationContext = OperationContext.getOperationContext();
    return new Action1<T>() {

        @Override
        public void call(T t) {
            OperationContext.restoreOperationContext(operationContext);
            original.call(t);
        }
    };
}
Also used : OperationContext(com.vmware.xenon.common.OperationContext) Action1(rx.functions.Action1)

Example 53 with Action1

use of rx.functions.Action1 in project knotx by Cognifide.

the class FragmentAssemblerTest method callAssemblerWithAssertions.

private void callAssemblerWithAssertions(TestContext context, List<Pair<List<String>, String>> fragments, Action1<KnotContext> testFunction) {
    Async async = context.async();
    KnotProxy service = KnotProxy.createProxy(new Vertx(vertx.vertx()), ADDRESS);
    service.rxProcess(KnotContextFactory.create(fragments)).map(ctx -> Pair.of(async, ctx)).doOnSuccess(success -> testFunction.call(success.getRight())).subscribe(success -> async.complete(), context::fail);
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Arrays(java.util.Arrays) KnotContext(io.knotx.dataobjects.KnotContext) RunWith(org.junit.runner.RunWith) Logback(io.knotx.junit.rule.Logback) Action1(rx.functions.Action1) StringUtils(org.apache.commons.lang3.StringUtils) Vertx(io.vertx.reactivex.core.Vertx) FileReader(io.knotx.junit.util.FileReader) Pair(org.apache.commons.lang3.tuple.Pair) KnotxConfiguration(io.knotx.junit.rule.KnotxConfiguration) TestVertxDeployer(io.knotx.junit.rule.TestVertxDeployer) KnotProxy(io.knotx.reactivex.proxy.KnotProxy) KnotContextFactory(io.knotx.junit.util.KnotContextFactory) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) IOException(java.io.IOException) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) RuleChain(org.junit.rules.RuleChain) List(java.util.List) Rule(org.junit.Rule) RunTestOnContext(io.vertx.ext.unit.junit.RunTestOnContext) Collections(java.util.Collections) Async(io.vertx.ext.unit.Async) KnotProxy(io.knotx.reactivex.proxy.KnotProxy) Vertx(io.vertx.reactivex.core.Vertx)

Example 54 with Action1

use of rx.functions.Action1 in project knotx by Cognifide.

the class HtmlFragmentSplitterVerticleTest method callFragmentSplitterWithAssertions.

private void callFragmentSplitterWithAssertions(TestContext context, String template, Action1<KnotContext> testFunction) {
    Async async = context.async();
    KnotProxy service = KnotProxy.createProxy(new Vertx(vertx.vertx()), ADDRESS);
    service.rxProcess(KnotContextFactory.empty(template)).map(ctx -> Pair.of(async, ctx)).doOnSuccess(success -> testFunction.call(success.getRight())).subscribe(success -> async.complete(), context::fail);
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) KnotContext(io.knotx.dataobjects.KnotContext) KnotProxy(io.knotx.reactivex.proxy.KnotProxy) RunWith(org.junit.runner.RunWith) KnotContextFactory(io.knotx.junit.util.KnotContextFactory) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) Test(org.junit.Test) Logback(io.knotx.junit.rule.Logback) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) Action1(rx.functions.Action1) RuleChain(org.junit.rules.RuleChain) Vertx(io.vertx.reactivex.core.Vertx) Rule(org.junit.Rule) FileReader(io.knotx.junit.util.FileReader) Pair(org.apache.commons.lang3.tuple.Pair) KnotxConfiguration(io.knotx.junit.rule.KnotxConfiguration) RunTestOnContext(io.vertx.ext.unit.junit.RunTestOnContext) TestVertxDeployer(io.knotx.junit.rule.TestVertxDeployer) Async(io.vertx.ext.unit.Async) KnotProxy(io.knotx.reactivex.proxy.KnotProxy) Vertx(io.vertx.reactivex.core.Vertx)

Example 55 with Action1

use of rx.functions.Action1 in project jbpm-work-items by kiegroup.

the class EthereumWorkitemHandlerTest method setUp.

@Before
public void setUp() {
    try {
        when(web3j.ethGetBalance(anyString(), any(DefaultBlockParameterName.class))).thenReturn(balanceRequest);
        when(balanceRequest.send()).thenReturn(ethGetBalance);
        when(ethGetBalance.getBalance()).thenReturn(BigInteger.valueOf(100));
        when(transfer.sendFunds(anyString(), any(BigDecimal.class), any(Unit.class))).thenReturn(transferRequest);
        when(transferRequest.send()).thenReturn(transactionReceipt);
        when(transactionReceipt.getStatus()).thenReturn("testStatus");
        when(transactionReceipt.getBlockHash()).thenReturn("testBlockHash");
        when(transactionReceipt.getBlockNumber()).thenReturn(BigInteger.valueOf(1));
        when(web3j.ethCall(any(Transaction.class), any(DefaultBlockParameterName.class))).thenReturn(ethCallRequest);
        when(ethCallRequest.sendAsync()).thenReturn(ethCallCompletable);
        when(ethCallCompletable.get()).thenReturn(ethCall);
        when(ethCall.getValue()).thenReturn("testResultValue");
        when(web3j.ethGetTransactionCount(anyString(), any(DefaultBlockParameterName.class))).thenReturn(ethCountRequest);
        when(ethCountRequest.sendAsync()).thenReturn(ethCountCompletable);
        when(ethCountCompletable.get()).thenReturn(transactionCount);
        when(transactionCount.getTransactionCount()).thenReturn(BigInteger.valueOf(10));
        when(web3j.ethSendTransaction(any(Transaction.class))).thenReturn(ethSendRequest);
        when(ethSendRequest.sendAsync()).thenReturn(ethSendCompletable);
        when(ethSendCompletable.get()).thenReturn(ethSendTransaction);
        when(ethSendTransaction.getTransactionHash()).thenReturn("testTransactionHash");
        when(web3j.ethSendRawTransaction(anyString())).thenReturn(ethSendRawRequest);
        when(ethSendRawRequest.sendAsync()).thenReturn(ethSendRawCompletable);
        when(ethSendRawCompletable.get()).thenReturn(ethSendRawTransaction);
        when(ethSendRawTransaction.getTransactionHash()).thenReturn("testTransactionHash");
        when(web3j.ethGetTransactionReceipt(anyString())).thenReturn(ethSendTransactionReceipt);
        when(ethSendTransactionReceipt.send()).thenReturn(ethGetTransactionReceipt);
        when(ethGetTransactionReceipt.getTransactionReceipt()).thenReturn(Optional.of(rawTransactionalRecept));
        when(ethGetTransactionReceipt.getResult()).thenReturn(rawTransactionalRecept);
        when(rawTransactionalRecept.getContractAddress()).thenReturn("testContractAddress");
        signalList = new ArrayList();
        doAnswer(new Answer() {

            public Void answer(InvocationOnMock invocation) {
                signalList.add(Arrays.toString(invocation.getArguments()));
                return null;
            }
        }).when(kieSession).signalEvent(anyString(), any(Object.class));
        Observable logObservable = PowerMockito.mock(Observable.class);
        when(web3j.ethLogObservable(any(EthFilter.class))).thenReturn(logObservable);
        when(logObservable.subscribe()).thenReturn(subscription);
        when(logObservable.subscribe(any(Action1.class))).thenReturn(subscription);
    } catch (Exception e) {
        fail(e.getMessage());
    }
}
Also used : EthFilter(org.web3j.protocol.core.methods.request.EthFilter) Action1(rx.functions.Action1) ArrayList(java.util.ArrayList) Unit(org.web3j.utils.Convert.Unit) BigDecimal(java.math.BigDecimal) Observable(rx.Observable) Answer(org.mockito.stubbing.Answer) Transaction(org.web3j.protocol.core.methods.request.Transaction) EthSendTransaction(org.web3j.protocol.core.methods.response.EthSendTransaction) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DefaultBlockParameterName(org.web3j.protocol.core.DefaultBlockParameterName) Before(org.junit.Before)

Aggregations

Action1 (rx.functions.Action1)106 Test (org.junit.Test)33 Action0 (rx.functions.Action0)28 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)24 UiThreadTest (android.support.test.annotation.UiThreadTest)20 Observable (rx.Observable)18 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)12 HystrixRuntimeException (com.netflix.hystrix.exception.HystrixRuntimeException)11 ArrayList (java.util.ArrayList)11 CountDownLatch (java.util.concurrent.CountDownLatch)11 TestSubscriber (rx.observers.TestSubscriber)10 AllTypes (io.realm.entities.AllTypes)9 List (java.util.List)9 TestCircuitBreaker (com.netflix.hystrix.HystrixCircuitBreakerTest.TestCircuitBreaker)7 OnSubscribe (rx.Observable.OnSubscribe)7 RunTestInLooperThread (io.realm.rule.RunTestInLooperThread)6 IOException (java.io.IOException)6 PluginTestVerifier (com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier)5 Method (java.lang.reflect.Method)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)5