Search in sources :

Example 81 with DocumentSnapshot

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"));
}
Also used : QueryDocumentSnapshot(com.google.cloud.firestore.QueryDocumentSnapshot) DocumentSnapshot(com.google.cloud.firestore.DocumentSnapshot) DocumentReference(com.google.cloud.firestore.DocumentReference) Test(org.junit.Test)

Example 82 with DocumentSnapshot

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());
}
Also used : QueryDocumentSnapshot(com.google.cloud.firestore.QueryDocumentSnapshot) DocumentSnapshot(com.google.cloud.firestore.DocumentSnapshot) FirestoreBundleTest.verifyNamedQuery(com.google.cloud.firestore.FirestoreBundleTest.verifyNamedQuery) NamedQuery(com.google.firestore.bundle.NamedQuery) Query(com.google.cloud.firestore.Query) ArrayList(java.util.ArrayList) WriteBatch(com.google.cloud.firestore.WriteBatch) Test(org.junit.Test)

Example 83 with DocumentSnapshot

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));
}
Also used : QueryDocumentSnapshot(com.google.cloud.firestore.QueryDocumentSnapshot) DocumentSnapshot(com.google.cloud.firestore.DocumentSnapshot) SingleField(com.google.cloud.firestore.LocalFirestoreHelper.SingleField) Test(org.junit.Test)

Example 84 with DocumentSnapshot

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"));
}
Also used : QueryDocumentSnapshot(com.google.cloud.firestore.QueryDocumentSnapshot) DocumentSnapshot(com.google.cloud.firestore.DocumentSnapshot) DocumentReference(com.google.cloud.firestore.DocumentReference) Test(org.junit.Test)

Example 85 with DocumentSnapshot

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());
}
Also used : QueryDocumentSnapshot(com.google.cloud.firestore.QueryDocumentSnapshot) DocumentSnapshot(com.google.cloud.firestore.DocumentSnapshot) BundleElement(com.google.firestore.bundle.BundleElement) FirestoreBundle(com.google.cloud.firestore.FirestoreBundle) Test(org.junit.Test)

Aggregations

DocumentSnapshot (com.google.cloud.firestore.DocumentSnapshot)103 QueryDocumentSnapshot (com.google.cloud.firestore.QueryDocumentSnapshot)73 Test (org.junit.Test)52 DocumentReference (com.google.cloud.firestore.DocumentReference)49 QuerySnapshot (com.google.cloud.firestore.QuerySnapshot)23 ExecutionException (java.util.concurrent.ExecutionException)13 CollectionReference (com.google.cloud.firestore.CollectionReference)12 Query (com.google.cloud.firestore.Query)12 BaseIntegrationTest (com.example.firestore.BaseIntegrationTest)10 SingleField (com.google.cloud.firestore.LocalFirestoreHelper.SingleField)9 WriteResult (com.google.cloud.firestore.WriteResult)9 ArrayList (java.util.ArrayList)8 FileSystemExecutionException (bio.terra.service.filedata.exception.FileSystemExecutionException)6 HashMap (java.util.HashMap)6 BulkWriter (com.google.cloud.firestore.BulkWriter)5 City (com.example.firestore.snippets.model.City)4 Timestamp (com.google.cloud.Timestamp)4 FirestoreBundleTest.verifyNamedQuery (com.google.cloud.firestore.FirestoreBundleTest.verifyNamedQuery)4 AllSupportedTypes (com.google.cloud.firestore.LocalFirestoreHelper.AllSupportedTypes)4 WriteBatch (com.google.cloud.firestore.WriteBatch)4