Search in sources :

Example 26 with DocumentSnapshot

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

the class ITSystemTest method nestedQuery.

@Test
public void nestedQuery() throws Exception {
    randomColl = randomColl.document("foo").collection("bar");
    addDocument("foo", "bar");
    QuerySnapshot querySnapshot = randomColl.get().get();
    DocumentSnapshot documentSnapshot = querySnapshot.getDocuments().get(0);
    assertTrue(documentSnapshot.getReference().getPath().contains("/foo/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 27 with DocumentSnapshot

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

the class ITSystemTest method createDocumentWithFloat.

@Test
public void createDocumentWithFloat() throws Exception {
    assertEquals(20, randomDoc.getId().length());
    randomDoc.create(LocalFirestoreHelper.SINGLE_FLOAT_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 28 with DocumentSnapshot

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

the class ITSystemTest method readOnlyTransaction_successfulGet.

@Test
public void readOnlyTransaction_successfulGet() throws ExecutionException, InterruptedException, TimeoutException {
    final DocumentReference documentReference = randomColl.add(SINGLE_FIELD_MAP).get();
    final AtomicReference<DocumentSnapshot> ref = new AtomicReference<>();
    final ApiFuture<Void> runTransaction = firestore.runTransaction(transaction -> {
        final DocumentSnapshot snapshot = transaction.get(documentReference).get(5, TimeUnit.SECONDS);
        ref.compareAndSet(null, snapshot);
        return null;
    }, TransactionOptions.createReadOnlyOptionsBuilder().build());
    runTransaction.get(10, TimeUnit.SECONDS);
    assertEquals("bar", ref.get().get("foo"));
}
Also used : QueryDocumentSnapshot(com.google.cloud.firestore.QueryDocumentSnapshot) DocumentSnapshot(com.google.cloud.firestore.DocumentSnapshot) AtomicReference(java.util.concurrent.atomic.AtomicReference) DocumentReference(com.google.cloud.firestore.DocumentReference) Test(org.junit.Test)

Example 29 with DocumentSnapshot

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

the class ITSystemTest method deserializeCustomMap.

@Test
public void deserializeCustomMap() throws Exception {
    LocalFirestoreHelper.CustomMap customMap = new LocalFirestoreHelper.CustomMap();
    customMap.fooMap = FOO_MAP;
    DocumentReference documentReference = randomColl.document("doc1");
    documentReference.set(customMap).get();
    DocumentSnapshot documentSnapshots = documentReference.get().get();
    LocalFirestoreHelper.CustomMap targetCustomMap = documentSnapshots.toObject(LocalFirestoreHelper.CustomMap.class);
    assertEquals(FOO_MAP, targetCustomMap.fooMap);
    assertEquals(SINGLE_FIELD_OBJECT, targetCustomMap.fooMap.get("customMap"));
}
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)

Example 30 with DocumentSnapshot

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

the class ITSystemTest method getAllWithFieldMask.

@Test
public void getAllWithFieldMask() throws Exception {
    DocumentReference ref = randomColl.document("doc1");
    ref.set(ALL_SUPPORTED_TYPES_MAP).get();
    List<DocumentSnapshot> documentSnapshots = firestore.getAll(new DocumentReference[] { ref }, FieldMask.of("foo")).get();
    assertEquals(map("foo", "bar"), documentSnapshots.get(0).getData());
}
Also used : QueryDocumentSnapshot(com.google.cloud.firestore.QueryDocumentSnapshot) DocumentSnapshot(com.google.cloud.firestore.DocumentSnapshot) 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)7 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