Search in sources :

Example 1 with BundleElement

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);
}
Also used : BundleElement(com.google.firestore.bundle.BundleElement) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 2 with BundleElement

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);
}
Also used : BundleElement(com.google.firestore.bundle.BundleElement) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 3 with BundleElement

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);
}
Also used : BundleElement(com.google.firestore.bundle.BundleElement) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 4 with BundleElement

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);
}
Also used : BundleElement(com.google.firestore.bundle.BundleElement) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 5 with BundleElement

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);
}
Also used : BundleElement(com.google.firestore.bundle.BundleElement) ByteBuffer(java.nio.ByteBuffer) 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