Search in sources :

Example 11 with ResourcePath

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

the class EncodedPathTest method assertEncoded.

private void assertEncoded(String expected, ResourcePath path) {
    String encoded = EncodedPath.encode(path);
    assertEquals(expected, encoded);
    ResourcePath decoded = EncodedPath.decodeResourcePath(encoded);
    assertEquals(path, decoded);
    // Verify that the value round trips through the SQLite API too.
    db.execSQL("INSERT INTO keys VALUES (?)", new String[] { encoded });
    Cursor cursor = db.rawQuery("SELECT key FROM keys WHERE key = ?", new String[] { encoded });
    try {
        assertTrue(cursor.moveToNext());
        assertEquals(expected, cursor.getString(0));
    } finally {
        cursor.close();
    }
}
Also used : ResourcePath(com.google.firebase.firestore.model.ResourcePath) Cursor(android.database.Cursor)

Example 12 with ResourcePath

use of com.google.firebase.firestore.model.ResourcePath 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 13 with ResourcePath

use of com.google.firebase.firestore.model.ResourcePath 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 14 with ResourcePath

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

the class RemoteDocumentCacheTestCase method testGetAllFromUsesReadTimeNotUpdateTime.

@Test
public void testGetAllFromUsesReadTimeNotUpdateTime() {
    addTestDocumentAtPath("b/old", /* updateTime= */
    1, /* readTime= */
    2);
    addTestDocumentAtPath("b/new", /* updateTime= */
    2, /* readTime= */
    1);
    ResourcePath collection = path("b");
    Map<DocumentKey, MutableDocument> results = remoteDocumentCache.getAll(collection, IndexOffset.createSuccessor(version(1), -1));
    assertThat(results.values()).containsExactly(doc("b/old", 1, DOC_DATA));
}
Also used : ResourcePath(com.google.firebase.firestore.model.ResourcePath) DocumentKey(com.google.firebase.firestore.model.DocumentKey) MutableDocument(com.google.firebase.firestore.model.MutableDocument) Test(org.junit.Test)

Example 15 with ResourcePath

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

the class RemoteDocumentCacheTestCase method testGetAllFromExcludesSubcollections.

@Test
public void testGetAllFromExcludesSubcollections() {
    addTestDocumentAtPath("a/1");
    addTestDocumentAtPath("a/1/b/1");
    addTestDocumentAtPath("a/2");
    ResourcePath collection = path("a");
    Map<DocumentKey, MutableDocument> results = remoteDocumentCache.getAll(collection, IndexOffset.NONE);
    assertThat(results.values()).containsExactly(doc("a/1", 42, DOC_DATA), doc("a/2", 42, DOC_DATA));
}
Also used : ResourcePath(com.google.firebase.firestore.model.ResourcePath) DocumentKey(com.google.firebase.firestore.model.DocumentKey) MutableDocument(com.google.firebase.firestore.model.MutableDocument) Test(org.junit.Test)

Aggregations

ResourcePath (com.google.firebase.firestore.model.ResourcePath)34 MutableDocument (com.google.firebase.firestore.model.MutableDocument)13 DocumentKey (com.google.firebase.firestore.model.DocumentKey)12 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)8 OrderBy (com.google.firebase.firestore.core.OrderBy)4 HashMap (java.util.HashMap)4 Bound (com.google.firebase.firestore.core.Bound)3 Cursor (android.database.Cursor)2 SQLiteStatement (android.database.sqlite.SQLiteStatement)2 ImmutableSortedMap (com.google.firebase.database.collection.ImmutableSortedMap)2 ImmutableSortedSet (com.google.firebase.database.collection.ImmutableSortedSet)2 FieldFilter (com.google.firebase.firestore.core.FieldFilter)2 Filter (com.google.firebase.firestore.core.Filter)2 Query (com.google.firebase.firestore.core.Query)2 EncodedPath.decodeResourcePath (com.google.firebase.firestore.local.EncodedPath.decodeResourcePath)2 DocumentCollections.emptyDocumentMap (com.google.firebase.firestore.model.DocumentCollections.emptyDocumentMap)2 SnapshotVersion (com.google.firebase.firestore.model.SnapshotVersion)2 BackgroundQueue (com.google.firebase.firestore.util.BackgroundQueue)2 CollectionSelector (com.google.firestore.v1.StructuredQuery.CollectionSelector)2