use of com.google.firestore.bundle.BundleElement in project java-firestore by googleapis.
the class FirestoreBundleTest method bundleWithQuerySnapshot.
@Test
public void bundleWithQuerySnapshot() {
FirestoreBundle.Builder bundleBuilder = new FirestoreBundle.Builder(TEST_BUNDLE_ID);
QuerySnapshot snapshot = QuerySnapshot.withDocuments(query, SINGLE_FIELD_SNAPSHOT.getReadTime(), Lists.newArrayList(QueryDocumentSnapshot.fromDocument(null, SINGLE_FIELD_SNAPSHOT.getReadTime(), SINGLE_FIELD_SNAPSHOT.toDocumentPb().build())));
bundleBuilder.add("test-query", snapshot);
ByteBuffer bundleBuffer = bundleBuilder.build().toByteBuffer();
// Expected bundle elements are [bundleMetadata, named query, meta of SINGLE_FIELD_SNAPSHOT,
// SINGLE_FIELD_SNAPSHOT]
List<BundleElement> elements = toBundleElements(bundleBuffer);
assertEquals(4, elements.size());
verifyMetadata(elements.get(0).getMetadata(), SINGLE_FIELD_SNAPSHOT.getReadTime().toProto(), /*totalDocuments*/
1, /*expectEmptyContent*/
false);
verifyNamedQuery(elements.get(1).getNamedQuery(), "test-query", SINGLE_FIELD_SNAPSHOT.getReadTime().toProto(), query, LimitType.FIRST);
verifyDocumentAndMeta(elements.get(2).getDocumentMetadata(), elements.get(3).getDocument(), DOCUMENT_NAME, Lists.newArrayList("test-query"), SINGLE_FIELD_SNAPSHOT);
}
use of com.google.firestore.bundle.BundleElement in project java-firestore by googleapis.
the class FirestoreBundleTest method bundleWithQueryReturningNoResult.
@Test
public void bundleWithQueryReturningNoResult() {
FirestoreBundle.Builder bundleBuilder = new FirestoreBundle.Builder(TEST_BUNDLE_ID);
QuerySnapshot snapshot = QuerySnapshot.withDocuments(query, SINGLE_FIELD_SNAPSHOT.getReadTime(), Lists.newArrayList());
bundleBuilder.add("test-query", snapshot);
ByteBuffer bundleBuffer = bundleBuilder.build().toByteBuffer();
// Expected bundle elements are [bundleMetadata, named query]
List<BundleElement> elements = toBundleElements(bundleBuffer);
assertEquals(2, elements.size());
verifyMetadata(elements.get(0).getMetadata(), SINGLE_FIELD_SNAPSHOT.getReadTime().toProto(), /*totalDocuments*/
0, /*expectEmptyContent*/
false);
verifyNamedQuery(elements.get(1).getNamedQuery(), "test-query", SINGLE_FIELD_SNAPSHOT.getReadTime().toProto(), query, LimitType.FIRST);
}
use of com.google.firestore.bundle.BundleElement in project java-firestore by googleapis.
the class FirestoreBundleTest method bundleWithNothingAdded.
@Test
public void bundleWithNothingAdded() {
FirestoreBundle.Builder bundleBuilder = new FirestoreBundle.Builder(TEST_BUNDLE_ID);
ByteBuffer bundleBuffer = bundleBuilder.build().toByteBuffer();
// Expected bundle elements are [bundleMetadata]
List<BundleElement> elements = toBundleElements(bundleBuffer);
assertEquals(1, elements.size());
verifyMetadata(elements.get(0).getMetadata(), com.google.cloud.Timestamp.MIN_VALUE.toProto(), /*totalDocuments*/
0, /*expectEmptyContent*/
true);
}
use of com.google.firestore.bundle.BundleElement in project java-firestore by googleapis.
the class FirestoreBundleTest method bundleWithDocumentSnapshots.
@Test
public void bundleWithDocumentSnapshots() {
FirestoreBundle.Builder bundleBuilder = new FirestoreBundle.Builder(TEST_BUNDLE_ID);
bundleBuilder.add(UPDATED_SINGLE_FIELD_SNAPSHOT);
bundleBuilder.add(SINGLE_FIELD_SNAPSHOT);
ByteBuffer bundleBuffer = bundleBuilder.build().toByteBuffer();
// Expected bundle elements are [bundleMetadata, meta of UPDATED_SINGLE_FIELD_SNAPSHOT,
// UPDATED_SINGLE_FIELD_SNAPSHOT]
// because UPDATED_SINGLE_FIELD_SNAPSHOT is newer.
List<BundleElement> elements = toBundleElements(bundleBuffer);
assertEquals(3, elements.size());
verifyMetadata(elements.get(0).getMetadata(), // because it is the largest read time came across.
UPDATED_SINGLE_FIELD_SNAPSHOT.getReadTime().toProto(), /*totalDocuments*/
1, /*expectEmptyContent*/
false);
verifyDocumentAndMeta(elements.get(1).getDocumentMetadata(), elements.get(2).getDocument(), DOCUMENT_NAME, Lists.newArrayList(), UPDATED_SINGLE_FIELD_SNAPSHOT);
}
use of com.google.firestore.bundle.BundleElement in project java-firestore by googleapis.
the class FirestoreBundleTest method bundleBuiltMultipleTimes.
@Test
public void bundleBuiltMultipleTimes() {
FirestoreBundle.Builder bundleBuilder = new FirestoreBundle.Builder(TEST_BUNDLE_ID);
bundleBuilder.add(SINGLE_FIELD_SNAPSHOT);
ByteBuffer bundleBuffer = bundleBuilder.build().toByteBuffer();
// Expected bundle elements are [bundleMetadata, meta of SINGLE_FIELD_SNAPSHOT,
// SINGLE_FIELD_SNAPSHOT]
List<BundleElement> elements = toBundleElements(bundleBuffer);
assertEquals(3, elements.size());
verifyMetadata(elements.get(0).getMetadata(), SINGLE_FIELD_SNAPSHOT.getReadTime().toProto(), /*totalDocuments*/
1, /*expectEmptyContent*/
false);
verifyDocumentAndMeta(elements.get(1).getDocumentMetadata(), elements.get(2).getDocument(), DOCUMENT_NAME, Lists.newArrayList(), SINGLE_FIELD_SNAPSHOT);
bundleBuilder.add(UPDATED_SINGLE_FIELD_SNAPSHOT);
bundleBuffer = bundleBuilder.build().toByteBuffer();
// Expected bundle elements are [bundleMetadata, meta of UPDATED_SINGLE_FIELD_SNAPSHOT,
// UPDATED_SINGLE_FIELD_SNAPSHOT]
elements = toBundleElements(bundleBuffer);
assertEquals(3, elements.size());
verifyMetadata(elements.get(0).getMetadata(), UPDATED_SINGLE_FIELD_SNAPSHOT.getReadTime().toProto(), /*totalDocuments*/
1, /*expectEmptyContent*/
false);
verifyDocumentAndMeta(elements.get(1).getDocumentMetadata(), elements.get(2).getDocument(), DOCUMENT_NAME, Lists.newArrayList(), UPDATED_SINGLE_FIELD_SNAPSHOT);
}
Aggregations