use of com.google.firestore.v1beta1.GetDocumentRequest in project spring-cloud-gcp by spring-cloud.
the class FirestoreTemplateTests method findAllByIdTest.
@Test
public void findAllByIdTest() {
GetDocumentRequest request1 = GetDocumentRequest.newBuilder().setName(this.parent + "/testEntities/e1").build();
GetDocumentRequest request2 = GetDocumentRequest.newBuilder().setName(this.parent + "/testEntities/e2").build();
GetDocumentRequest request3 = GetDocumentRequest.newBuilder().setName(this.parent + "/testEntities/e3").build();
doAnswer(invocation -> {
StreamObserver<com.google.firestore.v1.Document> streamObserver = invocation.getArgument(1);
streamObserver.onNext(buildDocument("e1", 100L));
streamObserver.onCompleted();
return null;
}).when(this.firestoreStub).getDocument(eq(request1), any());
doAnswer(invocation -> {
StreamObserver<com.google.firestore.v1.Document> streamObserver = invocation.getArgument(1);
streamObserver.onNext(buildDocument("e2", 200L));
streamObserver.onCompleted();
return null;
}).when(this.firestoreStub).getDocument(eq(request2), any());
doAnswer(invocation -> {
StreamObserver<com.google.firestore.v1.Document> streamObserver = invocation.getArgument(1);
streamObserver.onError(new RuntimeException("NOT_FOUND: Document"));
streamObserver.onCompleted();
return null;
}).when(this.firestoreStub).getDocument(eq(request3), any());
StepVerifier.create(this.firestoreTemplate.findAllById(Flux.just("e1", "e2"), TestEntity.class)).expectNext(new TestEntity("e1", 100L), new TestEntity("e2", 200L)).verifyComplete();
verify(this.firestoreStub, times(1)).getDocument(eq(request1), any());
}
use of com.google.firestore.v1beta1.GetDocumentRequest in project spring-cloud-gcp by spring-cloud.
the class FirestoreTemplateTests method findByIdTest.
@Test
public void findByIdTest() {
doAnswer(invocation -> {
StreamObserver<com.google.firestore.v1.Document> streamObserver = invocation.getArgument(1);
streamObserver.onNext(buildDocument("e1", 100L));
streamObserver.onCompleted();
return null;
}).when(this.firestoreStub).getDocument(any(), any());
StepVerifier.create(this.firestoreTemplate.findById(Mono.just("e1"), TestEntity.class)).expectNext(new TestEntity("e1", 100L)).verifyComplete();
GetDocumentRequest request = GetDocumentRequest.newBuilder().setName(this.parent + "/testEntities/" + "e1").build();
verify(this.firestoreStub, times(1)).getDocument(eq(request), any());
}
use of com.google.firestore.v1beta1.GetDocumentRequest in project spring-cloud-gcp by spring-cloud.
the class FirestoreTemplateTests method findByIdErrorTest.
@Test
public void findByIdErrorTest() {
doAnswer(invocation -> {
StreamObserver<com.google.firestore.v1.Document> streamObserver = invocation.getArgument(1);
streamObserver.onError(new RuntimeException("Firestore error"));
return null;
}).when(this.firestoreStub).getDocument(any(), any());
StepVerifier.create(this.firestoreTemplate.findById(Mono.just("e1"), TestEntity.class)).expectErrorMatches(e -> e instanceof FirestoreDataException && e.getMessage().contains("Firestore error") && e.getMessage().contains("Error while reading entries by id")).verify();
GetDocumentRequest request = GetDocumentRequest.newBuilder().setName(this.parent + "/testEntities/" + "e1").build();
verify(this.firestoreStub, times(1)).getDocument(eq(request), any());
}
use of com.google.firestore.v1beta1.GetDocumentRequest in project spring-cloud-gcp by spring-cloud.
the class FirestoreTemplateTests method existsByIdTest.
@Test
public void existsByIdTest() {
GetDocumentRequest request = GetDocumentRequest.newBuilder().setName(this.parent + "/testEntities/" + "e1").setMask(DocumentMask.newBuilder().addFieldPaths("__name__").build()).build();
doAnswer(invocation -> {
StreamObserver<com.google.firestore.v1.Document> streamObserver = invocation.getArgument(1);
streamObserver.onNext(buildDocument("e1", 100L));
streamObserver.onCompleted();
return null;
}).when(this.firestoreStub).getDocument(eq(request), any());
StepVerifier.create(this.firestoreTemplate.existsById(Mono.just("e1"), TestEntity.class)).expectNext(Boolean.TRUE).verifyComplete();
verify(this.firestoreStub, times(1)).getDocument(eq(request), any());
verify(this.firestoreStub, times(1)).getDocument(any(), any());
}
use of com.google.firestore.v1beta1.GetDocumentRequest in project spring-cloud-gcp by GoogleCloudPlatform.
the class FirestoreTemplateTests method withParentTest_entityReference.
@Test
void withParentTest_entityReference() {
doAnswer(invocation -> {
StreamObserver<com.google.firestore.v1.Document> streamObserver = invocation.getArgument(1);
streamObserver.onNext(buildDocument("e1", 100L));
streamObserver.onCompleted();
return null;
}).when(this.firestoreStub).getDocument(any(), any());
this.firestoreTemplate.withParent(new TestEntity("parent", 0L)).findById(Mono.just("child"), TestEntity.class).block();
GetDocumentRequest request = GetDocumentRequest.newBuilder().setName(this.parent + "/testEntities/parent/testEntities/child").build();
verify(this.firestoreStub, times(1)).getDocument(eq(request), any());
}
Aggregations