Search in sources :

Example 46 with MutableDocument

use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.

the class QueryTest method testComplexObjectFilters.

@Test
public void testComplexObjectFilters() {
    Query query1 = Query.atPath(ResourcePath.fromString("collection")).filter(filter("sort", "<=", 2));
    Query query2 = Query.atPath(ResourcePath.fromString("collection")).filter(filter("sort", ">=", 2));
    MutableDocument doc1 = doc("collection/1", 0, map("sort", 2));
    MutableDocument doc2 = doc("collection/2", 0, map("sort", asList()));
    MutableDocument doc3 = doc("collection/3", 0, map("sort", asList(1)));
    MutableDocument doc4 = doc("collection/4", 0, map("sort", map("foo", 2)));
    MutableDocument doc5 = doc("collection/5", 0, map("sort", map("foo", "bar")));
    MutableDocument doc6 = doc("collection/6", 0, map("sort", map()));
    MutableDocument doc7 = doc("collection/7", 0, map("sort", asList(3, 1)));
    assertTrue(query1.matches(doc1));
    assertFalse(query1.matches(doc2));
    assertFalse(query1.matches(doc3));
    assertFalse(query1.matches(doc4));
    assertFalse(query1.matches(doc5));
    assertFalse(query1.matches(doc6));
    assertFalse(query1.matches(doc7));
    assertTrue(query2.matches(doc1));
    assertFalse(query2.matches(doc2));
    assertFalse(query2.matches(doc3));
    assertFalse(query2.matches(doc4));
    assertFalse(query2.matches(doc5));
    assertFalse(query2.matches(doc6));
    assertFalse(query2.matches(doc7));
}
Also used : MutableDocument(com.google.firebase.firestore.model.MutableDocument) Test(org.junit.Test)

Example 47 with MutableDocument

use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.

the class QueryTest method testMatchesShallowAncestorQuery.

@Test
public void testMatchesShallowAncestorQuery() {
    ResourcePath queryPath = ResourcePath.fromString("rooms/eros/messages");
    MutableDocument doc1 = doc("rooms/eros/messages/1", 0, map("text", "msg1"));
    MutableDocument doc1meta = doc("rooms/eros/messages/1/meta/1", 0, map("meta", "meta-value"));
    MutableDocument doc2 = doc("rooms/eros/messages/2", 0, map("text", "msg2"));
    MutableDocument doc3 = doc("rooms/other/messages/1", 0, map("text", "msg3"));
    Query query = Query.atPath(queryPath);
    assertTrue(query.matches(doc1));
    assertFalse(query.matches(doc1meta));
    assertTrue(query.matches(doc2));
    assertFalse(query.matches(doc3));
}
Also used : ResourcePath(com.google.firebase.firestore.model.ResourcePath) MutableDocument(com.google.firebase.firestore.model.MutableDocument) Test(org.junit.Test)

Example 48 with MutableDocument

use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.

the class QueryTest method testArrayContainsAnyFilters.

@Test
public void testArrayContainsAnyFilters() {
    Query query = Query.atPath(ResourcePath.fromString("collection")).filter(filter("zip", "array-contains-any", asList(12345)));
    MutableDocument document = doc("collection/1", 0, map("zip", asList(12345)));
    assertTrue(query.matches(document));
    // Value matches in non-array.
    document = doc("collection/1", 0, map("zip", 12345));
    assertFalse(query.matches(document));
    // Non-type match.
    document = doc("collection/1", 0, map("zip", asList("12345")));
    assertFalse(query.matches(document));
    // Nested match.
    document = doc("collection/1", 0, map("zip", asList("12345", map("zip", asList(12345)))));
    assertFalse(query.matches(document));
}
Also used : MutableDocument(com.google.firebase.firestore.model.MutableDocument) Test(org.junit.Test)

Example 49 with MutableDocument

use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.

the class QueryTest method testEmptyFieldsAreAllowedForQueries.

@Test
public void testEmptyFieldsAreAllowedForQueries() {
    ResourcePath queryPath = ResourcePath.fromString("rooms/eros/messages");
    MutableDocument doc1 = doc("rooms/eros/messages/1", 0, map("text", "msg1"));
    MutableDocument doc2 = doc("rooms/eros/messages/2", 0, map());
    Query query = Query.atPath(queryPath).filter(filter("text", "==", "msg1"));
    assertTrue(query.matches(doc1));
    assertFalse(query.matches(doc2));
}
Also used : ResourcePath(com.google.firebase.firestore.model.ResourcePath) MutableDocument(com.google.firebase.firestore.model.MutableDocument) Test(org.junit.Test)

Example 50 with MutableDocument

use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.

the class QueryTest method testNullFilter.

@Test
public void testNullFilter() {
    Query query = Query.atPath(ResourcePath.fromString("collection")).filter(filter("sort", "==", null));
    MutableDocument doc1 = doc("collection/1", 0, map("sort", null));
    MutableDocument doc2 = doc("collection/2", 0, map("sort", 2));
    MutableDocument doc3 = doc("collection/3", 0, map("sort", 3.1));
    MutableDocument doc4 = doc("collection/4", 0, map("sort", false));
    MutableDocument doc5 = doc("collection/5", 0, map("sort", "string"));
    MutableDocument doc6 = doc("collection/6", 0, map("sort", Double.NaN));
    assertTrue(query.matches(doc1));
    assertFalse(query.matches(doc2));
    assertFalse(query.matches(doc3));
    assertFalse(query.matches(doc4));
    assertFalse(query.matches(doc5));
    assertFalse(query.matches(doc6));
    query = Query.atPath(ResourcePath.fromString("collection")).filter(filter("sort", "!=", null));
    assertFalse(query.matches(doc1));
    assertTrue(query.matches(doc2));
    assertTrue(query.matches(doc3));
    assertTrue(query.matches(doc4));
    assertTrue(query.matches(doc5));
    assertTrue(query.matches(doc6));
}
Also used : MutableDocument(com.google.firebase.firestore.model.MutableDocument) Test(org.junit.Test)

Aggregations

MutableDocument (com.google.firebase.firestore.model.MutableDocument)166 Test (org.junit.Test)125 DocumentKey (com.google.firebase.firestore.model.DocumentKey)43 Mutation.calculateOverlayMutation (com.google.firebase.firestore.model.mutation.Mutation.calculateOverlayMutation)30 TestUtil.deleteMutation (com.google.firebase.firestore.testutil.TestUtil.deleteMutation)30 TestUtil.mergeMutation (com.google.firebase.firestore.testutil.TestUtil.mergeMutation)30 TestUtil.patchMutation (com.google.firebase.firestore.testutil.TestUtil.patchMutation)30 TestUtil.setMutation (com.google.firebase.firestore.testutil.TestUtil.setMutation)30 HashMap (java.util.HashMap)22 TestUtil.wrapObject (com.google.firebase.firestore.testutil.TestUtil.wrapObject)18 ArrayList (java.util.ArrayList)18 TargetData (com.google.firebase.firestore.local.TargetData)15 WatchTargetChange (com.google.firebase.firestore.remote.WatchChange.WatchTargetChange)14 DocumentChange (com.google.firebase.firestore.remote.WatchChange.DocumentChange)13 ResourcePath (com.google.firebase.firestore.model.ResourcePath)12 Query (com.google.firebase.firestore.core.Query)10 Map (java.util.Map)10 SnapshotVersion (com.google.firebase.firestore.model.SnapshotVersion)8 Document (com.google.firebase.firestore.model.Document)7 Timestamp (com.google.firebase.Timestamp)6