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());
}
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);
}
Aggregations