use of com.google.cloud.firestore.DocumentSnapshot in project java-firestore by googleapis.
the class ITSystemTest method floatIncrement.
@Test
public void floatIncrement() throws ExecutionException, InterruptedException {
DocumentReference docRef = randomColl.document();
docRef.set(Collections.singletonMap("sum", 1.1)).get();
docRef.update("sum", FieldValue.increment(2.2)).get();
DocumentSnapshot docSnap = docRef.get().get();
assertEquals(3.3, (Double) docSnap.get("sum"), DOUBLE_EPSILON);
}
use of com.google.cloud.firestore.DocumentSnapshot in project java-firestore by googleapis.
the class ITSystemTest method timestampDoesntGetTruncatedDuringUpdate.
@Test
public void timestampDoesntGetTruncatedDuringUpdate() throws Exception {
DocumentReference documentReference = addDocument("time", Timestamp.ofTimeSecondsAndNanos(0, 123000));
DocumentSnapshot documentSnapshot = documentReference.get().get();
Timestamp timestamp = documentSnapshot.getTimestamp("time");
documentReference.update("time", timestamp);
documentSnapshot = documentReference.get().get();
timestamp = documentSnapshot.getTimestamp("time");
assertEquals(123000, timestamp.getNanos());
}
use of com.google.cloud.firestore.DocumentSnapshot in project java-firestore by googleapis.
the class ITSystemTest method setDocumentWithMerge.
@Test
public void setDocumentWithMerge() throws Exception {
Map<String, Object> originalMap = LocalFirestoreHelper.map("a.b", "c", "nested", map("d", "e"));
Map<String, Object> updateMap = LocalFirestoreHelper.map("f.g", "h", "nested", map("i", "j"));
Map<String, Object> resultMap = LocalFirestoreHelper.map("a.b", "c", "f.g", "h", "nested", map("d", "e", "i", "j"));
randomDoc.set(originalMap).get();
randomDoc.set(updateMap, SetOptions.merge()).get();
DocumentSnapshot documentSnapshot = randomDoc.get().get();
assertEquals(resultMap, documentSnapshot.getData());
}
use of com.google.cloud.firestore.DocumentSnapshot in project java-firestore by googleapis.
the class ITSystemTest method deleteDocument.
@Test
public void deleteDocument() throws Exception {
randomDoc.delete().get();
WriteResult writeResult = randomDoc.set(ALL_SUPPORTED_TYPES_MAP).get();
try {
randomDoc.delete(Precondition.updatedAt(Timestamp.ofTimeSecondsAndNanos(1, 0))).get();
fail();
} catch (ExecutionException e) {
assertTrue(e.getMessage().contains("FAILED_PRECONDITION"));
}
writeResult = randomDoc.delete(Precondition.updatedAt(writeResult.getUpdateTime())).get();
DocumentSnapshot documentSnapshot = randomDoc.get().get();
assertFalse(documentSnapshot.exists());
assertTrue(writeResult.getUpdateTime().getSeconds() > 0);
}
use of com.google.cloud.firestore.DocumentSnapshot in project java-firestore by googleapis.
the class ITBulkWriterTest method bulkWriterCreate.
@Test
public void bulkWriterCreate() throws Exception {
DocumentReference docRef = randomColl.document();
firestore.bulkWriter();
BulkWriter writer = firestore.bulkWriter();
ApiFuture<WriteResult> result = writer.create(docRef, Collections.singletonMap("foo", "bar"));
writer.close();
assertNotNull(result.get().getUpdateTime());
DocumentSnapshot snapshot = docRef.get().get();
assertEquals("bar", snapshot.get("foo"));
}
Aggregations