use of com.google.firestore.v1beta1.CommitRequest in project java-firestore by googleapis.
the class DocumentReferenceTest method setWithArrayRemove.
@Test
public void setWithArrayRemove() throws Exception {
doReturn(FIELD_TRANSFORM_COMMIT_RESPONSE).when(firestoreMock).sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
documentReference.set(map("foo", FieldValue.arrayRemove("bar", map("foo", "baz")))).get();
CommitRequest set = commit(set(Collections.emptyMap()), transform("foo", arrayRemove(string("bar"), object("foo", string("baz")))));
CommitRequest commitRequest = commitCapture.getValue();
assertCommitEquals(set, commitRequest);
}
use of com.google.firestore.v1beta1.CommitRequest in project java-firestore by googleapis.
the class DocumentReferenceTest method updateNestedMap.
@Test
public void updateNestedMap() throws Exception {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE).when(firestoreMock).sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
documentReference.update("a.b", "foo", "a.c", FieldValue.delete()).get();
Map<String, Value> nestedUpdate = new HashMap<>();
Value.Builder valueProto = Value.newBuilder();
valueProto.getMapValueBuilder().putFields("b", Value.newBuilder().setStringValue("foo").build());
nestedUpdate.put("a", valueProto.build());
CommitRequest expectedCommit = commit(update(nestedUpdate, Arrays.asList("a.b", "a.c")));
assertCommitEquals(expectedCommit, commitCapture.getValue());
}
use of com.google.firestore.v1beta1.CommitRequest in project java-firestore by googleapis.
the class DocumentReferenceTest method deleteField.
@Test
public void deleteField() throws Exception {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE).when(firestoreMock).sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
documentReference.update("foo", "bar", "bar.foo", FieldValue.delete()).get();
Value.Builder emptyMap = Value.newBuilder();
emptyMap.getMapValueBuilder();
Map<String, Value> fieldMap = new HashMap<>();
fieldMap.put("foo", string("bar"));
CommitRequest expectedCommit = commit(update(fieldMap, Arrays.asList("foo", "bar.foo")));
assertCommitEquals(expectedCommit, commitCapture.getValue());
}
use of com.google.firestore.v1beta1.CommitRequest in project java-firestore by googleapis.
the class DocumentReferenceTest method updateWithDotsInFieldName.
@Test
public void updateWithDotsInFieldName() throws Exception {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE).when(firestoreMock).sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
documentReference.update(map("a.b.c", map("d.e", "foo"))).get();
Map<String, Value> nestedUpdate = new HashMap<>();
Value.Builder valueProto = Value.newBuilder();
valueProto.getMapValueBuilder().putFields("d.e", Value.newBuilder().setStringValue("foo").build());
Value.Builder cProto = Value.newBuilder();
cProto.getMapValueBuilder().putFields("c", valueProto.build());
Value.Builder bProto = Value.newBuilder();
bProto.getMapValueBuilder().putFields("b", cProto.build());
nestedUpdate.put("a", bProto.build());
CommitRequest expectedCommit = commit(update(nestedUpdate, Arrays.asList("a.b.c")));
assertCommitEquals(expectedCommit, commitCapture.getValue());
}
use of com.google.firestore.v1beta1.CommitRequest in project java-firestore by googleapis.
the class DocumentReferenceTest method setNestedMapWithMerge.
@Test
public void setNestedMapWithMerge() 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", "second")).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());
CommitRequest expectedCommit = commit(set(nestedUpdate, Arrays.asList("first", "second")));
assertCommitEquals(expectedCommit, commitCapture.getValue());
}
Aggregations