use of com.google.cloud.firestore.DocumentSnapshot in project java-firestore by googleapis.
the class ITSystemTest method createDocument.
@Test
public void createDocument() throws Exception {
assertEquals(20, randomDoc.getId().length());
randomDoc.create(SINGLE_FIELD_MAP).get();
DocumentSnapshot documentSnapshot = randomDoc.get().get();
assertEquals(SINGLE_FIELD_OBJECT, documentSnapshot.toObject(SingleField.class));
}
use of com.google.cloud.firestore.DocumentSnapshot in project java-firestore by googleapis.
the class ITSystemTest method getAllWithObserver.
@Test
public void getAllWithObserver() throws Exception {
DocumentReference ref1 = randomColl.document("doc1");
ref1.set(ALL_SUPPORTED_TYPES_MAP).get();
DocumentReference ref2 = randomColl.document("doc2");
ref2.set(ALL_SUPPORTED_TYPES_MAP).get();
DocumentReference ref3 = randomColl.document("doc3");
final DocumentReference[] documentReferences = { ref1, ref2, ref3 };
StreamConsumer<DocumentSnapshot> consumer = new StreamConsumer<>();
firestore.getAll(documentReferences, FieldMask.of("foo"), consumer);
final List<DocumentSnapshot> documentSnapshots = consumer.consume().get();
assertEquals(ALL_SUPPORTED_TYPES_OBJECT, documentSnapshots.get(0).toObject(AllSupportedTypes.class));
assertEquals(ALL_SUPPORTED_TYPES_OBJECT, documentSnapshots.get(1).toObject(AllSupportedTypes.class));
assertNotEquals(ALL_SUPPORTED_TYPES_OBJECT, documentSnapshots.get(2).toObject(AllSupportedTypes.class));
assertEquals(ref1.getId(), documentSnapshots.get(0).getId());
assertEquals(ref2.getId(), documentSnapshots.get(1).getId());
assertEquals(ref3.getId(), documentSnapshots.get(2).getId());
assertEquals(3, documentSnapshots.size());
}
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());
}
Aggregations