|
46 | 46 | import com.google.api.gax.rpc.UnaryCallable; |
47 | 47 | import com.google.cloud.Timestamp; |
48 | 48 | import com.google.cloud.firestore.spi.v1beta1.FirestoreRpc; |
| 49 | +import com.google.firestore.v1beta1.BatchGetDocumentsRequest; |
| 50 | +import com.google.firestore.v1beta1.DocumentMask; |
49 | 51 | import com.google.firestore.v1beta1.Write; |
50 | 52 | import com.google.protobuf.ByteString; |
51 | 53 | import com.google.protobuf.Message; |
@@ -386,6 +388,50 @@ public List<DocumentSnapshot> updateCallback(Transaction transaction) |
386 | 388 | assertEquals(commit(TRANSACTION_ID), requests.get(2)); |
387 | 389 | } |
388 | 390 |
|
| 391 | + @Test |
| 392 | + public void getMultipleDocumentsWithFieldMask() throws Exception { |
| 393 | + doReturn(beginResponse()) |
| 394 | + .doReturn(commitResponse(0, 0)) |
| 395 | + .when(firestoreMock) |
| 396 | + .sendRequest(requestCapture.capture(), Matchers.<UnaryCallable<Message, Message>>any()); |
| 397 | + |
| 398 | + doAnswer(getAllResponse(SINGLE_FIELD_PROTO)) |
| 399 | + .when(firestoreMock) |
| 400 | + .streamRequest( |
| 401 | + requestCapture.capture(), |
| 402 | + streamObserverCapture.capture(), |
| 403 | + Matchers.<ServerStreamingCallable>any()); |
| 404 | + |
| 405 | + final DocumentReference doc1 = firestoreMock.document("coll/doc1"); |
| 406 | + final FieldMask fieldMask = FieldMask.of(FieldPath.of("foo", "bar")); |
| 407 | + |
| 408 | + ApiFuture<List<DocumentSnapshot>> transaction = |
| 409 | + firestoreMock.runTransaction( |
| 410 | + new Transaction.Function<List<DocumentSnapshot>>() { |
| 411 | + @Override |
| 412 | + public List<DocumentSnapshot> updateCallback(Transaction transaction) |
| 413 | + throws ExecutionException, InterruptedException { |
| 414 | + return transaction.getAll(new DocumentReference[] {doc1}, fieldMask).get(); |
| 415 | + } |
| 416 | + }, |
| 417 | + options); |
| 418 | + transaction.get(); |
| 419 | + |
| 420 | + List<Message> requests = requestCapture.getAllValues(); |
| 421 | + assertEquals(3, requests.size()); |
| 422 | + |
| 423 | + assertEquals(begin(), requests.get(0)); |
| 424 | + BatchGetDocumentsRequest expectedGetAll = |
| 425 | + getAll(TRANSACTION_ID, doc1.getResourcePath().toString()); |
| 426 | + expectedGetAll = |
| 427 | + expectedGetAll |
| 428 | + .toBuilder() |
| 429 | + .setMask(DocumentMask.newBuilder().addFieldPaths("foo.bar")) |
| 430 | + .build(); |
| 431 | + assertEquals(expectedGetAll, requests.get(1)); |
| 432 | + assertEquals(commit(TRANSACTION_ID), requests.get(2)); |
| 433 | + } |
| 434 | + |
389 | 435 | @Test |
390 | 436 | public void getQuery() throws Exception { |
391 | 437 | doReturn(beginResponse()) |
|
0 commit comments