Search in sources :

Example 31 with Timestamp

use of com.google.firebase.Timestamp in project firebase-android-sdk by firebase.

the class SQLiteTargetCache method saveTargetData.

private void saveTargetData(TargetData targetData) {
    int targetId = targetData.getTargetId();
    String canonicalId = targetData.getTarget().getCanonicalId();
    Timestamp version = targetData.getSnapshotVersion().getTimestamp();
    com.google.firebase.firestore.proto.Target targetProto = localSerializer.encodeTargetData(targetData);
    db.execute("INSERT OR REPLACE INTO targets (" + "target_id, " + "canonical_id, " + "snapshot_version_seconds, " + "snapshot_version_nanos, " + "resume_token, " + "last_listen_sequence_number, " + "target_proto) " + "VALUES (?, ?, ?, ?, ?, ?, ?)", targetId, canonicalId, version.getSeconds(), version.getNanoseconds(), targetData.getResumeToken().toByteArray(), targetData.getSequenceNumber(), targetProto.toByteArray());
}
Also used : Timestamp(com.google.firebase.Timestamp)

Example 32 with Timestamp

use of com.google.firebase.Timestamp in project firebase-android-sdk by firebase.

the class UserDataWriterTest method testConvertsTimestampValue.

@Test
public void testConvertsTimestampValue() {
    List<Timestamp> testCases = asList(new Timestamp(0, 0), new Timestamp(1356048000L, 0));
    for (Timestamp t : testCases) {
        Value value = wrap(t);
        assertValueType(Value.ValueTypeCase.TIMESTAMP_VALUE, value);
        Object convertedValue = convertValue(value);
        assertEquals(t, convertedValue);
    }
}
Also used : ObjectValue(com.google.firebase.firestore.model.ObjectValue) Value(com.google.firestore.v1.Value) ArrayValue(com.google.firestore.v1.ArrayValue) TestUtil.wrapObject(com.google.firebase.firestore.testutil.TestUtil.wrapObject) Timestamp(com.google.firebase.Timestamp) Test(org.junit.Test)

Example 33 with Timestamp

use of com.google.firebase.Timestamp in project firebase-android-sdk by firebase.

the class UserDataWriterTest method testConvertsDateValue.

@Test
public void testConvertsDateValue() {
    UserDataWriter dateWriter = new UserDataWriter(TestUtil.firestore(), DocumentSnapshot.ServerTimestampBehavior.DEFAULT);
    List<Date> testCases = asList(new Date(0), new Date(1356048000000L));
    for (Date d : testCases) {
        Value value = wrap(d);
        assertValueType(Value.ValueTypeCase.TIMESTAMP_VALUE, value);
        Object convertedValue = dateWriter.convertValue(value);
        assertTrue(convertedValue instanceof Timestamp);
        assertEquals(d, ((Timestamp) convertedValue).toDate());
    }
}
Also used : ObjectValue(com.google.firebase.firestore.model.ObjectValue) Value(com.google.firestore.v1.Value) ArrayValue(com.google.firestore.v1.ArrayValue) TestUtil.wrapObject(com.google.firebase.firestore.testutil.TestUtil.wrapObject) Timestamp(com.google.firebase.Timestamp) Date(java.util.Date) Test(org.junit.Test)

Example 34 with Timestamp

use of com.google.firebase.Timestamp in project firebase-android-sdk by firebase.

the class QueryTest method testCanonicalIdsAreStable.

@Test
public void testCanonicalIdsAreStable() {
    // This test aims to ensure that we do not break canonical IDs, as they are used as keys in
    // the TargetCache.
    Query baseQuery = Query.atPath(ResourcePath.fromString("collection"));
    assertCanonicalId(baseQuery, "collection|f:|ob:__name__asc");
    assertCanonicalId(baseQuery.filter(filter("a", ">", "a")), "collection|f:a>a|ob:aasc__name__asc");
    assertCanonicalId(baseQuery.filter(filter("a", "<=", new GeoPoint(90.0, -90.0))), "collection|f:a<=geo(90.0,-90.0)|ob:aasc__name__asc");
    assertCanonicalId(baseQuery.filter(filter("a", "<=", new Timestamp(60, 3000))), "collection|f:a<=time(60,3000)|ob:aasc__name__asc");
    assertCanonicalId(baseQuery.filter(filter("a", ">=", Blob.fromBytes(new byte[] { 1, 2, 3 }))), "collection|f:a>=010203|ob:aasc__name__asc");
    assertCanonicalId(baseQuery.filter(filter("a", "==", Arrays.asList(1, 2, 3))), "collection|f:a==[1,2,3]|ob:__name__asc");
    assertCanonicalId(baseQuery.filter(filter("a", "!=", Arrays.asList(1, 2, 3))), "collection|f:a!=[1,2,3]|ob:aasc__name__asc");
    assertCanonicalId(baseQuery.filter(filter("a", "==", Double.NaN)), "collection|f:a==NaN|ob:__name__asc");
    assertCanonicalId(baseQuery.filter(filter("__name__", "==", ref("collection/id"))), "collection|f:__name__==collection/id|ob:__name__asc");
    assertCanonicalId(baseQuery.filter(filter("a", "==", map("a", "b", "inner", map("d", "c")))), "collection|f:a=={a:b,inner:{d:c}}|ob:__name__asc");
    assertCanonicalId(baseQuery.filter(filter("a", "in", Arrays.asList(1, 2, 3))), "collection|f:ain[1,2,3]|ob:__name__asc");
    assertCanonicalId(baseQuery.filter(filter("a", "not-in", Arrays.asList(1, 2, 3))), "collection|f:anot_in[1,2,3]|ob:aasc__name__asc");
    assertCanonicalId(baseQuery.filter(filter("a", "array-contains-any", Arrays.asList(1, 2, 3))), "collection|f:aarray_contains_any[1,2,3]|ob:__name__asc");
    assertCanonicalId(baseQuery.filter(filter("a", "array-contains", "a")), "collection|f:aarray_containsa|ob:__name__asc");
    assertCanonicalId(baseQuery.orderBy(orderBy("a")), "collection|f:|ob:aasc__name__asc");
    assertCanonicalId(baseQuery.orderBy(orderBy("a")).startAt(bound(/* inclusive= */
    true, "foo", Arrays.asList(1, 2, 3))), "collection|f:|ob:aasc__name__asc|lb:b:foo,[1,2,3]");
    assertCanonicalId(baseQuery.orderBy(orderBy("a")).endAt(bound(/* inclusive= */
    true, "foo", Arrays.asList(1, 2, 3))), "collection|f:|ob:aasc__name__asc|ub:a:foo,[1,2,3]");
    assertCanonicalId(baseQuery.limitToFirst(5), "collection|f:|ob:__name__asc|l:5");
    assertCanonicalId(baseQuery.limitToLast(5), "collection|f:|ob:__name__desc|l:5");
}
Also used : GeoPoint(com.google.firebase.firestore.GeoPoint) Timestamp(com.google.firebase.Timestamp) Test(org.junit.Test)

Example 35 with Timestamp

use of com.google.firebase.Timestamp in project firebase-android-sdk by firebase.

the class MutationTest method testAppliesServerAckedServerTimestampTransformsToDocuments.

@Test
public void testAppliesServerAckedServerTimestampTransformsToDocuments() {
    Map<String, Object> data = map("foo", map("bar", "bar-value"), "baz", "baz-value");
    MutableDocument transformedDoc = doc("collection/key", 1, data);
    Mutation transform = patchMutation("collection/key", map("foo.bar", FieldValue.serverTimestamp()));
    Timestamp serverTimestamp = new Timestamp(2, 0);
    MutationResult mutationResult = new MutationResult(version(1), Collections.singletonList(wrap(serverTimestamp)));
    transform.applyToRemoteDocument(transformedDoc, mutationResult);
    Map<String, Object> expectedData = map("foo", map("bar", serverTimestamp.toDate()), "baz", "baz-value");
    assertEquals(doc("collection/key", 1, expectedData).setHasCommittedMutations(), transformedDoc);
}
Also used : MutableDocument(com.google.firebase.firestore.model.MutableDocument) 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)

Aggregations

Timestamp (com.google.firebase.Timestamp)36 Test (org.junit.Test)18 MutableDocument (com.google.firebase.firestore.model.MutableDocument)7 Date (java.util.Date)6 DocumentKey (com.google.firebase.firestore.model.DocumentKey)5 SnapshotVersion (com.google.firebase.firestore.model.SnapshotVersion)5 ArrayList (java.util.ArrayList)5 GeoPoint (com.google.firebase.firestore.GeoPoint)4 ObjectValue (com.google.firebase.firestore.model.ObjectValue)4 TestUtil.wrapObject (com.google.firebase.firestore.testutil.TestUtil.wrapObject)4 Mutation (com.google.firebase.firestore.model.mutation.Mutation)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 TestUtil.setMutation (com.google.firebase.firestore.testutil.TestUtil.setMutation)3 Value (com.google.firestore.v1.Value)3 HashMap (java.util.HashMap)3 FieldValue (com.google.firebase.firestore.FieldValue)2 Query (com.google.firebase.firestore.core.Query)2