diff --git a/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/TestUtils.java b/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/TestUtils.java new file mode 100644 index 0000000000..d9ee4d437a --- /dev/null +++ b/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/TestUtils.java @@ -0,0 +1,34 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.spring.autoconfigure; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import com.google.auth.CredentialTypeForMetrics; +import com.google.auth.Credentials; + +public class TestUtils { + public static final Credentials MOCK_CREDENTIALS = createMockCredentials(); + + private static Credentials createMockCredentials() { + Credentials mockCredential = mock(Credentials.class); + when(mockCredential.getMetricsCredentialType()) + .thenReturn(CredentialTypeForMetrics.DO_NOT_SEND); + return mockCredential; + } +} diff --git a/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/bigquery/GcpBigQueryAutoConfigurationTests.java b/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/bigquery/GcpBigQueryAutoConfigurationTests.java index 07d62ce5f5..986998fd03 100644 --- a/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/bigquery/GcpBigQueryAutoConfigurationTests.java +++ b/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/bigquery/GcpBigQueryAutoConfigurationTests.java @@ -17,12 +17,11 @@ package com.google.cloud.spring.autoconfigure.bigquery; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; import com.google.api.gax.core.CredentialsProvider; -import com.google.auth.oauth2.GoogleCredentials; import com.google.cloud.bigquery.BigQuery; import com.google.cloud.bigquery.BigQueryOptions; +import com.google.cloud.spring.autoconfigure.TestUtils; import com.google.cloud.spring.autoconfigure.core.GcpContextAutoConfiguration; import com.google.cloud.spring.bigquery.core.BigQueryTemplate; import org.junit.jupiter.api.Test; @@ -33,8 +32,6 @@ class GcpBigQueryAutoConfigurationTests { - private static final GoogleCredentials MOCK_CREDENTIALS = mock(GoogleCredentials.class); - private ApplicationContextRunner contextRunner = new ApplicationContextRunner() .withConfiguration( @@ -51,7 +48,7 @@ void testSettingBigQueryOptions() { context -> { BigQueryOptions bigQueryOptions = context.getBean(BigQuery.class).getOptions(); assertThat(bigQueryOptions.getProjectId()).isEqualTo("test-project"); - assertThat(bigQueryOptions.getCredentials()).isEqualTo(MOCK_CREDENTIALS); + assertThat(bigQueryOptions.getCredentials()).isEqualTo(TestUtils.MOCK_CREDENTIALS); BigQueryTemplate bigQueryTemplate = context.getBean(BigQueryTemplate.class); assertThat(bigQueryTemplate.getDatasetName()).isEqualTo("test-dataset"); @@ -66,7 +63,7 @@ static class TestConfiguration { @Bean public CredentialsProvider credentialsProvider() { - return () -> MOCK_CREDENTIALS; + return () -> TestUtils.MOCK_CREDENTIALS; } } } diff --git a/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/core/GcpContextAutoConfigurationTests.java b/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/core/GcpContextAutoConfigurationTests.java index 2e65cdd7ac..3fc700cef6 100644 --- a/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/core/GcpContextAutoConfigurationTests.java +++ b/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/core/GcpContextAutoConfigurationTests.java @@ -17,10 +17,9 @@ package com.google.cloud.spring.autoconfigure.core; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; import com.google.api.gax.core.CredentialsProvider; -import com.google.auth.Credentials; +import com.google.cloud.spring.autoconfigure.TestUtils; import com.google.cloud.spring.core.DefaultGcpEnvironmentProvider; import com.google.cloud.spring.core.DefaultGcpProjectIdProvider; import com.google.cloud.spring.core.GcpEnvironmentProvider; @@ -99,7 +98,7 @@ private static class TestConfiguration { @Bean public CredentialsProvider googleCredentials() { - return () -> mock(Credentials.class); + return () -> TestUtils.MOCK_CREDENTIALS; } } } diff --git a/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/datastore/health/DatastoreHealthIndicatorAutoConfigurationTests.java b/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/datastore/health/DatastoreHealthIndicatorAutoConfigurationTests.java index 9c18936c9e..7f04bd967f 100644 --- a/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/datastore/health/DatastoreHealthIndicatorAutoConfigurationTests.java +++ b/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/datastore/health/DatastoreHealthIndicatorAutoConfigurationTests.java @@ -20,7 +20,7 @@ import static org.mockito.Mockito.mock; import com.google.api.gax.core.CredentialsProvider; -import com.google.auth.Credentials; +import com.google.cloud.spring.autoconfigure.TestUtils; import com.google.cloud.spring.autoconfigure.core.GcpContextAutoConfiguration; import com.google.cloud.spring.autoconfigure.datastore.GcpDatastoreAutoConfiguration; import org.junit.jupiter.api.Test; @@ -61,7 +61,7 @@ static class TestConfiguration { @Bean public CredentialsProvider credentialsProvider() { - return () -> mock(Credentials.class); + return () -> TestUtils.MOCK_CREDENTIALS; } } } diff --git a/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/datastore/it/GcpDatastoreEmulatorIntegrationTests.java b/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/datastore/it/GcpDatastoreEmulatorIntegrationTests.java index b6819b2ee6..c466e8e62c 100644 --- a/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/datastore/it/GcpDatastoreEmulatorIntegrationTests.java +++ b/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/datastore/it/GcpDatastoreEmulatorIntegrationTests.java @@ -18,16 +18,15 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.mockito.Mockito.mock; import com.google.api.gax.core.CredentialsProvider; -import com.google.auth.Credentials; import com.google.cloud.datastore.Datastore; import com.google.cloud.datastore.DatastoreException; import com.google.cloud.datastore.DatastoreOptions; import com.google.cloud.datastore.EntityQuery; import com.google.cloud.datastore.Query; import com.google.cloud.datastore.StructuredQuery; +import com.google.cloud.spring.autoconfigure.TestUtils; import com.google.cloud.spring.autoconfigure.core.GcpContextAutoConfiguration; import com.google.cloud.spring.autoconfigure.datastore.DatastoreRepositoriesAutoConfiguration; import com.google.cloud.spring.autoconfigure.datastore.DatastoreTransactionManagerAutoConfiguration; @@ -118,7 +117,7 @@ static class TestConfiguration { @Bean public CredentialsProvider credentialsProvider() { - return () -> mock(Credentials.class); + return () -> TestUtils.MOCK_CREDENTIALS; } } diff --git a/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/firestore/GcpFirestoreAutoConfigurationTests.java b/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/firestore/GcpFirestoreAutoConfigurationTests.java index a86a424eed..c99f2cb27b 100644 --- a/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/firestore/GcpFirestoreAutoConfigurationTests.java +++ b/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/firestore/GcpFirestoreAutoConfigurationTests.java @@ -18,12 +18,11 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.Mockito.mock; import com.google.api.gax.core.CredentialsProvider; -import com.google.auth.oauth2.GoogleCredentials; import com.google.cloud.firestore.Firestore; import com.google.cloud.firestore.FirestoreOptions; +import com.google.cloud.spring.autoconfigure.TestUtils; import com.google.cloud.spring.autoconfigure.core.GcpContextAutoConfiguration; import com.google.firestore.v1.FirestoreGrpc; import io.grpc.ClientInterceptor; @@ -136,7 +135,7 @@ static class TestConfiguration { @Bean public CredentialsProvider credentialsProvider() { - return () -> mock(GoogleCredentials.class); + return () -> TestUtils.MOCK_CREDENTIALS; } } } diff --git a/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/kms/KmsAutoConfigurationTests.java b/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/kms/KmsAutoConfigurationTests.java index 51856e6ebb..e9c4c4d317 100644 --- a/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/kms/KmsAutoConfigurationTests.java +++ b/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/kms/KmsAutoConfigurationTests.java @@ -21,6 +21,7 @@ import static org.mockito.Mockito.when; import com.google.api.gax.core.CredentialsProvider; +import com.google.auth.CredentialTypeForMetrics; import com.google.auth.Credentials; import com.google.auth.oauth2.ServiceAccountCredentials; import com.google.auth.oauth2.UserCredentials; @@ -125,6 +126,7 @@ static class TestConfiguration { public static CredentialsProvider googleCredentials() { UserCredentials mockUserCredential = mock(UserCredentials.class); when(mockUserCredential.getClientId()).thenReturn(CORE_CREDENTIAL_CLIENT_ID); + when(mockUserCredential.getMetricsCredentialType()).thenReturn(CredentialTypeForMetrics.DO_NOT_SEND); return () -> mockUserCredential; } diff --git a/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/logging/StackdriverLoggingAutoConfigurationTests.java b/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/logging/StackdriverLoggingAutoConfigurationTests.java index f23921b224..185448f284 100644 --- a/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/logging/StackdriverLoggingAutoConfigurationTests.java +++ b/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/logging/StackdriverLoggingAutoConfigurationTests.java @@ -17,10 +17,9 @@ package com.google.cloud.spring.autoconfigure.logging; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; import com.google.api.gax.core.CredentialsProvider; -import com.google.auth.Credentials; +import com.google.cloud.spring.autoconfigure.TestUtils; import com.google.cloud.spring.autoconfigure.core.GcpContextAutoConfiguration; import com.google.cloud.spring.autoconfigure.trace.StackdriverTraceAutoConfiguration; import com.google.cloud.spring.logging.TraceIdLoggingWebMvcInterceptor; @@ -105,7 +104,7 @@ private static class TestConfiguration { @Bean public CredentialsProvider googleCredentials() { - return () -> mock(Credentials.class); + return () -> TestUtils.MOCK_CREDENTIALS; } @Bean diff --git a/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/pubsub/GcpPubSubAutoConfigurationTests.java b/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/pubsub/GcpPubSubAutoConfigurationTests.java index 3f18d1e72c..8b72f9af70 100644 --- a/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/pubsub/GcpPubSubAutoConfigurationTests.java +++ b/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/pubsub/GcpPubSubAutoConfigurationTests.java @@ -29,9 +29,9 @@ import com.google.api.gax.retrying.RetrySettings; import com.google.api.gax.rpc.StatusCode.Code; import com.google.api.gax.rpc.TransportChannelProvider; -import com.google.auth.Credentials; import com.google.cloud.pubsub.v1.Publisher; import com.google.cloud.pubsub.v1.Subscriber; +import com.google.cloud.spring.autoconfigure.TestUtils; import com.google.cloud.spring.core.GcpProjectIdProvider; import com.google.cloud.spring.pubsub.core.PubSubConfiguration; import com.google.cloud.spring.pubsub.core.publisher.PublisherCustomizer; @@ -1448,7 +1448,7 @@ public GcpProjectIdProvider projectIdProvider() { @Bean public CredentialsProvider googleCredentials() { - return () -> mock(Credentials.class); + return () -> TestUtils.MOCK_CREDENTIALS; } } } diff --git a/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/pubsub/GcpPubSubEmulatorAutoConfigurationTests.java b/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/pubsub/GcpPubSubEmulatorAutoConfigurationTests.java index d10b1a5058..005778ac88 100644 --- a/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/pubsub/GcpPubSubEmulatorAutoConfigurationTests.java +++ b/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/pubsub/GcpPubSubEmulatorAutoConfigurationTests.java @@ -28,6 +28,7 @@ import com.google.api.gax.rpc.TransportChannelProvider; import com.google.auth.Credentials; import com.google.cloud.pubsub.v1.TopicAdminSettings; +import com.google.cloud.spring.autoconfigure.TestUtils; import com.google.cloud.spring.autoconfigure.core.GcpContextAutoConfiguration; import com.google.cloud.spring.pubsub.core.PubSubConfiguration; import org.assertj.core.data.Offset; @@ -187,7 +188,7 @@ void testPublisherBatchingSettings() { private static class TestConfiguration { @Bean public CredentialsProvider googleCredentials() { - return () -> mock(Credentials.class); + return () -> TestUtils.MOCK_CREDENTIALS; } } } diff --git a/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/pubsub/GcpPubSubReactiveAutoConfigurationTest.java b/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/pubsub/GcpPubSubReactiveAutoConfigurationTest.java index 52f9802b62..463ba373ee 100644 --- a/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/pubsub/GcpPubSubReactiveAutoConfigurationTest.java +++ b/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/pubsub/GcpPubSubReactiveAutoConfigurationTest.java @@ -22,6 +22,7 @@ import com.google.api.gax.core.CredentialsProvider; import com.google.auth.Credentials; +import com.google.cloud.spring.autoconfigure.TestUtils; import com.google.cloud.spring.core.GcpProjectIdProvider; import com.google.cloud.spring.pubsub.core.subscriber.PubSubSubscriberOperations; import com.google.cloud.spring.pubsub.core.subscriber.PubSubSubscriberTemplate; @@ -165,7 +166,7 @@ public GcpProjectIdProvider projectIdProvider() { @Bean public CredentialsProvider googleCredentials() { - return () -> mock(Credentials.class); + return () -> TestUtils.MOCK_CREDENTIALS; } } } diff --git a/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/pubsub/health/PubSubHealthIndicatorAutoConfigurationTests.java b/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/pubsub/health/PubSubHealthIndicatorAutoConfigurationTests.java index 97504d05f5..c30cd4e2f8 100644 --- a/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/pubsub/health/PubSubHealthIndicatorAutoConfigurationTests.java +++ b/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/pubsub/health/PubSubHealthIndicatorAutoConfigurationTests.java @@ -28,6 +28,7 @@ import com.google.api.gax.core.CredentialsProvider; import com.google.auth.Credentials; +import com.google.cloud.spring.autoconfigure.TestUtils; import com.google.cloud.spring.autoconfigure.pubsub.GcpPubSubAutoConfiguration; import com.google.cloud.spring.core.GcpProjectIdProvider; import com.google.cloud.spring.pubsub.core.PubSubTemplate; @@ -55,7 +56,7 @@ class PubSubHealthIndicatorAutoConfigurationTests { AutoConfigurations.of( PubSubHealthIndicatorAutoConfiguration.class, GcpPubSubAutoConfiguration.class)) .withBean(GcpProjectIdProvider.class, () -> () -> "fake project") - .withBean(CredentialsProvider.class, () -> () -> mock(Credentials.class)); + .withBean(CredentialsProvider.class, () -> () -> TestUtils.MOCK_CREDENTIALS); @SuppressWarnings("unchecked") @Test diff --git a/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/pubsub/health/PubSubSubscriptionHealthIndicatorAutoConfigurationTests.java b/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/pubsub/health/PubSubSubscriptionHealthIndicatorAutoConfigurationTests.java index e92cf0edf7..4b3ad4b410 100644 --- a/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/pubsub/health/PubSubSubscriptionHealthIndicatorAutoConfigurationTests.java +++ b/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/pubsub/health/PubSubSubscriptionHealthIndicatorAutoConfigurationTests.java @@ -22,6 +22,7 @@ import com.google.api.gax.core.CredentialsProvider; import com.google.auth.Credentials; import com.google.cloud.monitoring.v3.MetricServiceClient; +import com.google.cloud.spring.autoconfigure.TestUtils; import com.google.cloud.spring.autoconfigure.pubsub.GcpPubSubAutoConfiguration; import com.google.cloud.spring.core.GcpProjectIdProvider; import org.junit.jupiter.api.Test; @@ -40,7 +41,7 @@ class PubSubSubscriptionHealthIndicatorAutoConfigurationTests { PubSubSubscriptionHealthIndicatorAutoConfiguration.class, GcpPubSubAutoConfiguration.class)) .withBean(GcpProjectIdProvider.class, () -> () -> "fake project") - .withBean(CredentialsProvider.class, () -> () -> mock(Credentials.class)) + .withBean(CredentialsProvider.class, () -> () -> TestUtils.MOCK_CREDENTIALS) .withBean(MetricServiceClient.class, () -> mock(MetricServiceClient.class)); @Test diff --git a/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/secretmanager/GcpSecretManagerAutoConfigurationUnitTests.java b/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/secretmanager/GcpSecretManagerAutoConfigurationUnitTests.java index 646b0ece1f..f90ab28286 100644 --- a/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/secretmanager/GcpSecretManagerAutoConfigurationUnitTests.java +++ b/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/secretmanager/GcpSecretManagerAutoConfigurationUnitTests.java @@ -22,6 +22,7 @@ import com.google.api.gax.core.CredentialsProvider; import com.google.auth.Credentials; import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.cloud.spring.autoconfigure.TestUtils; import com.google.cloud.spring.autoconfigure.core.GcpContextAutoConfiguration; import com.google.cloud.spring.secretmanager.SecretManagerTemplate; import org.junit.jupiter.api.BeforeEach; @@ -77,7 +78,7 @@ static class TestConfig { @Bean public CredentialsProvider googleCredentials() { - return () -> mock(Credentials.class); + return () -> TestUtils.MOCK_CREDENTIALS; } } } diff --git a/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/security/FirebaseAuthenticationAutoConfigurationTests.java b/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/security/FirebaseAuthenticationAutoConfigurationTests.java index 8a46e12ed5..72594e1972 100644 --- a/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/security/FirebaseAuthenticationAutoConfigurationTests.java +++ b/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/security/FirebaseAuthenticationAutoConfigurationTests.java @@ -22,6 +22,7 @@ import com.google.api.gax.core.CredentialsProvider; import com.google.auth.Credentials; +import com.google.cloud.spring.autoconfigure.TestUtils; import com.google.cloud.spring.core.GcpProjectIdProvider; import com.google.cloud.spring.security.firebase.FirebaseJwtTokenDecoder; import org.junit.jupiter.api.Test; @@ -72,7 +73,7 @@ public GcpProjectIdProvider projectIdProvider() { @Bean public CredentialsProvider googleCredentials() { - return () -> mock(Credentials.class); + return () -> TestUtils.MOCK_CREDENTIALS; } } } diff --git a/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/spanner/GcpSpannerAutoConfigurationTests.java b/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/spanner/GcpSpannerAutoConfigurationTests.java index 925af9b691..0faeac5dbd 100644 --- a/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/spanner/GcpSpannerAutoConfigurationTests.java +++ b/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/spanner/GcpSpannerAutoConfigurationTests.java @@ -21,9 +21,11 @@ import com.google.api.gax.core.CredentialsProvider; import com.google.api.gax.retrying.RetrySettings; +import com.google.auth.CredentialTypeForMetrics; import com.google.auth.Credentials; import com.google.cloud.NoCredentials; import com.google.cloud.spanner.SpannerOptions; +import com.google.cloud.spring.autoconfigure.TestUtils; import com.google.cloud.spring.autoconfigure.core.GcpContextAutoConfiguration; import com.google.cloud.spring.data.spanner.core.SpannerOperations; import com.google.cloud.spring.data.spanner.core.SpannerTransactionManager; @@ -174,7 +176,7 @@ static class TestConfiguration { /** Mock bean for credentials provider. */ @Bean public CredentialsProvider credentialsProvider() { - return () -> mock(Credentials.class); + return () -> TestUtils.MOCK_CREDENTIALS; } /** Mock bean for Gson. */ diff --git a/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/spanner/health/SpannerHealthIndicatorAutoConfigurationTests.java b/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/spanner/health/SpannerHealthIndicatorAutoConfigurationTests.java index 5ae4e41fad..7053c959c8 100644 --- a/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/spanner/health/SpannerHealthIndicatorAutoConfigurationTests.java +++ b/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/spanner/health/SpannerHealthIndicatorAutoConfigurationTests.java @@ -23,6 +23,7 @@ import com.google.api.gax.core.CredentialsProvider; import com.google.auth.Credentials; import com.google.cloud.spanner.Statement; +import com.google.cloud.spring.autoconfigure.TestUtils; import com.google.cloud.spring.autoconfigure.core.GcpContextAutoConfiguration; import com.google.cloud.spring.autoconfigure.spanner.GcpSpannerAutoConfiguration; import com.google.gson.Gson; @@ -94,7 +95,7 @@ static class TestConfiguration { @Bean public CredentialsProvider credentialsProvider() { - return () -> mock(Credentials.class); + return () -> TestUtils.MOCK_CREDENTIALS; } @Bean diff --git a/spring-cloud-gcp-dependencies/pom.xml b/spring-cloud-gcp-dependencies/pom.xml index 48f9531592..c1fcfc9d29 100644 --- a/spring-cloud-gcp-dependencies/pom.xml +++ b/spring-cloud-gcp-dependencies/pom.xml @@ -34,8 +34,8 @@ - 26.48.0 - 1.21.0 + 26.49.0 + 1.20.1 1.0.7.RELEASE 1.3.0 diff --git a/spring-cloud-gcp-pubsub-stream-binder/src/test/java/com/google/cloud/spring/stream/binder/pubsub/PubSubMessageChannelBinderTests.java b/spring-cloud-gcp-pubsub-stream-binder/src/test/java/com/google/cloud/spring/stream/binder/pubsub/PubSubMessageChannelBinderTests.java index 16ce391154..f0f8a882d4 100644 --- a/spring-cloud-gcp-pubsub-stream-binder/src/test/java/com/google/cloud/spring/stream/binder/pubsub/PubSubMessageChannelBinderTests.java +++ b/spring-cloud-gcp-pubsub-stream-binder/src/test/java/com/google/cloud/spring/stream/binder/pubsub/PubSubMessageChannelBinderTests.java @@ -22,6 +22,7 @@ import static org.mockito.Mockito.when; import com.google.api.gax.core.CredentialsProvider; +import com.google.auth.CredentialTypeForMetrics; import com.google.auth.Credentials; import com.google.cloud.spring.core.GcpProjectIdProvider; import com.google.cloud.spring.pubsub.PubSubAdmin; @@ -394,7 +395,7 @@ public GcpProjectIdProvider projectIdProvider() { @Bean public CredentialsProvider googleCredentials() { - return () -> mock(Credentials.class); + return () -> TestUtils.MOCK_CREDENTIALS; } } } diff --git a/spring-cloud-gcp-pubsub-stream-binder/src/test/java/com/google/cloud/spring/stream/binder/pubsub/TestUtils.java b/spring-cloud-gcp-pubsub-stream-binder/src/test/java/com/google/cloud/spring/stream/binder/pubsub/TestUtils.java new file mode 100644 index 0000000000..aa38cd83ad --- /dev/null +++ b/spring-cloud-gcp-pubsub-stream-binder/src/test/java/com/google/cloud/spring/stream/binder/pubsub/TestUtils.java @@ -0,0 +1,35 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.spring.stream.binder.pubsub; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import com.google.auth.CredentialTypeForMetrics; +import com.google.auth.Credentials; + +public class TestUtils { + public static final Credentials MOCK_CREDENTIALS = createMockCredentials(); + + private static Credentials createMockCredentials() { + Credentials mockCredential = mock(Credentials.class); + when(mockCredential.getMetricsCredentialType()) + .thenReturn(CredentialTypeForMetrics.DO_NOT_SEND); + return mockCredential; + } +} + diff --git a/spring-cloud-gcp-pubsub-stream-binder/src/test/java/com/google/cloud/spring/stream/binder/pubsub/config/PubSubBinderConfigurationTests.java b/spring-cloud-gcp-pubsub-stream-binder/src/test/java/com/google/cloud/spring/stream/binder/pubsub/config/PubSubBinderConfigurationTests.java index ea41b2a5c5..9729a14ff8 100644 --- a/spring-cloud-gcp-pubsub-stream-binder/src/test/java/com/google/cloud/spring/stream/binder/pubsub/config/PubSubBinderConfigurationTests.java +++ b/spring-cloud-gcp-pubsub-stream-binder/src/test/java/com/google/cloud/spring/stream/binder/pubsub/config/PubSubBinderConfigurationTests.java @@ -18,8 +18,10 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import com.google.api.gax.core.CredentialsProvider; +import com.google.auth.CredentialTypeForMetrics; import com.google.auth.Credentials; import com.google.cloud.spring.autoconfigure.core.GcpContextAutoConfiguration; import com.google.cloud.spring.autoconfigure.pubsub.GcpPubSubAutoConfiguration; @@ -28,6 +30,7 @@ import com.google.cloud.spring.pubsub.core.PubSubTemplate; import com.google.cloud.spring.pubsub.core.health.HealthTrackerRegistry; import com.google.cloud.spring.stream.binder.pubsub.PubSubMessageChannelBinder; +import com.google.cloud.spring.stream.binder.pubsub.TestUtils; import com.google.cloud.spring.stream.binder.pubsub.provisioning.PubSubChannelProvisioner; import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.AutoConfigurations; @@ -165,7 +168,7 @@ void test_healthRegistryEnabled() { private static class TestConfiguration { @Bean public CredentialsProvider googleCredentials() { - return () -> mock(Credentials.class); + return () -> TestUtils.MOCK_CREDENTIALS; } @Bean