From 0e02c0a92f871521d6f7d504ecdcd10d6a2354b0 Mon Sep 17 00:00:00 2001 From: eranl <1707552+eranl@users.noreply.github.com> Date: Mon, 1 May 2023 22:00:34 +0300 Subject: [PATCH 1/6] feat: Add toString methods to classes comprising WriteBatch --- .../com/google/cloud/firestore/DocumentSnapshot.java | 6 ++++++ .../java/com/google/cloud/firestore/UpdateBuilder.java | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/DocumentSnapshot.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/DocumentSnapshot.java index 771389973..fc04b45ca 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/DocumentSnapshot.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/DocumentSnapshot.java @@ -448,4 +448,10 @@ public boolean equals(Object obj) { public int hashCode() { return Objects.hash(rpcContext, docRef, fields); } + + @Override + public String toString() { + return String.format("DocumentSnapshot{docRef=%s, fields=%s, readTime=%s, updateTime=%s, createTime=%s}", docRef, + fields, readTime, updateTime, createTime); + } } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/UpdateBuilder.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/UpdateBuilder.java index ee21f0e06..3b395fdae 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/UpdateBuilder.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/UpdateBuilder.java @@ -53,6 +53,11 @@ static class WriteOperation { this.documentReference = documentReference; this.write = write; } + + @Override + public String toString() { + return String.format("WriteOperation{write=%s, documentReference=%s}", write, documentReference); + } } final FirestoreImpl firestore; @@ -646,4 +651,9 @@ List getWrites() { public int getMutationsSize() { return writes.size(); } + + @Override + public String toString() { + return String.format("UpdateBuilder{writes=%s, committed=%s}", writes, committed); + } } From e53f6e3f33d40c35c07e3585f1b9d4839033ae0c Mon Sep 17 00:00:00 2001 From: eranl <1707552+eranl@users.noreply.github.com> Date: Tue, 2 May 2023 03:46:25 +0300 Subject: [PATCH 2/6] feat: Add toString methods to classes comprising WriteBatch take2: use dynamic class names --- .../java/com/google/cloud/firestore/DocumentSnapshot.java | 4 ++-- .../main/java/com/google/cloud/firestore/UpdateBuilder.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/DocumentSnapshot.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/DocumentSnapshot.java index fc04b45ca..4d0d4bcd9 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/DocumentSnapshot.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/DocumentSnapshot.java @@ -451,7 +451,7 @@ public int hashCode() { @Override public String toString() { - return String.format("DocumentSnapshot{docRef=%s, fields=%s, readTime=%s, updateTime=%s, createTime=%s}", docRef, - fields, readTime, updateTime, createTime); + return String.format("%s{docRef=%s, fields=%s, readTime=%s, updateTime=%s, createTime=%s}", + getClass().getSimpleName(), docRef, fields, readTime, updateTime, createTime); } } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/UpdateBuilder.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/UpdateBuilder.java index 3b395fdae..0980a9b4b 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/UpdateBuilder.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/UpdateBuilder.java @@ -654,6 +654,6 @@ public int getMutationsSize() { @Override public String toString() { - return String.format("UpdateBuilder{writes=%s, committed=%s}", writes, committed); + return String.format("%s{writes=%s, committed=%s}", getClass().getSimpleName(), writes, committed); } } From 885046dbb13794842ef19876f7636474624aa3fa Mon Sep 17 00:00:00 2001 From: eranl <1707552+eranl@users.noreply.github.com> Date: Sat, 6 May 2023 03:53:58 +0300 Subject: [PATCH 3/6] feat: Add toString methods to classes comprising WriteBatch take3: - fix formatting - add unit tests --- .../cloud/firestore/DocumentSnapshot.java | 5 +- .../google/cloud/firestore/UpdateBuilder.java | 6 +- .../google/cloud/firestore/ToStringTest.java | 136 ++++++++++++++++++ 3 files changed, 143 insertions(+), 4 deletions(-) create mode 100644 google-cloud-firestore/src/test/java/com/google/cloud/firestore/ToStringTest.java diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/DocumentSnapshot.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/DocumentSnapshot.java index 4d0d4bcd9..e1bc5b445 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/DocumentSnapshot.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/DocumentSnapshot.java @@ -451,7 +451,8 @@ public int hashCode() { @Override public String toString() { - return String.format("%s{docRef=%s, fields=%s, readTime=%s, updateTime=%s, createTime=%s}", - getClass().getSimpleName(), docRef, fields, readTime, updateTime, createTime); + return String.format( + "%s{docRef=%s, fields=%s, readTime=%s, updateTime=%s, createTime=%s}", + getClass().getSimpleName(), docRef, fields, readTime, updateTime, createTime); } } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/UpdateBuilder.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/UpdateBuilder.java index 0980a9b4b..748c9fe9e 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/UpdateBuilder.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/UpdateBuilder.java @@ -56,7 +56,8 @@ static class WriteOperation { @Override public String toString() { - return String.format("WriteOperation{write=%s, documentReference=%s}", write, documentReference); + return String.format( + "WriteOperation{write=%s, documentReference=%s}", write, documentReference); } } @@ -654,6 +655,7 @@ public int getMutationsSize() { @Override public String toString() { - return String.format("%s{writes=%s, committed=%s}", getClass().getSimpleName(), writes, committed); + return String.format( + "%s{writes=%s, committed=%s}", getClass().getSimpleName(), writes, committed); } } diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/ToStringTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/ToStringTest.java new file mode 100644 index 000000000..0c1867718 --- /dev/null +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/ToStringTest.java @@ -0,0 +1,136 @@ +/* + * Copyright 2023 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 + * + * http://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.firestore; + +import com.google.cloud.Timestamp; +import com.google.cloud.firestore.spi.v1.FirestoreRpc; +import java.util.Collections; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.Spy; +import org.mockito.runners.MockitoJUnitRunner; + +/** @author Eran Leshem */ +@RunWith(MockitoJUnitRunner.class) +public class ToStringTest { + + @Spy + private final FirestoreImpl firestoreMock = + new FirestoreImpl( + FirestoreOptions.newBuilder().setProjectId("test-project").build(), + Mockito.mock(FirestoreRpc.class)); + + private WriteBatch batch; + private DocumentReference documentReference; + + @Before + public void before() { + batch = firestoreMock.batch(); + documentReference = firestoreMock.document("coll/doc"); + } + + @Test + public void testDocumentSnapshot() { + Assert.assertEquals( + "DocumentSnapshot{docRef=DocumentReference{path=projects/test-project/databases/(default)" + + "/documents/coll/doc}, fields={key=string_value: \"value\"\n" + + "}, readTime=null, updateTime=null, createTime=null}", + getDocumentSnapshot().toString()); + } + + @Test + public void testWriteOperation() { + Assert.assertEquals( + "WriteOperation{write=update {\n" + + " name: \"projects/test-project/databases/(default)/documents/coll/doc\"\n" + + " fields {\n" + + " key: \"key\"\n" + + " value {\n" + + " string_value: \"value\"\n" + + " }\n" + + " }\n" + + "}\n" + + ", documentReference=DocumentReference{path=projects/test-project/databases/(default)/documents/coll/doc}}", + new UpdateBuilder.WriteOperation(documentReference, getDocumentSnapshot().toPb()) + .toString()); + } + + private DocumentSnapshot getDocumentSnapshot() { + return DocumentSnapshot.fromObject( + null, + documentReference, + Collections.singletonMap("key", "value"), + UserDataConverter.NO_DELETES); + } + + @Test + public void testWriteBatchDelete() { + batch.delete(documentReference); + Assert.assertEquals( + "WriteBatch{writes=[WriteOperation{write=delete: \"projects/test-project/databases/(default)" + + "/documents/coll/doc\"\n, documentReference=DocumentReference{path=projects/test-project" + + "/databases/(default)/documents/coll/doc}}], committed=false}", + batch.toString()); + } + + @Test + public void testWriteBatchSet() { + batch.set(documentReference, Collections.singletonMap("key", "value"), SetOptions.OVERWRITE); + Assert.assertEquals( + "WriteBatch{writes=[WriteOperation{write=update {\n" + + " name: \"projects/test-project/databases/(default)/documents/coll/doc\"\n" + + " fields {\n" + + " key: \"key\"\n" + + " value {\n" + + " string_value: \"value\"\n" + + " }\n" + + " }\n" + + "}\n, documentReference=DocumentReference{path=projects/test-project" + + "/databases/(default)/documents/coll/doc}}], committed=false}", + batch.toString()); + } + + @Test + public void testWriteBatchUpdate() { + batch.update( + documentReference, + Collections.singletonMap("key", "value"), + Precondition.updatedAt(Timestamp.ofTimeMicroseconds(1))); + Assert.assertEquals( + "WriteBatch{writes=[WriteOperation{write=update {\n" + + " name: \"projects/test-project/databases/(default)/documents/coll/doc\"\n" + + " fields {\n" + + " key: \"key\"\n" + + " value {\n" + + " string_value: \"value\"\n" + + " }\n" + + " }\n" + + "}\nupdate_mask {\n" + + " field_paths: \"key\"\n" + + "}\n" + + "current_document {\n" + + " update_time {\n" + + " nanos: 1000\n" + + " }\n" + + "}\n, documentReference=DocumentReference{path=projects/test-project" + + "/databases/(default)/documents/coll/doc}}], committed=false}", + batch.toString()); + } +} From 4969cd6abf19c240adc7ea238731709588476842 Mon Sep 17 00:00:00 2001 From: eranl <1707552+eranl@users.noreply.github.com> Date: Fri, 2 Jun 2023 16:48:00 +0300 Subject: [PATCH 4/6] feat: Add toString methods to classes comprising WriteBatch take4: address review comments --- .../cloud/firestore/DocumentSnapshot.java | 2 +- .../google/cloud/firestore/UpdateBuilder.java | 3 +- .../google/cloud/firestore/ToStringTest.java | 128 +++++++----------- 3 files changed, 52 insertions(+), 81 deletions(-) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/DocumentSnapshot.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/DocumentSnapshot.java index e1bc5b445..a9a83e9cd 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/DocumentSnapshot.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/DocumentSnapshot.java @@ -452,7 +452,7 @@ public int hashCode() { @Override public String toString() { return String.format( - "%s{docRef=%s, fields=%s, readTime=%s, updateTime=%s, createTime=%s}", + "%s{doc=%s, fields=%s, readTime=%s, updateTime=%s, createTime=%s}", getClass().getSimpleName(), docRef, fields, readTime, updateTime, createTime); } } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/UpdateBuilder.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/UpdateBuilder.java index 748c9fe9e..d7f98808a 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/UpdateBuilder.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/UpdateBuilder.java @@ -56,8 +56,7 @@ static class WriteOperation { @Override public String toString() { - return String.format( - "WriteOperation{write=%s, documentReference=%s}", write, documentReference); + return String.format("WriteOperation{write=%s, doc=%s}", write, documentReference); } } diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/ToStringTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/ToStringTest.java index 0c1867718..eaa390f53 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/ToStringTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/ToStringTest.java @@ -16,10 +16,13 @@ package com.google.cloud.firestore; +import static com.google.common.truth.Truth.assertThat; + import com.google.cloud.Timestamp; import com.google.cloud.firestore.spi.v1.FirestoreRpc; +import com.google.firestore.v1.Value; import java.util.Collections; -import org.junit.Assert; +import java.util.Map; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -48,89 +51,58 @@ public void before() { @Test public void testDocumentSnapshot() { - Assert.assertEquals( - "DocumentSnapshot{docRef=DocumentReference{path=projects/test-project/databases/(default)" - + "/documents/coll/doc}, fields={key=string_value: \"value\"\n" - + "}, readTime=null, updateTime=null, createTime=null}", - getDocumentSnapshot().toString()); + Map fields = + Collections.singletonMap( + "key", + UserDataConverter.encodeValue( + FieldPath.of("key"), + CustomClassMapper.convertToPlainJavaTypes("value"), + UserDataConverter.NO_DELETES)); + String toStringResult = + new DocumentSnapshot( + null, + documentReference, + fields, + Timestamp.ofTimeMicroseconds(1), + Timestamp.ofTimeMicroseconds(2), + Timestamp.ofTimeMicroseconds(3)) + .toString(); + assertThat(toStringResult).startsWith("DocumentSnapshot{"); + assertThat(toStringResult).containsMatch("doc=DocumentReference\\{path=.*/documents/coll/doc}"); + assertThat(toStringResult).containsMatch("(?s)fields=\\{key=string_value:.*value.*}"); + assertThat(toStringResult).contains("readTime=1970-01-01T00:00:00.000001000Z"); + assertThat(toStringResult).contains("updateTime=1970-01-01T00:00:00.000002000Z"); + assertThat(toStringResult).contains("createTime=1970-01-01T00:00:00.000003000Z"); + assertThat(toStringResult).endsWith("}"); } @Test public void testWriteOperation() { - Assert.assertEquals( - "WriteOperation{write=update {\n" - + " name: \"projects/test-project/databases/(default)/documents/coll/doc\"\n" - + " fields {\n" - + " key: \"key\"\n" - + " value {\n" - + " string_value: \"value\"\n" - + " }\n" - + " }\n" - + "}\n" - + ", documentReference=DocumentReference{path=projects/test-project/databases/(default)/documents/coll/doc}}", - new UpdateBuilder.WriteOperation(documentReference, getDocumentSnapshot().toPb()) - .toString()); - } - - private DocumentSnapshot getDocumentSnapshot() { - return DocumentSnapshot.fromObject( - null, - documentReference, - Collections.singletonMap("key", "value"), - UserDataConverter.NO_DELETES); - } - - @Test - public void testWriteBatchDelete() { - batch.delete(documentReference); - Assert.assertEquals( - "WriteBatch{writes=[WriteOperation{write=delete: \"projects/test-project/databases/(default)" - + "/documents/coll/doc\"\n, documentReference=DocumentReference{path=projects/test-project" - + "/databases/(default)/documents/coll/doc}}], committed=false}", - batch.toString()); - } - - @Test - public void testWriteBatchSet() { - batch.set(documentReference, Collections.singletonMap("key", "value"), SetOptions.OVERWRITE); - Assert.assertEquals( - "WriteBatch{writes=[WriteOperation{write=update {\n" - + " name: \"projects/test-project/databases/(default)/documents/coll/doc\"\n" - + " fields {\n" - + " key: \"key\"\n" - + " value {\n" - + " string_value: \"value\"\n" - + " }\n" - + " }\n" - + "}\n, documentReference=DocumentReference{path=projects/test-project" - + "/databases/(default)/documents/coll/doc}}], committed=false}", - batch.toString()); + String toStringResult = + new UpdateBuilder.WriteOperation( + documentReference, + DocumentSnapshot.fromObject( + null, + documentReference, + Collections.singletonMap("key", "value"), + UserDataConverter.NO_DELETES) + .toPb()) + .toString(); + assertThat(toStringResult).startsWith("WriteOperation{"); + assertThat(toStringResult) + .containsMatch("(?s)write=update\\s*\\{\\s*name:.*/documents/coll/doc.*}"); + assertThat(toStringResult).containsMatch("doc=DocumentReference\\{path=.*/documents/coll/doc}"); + assertThat(toStringResult).endsWith("}"); } @Test - public void testWriteBatchUpdate() { - batch.update( - documentReference, - Collections.singletonMap("key", "value"), - Precondition.updatedAt(Timestamp.ofTimeMicroseconds(1))); - Assert.assertEquals( - "WriteBatch{writes=[WriteOperation{write=update {\n" - + " name: \"projects/test-project/databases/(default)/documents/coll/doc\"\n" - + " fields {\n" - + " key: \"key\"\n" - + " value {\n" - + " string_value: \"value\"\n" - + " }\n" - + " }\n" - + "}\nupdate_mask {\n" - + " field_paths: \"key\"\n" - + "}\n" - + "current_document {\n" - + " update_time {\n" - + " nanos: 1000\n" - + " }\n" - + "}\n, documentReference=DocumentReference{path=projects/test-project" - + "/databases/(default)/documents/coll/doc}}], committed=false}", - batch.toString()); + public void testWriteBatch() { + batch.update(documentReference, Collections.singletonMap("key", "value")); + String toStringResult = batch.toString(); + assertThat(toStringResult).startsWith("WriteBatch{"); + assertThat(toStringResult) + .containsMatch("(?s)writes=\\[WriteOperation\\{write=update.*/documents/coll/doc.*}]"); + assertThat(toStringResult).contains("committed=false"); + assertThat(toStringResult).endsWith("}"); } } From 760fdf731d2012a14f7a67f378c80ed7077f609f Mon Sep 17 00:00:00 2001 From: eranl <1707552+eranl@users.noreply.github.com> Date: Sat, 3 Jun 2023 01:49:16 +0300 Subject: [PATCH 5/6] feat: Add toString methods to classes comprising WriteBatch take5: address review comment --- .../java/com/google/cloud/firestore/ToStringTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/ToStringTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/ToStringTest.java index eaa390f53..db0843f83 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/ToStringTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/ToStringTest.java @@ -53,10 +53,10 @@ public void before() { public void testDocumentSnapshot() { Map fields = Collections.singletonMap( - "key", + "key123", UserDataConverter.encodeValue( - FieldPath.of("key"), - CustomClassMapper.convertToPlainJavaTypes("value"), + FieldPath.of("key456"), + CustomClassMapper.convertToPlainJavaTypes("value789"), UserDataConverter.NO_DELETES)); String toStringResult = new DocumentSnapshot( @@ -69,7 +69,7 @@ public void testDocumentSnapshot() { .toString(); assertThat(toStringResult).startsWith("DocumentSnapshot{"); assertThat(toStringResult).containsMatch("doc=DocumentReference\\{path=.*/documents/coll/doc}"); - assertThat(toStringResult).containsMatch("(?s)fields=\\{key=string_value:.*value.*}"); + assertThat(toStringResult).containsMatch("(?s)fields=\\{key123=string_value:.*value789.*}"); assertThat(toStringResult).contains("readTime=1970-01-01T00:00:00.000001000Z"); assertThat(toStringResult).contains("updateTime=1970-01-01T00:00:00.000002000Z"); assertThat(toStringResult).contains("createTime=1970-01-01T00:00:00.000003000Z"); From eb530a3a4c903d7024a188dd9488cc14a6cb741a Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Tue, 6 Jun 2023 12:34:03 +0000 Subject: [PATCH 6/6] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20po?= =?UTF-8?q?st-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 5272b7908..be9f58539 100644 --- a/README.md +++ b/README.md @@ -50,20 +50,20 @@ If you are using Maven without the BOM, add this to your dependencies: If you are using Gradle 5.x or later, add this to your dependencies: ```Groovy -implementation platform('com.google.cloud:libraries-bom:26.15.0') +implementation platform('com.google.cloud:libraries-bom:26.16.0') implementation 'com.google.cloud:google-cloud-firestore' ``` If you are using Gradle without BOM, add this to your dependencies: ```Groovy -implementation 'com.google.cloud:google-cloud-firestore:3.11.0' +implementation 'com.google.cloud:google-cloud-firestore:3.12.1' ``` If you are using SBT, add this to your dependencies: ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-firestore" % "3.11.0" +libraryDependencies += "com.google.cloud" % "google-cloud-firestore" % "3.12.1" ``` @@ -222,7 +222,7 @@ Java is a registered trademark of Oracle and/or its affiliates. [kokoro-badge-link-5]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-firestore/java11.html [stability-image]: https://img.shields.io/badge/stability-stable-green [maven-version-image]: https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-firestore.svg -[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-firestore/3.11.0 +[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-firestore/3.12.1 [authentication]: https://github.com/googleapis/google-cloud-java#authentication [auth-scopes]: https://developers.google.com/identity/protocols/oauth2/scopes [predefined-iam-roles]: https://cloud.google.com/iam/docs/understanding-roles#predefined_roles