use of com.google.api.gax.rpc.testing.FakeChannel in project gax-java by googleapis.
the class ClientContextTest method testUserAgentConcat.
@Test
public void testUserAgentConcat() throws Exception {
TransportChannelProvider transportChannelProvider = new FakeTransportProvider(FakeTransportChannel.create(new FakeChannel()), null, true, null, null);
ClientSettings.Builder builder = new FakeClientSettings.Builder().setExecutorProvider(FixedExecutorProvider.create(Mockito.mock(ScheduledExecutorService.class))).setTransportChannelProvider(transportChannelProvider).setCredentialsProvider(FixedCredentialsProvider.create(Mockito.mock(GoogleCredentials.class)));
builder.setHeaderProvider(FixedHeaderProvider.create("user-agent", "user-supplied-agent"));
builder.setInternalHeaderProvider(FixedHeaderProvider.create("user-agent", "internal-agent"));
ClientContext clientContext = ClientContext.create(builder.build());
FakeTransportChannel transportChannel = (FakeTransportChannel) clientContext.getTransportChannel();
assertThat(transportChannel.getHeaders()).containsEntry("user-agent", "user-supplied-agent internal-agent");
}
use of com.google.api.gax.rpc.testing.FakeChannel in project gax-java by googleapis.
the class ClientContextTest method testHidingQuotaProjectId_noQuotaSetFromSetting.
@Test
public void testHidingQuotaProjectId_noQuotaSetFromSetting() throws IOException {
FakeClientSettings.Builder builder = new FakeClientSettings.Builder();
InterceptingExecutor executor = new InterceptingExecutor(1);
FakeTransportChannel transportChannel = FakeTransportChannel.create(new FakeChannel());
FakeTransportProvider transportProvider = new FakeTransportProvider(transportChannel, executor, true, null, null);
Map<String, List<String>> metaData = ImmutableMap.of("k1", Collections.singletonList("v1"));
final Credentials credentialsWithoutQuotaProjectId = Mockito.mock(GoogleCredentials.class);
Mockito.when(credentialsWithoutQuotaProjectId.getRequestMetadata(null)).thenReturn(metaData);
HeaderProvider headerProviderWithQuota = Mockito.mock(HeaderProvider.class);
HeaderProvider internalHeaderProvider = Mockito.mock(HeaderProvider.class);
builder.setExecutorProvider(new FakeExecutorProvider(executor, true));
builder.setTransportChannelProvider(transportProvider);
builder.setCredentialsProvider(new CredentialsProvider() {
@Override
public Credentials getCredentials() throws IOException {
return credentialsWithoutQuotaProjectId;
}
});
builder.setHeaderProvider(headerProviderWithQuota);
builder.setInternalHeaderProvider(internalHeaderProvider);
ClientContext clientContext = ClientContext.create(builder.build());
assertThat(clientContext.getCredentials().getRequestMetadata(null)).isEqualTo(metaData);
}
use of com.google.api.gax.rpc.testing.FakeChannel in project gax-java by googleapis.
the class ClientContextTest method testUserAgentInternalOnly.
@Test
public void testUserAgentInternalOnly() throws Exception {
TransportChannelProvider transportChannelProvider = new FakeTransportProvider(FakeTransportChannel.create(new FakeChannel()), null, true, null, null);
ClientSettings.Builder builder = new FakeClientSettings.Builder().setExecutorProvider(FixedExecutorProvider.create(Mockito.mock(ScheduledExecutorService.class))).setTransportChannelProvider(transportChannelProvider).setCredentialsProvider(FixedCredentialsProvider.create(Mockito.mock(GoogleCredentials.class)));
builder.setInternalHeaderProvider(FixedHeaderProvider.create("user-agent", "internal-agent"));
ClientContext clientContext = ClientContext.create(builder.build());
FakeTransportChannel transportChannel = (FakeTransportChannel) clientContext.getTransportChannel();
assertThat(transportChannel.getHeaders()).containsEntry("user-agent", "internal-agent");
}
use of com.google.api.gax.rpc.testing.FakeChannel in project gax-java by googleapis.
the class ClientContextTest method testMergeHeaders_noQuotaProjectIdSet.
@Test
public void testMergeHeaders_noQuotaProjectIdSet() throws IOException {
final String QUOTA_PROJECT_ID_KEY = "x-goog-user-project";
FakeClientSettings.Builder builder = new FakeClientSettings.Builder();
InterceptingExecutor executor = new InterceptingExecutor(1);
FakeTransportChannel transportChannel = FakeTransportChannel.create(new FakeChannel());
FakeTransportProvider transportProvider = new FakeTransportProvider(transportChannel, executor, true, null, null);
HeaderProvider headerProvider = Mockito.mock(HeaderProvider.class);
Mockito.when(headerProvider.getHeaders()).thenReturn(ImmutableMap.of("header_k1", "v1"));
HeaderProvider internalHeaderProvider = Mockito.mock(HeaderProvider.class);
Mockito.when(internalHeaderProvider.getHeaders()).thenReturn(ImmutableMap.of("internal_header_k1", "v1"));
builder.setTransportChannelProvider(transportProvider);
builder.setCredentialsProvider(FixedCredentialsProvider.create(Mockito.mock(Credentials.class)));
builder.setHeaderProvider(headerProvider);
builder.setInternalHeaderProvider(internalHeaderProvider);
ClientContext context = ClientContext.create(builder.build());
List<BackgroundResource> resources = context.getBackgroundResources();
FakeTransportChannel fakeTransportChannel = (FakeTransportChannel) resources.get(0);
assertThat(fakeTransportChannel.getHeaders().size()).isEqualTo(headerProvider.getHeaders().size() + internalHeaderProvider.getHeaders().size());
assertThat(fakeTransportChannel.getHeaders().containsKey(QUOTA_PROJECT_ID_KEY)).isFalse();
}
use of com.google.api.gax.rpc.testing.FakeChannel in project gax-java by googleapis.
the class BatchingTest method setUp.
@Before
public void setUp() {
batchingExecutor = new ScheduledThreadPoolExecutor(1);
clientContext = ClientContext.newBuilder().setExecutor(batchingExecutor).setDefaultCallContext(FakeCallContext.createDefault()).setTransportChannel(FakeTransportChannel.create(new FakeChannel())).build();
}
Aggregations