Search in sources :

Example 6 with BundledQuery

use of com.google.firebase.firestore.bundle.BundledQuery in project firebase-android-sdk by firebase.

the class LocalStoreTestCase method testLoadingNamedQueriesAllocatesTargetsAndUpdatesTargetDocumentMapping.

@Test
public void testLoadingNamedQueriesAllocatesTargetsAndUpdatesTargetDocumentMapping() {
    bundleDocuments(doc("foo1/bar", 1, map("sum", 1337)), doc("foo2/bar", 1, map("sum", 42)));
    assertChanged(doc("foo1/bar", 1, map("sum", 1337)), doc("foo2/bar", 1, map("sum", 42)));
    assertContains(doc("foo1/bar", 1, map("sum", 1337)));
    assertContains(doc("foo2/bar", 1, map("sum", 42)));
    Target target1 = Query.atPath(ResourcePath.fromString("foo1")).toTarget();
    NamedQuery namedQuery1 = new NamedQuery("query-1", new BundledQuery(target1, Query.LimitType.LIMIT_TO_FIRST), new SnapshotVersion(Timestamp.now()));
    saveNamedQuery(namedQuery1, key("foo1/bar"));
    assertHasNamedQuery(namedQuery1);
    assertQueryDocumentMapping(/* targetId= */
    4, key("foo1/bar"));
    Target target2 = Query.atPath(ResourcePath.fromString("foo2")).toTarget();
    NamedQuery namedQuery2 = new NamedQuery("query-2", new BundledQuery(target2, Query.LimitType.LIMIT_TO_FIRST), new SnapshotVersion(Timestamp.now()));
    saveNamedQuery(namedQuery2, key("foo2/bar"));
    assertHasNamedQuery(namedQuery2);
    assertQueryDocumentMapping(/* targetId= */
    6, key("foo2/bar"));
}
Also used : Target(com.google.firebase.firestore.core.Target) SnapshotVersion(com.google.firebase.firestore.model.SnapshotVersion) BundledQuery(com.google.firebase.firestore.bundle.BundledQuery) NamedQuery(com.google.firebase.firestore.bundle.NamedQuery) Test(org.junit.Test)

Example 7 with BundledQuery

use of com.google.firebase.firestore.bundle.BundledQuery in project firebase-android-sdk by firebase.

the class LocalSerializerTest method testEncodesQuery.

@Test
public void testEncodesQuery() {
    Target target = new Target(path("room"), /* collectionGroup= */
    null, Collections.emptyList(), Collections.emptyList(), Target.NO_LIMIT, /* startAt= */
    null, /* endAt= */
    null);
    BundledQuery bundledQuery = new BundledQuery(target, Query.LimitType.LIMIT_TO_FIRST);
    com.google.firestore.bundle.BundledQuery encodedBundledQuery = serializer.encodeBundledQuery(bundledQuery);
    BundledQuery decodedBundledQuery = serializer.decodeBundledQuery(encodedBundledQuery);
    assertEquals(bundledQuery, decodedBundledQuery);
}
Also used : Target(com.google.firebase.firestore.core.Target) BundledQuery(com.google.firebase.firestore.bundle.BundledQuery) Test(org.junit.Test)

Example 8 with BundledQuery

use of com.google.firebase.firestore.bundle.BundledQuery in project firebase-android-sdk by firebase.

the class LocalStoreTestCase method testHandlesSavingAndLoadingLimitToLastQueries.

@Test
public void testHandlesSavingAndLoadingLimitToLastQueries() {
    Target target = query("foo").orderBy(orderBy("foo")).limitToFirst(// Use `limitToFirst` so toTarget() does not flip ordering constraint
    5).toTarget();
    NamedQuery namedQuery = new NamedQuery("testQuery", new BundledQuery(target, Query.LimitType.LIMIT_TO_LAST), SnapshotVersion.NONE);
    saveNamedQuery(namedQuery);
    assertHasNamedQuery(namedQuery);
}
Also used : Target(com.google.firebase.firestore.core.Target) BundledQuery(com.google.firebase.firestore.bundle.BundledQuery) NamedQuery(com.google.firebase.firestore.bundle.NamedQuery) Test(org.junit.Test)

Example 9 with BundledQuery

use of com.google.firebase.firestore.bundle.BundledQuery in project firebase-android-sdk by firebase.

the class BundleCacheTestCase method testReturnsSavedCollectionGroupQueries.

@Test
public void testReturnsSavedCollectionGroupQueries() {
    Target target = new Target(ResourcePath.EMPTY, /* collectionGroup= */
    "collectionGroup", Collections.emptyList(), Collections.emptyList(), /* limit= */
    1, /* startAt= */
    null, /* endAt= */
    null);
    BundledQuery bundledQuery = new BundledQuery(target, Query.LimitType.LIMIT_TO_FIRST);
    NamedQuery expectedQuery = new NamedQuery("query-1", bundledQuery, new SnapshotVersion(Timestamp.now()));
    bundleCache.saveNamedQuery(expectedQuery);
    NamedQuery actualQuery = bundleCache.getNamedQuery("query-1");
    assertEquals(expectedQuery, actualQuery);
}
Also used : Target(com.google.firebase.firestore.core.Target) SnapshotVersion(com.google.firebase.firestore.model.SnapshotVersion) BundledQuery(com.google.firebase.firestore.bundle.BundledQuery) NamedQuery(com.google.firebase.firestore.bundle.NamedQuery) Test(org.junit.Test)

Example 10 with BundledQuery

use of com.google.firebase.firestore.bundle.BundledQuery in project firebase-android-sdk by firebase.

the class BundleCacheTestCase method testReturnsSavedCollectionQueries.

@Test
public void testReturnsSavedCollectionQueries() {
    Target target = new Target(path("room"), /* collectionGroup= */
    null, Collections.emptyList(), Collections.emptyList(), Target.NO_LIMIT, /* startAt= */
    null, /* endAt= */
    null);
    BundledQuery bundledQuery = new BundledQuery(target, Query.LimitType.LIMIT_TO_FIRST);
    NamedQuery expectedQuery = new NamedQuery("query-1", bundledQuery, new SnapshotVersion(Timestamp.now()));
    bundleCache.saveNamedQuery(expectedQuery);
    NamedQuery actualQuery = bundleCache.getNamedQuery("query-1");
    assertEquals(expectedQuery, actualQuery);
}
Also used : Target(com.google.firebase.firestore.core.Target) SnapshotVersion(com.google.firebase.firestore.model.SnapshotVersion) BundledQuery(com.google.firebase.firestore.bundle.BundledQuery) NamedQuery(com.google.firebase.firestore.bundle.NamedQuery) Test(org.junit.Test)

Aggregations

BundledQuery (com.google.firebase.firestore.bundle.BundledQuery)10 Target (com.google.firebase.firestore.core.Target)10 Test (org.junit.Test)9 NamedQuery (com.google.firebase.firestore.bundle.NamedQuery)7 SnapshotVersion (com.google.firebase.firestore.model.SnapshotVersion)5 LimitType (com.google.firebase.firestore.core.Query.LimitType)1