Search in sources :

Example 81 with MutableDocument

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

the class RemoteDocumentCacheTestCase method testSetDocumentToNewValue.

@Test
public void testSetDocumentToNewValue() {
    String path = "a/b";
    MutableDocument written = addTestDocumentAtPath(path);
    MutableDocument newDoc = doc(path, 57, map("data", 5));
    add(newDoc, version(57));
    assertNotEquals(written, newDoc);
    assertEquals(newDoc, get(path));
}
Also used : MutableDocument(com.google.firebase.firestore.model.MutableDocument) Test(org.junit.Test)

Example 82 with MutableDocument

use of com.google.firebase.firestore.model.MutableDocument 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)

Example 83 with MutableDocument

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

the class RemoteDocumentCacheTestCase method testGetAllFromSinceReadTimeAndDocumentKey.

@Test
public void testGetAllFromSinceReadTimeAndDocumentKey() {
    addTestDocumentAtPath("b/a", /* updateTime= */
    1, /* readTime= */
    11);
    addTestDocumentAtPath("b/b", /* updateTime= */
    2, /*  readTime= = */
    11);
    addTestDocumentAtPath("b/c", /* updateTime= */
    3, /*  readTime= = */
    11);
    addTestDocumentAtPath("b/d", /* updateTime= */
    4, /*  readTime= = */
    12);
    ResourcePath collection = path("b");
    Map<DocumentKey, MutableDocument> results = remoteDocumentCache.getAll(collection, IndexOffset.create(version(11), key("b/b"), -1));
    assertThat(results.values()).containsExactly(doc("b/c", 3, DOC_DATA), doc("b/d", 4, 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 84 with MutableDocument

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

the class RemoteDocumentCacheTestCase method testGetAllFromCollection.

@Test
public void testGetAllFromCollection() {
    addTestDocumentAtPath("a/1");
    addTestDocumentAtPath("b/1");
    addTestDocumentAtPath("b/2");
    addTestDocumentAtPath("c/1");
    ResourcePath collection = path("b");
    Map<DocumentKey, MutableDocument> results = remoteDocumentCache.getAll(collection, IndexOffset.NONE);
    assertThat(results.values()).containsExactly(doc("b/1", 42, DOC_DATA), doc("b/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)

Example 85 with MutableDocument

use of com.google.firebase.firestore.model.MutableDocument 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)

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