Search in sources :

Example 6 with BundleElement

use of com.google.firestore.bundle.BundleElement 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 7 with BundleElement

use of com.google.firestore.bundle.BundleElement 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)

Example 8 with BundleElement

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

the class ITSystemTest method testBuildingBundleWhenDocumentDoesNotExist.

@Test
public void testBuildingBundleWhenDocumentDoesNotExist() throws Exception {
    FirestoreBundle.Builder bundleBuilder = firestore.bundleBuilder("test-bundle");
    DocumentSnapshot snapshot = randomDoc.get().get();
    bundleBuilder.add(snapshot);
    // Expected bundle elements are [bundleMetadata, documentMetadata]
    List<BundleElement> elements = toBundleElements(bundleBuilder.build().toByteBuffer());
    assertEquals(2, elements.size());
    verifyMetadata(elements.get(0).getMetadata(), snapshot.getReadTime().toProto(), /*totalDocuments*/
    1, /*expectEmptyContent*/
    false);
    assertEquals(BundledDocumentMetadata.newBuilder().setExists(false).setName(fullPath(randomDoc, firestore.getOptions())).setReadTime(snapshot.getReadTime().toProto()).build(), elements.get(1).getDocumentMetadata());
}
Also used : QueryDocumentSnapshot(com.google.cloud.firestore.QueryDocumentSnapshot) DocumentSnapshot(com.google.cloud.firestore.DocumentSnapshot) BundleElement(com.google.firestore.bundle.BundleElement) FirestoreBundle(com.google.cloud.firestore.FirestoreBundle) Test(org.junit.Test)

Aggregations

BundleElement (com.google.firestore.bundle.BundleElement)8 Test (org.junit.Test)8 ByteBuffer (java.nio.ByteBuffer)5 FirestoreBundle (com.google.cloud.firestore.FirestoreBundle)3 FirestoreBundleTest.verifyNamedQuery (com.google.cloud.firestore.FirestoreBundleTest.verifyNamedQuery)2 Query (com.google.cloud.firestore.Query)2 QuerySnapshot (com.google.cloud.firestore.QuerySnapshot)2 NamedQuery (com.google.firestore.bundle.NamedQuery)2 DocumentSnapshot (com.google.cloud.firestore.DocumentSnapshot)1 QueryDocumentSnapshot (com.google.cloud.firestore.QueryDocumentSnapshot)1