Search in sources :

Example 31 with Mutation

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

the class RemoteSerializerTest method assertRoundTripForMutation.

private void assertRoundTripForMutation(Mutation mutation, Write proto) {
    Write actualProto = serializer.encodeMutation(mutation);
    assertEquals(proto, actualProto);
    Mutation actualMutation = serializer.decodeMutation(proto);
    assertEquals(mutation, actualMutation);
}
Also used : Write(com.google.firestore.v1.Write) Mutation(com.google.firebase.firestore.model.mutation.Mutation) TestUtil.setMutation(com.google.firebase.firestore.testutil.TestUtil.setMutation) TestUtil.verifyMutation(com.google.firebase.firestore.testutil.TestUtil.verifyMutation) TestUtil.deleteMutation(com.google.firebase.firestore.testutil.TestUtil.deleteMutation) TestUtil.patchMutation(com.google.firebase.firestore.testutil.TestUtil.patchMutation) TestUtil.mergeMutation(com.google.firebase.firestore.testutil.TestUtil.mergeMutation)

Example 32 with Mutation

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

the class RemoteSerializerTest method testEncodesArrayMutations.

@Test
public void testEncodesArrayMutations() {
    Mutation mutation = setMutation("docs/1", map("a", com.google.firebase.firestore.FieldValue.arrayUnion("a", 2), "bar", com.google.firebase.firestore.FieldValue.arrayRemove(map("x", 1))));
    Write expected = Write.newBuilder().setUpdate(Document.newBuilder().setName("projects/p/databases/d/documents/docs/1")).addUpdateTransforms(FieldTransform.newBuilder().setFieldPath("a").setAppendMissingElements(ArrayValue.newBuilder().addValues(wrap("a")).addValues(wrap(2)))).addUpdateTransforms(FieldTransform.newBuilder().setFieldPath("bar").setRemoveAllFromArray(ArrayValue.newBuilder().addValues(wrap(map("x", 1))))).build();
    assertRoundTripForMutation(mutation, expected);
    mutation = patchMutation("docs/1", map("a", com.google.firebase.firestore.FieldValue.arrayUnion("a", 2), "bar.baz", com.google.firebase.firestore.FieldValue.arrayRemove(map("x", 1))));
    expected = Write.newBuilder().setUpdate(Document.newBuilder().setName("projects/p/databases/d/documents/docs/1")).setUpdateMask(DocumentMask.newBuilder().build()).addUpdateTransforms(FieldTransform.newBuilder().setFieldPath("a").setAppendMissingElements(ArrayValue.newBuilder().addValues(wrap("a")).addValues(wrap(2)))).addUpdateTransforms(FieldTransform.newBuilder().setFieldPath("bar.baz").setRemoveAllFromArray(ArrayValue.newBuilder().addValues(wrap(map("x", 1))))).setCurrentDocument(Precondition.newBuilder().setExists(true)).build();
    assertRoundTripForMutation(mutation, expected);
}
Also used : Write(com.google.firestore.v1.Write) Mutation(com.google.firebase.firestore.model.mutation.Mutation) TestUtil.setMutation(com.google.firebase.firestore.testutil.TestUtil.setMutation) TestUtil.verifyMutation(com.google.firebase.firestore.testutil.TestUtil.verifyMutation) TestUtil.deleteMutation(com.google.firebase.firestore.testutil.TestUtil.deleteMutation) TestUtil.patchMutation(com.google.firebase.firestore.testutil.TestUtil.patchMutation) TestUtil.mergeMutation(com.google.firebase.firestore.testutil.TestUtil.mergeMutation) Test(org.junit.Test)

Example 33 with Mutation

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

the class RemoteSerializerTest method testEncodesPatchMutation.

@Test
public void testEncodesPatchMutation() {
    Mutation mutation = patchMutation("docs/1", map("key", "value", "key2", true));
    Write expected = Write.newBuilder().setUpdate(Document.newBuilder().setName("projects/p/databases/d/documents/docs/1").putFields("key", Value.newBuilder().setStringValue("value").build()).putFields("key2", Value.newBuilder().setBooleanValue(true).build())).setUpdateMask(DocumentMask.newBuilder().addAllFieldPaths(asList("key", "key2"))).setCurrentDocument(Precondition.newBuilder().setExists(true)).build();
    assertRoundTripForMutation(mutation, expected);
}
Also used : Write(com.google.firestore.v1.Write) Mutation(com.google.firebase.firestore.model.mutation.Mutation) TestUtil.setMutation(com.google.firebase.firestore.testutil.TestUtil.setMutation) TestUtil.verifyMutation(com.google.firebase.firestore.testutil.TestUtil.verifyMutation) TestUtil.deleteMutation(com.google.firebase.firestore.testutil.TestUtil.deleteMutation) TestUtil.patchMutation(com.google.firebase.firestore.testutil.TestUtil.patchMutation) TestUtil.mergeMutation(com.google.firebase.firestore.testutil.TestUtil.mergeMutation) Test(org.junit.Test)

Example 34 with Mutation

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

the class RemoteSerializerTest method testEncodeSetMutation.

@Test
public void testEncodeSetMutation() {
    Mutation mutation = setMutation("docs/1", map("key", "value"));
    Write expected = Write.newBuilder().setUpdate(Document.newBuilder().setName("projects/p/databases/d/documents/docs/1").putFields("key", Value.newBuilder().setStringValue("value").build())).build();
    assertRoundTripForMutation(mutation, expected);
}
Also used : Write(com.google.firestore.v1.Write) Mutation(com.google.firebase.firestore.model.mutation.Mutation) TestUtil.setMutation(com.google.firebase.firestore.testutil.TestUtil.setMutation) TestUtil.verifyMutation(com.google.firebase.firestore.testutil.TestUtil.verifyMutation) TestUtil.deleteMutation(com.google.firebase.firestore.testutil.TestUtil.deleteMutation) TestUtil.patchMutation(com.google.firebase.firestore.testutil.TestUtil.patchMutation) TestUtil.mergeMutation(com.google.firebase.firestore.testutil.TestUtil.mergeMutation) Test(org.junit.Test)

Example 35 with Mutation

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

the class RemoteSerializerTest method testEncodeDeleteMutation.

@Test
public void testEncodeDeleteMutation() {
    Mutation mutation = deleteMutation("docs/1");
    Write expected = Write.newBuilder().setDelete("projects/p/databases/d/documents/docs/1").build();
    assertRoundTripForMutation(mutation, expected);
}
Also used : Write(com.google.firestore.v1.Write) Mutation(com.google.firebase.firestore.model.mutation.Mutation) TestUtil.setMutation(com.google.firebase.firestore.testutil.TestUtil.setMutation) TestUtil.verifyMutation(com.google.firebase.firestore.testutil.TestUtil.verifyMutation) TestUtil.deleteMutation(com.google.firebase.firestore.testutil.TestUtil.deleteMutation) TestUtil.patchMutation(com.google.firebase.firestore.testutil.TestUtil.patchMutation) TestUtil.mergeMutation(com.google.firebase.firestore.testutil.TestUtil.mergeMutation) 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