Search in sources :

Example 71 with DocumentSnapshot

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

the class ITBulkWriterTest method bulkWriterUpdate.

@Test
public void bulkWriterUpdate() throws Exception {
    DocumentReference docRef = randomColl.document();
    docRef.set(Collections.singletonMap("foo", "oldValue")).get();
    BulkWriter writer = firestore.bulkWriter();
    ApiFuture<WriteResult> result = writer.update(docRef, "foo", "newValue");
    writer.close();
    assertNotNull(result.get().getUpdateTime());
    DocumentSnapshot snapshot = docRef.get().get();
    assertEquals("newValue", snapshot.get("foo"));
}
Also used : DocumentSnapshot(com.google.cloud.firestore.DocumentSnapshot) WriteResult(com.google.cloud.firestore.WriteResult) BulkWriter(com.google.cloud.firestore.BulkWriter) DocumentReference(com.google.cloud.firestore.DocumentReference) Test(org.junit.Test)

Example 72 with DocumentSnapshot

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

the class ITBulkWriterTest method bulkWriterSet.

@Test
public void bulkWriterSet() throws Exception {
    DocumentReference docRef = randomColl.document();
    BulkWriter writer = firestore.bulkWriter();
    ApiFuture<WriteResult> result = writer.set(docRef, Collections.singletonMap("foo", "bar"));
    writer.close();
    assertNotNull(result.get().getUpdateTime());
    DocumentSnapshot snapshot = docRef.get().get();
    assertEquals("bar", snapshot.get("foo"));
}
Also used : DocumentSnapshot(com.google.cloud.firestore.DocumentSnapshot) WriteResult(com.google.cloud.firestore.WriteResult) BulkWriter(com.google.cloud.firestore.BulkWriter) DocumentReference(com.google.cloud.firestore.DocumentReference) Test(org.junit.Test)

Example 73 with DocumentSnapshot

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

the class ITSystemTest method testRecursiveDeleteNestedDocument.

@Test
public void testRecursiveDeleteNestedDocument() throws Exception {
    setupRecursiveDeleteTest();
    DocumentReference document = randomColl.document("bob/parentsCol/daniel");
    firestore.recursiveDelete(document).get();
    DocumentSnapshot snap = document.get().get();
    assertFalse(snap.exists());
    assertEquals(1, countDocumentChildren(randomColl.document("bob")));
    assertEquals(3, 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 74 with DocumentSnapshot

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

the class ITSystemTest method addDocument.

@Test
public void addDocument() throws Exception {
    DocumentReference documentReference = randomColl.add(SINGLE_FIELD_MAP).get();
    assertEquals(20, documentReference.getId().length());
    DocumentSnapshot documentSnapshot = documentReference.get().get();
    assertEquals(SINGLE_FIELD_OBJECT, documentSnapshot.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 75 with DocumentSnapshot

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

the class ITSystemTest method deserializeCustomList.

@Test
public void deserializeCustomList() throws Exception {
    LocalFirestoreHelper.CustomList customList = new LocalFirestoreHelper.CustomList();
    customList.fooList = FOO_LIST;
    DocumentReference documentReference = randomColl.document("doc1");
    documentReference.set(customList).get();
    DocumentSnapshot documentSnapshots = documentReference.get().get();
    LocalFirestoreHelper.CustomList targetCustomList = documentSnapshots.toObject(LocalFirestoreHelper.CustomList.class);
    assertEquals(FOO_LIST, targetCustomList.fooList);
    assertEquals(SINGLE_FIELD_OBJECT, targetCustomList.fooList.get(0));
}
Also used : QueryDocumentSnapshot(com.google.cloud.firestore.QueryDocumentSnapshot) DocumentSnapshot(com.google.cloud.firestore.DocumentSnapshot) LocalFirestoreHelper(com.google.cloud.firestore.LocalFirestoreHelper) DocumentReference(com.google.cloud.firestore.DocumentReference) 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