Search in sources :

Example 6 with BatchGetDocumentsRequest

use of com.google.firestore.v1beta1.BatchGetDocumentsRequest in project java-firestore by googleapis.

the class FirestoreClientTest method batchGetDocumentsExceptionTest.

@Test
public void batchGetDocumentsExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockFirestore.addException(exception);
    BatchGetDocumentsRequest request = BatchGetDocumentsRequest.newBuilder().setDatabase("database1789464955").addAllDocuments(new ArrayList<String>()).setMask(DocumentMask.newBuilder().build()).build();
    MockStreamObserver<BatchGetDocumentsResponse> responseObserver = new MockStreamObserver<>();
    ServerStreamingCallable<BatchGetDocumentsRequest, BatchGetDocumentsResponse> callable = client.batchGetDocumentsCallable();
    callable.serverStreamingCall(request, responseObserver);
    try {
        List<BatchGetDocumentsResponse> actualResponses = responseObserver.future().get();
        Assert.fail("No exception thrown");
    } catch (ExecutionException e) {
        Assert.assertTrue(e.getCause() instanceof InvalidArgumentException);
        InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause());
        Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode());
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) BatchGetDocumentsResponse(com.google.firestore.v1.BatchGetDocumentsResponse) ByteString(com.google.protobuf.ByteString) MockStreamObserver(com.google.api.gax.grpc.testing.MockStreamObserver) ExecutionException(java.util.concurrent.ExecutionException) BatchGetDocumentsRequest(com.google.firestore.v1.BatchGetDocumentsRequest) Test(org.junit.Test)

Example 7 with BatchGetDocumentsRequest

use of com.google.firestore.v1beta1.BatchGetDocumentsRequest in project java-firestore by googleapis.

the class FirestoreTest method getAllWithFieldMask.

@Test
public void getAllWithFieldMask() throws Exception {
    doAnswer(getAllResponse(SINGLE_FIELD_PROTO)).when(firestoreMock).streamRequest(getAllCapture.capture(), streamObserverCapture.capture(), Matchers.<ServerStreamingCallable>any());
    DocumentReference doc1 = firestoreMock.document("coll/doc1");
    FieldMask fieldMask = FieldMask.of(FieldPath.of("foo", "bar"));
    firestoreMock.getAll(new DocumentReference[] { doc1 }, fieldMask).get();
    BatchGetDocumentsRequest request = getAllCapture.getValue();
    assertEquals(1, request.getMask().getFieldPathsCount());
    assertEquals("foo.bar", request.getMask().getFieldPaths(0));
}
Also used : BatchGetDocumentsRequest(com.google.firestore.v1.BatchGetDocumentsRequest) Test(org.junit.Test)

Example 8 with BatchGetDocumentsRequest

use of com.google.firestore.v1beta1.BatchGetDocumentsRequest in project java-firestore by googleapis.

the class LocalFirestoreHelper method getAll.

public static BatchGetDocumentsRequest getAll(@Nullable String transactionId, String... documentNames) {
    BatchGetDocumentsRequest.Builder request = BatchGetDocumentsRequest.newBuilder();
    request.setDatabase(DATABASE_NAME);
    for (String documentName : documentNames) {
        request.addDocuments(documentName);
    }
    if (transactionId != null) {
        request.setTransaction(ByteString.copyFromUtf8(transactionId));
    }
    return request.build();
}
Also used : ByteString(com.google.protobuf.ByteString) BatchGetDocumentsRequest(com.google.firestore.v1.BatchGetDocumentsRequest)

Aggregations

BatchGetDocumentsRequest (com.google.firestore.v1.BatchGetDocumentsRequest)7 Test (org.junit.Test)5 BatchGetDocumentsResponse (com.google.firestore.v1.BatchGetDocumentsResponse)4 ByteString (com.google.protobuf.ByteString)3 MockStreamObserver (com.google.api.gax.grpc.testing.MockStreamObserver)2 ArrayList (java.util.ArrayList)2 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)1 BatchGetDocumentsRequest (com.google.firestore.v1beta1.BatchGetDocumentsRequest)1 BatchGetDocumentsResponse (com.google.firestore.v1beta1.BatchGetDocumentsResponse)1 Document (com.google.firestore.v1beta1.Document)1 FirestoreGrpc (com.google.firestore.v1beta1.FirestoreGrpc)1 Message (com.google.protobuf.Message)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1 StreamObserver (io.grpc.stub.StreamObserver)1 List (java.util.List)1 Scanner (java.util.Scanner)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutionException (java.util.concurrent.ExecutionException)1 BatchGetDocumentsFn (org.apache.beam.sdk.io.gcp.firestore.FirestoreV1ReadFn.BatchGetDocumentsFn)1 GRPCFirebaseClientFactory (org.roguewave.grpc.util.GRPCFirebaseClientFactory)1