Search in sources :

Example 76 with DocumentSnapshot

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

the class ITSystemTest method getAll.

@Test
public void getAll() throws Exception {
    DocumentReference ref1 = randomColl.document("doc1");
    DocumentReference ref2 = randomColl.document("doc2");
    ApiFutures.allAsList(ImmutableList.of(ref1.set(SINGLE_FIELD_MAP), ref2.set(SINGLE_FIELD_MAP))).get();
    List<DocumentSnapshot> documentSnapshots = firestore.getAll(ref1, ref2).get();
    assertEquals(2, documentSnapshots.size());
    assertEquals("doc1", documentSnapshots.get(0).getId());
    assertEquals(SINGLE_FIELD_OBJECT, documentSnapshots.get(0).toObject(SingleField.class));
    assertEquals("doc2", documentSnapshots.get(1).getId());
    assertEquals(SINGLE_FIELD_OBJECT, documentSnapshots.get(1).toObject(SingleField.class));
}
Also used : QueryDocumentSnapshot(com.google.cloud.firestore.QueryDocumentSnapshot) DocumentSnapshot(com.google.cloud.firestore.DocumentSnapshot) DocumentReference(com.google.cloud.firestore.DocumentReference) SingleField(com.google.cloud.firestore.LocalFirestoreHelper.SingleField) Test(org.junit.Test)

Example 77 with DocumentSnapshot

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

the class ITSystemTest method selectQuery.

@Test
public void selectQuery() throws Exception {
    addDocument("foo", 1, "bar", 2);
    QuerySnapshot querySnapshot = randomColl.select("foo").get().get();
    assertEquals(1, querySnapshot.size());
    DocumentSnapshot documentSnapshot = querySnapshot.getDocuments().get(0);
    assertEquals(1L, documentSnapshot.get("foo"));
    assertNull(documentSnapshot.get("bar"));
}
Also used : QueryDocumentSnapshot(com.google.cloud.firestore.QueryDocumentSnapshot) DocumentSnapshot(com.google.cloud.firestore.DocumentSnapshot) QuerySnapshot(com.google.cloud.firestore.QuerySnapshot) Test(org.junit.Test)

Example 78 with DocumentSnapshot

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

the class ITSystemTest method getFieldMaskWithDocumentReference.

@Test
public void getFieldMaskWithDocumentReference() throws Exception {
    DocumentReference ref = randomColl.document("doc1");
    ref.set(ALL_SUPPORTED_TYPES_MAP).get();
    DocumentSnapshot documentSnapshots = ref.get(FieldMask.of("foo", "foobar")).get();
    assertEquals("bar", documentSnapshots.get("foo"));
    assertNull(documentSnapshots.get("foobar"));
}
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 79 with DocumentSnapshot

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

the class ITSystemTest method testRecursiveDeleteLeafDocument.

@Test
public void testRecursiveDeleteLeafDocument() throws Exception {
    setupRecursiveDeleteTest();
    DocumentReference document = randomColl.document("bob/parentsCol/daniel/childCol/ernie");
    firestore.recursiveDelete(document).get();
    DocumentSnapshot snap = document.get().get();
    assertFalse(snap.exists());
    assertEquals(5, countCollectionChildren(randomColl));
}
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 80 with DocumentSnapshot

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

the class ITSystemTest method fieldDelete.

@Test
public void fieldDelete() throws Exception {
    Map<String, Object> fields = new HashMap<>();
    fields.put("foo1", "bar1");
    fields.put("foo2", "bar2");
    randomDoc.set(fields).get();
    DocumentSnapshot documentSnapshot = randomDoc.get().get();
    assertEquals("bar1", documentSnapshot.getString("foo1"));
    assertEquals("bar2", documentSnapshot.getString("foo2"));
    randomDoc.update("foo1", "bar3", "foo2", FieldValue.delete()).get();
    documentSnapshot = randomDoc.get().get();
    assertEquals("bar3", documentSnapshot.getString("foo1"));
    assertNull(documentSnapshot.getString("foo2"));
}
Also used : QueryDocumentSnapshot(com.google.cloud.firestore.QueryDocumentSnapshot) DocumentSnapshot(com.google.cloud.firestore.DocumentSnapshot) HashMap(java.util.HashMap) 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