use of com.google.firestore.v1.StructuredQuery in project spring-cloud-gcp by spring-cloud.
the class FirestoreTemplateTests method findAllTest.
@Test
public void findAllTest() {
mockRunQueryMethod();
StepVerifier.create(this.firestoreTemplate.findAll(TestEntity.class)).expectNext(new TestEntity("e1", 100L), new TestEntity("e2", 200L)).verifyComplete();
StructuredQuery structuredQuery = StructuredQuery.newBuilder().addFrom(StructuredQuery.CollectionSelector.newBuilder().setCollectionId("testEntities").build()).build();
RunQueryRequest request = RunQueryRequest.newBuilder().setParent(this.parent).setStructuredQuery(structuredQuery).build();
verify(this.firestoreStub, times(1)).runQuery(eq(request), any());
verify(this.firestoreStub, times(1)).runQuery(any(), any());
}
use of com.google.firestore.v1.StructuredQuery in project spring-cloud-gcp by spring-cloud.
the class FirestoreTemplateTests method countTest.
@Test
public void countTest() {
mockRunQueryMethod();
StepVerifier.create(this.firestoreTemplate.count(TestEntity.class)).expectNext(2L).verifyComplete();
StructuredQuery structuredQuery = StructuredQuery.newBuilder().addFrom(StructuredQuery.CollectionSelector.newBuilder().setCollectionId("testEntities").build()).setSelect(StructuredQuery.Projection.newBuilder().addFields(StructuredQuery.FieldReference.newBuilder().setFieldPath("__name__").build()).build()).build();
RunQueryRequest request = RunQueryRequest.newBuilder().setParent(this.parent).setStructuredQuery(structuredQuery).build();
verify(this.firestoreStub, times(1)).runQuery(eq(request), any());
verify(this.firestoreStub, times(1)).runQuery(any(), any());
}
use of com.google.firestore.v1.StructuredQuery in project beam by apache.
the class PartitionQueryResponseToRunQueryRequestTest method ensureCursorPairingWorks.
@Test
public void ensureCursorPairingWorks() {
StructuredQuery query = StructuredQuery.newBuilder().addFrom(CollectionSelector.newBuilder().setAllDescendants(true).setCollectionId("c1").build()).build();
Cursor cursor1 = referenceValueCursor("projects/p1/databases/d1/documents/c1/doc1");
Cursor cursor2 = referenceValueCursor("projects/p1/databases/d1/documents/c1/doc2");
Cursor cursor3 = referenceValueCursor("projects/p1/databases/d1/documents/c1/doc2/c2/doc2");
List<StructuredQuery> expectedQueries = newArrayList(newQueryWithCursors(query, null, cursor1), newQueryWithCursors(query, cursor1, cursor2), newQueryWithCursors(query, cursor2, cursor3), newQueryWithCursors(query, cursor3, null));
PartitionQueryPair partitionQueryPair = new PartitionQueryPair(PartitionQueryRequest.newBuilder().setStructuredQuery(query).build(), PartitionQueryResponse.newBuilder().addPartitions(cursor3).addPartitions(cursor1).addPartitions(cursor2).build());
ArgumentCaptor<RunQueryRequest> captor = ArgumentCaptor.forClass(RunQueryRequest.class);
when(processContext.element()).thenReturn(partitionQueryPair);
doNothing().when(processContext).output(captor.capture());
PartitionQueryResponseToRunQueryRequest fn = new PartitionQueryResponseToRunQueryRequest();
fn.processElement(processContext);
List<StructuredQuery> actualQueries = captor.getAllValues().stream().map(RunQueryRequest::getStructuredQuery).collect(Collectors.toList());
assertEquals(expectedQueries, actualQueries);
}
use of com.google.firestore.v1.StructuredQuery in project beam by apache.
the class PartitionQueryResponseToRunQueryRequestTest method ensureCursorPairingWorks_emptyCursorsInResponse.
@Test
public void ensureCursorPairingWorks_emptyCursorsInResponse() {
StructuredQuery query = StructuredQuery.newBuilder().addFrom(CollectionSelector.newBuilder().setAllDescendants(true).setCollectionId("c1").build()).build();
List<StructuredQuery> expectedQueries = newArrayList(query);
PartitionQueryPair partitionQueryPair = new PartitionQueryPair(PartitionQueryRequest.newBuilder().setStructuredQuery(query).build(), PartitionQueryResponse.newBuilder().build());
ArgumentCaptor<RunQueryRequest> captor = ArgumentCaptor.forClass(RunQueryRequest.class);
when(processContext.element()).thenReturn(partitionQueryPair);
doNothing().when(processContext).output(captor.capture());
PartitionQueryResponseToRunQueryRequest fn = new PartitionQueryResponseToRunQueryRequest();
fn.processElement(processContext);
List<StructuredQuery> actualQueries = captor.getAllValues().stream().map(RunQueryRequest::getStructuredQuery).collect(Collectors.toList());
assertEquals(expectedQueries, actualQueries);
}
Aggregations