use of com.google.firestore.v1beta1.CommitRequest in project java-firestore by googleapis.
the class DocumentReferenceTest method setMultipleFieldsWithMerge.
@Test
public void setMultipleFieldsWithMerge() 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", "second.foo", "second.trueValue")).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().putFields("trueValue", Value.newBuilder().setBooleanValue(true).build());
nestedUpdate.put("second", nestedProto.build());
CommitRequest expectedCommit = commit(set(nestedUpdate, Arrays.asList("first.foo", "second.foo", "second.trueValue")));
assertCommitEquals(expectedCommit, commitCapture.getValue());
}
use of com.google.firestore.v1beta1.CommitRequest in project java-firestore by googleapis.
the class DocumentReferenceTest method mergeWithDotsInFieldName.
@Test
public void mergeWithDotsInFieldName() throws Exception {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE).when(firestoreMock).sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
documentReference.set(map("a.b.c", map("d.e", "foo", "f.g", "bar")), SetOptions.mergeFieldPaths(Arrays.asList(FieldPath.of("a.b.c", "d.e")))).get();
Map<String, Value> nestedUpdate = new HashMap<>();
Value.Builder nestedProto = Value.newBuilder();
nestedProto.getMapValueBuilder().putFields("d.e", Value.newBuilder().setStringValue("foo").build());
nestedUpdate.put("a.b.c", nestedProto.build());
CommitRequest expectedCommit = commit(set(nestedUpdate, Arrays.asList("`a.b.c`.`d.e`")));
assertCommitEquals(expectedCommit, commitCapture.getValue());
}
use of com.google.firestore.v1beta1.CommitRequest in project java-firestore by googleapis.
the class DocumentReferenceTest method serializeBasicTypes.
@Test
public void serializeBasicTypes() throws Exception {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE).when(firestoreMock).sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
documentReference.set(ALL_SUPPORTED_TYPES_MAP).get();
documentReference.set(ALL_SUPPORTED_TYPES_OBJECT).get();
CommitRequest expectedCommit = commit(set(ALL_SUPPORTED_TYPES_PROTO));
assertCommitEquals(expectedCommit, commitCapture.getAllValues().get(0));
assertCommitEquals(expectedCommit, commitCapture.getAllValues().get(1));
}
use of com.google.firestore.v1beta1.CommitRequest in project java-firestore by googleapis.
the class DocumentReferenceTest method setDocumentWithMerge.
@Test
public void setDocumentWithMerge() throws Exception {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE).when(firestoreMock).sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
documentReference.set(SINGLE_FIELD_MAP, SetOptions.merge()).get();
documentReference.set(SINGLE_FIELD_OBJECT, SetOptions.merge()).get();
documentReference.set(ALL_SUPPORTED_TYPES_OBJECT, SetOptions.mergeFields("foo")).get();
documentReference.set(ALL_SUPPORTED_TYPES_OBJECT, SetOptions.mergeFields(Arrays.asList("foo"))).get();
documentReference.set(ALL_SUPPORTED_TYPES_OBJECT, SetOptions.mergeFieldPaths(Arrays.asList(FieldPath.of("foo")))).get();
CommitRequest expectedCommit = commit(set(SINGLE_FIELD_PROTO, Arrays.asList("foo")));
for (int i = 0; i < 5; ++i) {
assertCommitEquals(expectedCommit, commitCapture.getAllValues().get(i));
}
}
use of com.google.firestore.v1beta1.CommitRequest in project java-firestore by googleapis.
the class DocumentReferenceTest method updateIndividualPojo.
@Test
public void updateIndividualPojo() throws ExecutionException, InterruptedException {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE).when(firestoreMock).sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
documentReference.update(UPDATED_POJO);
documentReference.update(UPDATED_POJO).get();
CommitRequest expectedCommit = commit(update(UPDATED_POJO_PROTO, Collections.singletonList("model")));
for (CommitRequest request : commitCapture.getAllValues()) {
assertCommitEquals(expectedCommit, request);
}
}
Aggregations