Search in sources :

Example 1 with FirestoreDefaultClassMapper

use of com.google.cloud.spring.data.firestore.mapping.FirestoreDefaultClassMapper in project spring-cloud-gcp by GoogleCloudPlatform.

the class ReactiveFirestoreTransactionManagerTest method getFirestoreTemplate.

private FirestoreTemplate getFirestoreTemplate() {
    doAnswer(invocation -> {
        StreamObserver<BeginTransactionResponse> streamObserver = invocation.getArgument(1);
        streamObserver.onNext(BeginTransactionResponse.newBuilder().setTransaction(ByteString.copyFromUtf8("transaction1")).build());
        streamObserver.onCompleted();
        return null;
    }).when(this.firestoreStub).beginTransaction(any(), any());
    doAnswer(invocation -> {
        CommitRequest commitRequest = invocation.getArgument(0);
        StreamObserver<CommitResponse> streamObserver = invocation.getArgument(1);
        assertThat(commitRequest.getTransaction()).isEqualTo(ByteString.copyFromUtf8("transaction1"));
        streamObserver.onNext(CommitResponse.newBuilder().build());
        streamObserver.onCompleted();
        return null;
    }).when(this.firestoreStub).commit(any(), any());
    doAnswer(invocation -> {
        RollbackRequest rollbackRequest = invocation.getArgument(0);
        StreamObserver<Empty> streamObserver = invocation.getArgument(1);
        assertThat(rollbackRequest.getTransaction()).isEqualTo(ByteString.copyFromUtf8("transaction1"));
        streamObserver.onCompleted();
        return null;
    }).when(this.firestoreStub).rollback(any(), any());
    doAnswer(invocation -> {
        GetDocumentRequest request = invocation.getArgument(0);
        StreamObserver<Document> streamObserver = invocation.getArgument(1);
        assertThat(request.getTransaction()).isEqualTo(ByteString.copyFromUtf8("transaction1"));
        String name = request.getName();
        streamObserver.onNext(FirestoreTemplateTests.buildDocument(name.substring(name.length() - 2), 100L));
        streamObserver.onCompleted();
        return null;
    }).when(this.firestoreStub).getDocument(any(), any());
    FirestoreMappingContext mappingContext = new FirestoreMappingContext();
    FirestoreTemplate template = new FirestoreTemplate(this.firestoreStub, this.parent, new FirestoreDefaultClassMapper(mappingContext), mappingContext);
    StepVerifier.setDefaultTimeout(Duration.ofSeconds(5));
    return template;
}
Also used : CommitRequest(com.google.firestore.v1.CommitRequest) CommitResponse(com.google.firestore.v1.CommitResponse) ByteString(com.google.protobuf.ByteString) RollbackRequest(com.google.firestore.v1.RollbackRequest) GetDocumentRequest(com.google.firestore.v1.GetDocumentRequest) Document(com.google.firestore.v1.Document) BeginTransactionResponse(com.google.firestore.v1.BeginTransactionResponse) FirestoreMappingContext(com.google.cloud.spring.data.firestore.mapping.FirestoreMappingContext) FirestoreTemplate(com.google.cloud.spring.data.firestore.FirestoreTemplate) Empty(com.google.protobuf.Empty) FirestoreDefaultClassMapper(com.google.cloud.spring.data.firestore.mapping.FirestoreDefaultClassMapper)

Example 2 with FirestoreDefaultClassMapper

use of com.google.cloud.spring.data.firestore.mapping.FirestoreDefaultClassMapper in project spring-cloud-gcp by GoogleCloudPlatform.

the class FirestoreTemplateTests method setup.

@BeforeEach
void setup() {
    FirestoreMappingContext mappingContext = new FirestoreMappingContext();
    this.firestoreTemplate = new FirestoreTemplate(this.firestoreStub, this.parent, new FirestoreDefaultClassMapper(mappingContext), mappingContext);
}
Also used : FirestoreMappingContext(com.google.cloud.spring.data.firestore.mapping.FirestoreMappingContext) FirestoreDefaultClassMapper(com.google.cloud.spring.data.firestore.mapping.FirestoreDefaultClassMapper) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

FirestoreDefaultClassMapper (com.google.cloud.spring.data.firestore.mapping.FirestoreDefaultClassMapper)2 FirestoreMappingContext (com.google.cloud.spring.data.firestore.mapping.FirestoreMappingContext)2 FirestoreTemplate (com.google.cloud.spring.data.firestore.FirestoreTemplate)1 BeginTransactionResponse (com.google.firestore.v1.BeginTransactionResponse)1 CommitRequest (com.google.firestore.v1.CommitRequest)1 CommitResponse (com.google.firestore.v1.CommitResponse)1 Document (com.google.firestore.v1.Document)1 GetDocumentRequest (com.google.firestore.v1.GetDocumentRequest)1 RollbackRequest (com.google.firestore.v1.RollbackRequest)1 ByteString (com.google.protobuf.ByteString)1 Empty (com.google.protobuf.Empty)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1