use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.
the class QueryTest method testInFilters.
@Test
public void testInFilters() {
Query query = Query.atPath(ResourcePath.fromString("collection")).filter(filter("zip", "in", asList(12345)));
MutableDocument document = doc("collection/1", 0, map("zip", 12345));
assertTrue(query.matches(document));
// Value matches in array.
document = doc("collection/1", 0, map("zip", asList(12345)));
assertFalse(query.matches(document));
// Non-type match.
document = doc("collection/1", 0, map("zip", "12345"));
assertFalse(query.matches(document));
// Nested match.
document = doc("collection/1", 0, map("zip", asList("12345", map("zip", 12345))));
assertFalse(query.matches(document));
}
use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.
the class QueryTest method testInFiltersWithObjectValues.
@Test
public void testInFiltersWithObjectValues() {
Query query = Query.atPath(ResourcePath.fromString("collection")).filter(filter("zip", "in", asList(map("a", asList(42)))));
// Containing object in array.
MutableDocument document = doc("collection/1", 0, map("zip", asList(map("a", asList(42)))));
assertFalse(query.matches(document));
// Containing object.
document = doc("collection/1", 0, map("zip", map("a", asList(42))));
assertTrue(query.matches(document));
}
use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.
the class QueryTest method testArrayContainsFiltersWithObjectValues.
@Test
public void testArrayContainsFiltersWithObjectValues() {
// Search for arrays containing the object { a: [42] }
Query query = Query.atPath(ResourcePath.fromString("collection")).filter(filter("array", "array-contains", map("a", asList(42))));
// array without element
MutableDocument document = doc("collection/1", 0, map("array", asList(map("a", 42L), map("a", asList(42L, 43L)), map("b", asList(42L)), map("a", asList(42L), "b", 42L))));
assertFalse(query.matches(document));
// array with element
document = doc("collection/1", 0, map("array", asList(1L, "2", 42L, map("a", asList(42L)))));
assertTrue(query.matches(document));
}
use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.
the class QueryTest method testFiltersObjects.
@Test
public void testFiltersObjects() {
Query baseQuery = Query.atPath(ResourcePath.fromString("collection"));
MutableDocument doc1 = doc("collection/doc", 0, map("tags", map("foo", "foo", "a", 0, "b", true, "c", Double.NaN)));
List<Filter> matchingFilters = asList(filter("tags", "==", map("foo", "foo", "a", 0, "b", true, "c", Double.NaN)), filter("tags", "==", map("b", true, "a", 0, "foo", "foo", "c", Double.NaN)), filter("tags.foo", "==", "foo"));
List<Filter> nonMatchingFilters = asList(filter("tags", "==", "foo"), filter("tags", "==", map("foo", "foo", "a", 0, "b", true)));
for (Filter filter : matchingFilters) {
assertTrue(baseQuery.filter(filter).matches(doc1));
}
for (Filter filter : nonMatchingFilters) {
assertFalse(baseQuery.filter(filter).matches(doc1));
}
}
use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.
the class ViewTest method testViewsWithLimboDocumentsAreMarkedFromCache.
@Test
public void testViewsWithLimboDocumentsAreMarkedFromCache() {
Query query = messageQuery();
View view = new View(query, DocumentKey.emptyKeySet());
MutableDocument doc1 = doc("rooms/eros/messages/0", 0, map());
MutableDocument doc2 = doc("rooms/eros/messages/1", 0, map());
// Doc1 is contained in the local view, but we are not yet CURRENT so it is expected that the
// backend hasn't told us about all documents yet.
ViewChange change = applyChanges(view, doc1);
assertTrue(change.getSnapshot().isFromCache());
// Add doc2 to generate a snapshot. Doc1 is still missing.
View.DocumentChanges viewDocChanges = view.computeDocChanges(docUpdates(doc2));
change = view.applyChanges(viewDocChanges, targetChange(ByteString.EMPTY, true, asList(doc2), null, null));
// We are CURRENT but doc1 is in limbo.
assertTrue(change.getSnapshot().isFromCache());
// Add doc1 to the backend's result set.
change = view.applyChanges(viewDocChanges, targetChange(ByteString.EMPTY, true, asList(doc1), null, null));
assertFalse(change.getSnapshot().isFromCache());
}
Aggregations