@Test public void call() throws Exception { ApiCallContext defaultCallContext = FakeCallContext.createDefault(); OperationStashCallable stashCallable = new OperationStashCallable(); OperationCallable<Integer, String, Long> callable = stashCallable.withDefaultCallContext(defaultCallContext); String response = callable.call(1); Truth.assertThat(response).isEqualTo("1"); Truth.assertThat(stashCallable.getContext()).isSameAs(defaultCallContext); }
@Test public void testCall() { Color resp = getColor(1.0f); Currency meta = Currency.getInstance("UAH"); OperationSnapshot resultOperation = getOperation("testCall", resp, null, meta, true); UnaryCallable<Integer, OperationSnapshot> initialCallable = mockGetOpSnapshotCallable(StatusCode.Code.OK, resultOperation); LongRunningClient longRunningClient = new UnsupportedOperationApi(); OperationCallable<Integer, Color, Currency> callable = FakeCallableFactory.createOperationCallable( initialCallable, callSettings, initialContext, longRunningClient); Color response = callable.call(2, FakeCallContext.createDefault()); Truth.assertThat(response).isEqualTo(resp); assertThat(executor.getIterationsCount()).isEqualTo(0); }
@Test public void callWithContext() throws Exception { FakeChannel channel = new FakeChannel(); Credentials credentials = Mockito.mock(Credentials.class); ApiCallContext context = FakeCallContext.createDefault().withChannel(channel).withCredentials(credentials); OperationStashCallable stashCallable = new OperationStashCallable(); OperationCallable<Integer, String, Long> callable = stashCallable.withDefaultCallContext(FakeCallContext.createDefault()); String response = callable.call(2, context); Truth.assertThat(response).isEqualTo("2"); FakeCallContext actualContext = (FakeCallContext) stashCallable.getContext(); Truth.assertThat(actualContext.getChannel()).isSameAs(channel); Truth.assertThat(actualContext.getCredentials()).isSameAs(credentials); }
@Test public void testCall() { Color resp = getColor(1.0f); Money meta = getMoney("UAH"); Operation resultOperation = getOperation("testCall", resp, meta, true); mockResponse(channel, Code.OK, resultOperation); OperationCallable<Integer, Color, Money> callable = GrpcCallableFactory.createOperationCallable( createGrpcSettings(), callSettings, initialContext, operationsStub); Color response = callable.call(2, GrpcCallContext.createDefault()); assertThat(response).isEqualTo(resp); assertThat(executor.getIterationsCount()).isEqualTo(0); }