use of com.google.firestore.v1beta1.CommitRequest in project java-firestore by googleapis.
the class DocumentReferenceTest method updateWithServerTimestamp.
@Test
public void updateWithServerTimestamp() throws Exception {
doReturn(FIELD_TRANSFORM_COMMIT_RESPONSE).when(firestoreMock).sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
documentReference.update(LocalFirestoreHelper.SERVER_TIMESTAMP_MAP).get();
CommitRequest update = commit(update(Collections.emptyMap(), Collections.singletonList("inner")), transform("foo", serverTimestamp(), "inner.bar", serverTimestamp()));
assertCommitEquals(update, commitCapture.getValue());
documentReference.update("foo", FieldValue.serverTimestamp(), "inner.bar", FieldValue.serverTimestamp());
update = commit(update(Collections.emptyMap(), new ArrayList<>(), UPDATE_PRECONDITION), transform("foo", serverTimestamp(), "inner.bar", serverTimestamp()));
assertCommitEquals(update, commitCapture.getValue());
}
use of com.google.firestore.v1beta1.CommitRequest in project java-firestore by googleapis.
the class DocumentReferenceTest method setDocumentWithNestedMerge.
@Test
public void setDocumentWithNestedMerge() throws Exception {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE).when(firestoreMock).sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
documentReference.set(NESTED_CLASS_OBJECT, SetOptions.mergeFields("first.foo")).get();
documentReference.set(NESTED_CLASS_OBJECT, SetOptions.mergeFields(Arrays.asList("first.foo"))).get();
documentReference.set(NESTED_CLASS_OBJECT, SetOptions.mergeFieldPaths(Arrays.asList(FieldPath.of("first", "foo")))).get();
Map<String, Value> nestedUpdate = new HashMap<>();
Value.Builder nestedProto = Value.newBuilder();
nestedProto.getMapValueBuilder().putAllFields(SINGLE_FIELD_PROTO);
nestedUpdate.put("first", nestedProto.build());
CommitRequest expectedCommit = commit(set(nestedUpdate, Arrays.asList("first.foo")));
for (int i = 0; i < 3; ++i) {
assertCommitEquals(expectedCommit, commitCapture.getAllValues().get(i));
}
}
use of com.google.firestore.v1beta1.CommitRequest in project java-firestore by googleapis.
the class DocumentReferenceTest method deleteNestedFieldUsingFieldPath.
@Test
public void deleteNestedFieldUsingFieldPath() throws Exception {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE).when(firestoreMock).sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
FieldPath path = FieldPath.of("a.b", "c.d");
documentReference.update(path, FieldValue.delete()).get();
CommitRequest expectedCommit = commit(update(Collections.emptyMap(), Collections.singletonList("`a.b`.`c.d`")));
assertEquals(expectedCommit, commitCapture.getValue());
}
use of com.google.firestore.v1beta1.CommitRequest in project java-firestore by googleapis.
the class DocumentReferenceTest method extractFieldMaskFromMerge.
@Test
public void extractFieldMaskFromMerge() throws Exception {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE).when(firestoreMock).sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
documentReference.set(NESTED_CLASS_OBJECT, SetOptions.merge()).get();
Map<String, Value> nestedUpdate = new HashMap<>();
Value.Builder nestedProto = Value.newBuilder();
nestedProto.getMapValueBuilder().putAllFields(SINGLE_FIELD_PROTO);
nestedUpdate.put("first", nestedProto.build());
nestedProto.getMapValueBuilder().putAllFields(ALL_SUPPORTED_TYPES_PROTO);
nestedUpdate.put("second", nestedProto.build());
List<String> updateMask = Arrays.asList("first.foo", "second.arrayValue", "second.bytesValue", "second.dateValue", "second.doubleValue", "second.falseValue", "second.foo", "second.geoPointValue", "second.infValue", "second.longValue", "second.nanValue", "second.negInfValue", "second.nullValue", "second.objectValue.foo", "second.timestampValue", "second.trueValue", "second.model.foo");
CommitRequest expectedCommit = commit(set(nestedUpdate, updateMask));
assertCommitEquals(expectedCommit, commitCapture.getValue());
}
use of com.google.firestore.v1beta1.CommitRequest in project java-firestore by googleapis.
the class WriteBatchTest method updateDocumentWithPOJO.
@Test
public void updateDocumentWithPOJO() throws Exception {
doReturn(commitResponse(1, 0)).when(firestoreMock).sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
batch.update(documentReference, "foo", UPDATE_SINGLE_FIELD_OBJECT);
assertEquals(1, batch.getMutationsSize());
List<WriteResult> writeResults = batch.commit().get();
assertEquals(1, writeResults.size());
CommitRequest actual = commitCapture.getValue();
CommitRequest expected = commit(update(UPDATED_SINGLE_FIELD_PROTO, Collections.singletonList("foo")));
assertEquals(expected, actual);
}
Aggregations