Search in sources :

Example 36 with Mutation

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

the class DocumentOverlayCacheTestCase method saveOverlays.

void saveOverlays(int largestBatch, Mutation... mutations) {
    Map<DocumentKey, Mutation> data = new HashMap<>();
    for (Mutation mutation : mutations) {
        data.put(mutation.getKey(), mutation);
    }
    cache.saveOverlays(largestBatch, data);
}
Also used : HashMap(java.util.HashMap) DocumentKey(com.google.firebase.firestore.model.DocumentKey) Mutation(com.google.firebase.firestore.model.mutation.Mutation) TestUtil.deleteMutation(com.google.firebase.firestore.testutil.TestUtil.deleteMutation) TestUtil.setMutation(com.google.firebase.firestore.testutil.TestUtil.setMutation) TestUtil.patchMutation(com.google.firebase.firestore.testutil.TestUtil.patchMutation)

Example 37 with Mutation

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

the class DocumentOverlayCacheTestCase method testSaveOverlaysThrowsNullPointerExceptionOnNullMapValue.

@Test
public void testSaveOverlaysThrowsNullPointerExceptionOnNullMapValue() {
    Map<DocumentKey, Mutation> data = new HashMap<>();
    data.put(key("coll/doc"), null);
    NullPointerException e = assertThrows(NullPointerException.class, new ThrowingRunnable() {

        @Override
        public void run() {
            cache.saveOverlays(1, data);
        }
    });
    assertThat(e.getMessage()).contains("coll/doc");
}
Also used : HashMap(java.util.HashMap) DocumentKey(com.google.firebase.firestore.model.DocumentKey) Mutation(com.google.firebase.firestore.model.mutation.Mutation) TestUtil.deleteMutation(com.google.firebase.firestore.testutil.TestUtil.deleteMutation) TestUtil.setMutation(com.google.firebase.firestore.testutil.TestUtil.setMutation) TestUtil.patchMutation(com.google.firebase.firestore.testutil.TestUtil.patchMutation) ThrowingRunnable(org.junit.function.ThrowingRunnable) Test(org.junit.Test)

Example 38 with Mutation

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

the class DocumentOverlayCacheTestCase method testCanReadSavedOverlays.

@Test
public void testCanReadSavedOverlays() {
    Mutation m1 = patchMutation("coll/doc1", map("foo", "bar"));
    Mutation m2 = setMutation("coll/doc2", map("foo", "bar"));
    Mutation m3 = deleteMutation("coll/doc3");
    saveOverlays(3, m1, m2, m3);
    assertEquals(m1, cache.getOverlay(key("coll/doc1")).getMutation());
    assertEquals(m2, cache.getOverlay(key("coll/doc2")).getMutation());
    assertEquals(m3, cache.getOverlay(key("coll/doc3")).getMutation());
}
Also used : Mutation(com.google.firebase.firestore.model.mutation.Mutation) TestUtil.deleteMutation(com.google.firebase.firestore.testutil.TestUtil.deleteMutation) TestUtil.setMutation(com.google.firebase.firestore.testutil.TestUtil.setMutation) TestUtil.patchMutation(com.google.firebase.firestore.testutil.TestUtil.patchMutation) Test(org.junit.Test)

Example 39 with Mutation

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

the class DocumentOverlayCacheTestCase method testGetAllOverlaysForCollection.

@Test
public void testGetAllOverlaysForCollection() {
    Mutation m1 = patchMutation("coll/doc1", map("foo", "bar"));
    Mutation m2 = setMutation("coll/doc2", map("foo", "bar"));
    Mutation m3 = deleteMutation("coll/doc3");
    // m4 and m5 are not under "coll"
    Mutation m4 = setMutation("coll/doc1/sub/sub_doc", map("foo", "bar"));
    Mutation m5 = setMutation("other/doc1", map("foo", "bar"));
    saveOverlays(3, m1, m2, m3, m4, m5);
    Map<DocumentKey, Overlay> overlays = cache.getOverlays(path("coll"), -1);
    verifyOverlayContains(overlays, "coll/doc1", "coll/doc2", "coll/doc3");
}
Also used : DocumentKey(com.google.firebase.firestore.model.DocumentKey) Mutation(com.google.firebase.firestore.model.mutation.Mutation) TestUtil.deleteMutation(com.google.firebase.firestore.testutil.TestUtil.deleteMutation) TestUtil.setMutation(com.google.firebase.firestore.testutil.TestUtil.setMutation) TestUtil.patchMutation(com.google.firebase.firestore.testutil.TestUtil.patchMutation) Overlay(com.google.firebase.firestore.model.mutation.Overlay) Test(org.junit.Test)

Example 40 with Mutation

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

the class LocalSerializerTest method testEncodesMutationBatch.

@Test
public void testEncodesMutationBatch() {
    Mutation baseWrite = new PatchMutation(key("foo/bar"), TestUtil.wrapObject(map("a", "b")), FieldMask.fromSet(Collections.singleton(field("a"))), com.google.firebase.firestore.model.mutation.Precondition.NONE);
    Mutation set = setMutation("foo/bar", map("a", "b", "num", 1));
    Mutation patch = new PatchMutation(key("bar/baz"), TestUtil.wrapObject(map("a", "b", "num", 1)), fieldMask("a"), com.google.firebase.firestore.model.mutation.Precondition.exists(true));
    Mutation del = deleteMutation("baz/quux");
    MutationBatch model = new MutationBatch(42, writeTime, Collections.singletonList(baseWrite), asList(set, patch, del));
    Write baseWriteProto = Write.newBuilder().setUpdate(com.google.firestore.v1.Document.newBuilder().setName("projects/p/databases/d/documents/foo/bar").putFields("a", Value.newBuilder().setStringValue("b").build())).setUpdateMask(DocumentMask.newBuilder().addFieldPaths("a")).build();
    com.google.firebase.firestore.proto.WriteBatch batchProto = com.google.firebase.firestore.proto.WriteBatch.newBuilder().setBatchId(42).addBaseWrites(baseWriteProto).addAllWrites(asList(setProto, patchProto, deleteProto)).setLocalWriteTime(writeTimeProto).build();
    assertEquals(batchProto, serializer.encodeMutationBatch(model));
    MutationBatch decoded = serializer.decodeMutationBatch(batchProto);
    assertEquals(model.getBatchId(), decoded.getBatchId());
    assertEquals(model.getLocalWriteTime(), decoded.getLocalWriteTime());
    assertEquals(model.getMutations(), decoded.getMutations());
    assertEquals(model.getBaseMutations(), decoded.getBaseMutations());
    assertEquals(model.getKeys(), decoded.getKeys());
}
Also used : Write(com.google.firestore.v1.Write) MutationBatch(com.google.firebase.firestore.model.mutation.MutationBatch) WriteBatch(com.google.firebase.firestore.proto.WriteBatch) PatchMutation(com.google.firebase.firestore.model.mutation.PatchMutation) PatchMutation(com.google.firebase.firestore.model.mutation.PatchMutation) Mutation(com.google.firebase.firestore.model.mutation.Mutation) SetMutation(com.google.firebase.firestore.model.mutation.SetMutation) TestUtil.deleteMutation(com.google.firebase.firestore.testutil.TestUtil.deleteMutation) TestUtil.setMutation(com.google.firebase.firestore.testutil.TestUtil.setMutation) Test(org.junit.Test)

Aggregations

Mutation (com.google.firebase.firestore.model.mutation.Mutation)46 TestUtil.setMutation (com.google.firebase.firestore.testutil.TestUtil.setMutation)29 TestUtil.patchMutation (com.google.firebase.firestore.testutil.TestUtil.patchMutation)27 TestUtil.deleteMutation (com.google.firebase.firestore.testutil.TestUtil.deleteMutation)25 Test (org.junit.Test)25 DocumentKey (com.google.firebase.firestore.model.DocumentKey)18 MutationBatch (com.google.firebase.firestore.model.mutation.MutationBatch)13 Write (com.google.firestore.v1.Write)12 TestUtil.mergeMutation (com.google.firebase.firestore.testutil.TestUtil.mergeMutation)8 TestUtil.verifyMutation (com.google.firebase.firestore.testutil.TestUtil.verifyMutation)8 ArrayList (java.util.ArrayList)8 SetMutation (com.google.firebase.firestore.model.mutation.SetMutation)7 PatchMutation (com.google.firebase.firestore.model.mutation.PatchMutation)6 HashMap (java.util.HashMap)6 HashSet (java.util.HashSet)5 Map (java.util.Map)4 Timestamp (com.google.firebase.Timestamp)3 MutableDocument (com.google.firebase.firestore.model.MutableDocument)3 Overlay (com.google.firebase.firestore.model.mutation.Overlay)3 SQLiteStatement (android.database.sqlite.SQLiteStatement)2