ClientSettings { public final String getQuotaProjectId() { return stubSettings.getQuotaProjectId(); } protected  ClientSettings(Builder builder); final StubSettings getStubSettings(); final ExecutorProvider getExecutorProvider(); final TransportChannelProvider getTransportChannelProvider(); final CredentialsProvider getCredentialsProvider(); @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") final HeaderProvider getHeaderProvider(); final ApiClock getClock(); final String getEndpoint(); final String getQuotaProjectId(); @BetaApi("The surface for streaming is not stable yet and may change in the future.") @Nullable final WatchdogProvider getWatchdogProvider(); @BetaApi("The surface for streaming is not stable yet and may change in the future.") @Nonnull final Duration getWatchdogCheckInterval(); String toString(); abstract B toBuilder();  }
@Test public void testBuilderFromSettings_QuotaProjectId() { CredentialsProvider credentialsProvider_no_quota = Mockito.mock(CredentialsProvider.class); HeaderProvider headerProvider_no_quota = Mockito.mock(HeaderProvider.class); HeaderProvider internalHeaderProvider_no_quota = Mockito.mock(HeaderProvider.class); HeaderProvider headerProvider_with_quota = new HeaderProvider() { @Override public Map<String, String> getHeaders() { return Collections.singletonMap( QUOTA_PROJECT_ID_KEY, QUOTA_PROJECT_ID_FROM_HEADER_VALUE); } }; HeaderProvider internalHeaderProvider_with_quota = new HeaderProvider() { @Override public Map<String, String> getHeaders() { return Collections.singletonMap( QUOTA_PROJECT_ID_KEY, QUOTA_PROJECT_ID_FROM_INTERNAL_HEADER_VALUE); } }; CredentialsProvider credentialsProvider_with_quota = new CredentialsProvider() { @Override public Credentials getCredentials() throws IOException { return credentialsWithQuotaProject; } }; FakeClientSettings.Builder builder_setQuotaOnly = new FakeClientSettings.Builder(); builder_setQuotaOnly.setCredentialsProvider(credentialsProvider_no_quota); builder_setQuotaOnly.setHeaderProvider(headerProvider_no_quota); builder_setQuotaOnly.setInternalHeaderProvider(internalHeaderProvider_no_quota); builder_setQuotaOnly.setQuotaProjectId(QUOTA_PROJECT_ID_FROM_BUILDERS); FakeClientSettings.Builder builder_setQuotaFromHeadersOnly = new FakeClientSettings.Builder(); builder_setQuotaFromHeadersOnly.setHeaderProvider(headerProvider_with_quota); FakeClientSettings.Builder builder_setQuotaFromHeadersAndBuilders = new FakeClientSettings.Builder(); builder_setQuotaFromHeadersOnly.setHeaderProvider(headerProvider_with_quota); builder_setQuotaFromHeadersAndBuilders.setQuotaProjectId(QUOTA_PROJECT_ID_FROM_BUILDERS); FakeClientSettings.Builder builder_setQuotaFromInternalHeadersOnly = new FakeClientSettings.Builder(); builder_setQuotaFromInternalHeadersOnly.setInternalHeaderProvider( internalHeaderProvider_with_quota); FakeClientSettings.Builder builder_setQuotaFromInternalHeadersAndBuilders = new FakeClientSettings.Builder(); builder_setQuotaFromInternalHeadersAndBuilders.setInternalHeaderProvider( internalHeaderProvider_with_quota); builder_setQuotaFromInternalHeadersAndBuilders.setQuotaProjectId( QUOTA_PROJECT_ID_FROM_BUILDERS); FakeClientSettings.Builder builder_setQuotaFromCredentialsProvider = new FakeClientSettings.Builder(); builder_setQuotaFromCredentialsProvider.setCredentialsProvider(credentialsProvider_with_quota); FakeClientSettings.Builder builder_setQuotaFromCredentialsProviderAndBuilder = new FakeClientSettings.Builder(); builder_setQuotaFromCredentialsProviderAndBuilder.setCredentialsProvider( credentialsProvider_with_quota); builder_setQuotaFromCredentialsProviderAndBuilder.setQuotaProjectId( QUOTA_PROJECT_ID_FROM_BUILDERS); FakeClientSettings.Builder builder_setQuotaFromAllSources = new FakeClientSettings.Builder(); builder_setQuotaFromAllSources.setHeaderProvider(headerProvider_with_quota); builder_setQuotaFromAllSources.setInternalHeaderProvider(headerProvider_with_quota); builder_setQuotaFromAllSources.setCredentialsProvider(credentialsProvider_with_quota); builder_setQuotaFromAllSources.setQuotaProjectId(QUOTA_PROJECT_ID_FROM_BUILDERS); FakeClientSettings.Builder builder_setQuotaFromAllSourcesOrder = new FakeClientSettings.Builder(); builder_setQuotaFromAllSourcesOrder.setQuotaProjectId(QUOTA_PROJECT_ID_FROM_BUILDERS); builder_setQuotaFromAllSourcesOrder.setHeaderProvider(headerProvider_with_quota); builder_setQuotaFromAllSourcesOrder.setInternalHeaderProvider(headerProvider_with_quota); builder_setQuotaFromAllSourcesOrder.setCredentialsProvider(credentialsProvider_with_quota); Truth.assertThat(builder_setQuotaOnly.getQuotaProjectId()) .isEqualTo(QUOTA_PROJECT_ID_FROM_BUILDERS); Truth.assertThat(builder_setQuotaFromHeadersOnly.getQuotaProjectId()) .isEqualTo(QUOTA_PROJECT_ID_FROM_HEADER_VALUE); Truth.assertThat(builder_setQuotaFromHeadersAndBuilders.getQuotaProjectId()) .isEqualTo(QUOTA_PROJECT_ID_FROM_BUILDERS); Truth.assertThat((builder_setQuotaFromInternalHeadersOnly).getQuotaProjectId()) .isEqualTo(QUOTA_PROJECT_ID_FROM_INTERNAL_HEADER_VALUE); Truth.assertThat(builder_setQuotaFromInternalHeadersAndBuilders.getQuotaProjectId()) .isEqualTo(QUOTA_PROJECT_ID_FROM_BUILDERS); Truth.assertThat(builder_setQuotaFromCredentialsProviderAndBuilder.getQuotaProjectId()) .isEqualTo(QUOTA_PROJECT_ID_FROM_BUILDERS); Truth.assertThat(builder_setQuotaFromAllSources.getQuotaProjectId()) .isEqualTo(QUOTA_PROJECT_ID_FROM_BUILDERS); Truth.assertThat(builder_setQuotaFromAllSourcesOrder.getQuotaProjectId()) .isEqualTo(QUOTA_PROJECT_ID_FROM_BUILDERS); }
@Test public void testBuilderFromClientContext_QuotaProjectId() { ApiCallContext callContext = FakeCallContext.createDefault(); ClientContext clientContextQuotaOnly = ClientContext.newBuilder() .setTransportChannel(Mockito.mock(TransportChannel.class)) .setDefaultCallContext(callContext) .setQuotaProjectId(QUOTA_PROJECT_ID_FROM_CONTEXT) .build(); FakeClientSettings.Builder builderQuotaOnly = new FakeClientSettings.Builder(clientContextQuotaOnly); ClientContext clientContextCredentialOnly = ClientContext.newBuilder() .setTransportChannel(Mockito.mock(TransportChannel.class)) .setDefaultCallContext(callContext) .setCredentials(credentialsWithQuotaProject) .build(); FakeClientSettings.Builder builderCredentialOnly = new FakeClientSettings.Builder(clientContextCredentialOnly); ClientContext clientContextCredentialAndQuota = ClientContext.newBuilder() .setTransportChannel(Mockito.mock(TransportChannel.class)) .setDefaultCallContext(callContext) .setCredentials(credentialsWithQuotaProject) .setQuotaProjectId(QUOTA_PROJECT_ID_FROM_CONTEXT) .build(); FakeClientSettings.Builder builderCredentialAndQuota = new FakeClientSettings.Builder(clientContextCredentialAndQuota); ClientContext clientContextHeadersOnly = ClientContext.newBuilder() .setTransportChannel(Mockito.mock(TransportChannel.class)) .setDefaultCallContext(callContext) .setHeaders(ImmutableMap.of(QUOTA_PROJECT_ID_KEY, QUOTA_PROJECT_ID_FROM_HEADER_VALUE)) .build(); FakeClientSettings.Builder builderHeadersOnly = new FakeClientSettings.Builder(clientContextHeadersOnly); ClientContext clientContextHeadersAndQuota = ClientContext.newBuilder() .setTransportChannel(Mockito.mock(TransportChannel.class)) .setDefaultCallContext(callContext) .setQuotaProjectId(QUOTA_PROJECT_ID_FROM_CONTEXT) .setHeaders(ImmutableMap.of(QUOTA_PROJECT_ID_KEY, QUOTA_PROJECT_ID_FROM_HEADER_VALUE)) .build(); FakeClientSettings.Builder builderHeadersAndQuota = new FakeClientSettings.Builder(clientContextHeadersAndQuota); ClientContext clientContextInternalHeadersOnly = ClientContext.newBuilder() .setTransportChannel(Mockito.mock(TransportChannel.class)) .setDefaultCallContext(callContext) .setInternalHeaders( ImmutableMap.of(QUOTA_PROJECT_ID_KEY, QUOTA_PROJECT_ID_FROM_INTERNAL_HEADER_VALUE)) .build(); FakeClientSettings.Builder builderInternalHeadersOnly = new FakeClientSettings.Builder(clientContextInternalHeadersOnly); ClientContext clientContextInternalHeadersAndQuota = ClientContext.newBuilder() .setTransportChannel(Mockito.mock(TransportChannel.class)) .setDefaultCallContext(callContext) .setInternalHeaders( ImmutableMap.of(QUOTA_PROJECT_ID_KEY, QUOTA_PROJECT_ID_FROM_INTERNAL_HEADER_VALUE)) .setQuotaProjectId(QUOTA_PROJECT_ID_FROM_CONTEXT) .build(); FakeClientSettings.Builder builderInternalHeadersAndQuota = new FakeClientSettings.Builder(clientContextInternalHeadersAndQuota); ClientContext clientContextQuotaFromAllSources = ClientContext.newBuilder() .setTransportChannel(Mockito.mock(TransportChannel.class)) .setDefaultCallContext(callContext) .setHeaders( ImmutableMap.of(QUOTA_PROJECT_ID_KEY, QUOTA_PROJECT_ID_FROM_INTERNAL_HEADER_VALUE)) .setCredentials(credentialsWithQuotaProject) .setQuotaProjectId(QUOTA_PROJECT_ID_FROM_CONTEXT) .setInternalHeaders( ImmutableMap.of(QUOTA_PROJECT_ID_KEY, QUOTA_PROJECT_ID_FROM_INTERNAL_HEADER_VALUE)) .build(); FakeClientSettings.Builder builderQuotaFromAllSources = new FakeClientSettings.Builder(clientContextQuotaFromAllSources); Truth.assertThat(builderQuotaOnly.getQuotaProjectId()).isEqualTo(QUOTA_PROJECT_ID_FROM_CONTEXT); Truth.assertThat(builderCredentialOnly.getQuotaProjectId()) .isEqualTo(QUOTA_PROJECT_ID_FROM_CREDENTIALS_VALUE); Truth.assertThat(builderCredentialAndQuota.getQuotaProjectId()) .isEqualTo(QUOTA_PROJECT_ID_FROM_CONTEXT); Truth.assertThat(builderHeadersOnly.getQuotaProjectId()) .isEqualTo(QUOTA_PROJECT_ID_FROM_HEADER_VALUE); Truth.assertThat(builderHeadersAndQuota.getQuotaProjectId()) .isEqualTo(QUOTA_PROJECT_ID_FROM_CONTEXT); Truth.assertThat(builderInternalHeadersOnly.getQuotaProjectId()) .isEqualTo(QUOTA_PROJECT_ID_FROM_INTERNAL_HEADER_VALUE); Truth.assertThat(builderInternalHeadersAndQuota.getQuotaProjectId()) .isEqualTo(QUOTA_PROJECT_ID_FROM_CONTEXT); Truth.assertThat(builderQuotaFromAllSources.getQuotaProjectId()) .isEqualTo(QUOTA_PROJECT_ID_FROM_CONTEXT); }