Search in sources :

Example 21 with ObjectValue

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

the class BundleSerializerTest method assertDecodesValue.

private void assertDecodesValue(String json, Value proto) throws JSONException {
    String documentJson = "{\n" + "  name: '" + TEST_DOCUMENT + "',\n" + "  fields: {\n" + "    foo:\n" + json + "\n" + "  },\n" + "  crateTime: '2020-01-01T00:00:01.000000001Z',\n" + "  updateTime: '2020-01-01T00:00:02.000000002Z'\n" + "}";
    BundleDocument actualDocument = serializer.decodeDocument(new JSONObject(documentJson));
    BundleDocument expectedDocument = new BundleDocument(MutableDocument.newFoundDocument(DocumentKey.fromName(TEST_DOCUMENT), new SnapshotVersion(new com.google.firebase.Timestamp(1577836802, 2)), new ObjectValue(Value.newBuilder().setMapValue(MapValue.newBuilder().putFields("foo", proto)).build())));
    assertEquals(expectedDocument, actualDocument);
}
Also used : ObjectValue(com.google.firebase.firestore.model.ObjectValue) JSONObject(org.json.JSONObject) SnapshotVersion(com.google.firebase.firestore.model.SnapshotVersion)

Example 22 with ObjectValue

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

the class UserDataWriterTest method testConvertsSimpleObjects.

@Test
public void testConvertsSimpleObjects() {
    // Guava doesn't like null values, so we create a copy of the Immutable map without
    // the null value and then add the null value later.
    Map<String, Object> actual = map("a", "foo", "b", 1, "c", true, "d", null);
    ObjectValue wrappedExpected = fromMap("a", wrap("foo"), "b", wrap(1L), "c", wrap(true), "d", wrap(null));
    ObjectValue wrappedActual = wrapObject(actual);
    assertEquals(wrappedActual, wrappedExpected);
}
Also used : ObjectValue(com.google.firebase.firestore.model.ObjectValue) TestUtil.wrapObject(com.google.firebase.firestore.testutil.TestUtil.wrapObject) Test(org.junit.Test)

Example 23 with ObjectValue

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

the class RemoteSerializerTest method testEncodesNestedObjects.

@Test
public void testEncodesNestedObjects() {
    ObjectValue model = TestUtil.wrapObject(map("b", true, "d", Double.MAX_VALUE, "i", 1, "n", null, "s", "foo", "a", asList(2, "bar", map("b", false)), "o", map("d", 100, "nested", map("e", Long.MIN_VALUE))));
    MapValue.Builder inner = MapValue.newBuilder().putFields("b", Value.newBuilder().setBooleanValue(false).build());
    ArrayValue.Builder array = ArrayValue.newBuilder().addValues(Value.newBuilder().setIntegerValue(2)).addValues(Value.newBuilder().setStringValue("bar")).addValues(Value.newBuilder().setMapValue(inner));
    inner = MapValue.newBuilder().putFields("e", Value.newBuilder().setIntegerValue(Long.MIN_VALUE).build());
    MapValue.Builder middle = MapValue.newBuilder().putFields("d", Value.newBuilder().setIntegerValue(100).build()).putFields("nested", Value.newBuilder().setMapValue(inner).build());
    MapValue.Builder obj = MapValue.newBuilder().putFields("b", Value.newBuilder().setBooleanValue(true).build()).putFields("d", Value.newBuilder().setDoubleValue(Double.MAX_VALUE).build()).putFields("i", Value.newBuilder().setIntegerValue(1).build()).putFields("n", Value.newBuilder().setNullValueValue(0).build()).putFields("s", Value.newBuilder().setStringValue("foo").build()).putFields("a", Value.newBuilder().setArrayValue(array).build()).putFields("o", Value.newBuilder().setMapValue(middle).build());
    Value proto = Value.newBuilder().setMapValue(obj).build();
    assertRoundTrip(model.get(FieldPath.EMPTY_PATH), proto, Value.ValueTypeCase.MAP_VALUE);
}
Also used : ObjectValue(com.google.firebase.firestore.model.ObjectValue) ObjectValue(com.google.firebase.firestore.model.ObjectValue) Values.refValue(com.google.firebase.firestore.model.Values.refValue) NullValue(com.google.protobuf.NullValue) ServerValue(com.google.firestore.v1.DocumentTransform.FieldTransform.ServerValue) Value(com.google.firestore.v1.Value) Int32Value(com.google.protobuf.Int32Value) MapValue(com.google.firestore.v1.MapValue) ArrayValue(com.google.firestore.v1.ArrayValue) MapValue(com.google.firestore.v1.MapValue) ArrayValue(com.google.firestore.v1.ArrayValue) Test(org.junit.Test)

Example 24 with ObjectValue

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

the class MutationTest method testDeletesValuesFromTheFieldMask.

@Test
public void testDeletesValuesFromTheFieldMask() {
    Map<String, Object> data = map("foo", map("bar", "bar-value", "baz", "baz-value"));
    MutableDocument patchDoc = doc("collection/key", 1, data);
    DocumentKey key = key("collection/key");
    FieldMask mask = fieldMask("foo.bar");
    Mutation patch = new PatchMutation(key, new ObjectValue(), mask, Precondition.NONE);
    patch.applyToLocalView(patchDoc, /* previousMask= */
    null, Timestamp.now());
    Map<String, Object> expectedData = map("foo", map("baz", "baz-value"));
    assertEquals(doc("collection/key", 1, expectedData).setHasLocalMutations(), patchDoc);
}
Also used : ObjectValue(com.google.firebase.firestore.model.ObjectValue) MutableDocument(com.google.firebase.firestore.model.MutableDocument) DocumentKey(com.google.firebase.firestore.model.DocumentKey) TestUtil.wrapObject(com.google.firebase.firestore.testutil.TestUtil.wrapObject) 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) TestUtil.mergeMutation(com.google.firebase.firestore.testutil.TestUtil.mergeMutation) Mutation.calculateOverlayMutation(com.google.firebase.firestore.model.mutation.Mutation.calculateOverlayMutation) Test(org.junit.Test)

Aggregations

ObjectValue (com.google.firebase.firestore.model.ObjectValue)24 Value (com.google.firestore.v1.Value)12 FieldPath (com.google.firebase.firestore.model.FieldPath)8 Test (org.junit.Test)8 MutableDocument (com.google.firebase.firestore.model.MutableDocument)6 DocumentKey (com.google.firebase.firestore.model.DocumentKey)5 ParseAccumulator (com.google.firebase.firestore.core.UserData.ParseAccumulator)4 TestUtil.wrapObject (com.google.firebase.firestore.testutil.TestUtil.wrapObject)4 ArrayValue (com.google.firestore.v1.ArrayValue)4 MapValue (com.google.firestore.v1.MapValue)4 NullValue (com.google.protobuf.NullValue)4 ArrayRemoveFieldValue (com.google.firebase.firestore.FieldValue.ArrayRemoveFieldValue)3 ArrayUnionFieldValue (com.google.firebase.firestore.FieldValue.ArrayUnionFieldValue)3 DeleteFieldValue (com.google.firebase.firestore.FieldValue.DeleteFieldValue)3 ServerTimestampFieldValue (com.google.firebase.firestore.FieldValue.ServerTimestampFieldValue)3 SnapshotVersion (com.google.firebase.firestore.model.SnapshotVersion)3 Mutation.calculateOverlayMutation (com.google.firebase.firestore.model.mutation.Mutation.calculateOverlayMutation)3 TestUtil.deleteMutation (com.google.firebase.firestore.testutil.TestUtil.deleteMutation)3 TestUtil.mergeMutation (com.google.firebase.firestore.testutil.TestUtil.mergeMutation)3 TestUtil.patchMutation (com.google.firebase.firestore.testutil.TestUtil.patchMutation)3