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());
}
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());
}
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());
}
Aggregations