Skip to content

Commit f3e8e6c

Browse files
Praful Makanisduskis
authored andcommitted
---
yaml --- r: 26471 b: refs/heads/autosynth-securitycenter c: 554c109 h: refs/heads/master i: 26469: 03d1e27 26467: b53786d 26463: ef63cad
1 parent fd92b4d commit f3e8e6c

5 files changed

Lines changed: 77 additions & 2 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ refs/tags/v0.79.0: 82287b570708748c411d05c40f3932cff9606feb
169169
refs/tags/v0.80.0: f745e744d38e4fe636f34d0e04795ba3d014287d
170170
refs/tags/v0.81.0: ed3a0c85339ea6b73560b9a570abfbb76b93a263
171171
refs/heads/autosynth-dataproc: 812eb0e76f4543bffe59701872476c4b5b7415f5
172-
refs/heads/autosynth-securitycenter: 95a9cdf4f95ddfb2e157135e14b0c5dc406a02b2
172+
refs/heads/autosynth-securitycenter: 554c109518b4d70e6264a1cd2b1a13be65e230f9
173173
refs/heads/autosynth-talent: 383a363aeb0af16c9997201d1f963360641f68a8
174174
refs/heads/cscc-samples: 620d105e6b574cfeeee04e413a157b7bd34ebc8b
175175
refs/heads/igorbernstein2-patch-1: f62464ee14df1e44a3b173cdc3976563d1b3078b

branches/autosynth-securitycenter/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/CustomClassMapper.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.google.cloud.firestore.annotation.PropertyName;
2323
import com.google.cloud.firestore.annotation.ServerTimestamp;
2424
import com.google.cloud.firestore.annotation.ThrowOnExtraProperties;
25+
import com.google.firestore.v1.Value;
2526
import java.lang.reflect.AccessibleObject;
2627
import java.lang.reflect.Constructor;
2728
import java.lang.reflect.Field;
@@ -166,7 +167,8 @@ private static <T> Object serialize(T o, ErrorPath path) {
166167
|| o instanceof GeoPoint
167168
|| o instanceof Blob
168169
|| o instanceof DocumentReference
169-
|| o instanceof FieldValue) {
170+
|| o instanceof FieldValue
171+
|| o instanceof Value) {
170172
return o;
171173
} else {
172174
Class<T> clazz = (Class<T>) o.getClass();

branches/autosynth-securitycenter/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/UserDataConverter.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ static Value encodeValue(
148148
} else if (sanitizedObject instanceof Blob) {
149149
Blob blob = (Blob) sanitizedObject;
150150
return Value.newBuilder().setBytesValue(blob.toByteString()).build();
151+
} else if (sanitizedObject instanceof Value) {
152+
return (Value) sanitizedObject;
151153
} else if (sanitizedObject instanceof DocumentReference) {
152154
DocumentReference docRef = (DocumentReference) sanitizedObject;
153155
return Value.newBuilder().setReferenceValue(docRef.getName()).build();

branches/autosynth-securitycenter/google-cloud-clients/google-cloud-firestore/src/test/java/com/google/cloud/firestore/WriteBatchTest.java

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,36 @@ public void setDocument() throws Exception {
139139
assertEquals(commit(writes.toArray(new Write[] {})), commitRequest);
140140
}
141141

142+
@Test
143+
public void setDocumentWithValue() throws Exception {
144+
doReturn(commitResponse(4, 0))
145+
.when(firestoreMock)
146+
.sendRequest(
147+
commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
148+
149+
batch
150+
.set(documentReference, LocalFirestoreHelper.SINGLE_FIELD_PROTO)
151+
.set(documentReference, LocalFirestoreHelper.SINGLE_FIELD_OBJECT)
152+
.set(documentReference, LocalFirestoreHelper.SINGLE_FIELD_PROTO, SetOptions.merge())
153+
.set(documentReference, LocalFirestoreHelper.SINGLE_FIELD_OBJECT, SetOptions.merge());
154+
155+
List<Write> writes = new ArrayList<>();
156+
writes.add(set(LocalFirestoreHelper.SINGLE_FIELD_PROTO));
157+
writes.add(set(LocalFirestoreHelper.SINGLE_FIELD_PROTO));
158+
writes.add(set(LocalFirestoreHelper.SINGLE_FIELD_PROTO, Arrays.asList("foo")));
159+
writes.add(set(LocalFirestoreHelper.SINGLE_FIELD_PROTO, Arrays.asList("foo")));
160+
161+
assertEquals(4, batch.getMutationsSize());
162+
163+
List<WriteResult> writeResults = batch.commit().get();
164+
for (int i = 0; i < writeResults.size(); ++i) {
165+
assertEquals(Timestamp.ofTimeSecondsAndNanos(i, i), writeResults.get(i).getUpdateTime());
166+
}
167+
168+
CommitRequest commitRequest = commitCapture.getValue();
169+
assertEquals(commit(writes.toArray(new Write[] {})), commitRequest);
170+
}
171+
142172
@Test
143173
public void omitWriteResultForDocumentTransforms() throws Exception {
144174
doReturn(commitResponse(2, 0))
@@ -179,6 +209,31 @@ public void createDocument() throws Exception {
179209
assertEquals(commit(writes.toArray(new Write[] {})), commitRequest);
180210
}
181211

212+
@Test
213+
public void createDocumentWithValue() throws Exception {
214+
doReturn(commitResponse(2, 0))
215+
.when(firestoreMock)
216+
.sendRequest(
217+
commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
218+
219+
batch
220+
.create(documentReference, LocalFirestoreHelper.SINGLE_FIELD_PROTO)
221+
.create(documentReference, LocalFirestoreHelper.SINGLE_FIELD_OBJECT);
222+
223+
assertEquals(2, batch.getMutationsSize());
224+
225+
List<WriteResult> writeResults = batch.commit().get();
226+
List<Write> writes = new ArrayList<>();
227+
228+
for (int i = 0; i < writeResults.size(); ++i) {
229+
assertEquals(Timestamp.ofTimeSecondsAndNanos(i, i), writeResults.get(i).getUpdateTime());
230+
writes.add(create(LocalFirestoreHelper.SINGLE_FIELD_PROTO));
231+
}
232+
233+
CommitRequest commitRequest = commitCapture.getValue();
234+
assertEquals(commit(writes.toArray(new Write[] {})), commitRequest);
235+
}
236+
182237
@Test
183238
public void deleteDocument() throws Exception {
184239
doReturn(commitResponse(2, 0))

branches/autosynth-securitycenter/google-cloud-clients/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITSystemTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,14 @@ public void createDocument() throws Exception {
149149
assertEquals(SINGLE_FIELD_OBJECT, documentSnapshot.toObject(SingleField.class));
150150
}
151151

152+
@Test
153+
public void createDocumentWithValue() throws Exception {
154+
assertEquals(20, randomDoc.getId().length());
155+
randomDoc.create(LocalFirestoreHelper.SINGLE_FIELD_PROTO).get();
156+
DocumentSnapshot documentSnapshot = randomDoc.get().get();
157+
assertEquals(SINGLE_FIELD_OBJECT, documentSnapshot.toObject(SingleField.class));
158+
}
159+
152160
@Test
153161
public void setDocument() throws Exception {
154162
Map<String, Object> nanNullMap = new HashMap<>();
@@ -160,6 +168,14 @@ public void setDocument() throws Exception {
160168
assertEquals(null, documentSnapshot.get("null"));
161169
}
162170

171+
@Test
172+
public void setDocumentWithValue() throws Exception {
173+
assertEquals(20, randomDoc.getId().length());
174+
randomDoc.set(LocalFirestoreHelper.SINGLE_FIELD_PROTO).get();
175+
DocumentSnapshot documentSnapshot = randomDoc.get().get();
176+
assertEquals(SINGLE_FIELD_OBJECT, documentSnapshot.toObject(SingleField.class));
177+
}
178+
163179
@Test
164180
public void setDocumentWithMerge() throws Exception {
165181
Map<String, Object> originalMap =

0 commit comments

Comments
 (0)