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