Search in sources :

Example 71 with CollectionReference

use of com.google.cloud.firestore.CollectionReference in project java-firestore by googleapis.

the class RetrieveDataSnippetsIT method testGetSubcollections.

@Test
public void testGetSubcollections() throws Exception {
    // Add a landmark subcollection
    Map<String, String> data = new HashMap<>();
    data.put("foo", "bar");
    db.document("cities/SF/landmarks/example").set(data).get();
    Iterable<CollectionReference> collections = retrieveDataSnippets.listCollections();
    List<CollectionReference> collectionList = new ArrayList<>();
    for (CollectionReference collRef : collections) {
        collectionList.add(collRef);
    }
    assertEquals(collectionList.size(), 1);
    assertEquals(collectionList.get(0).getId(), "landmarks");
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CollectionReference(com.google.cloud.firestore.CollectionReference) Test(org.junit.Test) BaseIntegrationTest(com.example.firestore.BaseIntegrationTest)

Example 72 with CollectionReference

use of com.google.cloud.firestore.CollectionReference in project java-firestore by googleapis.

the class ManageDataSnippetsIT method testWriteBatchIsSuccessful.

@Test
public void testWriteBatchIsSuccessful() throws Exception {
    manageDataSnippets.writeBatch();
    CollectionReference collection = db.collection("cities");
    ApiFuture<DocumentSnapshot> document = collection.document("NYC").get();
    assertTrue(document.get().exists());
    DocumentReference documentReference = collection.document("SF");
    Map<String, Object> data = getDocumentDataAsMap(documentReference);
    assertTrue(data.containsKey("population"));
    document = collection.document("LA").get();
    assertFalse(document.get().exists());
}
Also used : DocumentSnapshot(com.google.cloud.firestore.DocumentSnapshot) CollectionReference(com.google.cloud.firestore.CollectionReference) DocumentReference(com.google.cloud.firestore.DocumentReference) Test(org.junit.Test) BaseIntegrationTest(com.example.firestore.BaseIntegrationTest)

Aggregations

CollectionReference (com.google.cloud.firestore.CollectionReference)72 Query (com.google.cloud.firestore.Query)48 QuerySnapshot (com.google.cloud.firestore.QuerySnapshot)16 QueryDocumentSnapshot (com.google.cloud.firestore.QueryDocumentSnapshot)12 DocumentReference (com.google.cloud.firestore.DocumentReference)11 DocumentSnapshot (com.google.cloud.firestore.DocumentSnapshot)11 ArrayList (java.util.ArrayList)11 ExecutionException (java.util.concurrent.ExecutionException)9 Test (org.junit.Test)9 WriteResult (com.google.cloud.firestore.WriteResult)7 DatasetDataProject (bio.terra.service.dataset.DatasetDataProject)6 ApiFuture (com.google.api.core.ApiFuture)6 BaseIntegrationTest (com.example.firestore.BaseIntegrationTest)5 HashMap (java.util.HashMap)5 FileSystemExecutionException (bio.terra.service.filedata.exception.FileSystemExecutionException)4 City (com.example.firestore.snippets.model.City)4 Firestore (com.google.cloud.firestore.Firestore)4 FileSystemCorruptException (bio.terra.service.filedata.exception.FileSystemCorruptException)2 TranslateMessage (com.getstarted.background.objects.TranslateMessage)2 FirestoreOptions (com.google.cloud.firestore.FirestoreOptions)2