Search in sources :

Example 91 with Value

use of com.google.firestore.v1beta1.Value in project firebase-android-sdk by firebase.

the class MutationTest method testAppliesLocalServerTimestampTransformsToDocuments.

@Test
public void testAppliesLocalServerTimestampTransformsToDocuments() {
    Map<String, Object> data = map("foo", map("bar", "bar-value"), "baz", "baz-value");
    MutableDocument transformedDoc = doc("collection/key", 1, data);
    Timestamp timestamp = Timestamp.now();
    Mutation transform = patchMutation("collection/key", map("foo.bar", FieldValue.serverTimestamp()));
    transform.applyToLocalView(transformedDoc, /* previousMask= */
    null, timestamp);
    // Server timestamps aren't parsed, so we manually insert it.
    ObjectValue expectedData = wrapObject(map("foo", map("bar", "<server-timestamp>"), "baz", "baz-value"));
    Value fieldValue = ServerTimestamps.valueOf(timestamp, wrap("bar-value"));
    expectedData.set(field("foo.bar"), fieldValue);
    MutableDocument expectedDoc = doc("collection/key", 1, expectedData).setHasLocalMutations();
    assertEquals(expectedDoc, transformedDoc);
}
Also used : ObjectValue(com.google.firebase.firestore.model.ObjectValue) MutableDocument(com.google.firebase.firestore.model.MutableDocument) ObjectValue(com.google.firebase.firestore.model.ObjectValue) FieldValue(com.google.firebase.firestore.FieldValue) Value(com.google.firestore.v1.Value) 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) Timestamp(com.google.firebase.Timestamp) Test(org.junit.Test)

Example 92 with Value

use of com.google.firestore.v1beta1.Value in project firebase-android-sdk by firebase.

the class RemoteSerializerTest method testEncodesDoubles.

@Test
public void testEncodesDoubles() {
    List<Double> tests = asList(Double.NEGATIVE_INFINITY, -Double.MAX_VALUE, Long.MAX_VALUE * -1.0 - 1.0, -2.0, -1.1, -1.0, -Double.MIN_VALUE, -Double.MIN_NORMAL, -0.0, 0.0, Double.MIN_NORMAL, Double.MIN_VALUE, 0.1, 1.1, Long.MAX_VALUE * 1.0, Double.MAX_VALUE, Double.POSITIVE_INFINITY);
    for (Double test : tests) {
        Value value = wrap(test);
        Value proto = Value.newBuilder().setDoubleValue(test).build();
        assertRoundTrip(value, proto, Value.ValueTypeCase.DOUBLE_VALUE);
    }
}
Also used : 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) Test(org.junit.Test)

Example 93 with Value

use of com.google.firestore.v1beta1.Value in project firebase-android-sdk by firebase.

the class RemoteSerializerTest method testEncodesDates.

@Test
public void testEncodesDates() {
    Calendar date1 = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    date1.set(2016, 0, 2, 10, 20, 50);
    date1.set(Calendar.MILLISECOND, 500);
    Calendar date2 = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    date2.set(2016, 5, 17, 10, 50, 15);
    date2.set(Calendar.MILLISECOND, 0);
    List<Date> tests = asList(date1.getTime(), date2.getTime());
    Timestamp ts1 = Timestamp.newBuilder().setNanos(500000000).setSeconds(1451730050).build();
    Timestamp ts2 = Timestamp.newBuilder().setNanos(0).setSeconds(1466160615).build();
    List<Value> expected = asList(Value.newBuilder().setTimestampValue(ts1).build(), Value.newBuilder().setTimestampValue(ts2).build());
    for (int i = 0; i < tests.size(); i++) {
        Value value = wrap(tests.get(i));
        assertRoundTrip(value, expected.get(i), Value.ValueTypeCase.TIMESTAMP_VALUE);
    }
}
Also used : Calendar(java.util.Calendar) 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) Timestamp(com.google.protobuf.Timestamp) Date(java.util.Date) GeoPoint(com.google.firebase.firestore.GeoPoint) Test(org.junit.Test)

Example 94 with Value

use of com.google.firestore.v1beta1.Value in project firebase-android-sdk by firebase.

the class RemoteSerializerTest method testEncodesBlobs.

@Test
public void testEncodesBlobs() {
    Value blob = wrap(TestUtil.blob(0, 1, 2, 3));
    Value.Builder proto = Value.newBuilder();
    proto.setBytesValue(TestUtil.byteString(0, 1, 2, 3));
    assertRoundTrip(blob, proto.build(), Value.ValueTypeCase.BYTES_VALUE);
}
Also used : 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) Test(org.junit.Test)

Example 95 with Value

use of com.google.firestore.v1beta1.Value in project firebase-android-sdk by firebase.

the class RemoteSerializerTest method testEncodesReferences.

@Test
public void testEncodesReferences() {
    DocumentReference value = ref("foo/bar");
    Value ref = wrap(value);
    Value.Builder proto = Value.newBuilder();
    proto.setReferenceValue("projects/project/databases/(default)/documents/foo/bar");
    assertRoundTrip(ref, proto.build(), Value.ValueTypeCase.REFERENCE_VALUE);
}
Also used : 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) DocumentReference(com.google.firebase.firestore.DocumentReference) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)126 Value (com.google.firestore.v1.Value)108 ArrayValue (com.google.firestore.v1.ArrayValue)73 LinkedHashSet (java.util.LinkedHashSet)71 ObjectValue (com.google.firebase.firestore.model.ObjectValue)53 NullValue (com.google.protobuf.NullValue)50 MapValue (com.google.firestore.v1.MapValue)47 ArrayList (java.util.ArrayList)30 HashMap (java.util.HashMap)25 Value (com.google.datastore.v1.Value)20 Map (java.util.Map)20 TableFieldSchema (com.google.api.services.bigquery.model.TableFieldSchema)17 List (java.util.List)17 Record (org.apache.avro.generic.GenericData.Record)16 SchemaAndRecord (org.apache.beam.sdk.io.gcp.bigquery.SchemaAndRecord)16 CoreMatchers.notNullValue (org.hamcrest.CoreMatchers.notNullValue)16 Set (java.util.Set)14 TestUtil.wrapObject (com.google.firebase.firestore.testutil.TestUtil.wrapObject)13 Nullable (androidx.annotation.Nullable)10 Value (com.google.privacy.dlp.v2.Value)9