Search in sources :

Example 6 with PatchMutation

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

Example 7 with PatchMutation

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

the class LocalSerializerTest method testPatchMutationAndTransFormMutationAreSquashed.

// TODO(b/174608374): Remove these tests once we perform a schema migration.
@Test
public void testPatchMutationAndTransFormMutationAreSquashed() {
    WriteBatch batchProto = com.google.firebase.firestore.proto.WriteBatch.newBuilder().setBatchId(42).addAllWrites(asList(patchProto, transformProto)).setLocalWriteTime(writeTimeProto).build();
    MutationBatch decoded = serializer.decodeMutationBatch(batchProto);
    assertEquals(1, decoded.getMutations().size());
    assertTrue(decoded.getMutations().get(0) instanceof PatchMutation);
    Write encoded = remoteSerializer.encodeMutation(decoded.getMutations().get(0));
    Write expected = new TestWriteBuilder().addPatch().addUpdateTransforms().build();
    assertEquals(expected, encoded);
}
Also used : Write(com.google.firestore.v1.Write) MutationBatch(com.google.firebase.firestore.model.mutation.MutationBatch) PatchMutation(com.google.firebase.firestore.model.mutation.PatchMutation) WriteBatch(com.google.firebase.firestore.proto.WriteBatch) Test(org.junit.Test)

Aggregations

PatchMutation (com.google.firebase.firestore.model.mutation.PatchMutation)7 MutationBatch (com.google.firebase.firestore.model.mutation.MutationBatch)4 Mutation (com.google.firebase.firestore.model.mutation.Mutation)3 SetMutation (com.google.firebase.firestore.model.mutation.SetMutation)3 WriteBatch (com.google.firebase.firestore.proto.WriteBatch)3 Write (com.google.firestore.v1.Write)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 ImmutableSortedMap (com.google.firebase.database.collection.ImmutableSortedMap)2 DocumentKey (com.google.firebase.firestore.model.DocumentKey)2 MutableDocument (com.google.firebase.firestore.model.MutableDocument)2 FieldTransform (com.google.firebase.firestore.model.mutation.FieldTransform)2 TestUtil.deleteMutation (com.google.firebase.firestore.testutil.TestUtil.deleteMutation)2 TestUtil.setMutation (com.google.firebase.firestore.testutil.TestUtil.setMutation)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Timestamp (com.google.firebase.Timestamp)1 UserDataReader (com.google.firebase.firestore.UserDataReader)1 ParsedUpdateData (com.google.firebase.firestore.core.UserData.ParsedUpdateData)1 DocumentCollections.emptyDocumentMap (com.google.firebase.firestore.model.DocumentCollections.emptyDocumentMap)1