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));
}
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));
}
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));
}
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));
}
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));
}
Aggregations