Search in sources :

Example 11 with Query

use of com.google.firebase.firestore.core.Query in project firebase-android-sdk by firebase.

the class SQLiteIndexManagerTest method testOrderByWithNotEqualsFilter.

@Test
public void testOrderByWithNotEqualsFilter() {
    indexManager.addFieldIndex(fieldIndex("coll", "count", Kind.ASCENDING));
    addDoc("coll/val1", map("count", 1));
    addDoc("coll/val2", map("count", 2));
    Query query = query("coll").filter(filter("count", "!=", 2)).orderBy(orderBy("count"));
    verifyResults(query, "coll/val1");
}
Also used : Query(com.google.firebase.firestore.core.Query) Test(org.junit.Test)

Example 12 with Query

use of com.google.firebase.firestore.core.Query in project firebase-android-sdk by firebase.

the class SQLiteIndexManagerTest method testStartAfterFilter.

@Test
public void testStartAfterFilter() {
    setUpSingleValueFilter();
    Query query = query("coll").orderBy(orderBy("count")).startAt(bound(/* inclusive= */
    false, 2));
    verifyResults(query, "coll/val3");
}
Also used : Query(com.google.firebase.firestore.core.Query) Test(org.junit.Test)

Example 13 with Query

use of com.google.firebase.firestore.core.Query in project firebase-android-sdk by firebase.

the class SQLiteIndexManagerTest method testGreaterThanFilter.

@Test
public void testGreaterThanFilter() {
    setUpSingleValueFilter();
    Query query = query("coll").filter(filter("count", ">", 2));
    verifyResults(query, "coll/val3");
}
Also used : Query(com.google.firebase.firestore.core.Query) Test(org.junit.Test)

Example 14 with Query

use of com.google.firebase.firestore.core.Query in project firebase-android-sdk by firebase.

the class SQLiteIndexManagerTest method testIndexEntriesAreUpdated.

@Test
public void testIndexEntriesAreUpdated() {
    indexManager.addFieldIndex(fieldIndex("coll", "value", Kind.ASCENDING));
    Query query = query("coll").orderBy(orderBy("value"));
    addDoc("coll/doc1", map("value", true));
    verifyResults(query, "coll/doc1");
    addDocs(doc("coll/doc1", 1, map()), doc("coll/doc2", 1, map("value", true)));
    verifyResults(query, "coll/doc2");
}
Also used : Query(com.google.firebase.firestore.core.Query) Test(org.junit.Test)

Example 15 with Query

use of com.google.firebase.firestore.core.Query in project firebase-android-sdk by firebase.

the class SQLiteIndexManagerTest method verifyResults.

private void verifyResults(Query query, String... documents) {
    Target target = query.toTarget();
    Iterable<DocumentKey> results = indexManager.getDocumentsMatchingTarget(target);
    assertNotNull("Target cannot be served from index.", results);
    List<DocumentKey> keys = Arrays.stream(documents).map(s -> key(s)).collect(Collectors.toList());
    assertWithMessage("Result for %s", query).that(results).containsExactlyElementsIn(keys);
}
Also used : IndexOffset(com.google.firebase.firestore.model.FieldIndex.IndexOffset) Arrays(java.util.Arrays) TestUtil.fieldIndex(com.google.firebase.firestore.testutil.TestUtil.fieldIndex) IndexState(com.google.firebase.firestore.model.FieldIndex.IndexState) RunWith(org.junit.runner.RunWith) Config(org.robolectric.annotation.Config) Kind(com.google.firebase.firestore.model.FieldIndex.Segment.Kind) TestUtil.filter(com.google.firebase.firestore.testutil.TestUtil.filter) TestUtil.bound(com.google.firebase.firestore.testutil.TestUtil.bound) TestUtil.query(com.google.firebase.firestore.testutil.TestUtil.query) ArrayList(java.util.ArrayList) TestUtil.wrap(com.google.firebase.firestore.testutil.TestUtil.wrap) Values(com.google.firebase.firestore.model.Values) TestUtil.doc(com.google.firebase.firestore.testutil.TestUtil.doc) Map(java.util.Map) TestUtil.docMap(com.google.firebase.firestore.testutil.TestUtil.docMap) Document(com.google.firebase.firestore.model.Document) Iterator(java.util.Iterator) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) Assert.assertNotNull(org.junit.Assert.assertNotNull) User(com.google.firebase.firestore.auth.User) Collection(java.util.Collection) TestUtil.deletedDoc(com.google.firebase.firestore.testutil.TestUtil.deletedDoc) Target(com.google.firebase.firestore.core.Target) Test(org.junit.Test) Collectors(java.util.stream.Collectors) RobolectricTestRunner(org.robolectric.RobolectricTestRunner) TestUtil.path(com.google.firebase.firestore.testutil.TestUtil.path) List(java.util.List) TestUtil.version(com.google.firebase.firestore.testutil.TestUtil.version) Assert.assertNull(org.junit.Assert.assertNull) FieldIndex(com.google.firebase.firestore.model.FieldIndex) Filter(com.google.firebase.firestore.core.Filter) TestUtil.map(com.google.firebase.firestore.testutil.TestUtil.map) TestUtil.key(com.google.firebase.firestore.testutil.TestUtil.key) Collections(java.util.Collections) TestUtil.orderBy(com.google.firebase.firestore.testutil.TestUtil.orderBy) Assert.assertEquals(org.junit.Assert.assertEquals) DocumentKey(com.google.firebase.firestore.model.DocumentKey) Query(com.google.firebase.firestore.core.Query) Target(com.google.firebase.firestore.core.Target) DocumentKey(com.google.firebase.firestore.model.DocumentKey)

Aggregations

Query (com.google.firebase.firestore.core.Query)189 Test (org.junit.Test)179 BundledQuery (com.google.firebase.firestore.bundle.BundledQuery)40 NamedQuery (com.google.firebase.firestore.bundle.NamedQuery)39 StructuredQuery (com.google.firestore.v1.StructuredQuery)16 Target (com.google.firestore.v1.Target)13 DocumentsTarget (com.google.firestore.v1.Target.DocumentsTarget)13 QueryTarget (com.google.firestore.v1.Target.QueryTarget)13 DocumentSet (com.google.firebase.firestore.model.DocumentSet)12 MutableDocument (com.google.firebase.firestore.model.MutableDocument)8 ArrayList (java.util.ArrayList)8 TargetData (com.google.firebase.firestore.local.TargetData)7 FieldIndex (com.google.firebase.firestore.model.FieldIndex)7 DocumentKey (com.google.firebase.firestore.model.DocumentKey)6 ByteString (com.google.protobuf.ByteString)5 Document (com.google.firebase.firestore.model.Document)4 HashMap (java.util.HashMap)4 Target (com.google.firebase.firestore.core.Target)3 SnapshotVersion (com.google.firebase.firestore.model.SnapshotVersion)3 Map (java.util.Map)3