use of org.springframework.cloud.gcp.data.firestore.mapping.FirestoreMappingContext in project spring-cloud-gcp by spring-cloud.
the class PartTreeFirestoreQueryTests method setUpPartTreeFirestoreQuery.
private PartTreeFirestoreQuery setUpPartTreeFirestoreQuery(String methodName) {
Parameters parametersMock = mock(Parameters.class);
when(parametersMock.isEmpty()).thenReturn(true);
when(this.queryMethod.getParameters()).thenReturn(parametersMock);
when(this.queryMethod.getName()).thenReturn(methodName);
ReturnedType returnedType = mock(ReturnedType.class);
when(returnedType.getDomainType()).thenAnswer(invocation -> User.class);
ResultProcessor resultProcessor = mock(ResultProcessor.class);
when(resultProcessor.getReturnedType()).thenReturn(returnedType);
when(this.queryMethod.getResultProcessor()).thenReturn(resultProcessor);
return new PartTreeFirestoreQuery(this.queryMethod, this.firestoreTemplate, new FirestoreMappingContext(), this.classMapper);
}
use of org.springframework.cloud.gcp.data.firestore.mapping.FirestoreMappingContext in project spring-cloud-gcp by spring-cloud.
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());
FirestoreTemplate template = new FirestoreTemplate(this.firestoreStub, this.parent, new FirestoreDefaultClassMapper(), new FirestoreMappingContext());
StepVerifier.setDefaultTimeout(Duration.ofSeconds(5));
return template;
}
Aggregations