Search in sources :

Example 11 with GetDocumentRequest

use of com.google.firestore.v1beta1.GetDocumentRequest in project spring-cloud-gcp by GoogleCloudPlatform.

the class FirestoreTemplateTests method withParentTest_idClassReference.

@Test
void withParentTest_idClassReference() {
    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("parent", TestEntity.class).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());
}
Also used : GetDocumentRequest(com.google.firestore.v1.GetDocumentRequest) Test(org.junit.jupiter.api.Test)

Example 12 with GetDocumentRequest

use of com.google.firestore.v1beta1.GetDocumentRequest in project spring-cloud-gcp by GoogleCloudPlatform.

the class FirestoreTemplateTests method findByIdTest.

@Test
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());
}
Also used : GetDocumentRequest(com.google.firestore.v1.GetDocumentRequest) Test(org.junit.jupiter.api.Test)

Example 13 with GetDocumentRequest

use of com.google.firestore.v1beta1.GetDocumentRequest in project spring-cloud-gcp by GoogleCloudPlatform.

the class FirestoreTemplateTests method existsByIdNotFoundTest.

@Test
void existsByIdNotFoundTest() {
    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.onError(new RuntimeException("NOT_FOUND: Document"));
        streamObserver.onCompleted();
        return null;
    }).when(this.firestoreStub).getDocument(eq(request), any());
    StepVerifier.create(this.firestoreTemplate.existsById(Mono.just("e1"), TestEntity.class)).expectNext(Boolean.FALSE).verifyComplete();
    verify(this.firestoreStub, times(1)).getDocument(eq(request), any());
    verify(this.firestoreStub, times(1)).getDocument(any(), any());
}
Also used : GetDocumentRequest(com.google.firestore.v1.GetDocumentRequest) Test(org.junit.jupiter.api.Test)

Example 14 with GetDocumentRequest

use of com.google.firestore.v1beta1.GetDocumentRequest in project spring-cloud-gcp by GoogleCloudPlatform.

the class FirestoreTemplateTests method findByIdNotFoundTest.

@Test
void findByIdNotFoundTest() {
    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(any(), any());
    StepVerifier.create(this.firestoreTemplate.findById(Mono.just("e1"), TestEntity.class)).verifyComplete();
    GetDocumentRequest request = GetDocumentRequest.newBuilder().setName(this.parent + "/testEntities/" + "e1").build();
    verify(this.firestoreStub, times(1)).getDocument(eq(request), any());
}
Also used : GetDocumentRequest(com.google.firestore.v1.GetDocumentRequest) Test(org.junit.jupiter.api.Test)

Example 15 with GetDocumentRequest

use of com.google.firestore.v1beta1.GetDocumentRequest in project spring-cloud-gcp by spring-cloud.

the class ReactiveFirestoreTransactionManagerTest method triggerCommitCorrectly.

@Test
public void triggerCommitCorrectly() {
    FirestoreTemplate template = getFirestoreTemplate();
    ReactiveFirestoreTransactionManager txManager = new ReactiveFirestoreTransactionManager(this.firestoreStub, this.parent);
    TransactionalOperator operator = TransactionalOperator.create(txManager);
    template.findById(Mono.just("e1"), FirestoreTemplateTests.TestEntity.class).concatWith(template.findById(Mono.just("e2"), FirestoreTemplateTests.TestEntity.class)).as(operator::transactional).as(StepVerifier::create).expectNext(new FirestoreTemplateTests.TestEntity("e1", 100L), new FirestoreTemplateTests.TestEntity("e2", 100L)).verifyComplete();
    verify(this.firestoreStub).beginTransaction(any(), any());
    verify(this.firestoreStub).commit(any(), any());
    GetDocumentRequest request1 = GetDocumentRequest.newBuilder().setName(this.parent + "/testEntities/" + "e1").setTransaction(ByteString.copyFromUtf8("transaction1")).build();
    verify(this.firestoreStub, times(1)).getDocument(eq(request1), any());
    GetDocumentRequest request2 = GetDocumentRequest.newBuilder().setName(this.parent + "/testEntities/" + "e2").setTransaction(ByteString.copyFromUtf8("transaction1")).build();
    verify(this.firestoreStub, times(1)).getDocument(eq(request2), any());
}
Also used : TransactionalOperator(org.springframework.transaction.reactive.TransactionalOperator) StepVerifier(reactor.test.StepVerifier) GetDocumentRequest(com.google.firestore.v1.GetDocumentRequest) FirestoreTemplate(org.springframework.cloud.gcp.data.firestore.FirestoreTemplate) Test(org.junit.Test)

Aggregations

GetDocumentRequest (com.google.firestore.v1.GetDocumentRequest)22 Test (org.junit.Test)10 Test (org.junit.jupiter.api.Test)10 CommitRequest (com.google.firestore.v1.CommitRequest)6 CommitResponse (com.google.firestore.v1.CommitResponse)6 StepVerifier (reactor.test.StepVerifier)6 Document (com.google.firestore.v1.Document)5 StreamObserver (io.grpc.stub.StreamObserver)5 BeginTransactionResponse (com.google.firestore.v1.BeginTransactionResponse)4 RollbackRequest (com.google.firestore.v1.RollbackRequest)4 ByteString (com.google.protobuf.ByteString)4 Empty (com.google.protobuf.Empty)4 HashMap (java.util.HashMap)4 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)4 ArgumentMatchers.eq (org.mockito.ArgumentMatchers.eq)4 Mockito.doAnswer (org.mockito.Mockito.doAnswer)4 Mockito.mock (org.mockito.Mockito.mock)4 Mockito.verify (org.mockito.Mockito.verify)4 Mono (reactor.core.publisher.Mono)4 FirestoreTemplate (com.google.cloud.spring.data.firestore.FirestoreTemplate)3