Search in sources :

Example 1 with NamedQuery

use of com.google.firestore.bundle.NamedQuery in project java-firestore by googleapis.

the class ITSystemTest method testBuildingBundleWithLimitToLastQuery.

@Test
public void testBuildingBundleWithLimitToLastQuery() throws Exception {
    setDocument("doc1", Collections.singletonMap("counter", 1));
    setDocument("doc2", Collections.singletonMap("counter", 2));
    Query limitToLastQuery = randomColl.orderBy("counter").limitToLast(1);
    QuerySnapshot limitToLastQuerySnap = limitToLastQuery.get().get();
    FirestoreBundle.Builder bundleBuilder = firestore.bundleBuilder("test-bundle");
    bundleBuilder.add("limitToLast", limitToLastQuerySnap);
    // Expected bundle elements are [bundleMetadata, limitToLastQuery,
    // documentMetadata, document]
    List<BundleElement> elements = toBundleElements(bundleBuilder.build().toByteBuffer());
    assertEquals(4, elements.size());
    verifyMetadata(elements.get(0).getMetadata(), limitToLastQuerySnap.getReadTime().toProto(), 1, false);
    NamedQuery namedLimitToLastQuery = elements.get(1).getNamedQuery();
    verifyNamedQuery(namedLimitToLastQuery, "limitToLast", limitToLastQuerySnap.getReadTime().toProto(), randomColl.orderBy("counter").limit(1), LimitType.LAST);
    verifyDocumentAndMeta(elements.get(2).getDocumentMetadata(), elements.get(3).getDocument(), fullPath(randomColl.document("doc2"), firestore.getOptions()), Lists.newArrayList("limitToLast"), randomColl.document("doc2").get().get(), limitToLastQuerySnap.getReadTime().toProto());
}
Also used : FirestoreBundleTest.verifyNamedQuery(com.google.cloud.firestore.FirestoreBundleTest.verifyNamedQuery) NamedQuery(com.google.firestore.bundle.NamedQuery) Query(com.google.cloud.firestore.Query) BundleElement(com.google.firestore.bundle.BundleElement) FirestoreBundle(com.google.cloud.firestore.FirestoreBundle) FirestoreBundleTest.verifyNamedQuery(com.google.cloud.firestore.FirestoreBundleTest.verifyNamedQuery) NamedQuery(com.google.firestore.bundle.NamedQuery) QuerySnapshot(com.google.cloud.firestore.QuerySnapshot) Test(org.junit.Test)

Example 2 with NamedQuery

use of com.google.firestore.bundle.NamedQuery in project java-firestore by googleapis.

the class ITSystemTest method testBuildingBundleWithLimitQuery.

@Test
public void testBuildingBundleWithLimitQuery() throws Exception {
    setDocument("doc1", Collections.singletonMap("counter", 1));
    setDocument("doc2", Collections.singletonMap("counter", 2));
    Query limitQuery = randomColl.orderBy("counter", Direction.DESCENDING).limit(1);
    QuerySnapshot limitQuerySnap = limitQuery.get().get();
    FirestoreBundle.Builder bundleBuilder = firestore.bundleBuilder("test-bundle");
    bundleBuilder.add("limit", limitQuerySnap);
    // Expected bundle elements are [bundleMetadata, limitQuery,
    // documentMetadata, document]
    List<BundleElement> elements = toBundleElements(bundleBuilder.build().toByteBuffer());
    assertEquals(4, elements.size());
    verifyMetadata(elements.get(0).getMetadata(), limitQuerySnap.getReadTime().toProto(), 1, false);
    NamedQuery namedLimitQuery = elements.get(1).getNamedQuery();
    verifyNamedQuery(namedLimitQuery, "limit", limitQuerySnap.getReadTime().toProto(), limitQuery, LimitType.FIRST);
    verifyDocumentAndMeta(elements.get(2).getDocumentMetadata(), elements.get(3).getDocument(), fullPath(randomColl.document("doc2"), firestore.getOptions()), Lists.newArrayList("limit"), randomColl.document("doc2").get().get(), limitQuerySnap.getReadTime().toProto());
}
Also used : FirestoreBundleTest.verifyNamedQuery(com.google.cloud.firestore.FirestoreBundleTest.verifyNamedQuery) NamedQuery(com.google.firestore.bundle.NamedQuery) Query(com.google.cloud.firestore.Query) BundleElement(com.google.firestore.bundle.BundleElement) FirestoreBundle(com.google.cloud.firestore.FirestoreBundle) FirestoreBundleTest.verifyNamedQuery(com.google.cloud.firestore.FirestoreBundleTest.verifyNamedQuery) NamedQuery(com.google.firestore.bundle.NamedQuery) QuerySnapshot(com.google.cloud.firestore.QuerySnapshot) Test(org.junit.Test)

Aggregations

FirestoreBundle (com.google.cloud.firestore.FirestoreBundle)2 FirestoreBundleTest.verifyNamedQuery (com.google.cloud.firestore.FirestoreBundleTest.verifyNamedQuery)2 Query (com.google.cloud.firestore.Query)2 QuerySnapshot (com.google.cloud.firestore.QuerySnapshot)2 BundleElement (com.google.firestore.bundle.BundleElement)2 NamedQuery (com.google.firestore.bundle.NamedQuery)2 Test (org.junit.Test)2