Search in sources :

Example 1 with ServerStreamingStashCallable

use of com.google.api.gax.rpc.testing.FakeStreamingApi.ServerStreamingStashCallable in project gax-java by googleapis.

the class ServerStreamingCallableTest method testIteratedServerStreamingCallWithContext.

@Test
public void testIteratedServerStreamingCallWithContext() {
    FakeChannel channel = new FakeChannel();
    Credentials credentials = Mockito.mock(Credentials.class);
    ApiCallContext context = FakeCallContext.createDefault().withChannel(channel).withCredentials(credentials);
    ServerStreamingStashCallable<Integer, Integer> stashCallable = new ServerStreamingStashCallable<>();
    ServerStreamingCallable<Integer, Integer> callable = stashCallable.withDefaultCallContext(FakeCallContext.createDefault());
    Integer request = 1;
    callable.call(request, context);
    Truth.assertThat(stashCallable.getActualRequest()).isSameInstanceAs(request);
    FakeCallContext actualContext = (FakeCallContext) stashCallable.getContext();
    Truth.assertThat(actualContext.getChannel()).isSameInstanceAs(channel);
    Truth.assertThat(actualContext.getCredentials()).isSameInstanceAs(credentials);
}
Also used : FakeCallContext(com.google.api.gax.rpc.testing.FakeCallContext) ServerStreamingStashCallable(com.google.api.gax.rpc.testing.FakeStreamingApi.ServerStreamingStashCallable) Credentials(com.google.auth.Credentials) FakeChannel(com.google.api.gax.rpc.testing.FakeChannel) Test(org.junit.Test)

Example 2 with ServerStreamingStashCallable

use of com.google.api.gax.rpc.testing.FakeStreamingApi.ServerStreamingStashCallable in project gax-java by googleapis.

the class ServerStreamingCallableTest method testServerStreamingCallWithContext.

@Test
public void testServerStreamingCallWithContext() {
    FakeChannel channel = new FakeChannel();
    Credentials credentials = Mockito.mock(Credentials.class);
    ApiCallContext context = FakeCallContext.createDefault().withChannel(channel).withCredentials(credentials);
    ServerStreamingStashCallable<Integer, Integer> stashCallable = new ServerStreamingStashCallable<>();
    ServerStreamingCallable<Integer, Integer> callable = stashCallable.withDefaultCallContext(FakeCallContext.createDefault());
    @SuppressWarnings("unchecked") ResponseObserver<Integer> observer = Mockito.mock(StateCheckingResponseObserver.class);
    Integer request = 1;
    callable.call(request, observer, context);
    Truth.assertThat(stashCallable.getActualObserver()).isSameInstanceAs(observer);
    Truth.assertThat(stashCallable.getActualRequest()).isSameInstanceAs(request);
    FakeCallContext actualContext = (FakeCallContext) stashCallable.getContext();
    Truth.assertThat(actualContext.getChannel()).isSameInstanceAs(channel);
    Truth.assertThat(actualContext.getCredentials()).isSameInstanceAs(credentials);
}
Also used : FakeCallContext(com.google.api.gax.rpc.testing.FakeCallContext) ServerStreamingStashCallable(com.google.api.gax.rpc.testing.FakeStreamingApi.ServerStreamingStashCallable) Credentials(com.google.auth.Credentials) FakeChannel(com.google.api.gax.rpc.testing.FakeChannel) Test(org.junit.Test)

Example 3 with ServerStreamingStashCallable

use of com.google.api.gax.rpc.testing.FakeStreamingApi.ServerStreamingStashCallable in project gax-java by googleapis.

the class ServerStreamingCallableTest method testAllElementCallWithContext.

@Test
public void testAllElementCallWithContext() {
    FakeChannel channel = new FakeChannel();
    Credentials credentials = Mockito.mock(Credentials.class);
    ApiCallContext context = FakeCallContext.createDefault().withChannel(channel).withCredentials(credentials);
    ServerStreamingStashCallable<Integer, Integer> stashCallable = new ServerStreamingStashCallable<>();
    UnaryCallable<Integer, List<Integer>> firstCallable = stashCallable.all().withDefaultCallContext(FakeCallContext.createDefault());
    Integer request = 1;
    firstCallable.call(request, context);
    Truth.assertThat(stashCallable.getActualRequest()).isSameInstanceAs(request);
    FakeCallContext actualContext = (FakeCallContext) stashCallable.getContext();
    Truth.assertThat(actualContext.getChannel()).isSameInstanceAs(channel);
    Truth.assertThat(actualContext.getCredentials()).isSameInstanceAs(credentials);
}
Also used : FakeCallContext(com.google.api.gax.rpc.testing.FakeCallContext) ServerStreamingStashCallable(com.google.api.gax.rpc.testing.FakeStreamingApi.ServerStreamingStashCallable) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Credentials(com.google.auth.Credentials) FakeChannel(com.google.api.gax.rpc.testing.FakeChannel) Test(org.junit.Test)

Example 4 with ServerStreamingStashCallable

use of com.google.api.gax.rpc.testing.FakeStreamingApi.ServerStreamingStashCallable in project gax-java by googleapis.

the class ServerStreamingCallableTest method testFirstElementCallWithContext.

@Test
public void testFirstElementCallWithContext() {
    FakeChannel channel = new FakeChannel();
    Credentials credentials = Mockito.mock(Credentials.class);
    ApiCallContext context = FakeCallContext.createDefault().withChannel(channel).withCredentials(credentials);
    ServerStreamingStashCallable<Integer, Integer> stashCallable = new ServerStreamingStashCallable<>();
    UnaryCallable<Integer, Integer> firstCallable = stashCallable.first().withDefaultCallContext(FakeCallContext.createDefault());
    Integer request = 1;
    firstCallable.call(request, context);
    Truth.assertThat(stashCallable.getActualRequest()).isSameInstanceAs(request);
    FakeCallContext actualContext = (FakeCallContext) stashCallable.getContext();
    Truth.assertThat(actualContext.getChannel()).isSameInstanceAs(channel);
    Truth.assertThat(actualContext.getCredentials()).isSameInstanceAs(credentials);
}
Also used : FakeCallContext(com.google.api.gax.rpc.testing.FakeCallContext) ServerStreamingStashCallable(com.google.api.gax.rpc.testing.FakeStreamingApi.ServerStreamingStashCallable) Credentials(com.google.auth.Credentials) FakeChannel(com.google.api.gax.rpc.testing.FakeChannel) Test(org.junit.Test)

Aggregations

FakeCallContext (com.google.api.gax.rpc.testing.FakeCallContext)4 FakeChannel (com.google.api.gax.rpc.testing.FakeChannel)4 ServerStreamingStashCallable (com.google.api.gax.rpc.testing.FakeStreamingApi.ServerStreamingStashCallable)4 Credentials (com.google.auth.Credentials)4 Test (org.junit.Test)4 ImmutableList (com.google.common.collect.ImmutableList)1 List (java.util.List)1