use of com.google.firebase.Timestamp in project firebase-android-sdk by firebase.
the class TypeTest method testCanUseTypedAccessors.
@Test
public void testCanUseTypedAccessors() {
DocumentReference doc = testDoc();
Map<String, Object> data = map("null", null, "boolean", true, "string", "string", "double", 0.0, "int", 1L, "geoPoint", new GeoPoint(1.24, 4.56), "blob", blob(0, 1, 2), "date", new Date(), "timestamp", new Timestamp(100, 123000000), "reference", doc);
waitFor(doc.set(data));
DocumentSnapshot snapshot = waitFor(doc.get());
assertEquals(data.get("null"), snapshot.get("null"));
assertEquals(data.get("null"), snapshot.get(FieldPath.fromDotSeparatedPath("null")));
assertEquals(data.get("boolean"), snapshot.getBoolean("boolean"));
assertEquals(data.get("string"), snapshot.getString("string"));
assertEquals(data.get("double"), snapshot.getDouble("double"));
assertEquals(Long.valueOf(0), snapshot.getLong("double"));
assertEquals(data.get("int"), snapshot.getLong("int"));
assertEquals(Double.valueOf(1.0), snapshot.getDouble("int"));
assertEquals(data.get("geoPoint"), snapshot.getGeoPoint("geoPoint"));
assertEquals(data.get("blob"), snapshot.getBlob("blob"));
assertEquals(data.get("date"), snapshot.getDate("date"));
assertEquals(new Timestamp((Date) data.get("date")), snapshot.getTimestamp("date"));
assertEquals(data.get("timestamp"), snapshot.getTimestamp("timestamp"));
Timestamp timestamp = (Timestamp) data.get("timestamp");
assertEquals(timestamp.toDate(), snapshot.getDate("timestamp"));
assertTrue(data.get("reference") instanceof DocumentReference);
assertEquals(((DocumentReference) data.get("reference")).getPath(), doc.getPath());
}
use of com.google.firebase.Timestamp in project firebase-android-sdk by firebase.
the class TypeTest method testCanReadAndWriteDates.
@Test
public void testCanReadAndWriteDates() {
Date date = new Date(1491847082123L);
// Tests are set up to read back Timestamps, not Dates.
verifySuccessfulWriteReadCycle(map("date", new Timestamp(date)), testDoc());
}
use of com.google.firebase.Timestamp in project firebase-android-sdk by firebase.
the class WriteBatchTest method testCanWriteTheSameDocumentMultipleTimes.
@Test
public void testCanWriteTheSameDocumentMultipleTimes() {
DocumentReference doc = testDocument();
EventAccumulator<DocumentSnapshot> accumulator = new EventAccumulator<>();
doc.addSnapshotListener(MetadataChanges.INCLUDE, accumulator.listener());
DocumentSnapshot initialSnap = accumulator.await();
assertFalse(initialSnap.exists());
waitFor(doc.getFirestore().batch().delete(doc).set(doc, map("a", 1, "b", 1, "when", "when")).update(doc, map("b", 2, "when", FieldValue.serverTimestamp())).commit());
DocumentSnapshot localSnap = accumulator.await();
assertTrue(localSnap.getMetadata().hasPendingWrites());
assertEquals(map("a", 1L, "b", 2L, "when", null), localSnap.getData());
DocumentSnapshot serverSnap = accumulator.await();
assertFalse(serverSnap.getMetadata().hasPendingWrites());
Timestamp when = serverSnap.getTimestamp("when");
assertNotNull(when);
assertEquals(map("a", 1L, "b", 2L, "when", when), serverSnap.getData());
}
use of com.google.firebase.Timestamp in project firebase-android-sdk by firebase.
the class FieldsTest method testTimestampsAreTruncated.
@Test
public void testTimestampsAreTruncated() {
Timestamp originalTimestamp = new Timestamp(100, 123456789);
// Timestamps are currently truncated to microseconds after being written to the database.
Timestamp truncatedTimestamp = new Timestamp(originalTimestamp.getSeconds(), originalTimestamp.getNanoseconds() / 1000 * 1000);
DocumentReference docRef = testCollection().document();
waitFor(docRef.set(objectWithTimestamp(originalTimestamp)));
DocumentSnapshot snapshot = waitFor(docRef.get());
Map<String, Object> data = snapshot.getData();
Timestamp readTimestamp = (Timestamp) snapshot.get("timestamp");
assertThat(readTimestamp).isEqualTo(truncatedTimestamp);
assertThat(readTimestamp).isEqualTo(data.get("timestamp"));
Timestamp readNestedTimestamp = (Timestamp) snapshot.get("nested.timestamp2");
assertThat(readNestedTimestamp).isEqualTo(truncatedTimestamp);
@SuppressWarnings("unchecked") Map<String, Object> nestedObject = (Map<String, Object>) data.get("nested");
assertThat(nestedObject.get("timestamp2")).isEqualTo(readNestedTimestamp);
}
use of com.google.firebase.Timestamp in project firebase-android-sdk by firebase.
the class ValuesTest method testCanonicalIds.
@Test
public void testCanonicalIds() {
assertCanonicalId(TestUtil.wrap(null), "null");
assertCanonicalId(TestUtil.wrap(true), "true");
assertCanonicalId(TestUtil.wrap(false), "false");
assertCanonicalId(TestUtil.wrap(1), "1");
assertCanonicalId(TestUtil.wrap(1.0), "1.0");
assertCanonicalId(TestUtil.wrap(new Timestamp(30, 1000)), "time(30,1000)");
assertCanonicalId(TestUtil.wrap("a"), "a");
assertCanonicalId(TestUtil.wrap(blob(1, 2, 3)), "010203");
assertCanonicalId(wrapRef(dbId("p1", "d1"), key("c1/doc1")), "c1/doc1");
assertCanonicalId(TestUtil.wrap(new GeoPoint(30, 60)), "geo(30.0,60.0)");
assertCanonicalId(TestUtil.wrap(Arrays.asList(1, 2, 3)), "[1,2,3]");
assertCanonicalId(TestUtil.wrap(map("a", 1, "b", 2, "c", "3")), "{a:1,b:2,c:3}");
assertCanonicalId(TestUtil.wrap(map("a", Arrays.asList("b", map("c", new GeoPoint(30, 60))))), "{a:[b,{c:geo(30.0,60.0)}]}");
}
Aggregations