|
22 | 22 | import com.example.firestore.snippets.model.City;
|
23 | 23 |
|
24 | 24 | import com.google.api.core.ApiFuture;
|
| 25 | +import com.google.cloud.firestore.CollectionReference; |
25 | 26 | import com.google.cloud.firestore.DocumentSnapshot;
|
26 | 27 | import com.google.cloud.firestore.Firestore;
|
27 | 28 | import com.google.cloud.firestore.FirestoreOptions;
|
28 | 29 | import com.google.cloud.firestore.QuerySnapshot;
|
| 30 | +import java.util.ArrayList; |
| 31 | +import java.util.HashMap; |
29 | 32 | import java.util.HashSet;
|
30 | 33 | import java.util.List;
|
31 | 34 | import java.util.Map;
|
@@ -99,6 +102,25 @@ public void testRetrieveAllDocuments() throws Exception {
|
99 | 102 | && docIds.contains("BJ"));
|
100 | 103 | }
|
101 | 104 |
|
| 105 | + @Test |
| 106 | + public void testGetSubcollections() throws Exception { |
| 107 | + // Add a landmark subcollection |
| 108 | + Map<String, String> data = new HashMap<>(); |
| 109 | + data.put("foo", "bar"); |
| 110 | + db.document("cities/SF/landmarks/example").set(data).get(); |
| 111 | + |
| 112 | + Iterable<CollectionReference> collections = |
| 113 | + retrieveDataSnippets.getCollections(); |
| 114 | + |
| 115 | + List<CollectionReference> collectionList = new ArrayList<>(); |
| 116 | + for (CollectionReference collRef : collections) { |
| 117 | + collectionList.add(collRef); |
| 118 | + } |
| 119 | + |
| 120 | + assertEquals(collectionList.size(), 1); |
| 121 | + assertEquals(collectionList.get(0).getId(), "landmarks"); |
| 122 | + } |
| 123 | + |
102 | 124 | private static void deleteAllDocuments() throws Exception {
|
103 | 125 | ApiFuture<QuerySnapshot> future = db.collection("cities").get();
|
104 | 126 | QuerySnapshot querySnapshot = future.get();
|
|
0 commit comments