Search in sources :

Example 6 with ListenResponse

use of com.google.firestore.v1.ListenResponse in project java-firestore by googleapis.

the class FirestoreClientTest method listenExceptionTest.

@Test
public void listenExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockFirestore.addException(exception);
    ListenRequest request = ListenRequest.newBuilder().setDatabase("database1789464955").putAllLabels(new HashMap<String, String>()).build();
    MockStreamObserver<ListenResponse> responseObserver = new MockStreamObserver<>();
    BidiStreamingCallable<ListenRequest, ListenResponse> callable = client.listenCallable();
    ApiStreamObserver<ListenRequest> requestObserver = callable.bidiStreamingCall(responseObserver);
    requestObserver.onNext(request);
    try {
        List<ListenResponse> 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) HashMap(java.util.HashMap) ListenRequest(com.google.firestore.v1.ListenRequest) StatusRuntimeException(io.grpc.StatusRuntimeException) MockStreamObserver(com.google.api.gax.grpc.testing.MockStreamObserver) ExecutionException(java.util.concurrent.ExecutionException) ListenResponse(com.google.firestore.v1.ListenResponse) Test(org.junit.Test)

Aggregations

ListenResponse (com.google.firestore.v1.ListenResponse)4 Test (org.junit.Test)4 MockStreamObserver (com.google.api.gax.grpc.testing.MockStreamObserver)2 ListenRequest (com.google.firestore.v1.ListenRequest)2 Status (io.grpc.Status)2 HashMap (java.util.HashMap)2 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)1 DocumentKey (com.google.firebase.firestore.model.DocumentKey)1 MutableDocument (com.google.firebase.firestore.model.MutableDocument)1 ObjectValue (com.google.firebase.firestore.model.ObjectValue)1 SnapshotVersion (com.google.firebase.firestore.model.SnapshotVersion)1 ExistenceFilterWatchChange (com.google.firebase.firestore.remote.WatchChange.ExistenceFilterWatchChange)1 WatchTargetChange (com.google.firebase.firestore.remote.WatchChange.WatchTargetChange)1 WatchTargetChangeType (com.google.firebase.firestore.remote.WatchChange.WatchTargetChangeType)1 Document (com.google.firestore.v1.Document)1 DocumentChange (com.google.firestore.v1.DocumentChange)1 DocumentDelete (com.google.firestore.v1.DocumentDelete)1 DocumentRemove (com.google.firestore.v1.DocumentRemove)1 TargetChange (com.google.firestore.v1.TargetChange)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1