Search in sources :

Example 6 with MtlsProvider

use of com.google.api.gax.rpc.mtls.MtlsProvider in project gax-java by googleapis.

the class ClientContextTest method testGetKeyStoreThrows.

@Test
public void testGetKeyStoreThrows() throws IOException {
    // Test the case that getKeyStore throws exceptions.
    try {
        boolean switchToMtlsEndpointAllowed = true;
        MtlsProvider provider = new FakeMtlsProvider(true, MtlsEndpointUsagePolicy.AUTO, null, "", true);
        ClientContext.getEndpoint(endpoint, mtlsEndpoint, switchToMtlsEndpointAllowed, provider);
        fail("should throw an exception");
    } catch (IOException e) {
        assertTrue("expected getKeyStore to throw an exception", e.getMessage().contains("getKeyStore throws exception"));
    }
}
Also used : FakeMtlsProvider(com.google.api.gax.rpc.testing.FakeMtlsProvider) MtlsProvider(com.google.api.gax.rpc.mtls.MtlsProvider) FakeMtlsProvider(com.google.api.gax.rpc.testing.FakeMtlsProvider) IOException(java.io.IOException) Test(org.junit.Test)

Example 7 with MtlsProvider

use of com.google.api.gax.rpc.mtls.MtlsProvider in project gax-java by googleapis.

the class ClientContextTest method testEndpointNotOverridable.

@Test
public void testEndpointNotOverridable() throws IOException {
    // Test the case that switching to mTLS endpoint is not allowed so the original endpoint is
    // selected.
    boolean switchToMtlsEndpointAllowed = false;
    MtlsProvider provider = new FakeMtlsProvider(true, MtlsEndpointUsagePolicy.AUTO, FakeMtlsProvider.createTestMtlsKeyStore(), "", false);
    String endpointSelected = ClientContext.getEndpoint(endpoint, mtlsEndpoint, switchToMtlsEndpointAllowed, provider);
    assertEquals(endpoint, endpointSelected);
}
Also used : FakeMtlsProvider(com.google.api.gax.rpc.testing.FakeMtlsProvider) MtlsProvider(com.google.api.gax.rpc.mtls.MtlsProvider) FakeMtlsProvider(com.google.api.gax.rpc.testing.FakeMtlsProvider) Test(org.junit.Test)

Aggregations

MtlsProvider (com.google.api.gax.rpc.mtls.MtlsProvider)7 FakeMtlsProvider (com.google.api.gax.rpc.testing.FakeMtlsProvider)6 Test (org.junit.Test)6 ApiClock (com.google.api.core.ApiClock)1 BackgroundResource (com.google.api.gax.core.BackgroundResource)1 ExecutorAsBackgroundResource (com.google.api.gax.core.ExecutorAsBackgroundResource)1 ExecutorProvider (com.google.api.gax.core.ExecutorProvider)1 QuotaProjectIdHidingCredentials (com.google.api.gax.rpc.internal.QuotaProjectIdHidingCredentials)1 Credentials (com.google.auth.Credentials)1 ImmutableList (com.google.common.collect.ImmutableList)1 IOException (java.io.IOException)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 Nullable (javax.annotation.Nullable)1