use of com.google.cloud.firestore.DocumentSnapshot in project java-firestore by googleapis.
the class ITSystemTest method integerIncrement.
@Test
public void integerIncrement() throws ExecutionException, InterruptedException {
DocumentReference docRef = randomColl.document();
docRef.set(Collections.singletonMap("sum", 1L)).get();
docRef.update("sum", FieldValue.increment(2)).get();
DocumentSnapshot docSnap = docRef.get().get();
assertEquals(3L, docSnap.get("sum"));
}
use of com.google.cloud.firestore.DocumentSnapshot in project java-firestore by googleapis.
the class ITSystemTest method queryPaginationWithWhereClause.
@Test
public void queryPaginationWithWhereClause() throws ExecutionException, InterruptedException {
WriteBatch batch = firestore.batch();
for (int i = 0; i < 10; ++i) {
batch.set(randomColl.document(), map("val", i));
}
batch.commit().get();
Query query = randomColl.whereGreaterThanOrEqualTo("val", 1).limit(3);
List<DocumentSnapshot> results = new ArrayList<>();
int pageCount = paginateResults(query, results);
assertEquals(3, pageCount);
assertEquals(9, results.size());
}
use of com.google.cloud.firestore.DocumentSnapshot in project java-firestore by googleapis.
the class ITSystemTest method createDocumentWithValue.
@Test
public void createDocumentWithValue() throws Exception {
assertEquals(20, randomDoc.getId().length());
randomDoc.create(LocalFirestoreHelper.SINGLE_FIELD_PROTO).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 setWithIncrementAndMerge.
@Test
public void setWithIncrementAndMerge() throws ExecutionException, InterruptedException {
DocumentReference docRef = randomColl.document();
docRef.set(Collections.singletonMap("sum", 1L)).get();
docRef.set(Collections.singletonMap("sum", FieldValue.increment(2)), SetOptions.merge()).get();
DocumentSnapshot docSnap = docRef.get().get();
assertEquals(3L, docSnap.get("sum"));
}
use of com.google.cloud.firestore.DocumentSnapshot in project java-firestore by googleapis.
the class ITSystemTest method testBuildingBundleWhenDocumentDoesNotExist.
@Test
public void testBuildingBundleWhenDocumentDoesNotExist() throws Exception {
FirestoreBundle.Builder bundleBuilder = firestore.bundleBuilder("test-bundle");
DocumentSnapshot snapshot = randomDoc.get().get();
bundleBuilder.add(snapshot);
// Expected bundle elements are [bundleMetadata, documentMetadata]
List<BundleElement> elements = toBundleElements(bundleBuilder.build().toByteBuffer());
assertEquals(2, elements.size());
verifyMetadata(elements.get(0).getMetadata(), snapshot.getReadTime().toProto(), /*totalDocuments*/
1, /*expectEmptyContent*/
false);
assertEquals(BundledDocumentMetadata.newBuilder().setExists(false).setName(fullPath(randomDoc, firestore.getOptions())).setReadTime(snapshot.getReadTime().toProto()).build(), elements.get(1).getDocumentMetadata());
}
Aggregations