Skip to content

Commit

Permalink
deps: bump com.google.cloud:libraries-bom from 26.48.0 to 26.49.0 (#3306
Browse files Browse the repository at this point in the history
)

* deps: bump com.google.cloud:libraries-bom from 26.48.0 to 26.49.0

Bumps [com.google.cloud:libraries-bom](https://github.com/googleapis/java-cloud-bom) from 26.48.0 to 26.49.0.
- [Release notes](https://github.com/googleapis/java-cloud-bom/releases)
- [Changelog](https://github.com/googleapis/java-cloud-bom/blob/main/release-please-config.json)
- [Commits](googleapis/java-cloud-bom@v26.48.0...v26.49.0)

---
updated-dependencies:
- dependency-name: com.google.cloud:libraries-bom
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* fix(test): add mock method to mock credentials.

* review feedback: avoid dup in pubsub tests, abstract to util method.

* chore: rm unused method in utils classes.

BEGIN_COMMIT_OVERRIDE
deps: bump com.google.cloud:libraries-bom from 26.48.0 to 26.49.0

fix(test): add mock method to mock credentials.
END_COMMIT_OVERRIDE
---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Min Zhu <[email protected]>
  • Loading branch information
dependabot[bot] and zhumin8 authored Oct 23, 2024
1 parent 8d9657b commit d271404
Show file tree
Hide file tree
Showing 19 changed files with 106 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,8 +32,6 @@

class GcpBigQueryAutoConfigurationTests {

private static final GoogleCredentials MOCK_CREDENTIALS = mock(GoogleCredentials.class);

private ApplicationContextRunner contextRunner =
new ApplicationContextRunner()
.withConfiguration(
Expand All @@ -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");
Expand All @@ -66,7 +63,7 @@ static class TestConfiguration {

@Bean
public CredentialsProvider credentialsProvider() {
return () -> MOCK_CREDENTIALS;
return () -> TestUtils.MOCK_CREDENTIALS;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -99,7 +98,7 @@ private static class TestConfiguration {

@Bean
public CredentialsProvider googleCredentials() {
return () -> mock(Credentials.class);
return () -> TestUtils.MOCK_CREDENTIALS;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -61,7 +61,7 @@ static class TestConfiguration {

@Bean
public CredentialsProvider credentialsProvider() {
return () -> mock(Credentials.class);
return () -> TestUtils.MOCK_CREDENTIALS;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -118,7 +117,7 @@ static class TestConfiguration {

@Bean
public CredentialsProvider credentialsProvider() {
return () -> mock(Credentials.class);
return () -> TestUtils.MOCK_CREDENTIALS;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -136,7 +135,7 @@ static class TestConfiguration {

@Bean
public CredentialsProvider credentialsProvider() {
return () -> mock(GoogleCredentials.class);
return () -> TestUtils.MOCK_CREDENTIALS;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -103,7 +102,7 @@ private static class TestConfiguration {

@Bean
public CredentialsProvider googleCredentials() {
return () -> mock(Credentials.class);
return () -> TestUtils.MOCK_CREDENTIALS;
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1446,7 +1446,7 @@ public GcpProjectIdProvider projectIdProvider() {

@Bean
public CredentialsProvider googleCredentials() {
return () -> mock(Credentials.class);
return () -> TestUtils.MOCK_CREDENTIALS;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -187,7 +188,7 @@ void testPublisherBatchingSettings() {
private static class TestConfiguration {
@Bean
public CredentialsProvider googleCredentials() {
return () -> mock(Credentials.class);
return () -> TestUtils.MOCK_CREDENTIALS;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -165,7 +166,7 @@ public GcpProjectIdProvider projectIdProvider() {

@Bean
public CredentialsProvider googleCredentials() {
return () -> mock(Credentials.class);
return () -> TestUtils.MOCK_CREDENTIALS;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.google.api.gax.grpc.GrpcStatusCode;
import com.google.api.gax.rpc.ApiException;
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;
Expand Down Expand Up @@ -63,7 +64,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -72,7 +73,7 @@ public GcpProjectIdProvider projectIdProvider() {

@Bean
public CredentialsProvider googleCredentials() {
return () -> mock(Credentials.class);
return () -> TestUtils.MOCK_CREDENTIALS;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -94,7 +95,7 @@ static class TestConfiguration {

@Bean
public CredentialsProvider credentialsProvider() {
return () -> mock(Credentials.class);
return () -> TestUtils.MOCK_CREDENTIALS;
}

@Bean
Expand Down
2 changes: 1 addition & 1 deletion spring-cloud-gcp-dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</distributionManagement>

<properties>
<gcp-libraries-bom.version>26.48.0</gcp-libraries-bom.version>
<gcp-libraries-bom.version>26.49.0</gcp-libraries-bom.version>
<cloud-sql-socket-factory.version>1.20.1</cloud-sql-socket-factory.version>
<r2dbc-mysql-driver.version>0.9.7</r2dbc-mysql-driver.version>
<r2dbc-postgres-driver.version>0.8.13.RELEASE</r2dbc-postgres-driver.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,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;
Expand Down Expand Up @@ -389,7 +390,7 @@ public GcpProjectIdProvider projectIdProvider() {

@Bean
public CredentialsProvider googleCredentials() {
return () -> mock(Credentials.class);
return () -> TestUtils.MOCK_CREDENTIALS;
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}

Loading

0 comments on commit d271404

Please sign in to comment.