14
14
15
15
package com .google .firebase .firestore .local ;
16
16
17
+ import static com .google .common .truth .Truth .assertThat ;
17
18
import static com .google .firebase .firestore .testutil .TestUtil .assertDoesNotThrow ;
18
19
import static com .google .firebase .firestore .testutil .TestUtil .deletedDoc ;
19
20
import static com .google .firebase .firestore .testutil .TestUtil .doc ;
22
23
import static com .google .firebase .firestore .testutil .TestUtil .path ;
23
24
import static com .google .firebase .firestore .testutil .TestUtil .values ;
24
25
import static com .google .firebase .firestore .testutil .TestUtil .version ;
25
- import static java .util .Arrays .asList ;
26
26
import static org .junit .Assert .assertEquals ;
27
27
import static org .junit .Assert .assertFalse ;
28
28
import static org .junit .Assert .assertNotEquals ;
54
54
* </ol>
55
55
*/
56
56
abstract class RemoteDocumentCacheTestCase {
57
+ private final Map <String , Object > DOC_DATA = map ("data" , 2 );
57
58
58
59
private Persistence persistence ;
59
60
private RemoteDocumentCache remoteDocumentCache ;
@@ -127,7 +128,7 @@ public void testSetAndReadLotsOfDocuments() {
127
128
List <String > paths = new ArrayList <>();
128
129
Map <DocumentKey , MutableDocument > expected = new HashMap <>();
129
130
for (int i = 0 ; i < lotsOfDocuments ; i ++) {
130
- String path = "foo/" + String . valueOf ( i ) ;
131
+ String path = "foo/" + i ;
131
132
paths .add (path );
132
133
expected .put (DocumentKey .fromPathString (path ), addTestDocumentAtPath (path ));
133
134
}
@@ -173,7 +174,6 @@ public void testRemoveNonExistentDocument() {
173
174
public void testDocumentsMatchingQuery () {
174
175
// TODO: This just verifies that we do a prefix scan against the
175
176
// query path. We'll need more tests once we add index support.
176
- Map <String , Object > docData = map ("data" , 2 );
177
177
addTestDocumentAtPath ("a/1" );
178
178
addTestDocumentAtPath ("b/1" );
179
179
addTestDocumentAtPath ("b/2" );
@@ -182,41 +182,47 @@ public void testDocumentsMatchingQuery() {
182
182
Query query = Query .atPath (path ("b" ));
183
183
ImmutableSortedMap <DocumentKey , MutableDocument > results =
184
184
remoteDocumentCache .getAllDocumentsMatchingQuery (query , IndexOffset .NONE );
185
- List <MutableDocument > expected = asList (doc ("b/1" , 42 , docData ), doc ("b/2" , 42 , docData ));
186
- // assertEquals(expected, values(results));
185
+ assertThat (values (results )).containsExactly (doc ("b/1" , 42 , DOC_DATA ), doc ("b/2" , 42 , DOC_DATA ));
186
+ }
187
+
188
+ @ Test
189
+ public void testDocumentsMatchingQueryExcludesSubcollections () {
190
+ addTestDocumentAtPath ("a/1" );
191
+ addTestDocumentAtPath ("a/1/b/1" );
192
+ addTestDocumentAtPath ("a/2" );
193
+
194
+ Query query = Query .atPath (path ("a" ));
195
+ ImmutableSortedMap <DocumentKey , MutableDocument > results =
196
+ remoteDocumentCache .getAllDocumentsMatchingQuery (query , IndexOffset .NONE );
197
+ assertThat (values (results )).containsExactly (doc ("a/1" , 42 , DOC_DATA ), doc ("a/2" , 42 , DOC_DATA ));
187
198
}
188
199
189
200
@ Test
190
201
public void testDocumentsMatchingQuerySinceReadTimeAndSeconds () {
191
- Map <String , Object > docData = map ("data" , 2 );
192
202
addTestDocumentAtPath ("b/old" , /* updateTime= */ 1 , /* readTime= */ 11 );
193
203
addTestDocumentAtPath ("b/current" , /* updateTime= */ 2 , /* readTime= = */ 12 );
194
204
addTestDocumentAtPath ("b/new" , /* updateTime= */ 3 , /* readTime= = */ 13 );
195
205
196
206
Query query = Query .atPath (path ("b" ));
197
207
ImmutableSortedMap <DocumentKey , MutableDocument > results =
198
208
remoteDocumentCache .getAllDocumentsMatchingQuery (query , IndexOffset .create (version (12 )));
199
- List <MutableDocument > expected = asList (doc ("b/new" , 3 , docData ));
200
- assertEquals (expected , values (results ));
209
+ assertThat (values (results )).containsExactly (doc ("b/new" , 3 , DOC_DATA ));
201
210
}
202
211
203
212
@ Test
204
213
public void testDocumentsMatchingQuerySinceReadTimeAndNanoseconds () {
205
- Map <String , Object > docData = map ("data" , 2 );
206
- add (doc ("b/old" , 1 , docData ), version (1 , 1 ));
207
- add (doc ("b/current" , 1 , docData ), version (1 , 2 ));
208
- add (doc ("b/new" , 1 , docData ), version (1 , 3 ));
214
+ add (doc ("b/old" , 1 , DOC_DATA ), version (1 , 1 ));
215
+ add (doc ("b/current" , 1 , DOC_DATA ), version (1 , 2 ));
216
+ add (doc ("b/new" , 1 , DOC_DATA ), version (1 , 3 ));
209
217
210
218
Query query = Query .atPath (path ("b" ));
211
219
ImmutableSortedMap <DocumentKey , MutableDocument > results =
212
220
remoteDocumentCache .getAllDocumentsMatchingQuery (query , IndexOffset .create (version (1 , 2 )));
213
- List <MutableDocument > expected = asList (doc ("b/new" , 1 , docData ));
214
- assertEquals (expected , values (results ));
221
+ assertThat (values (results )).containsExactly (doc ("b/new" , 1 , DOC_DATA ));
215
222
}
216
223
217
224
@ Test
218
225
public void testDocumentsMatchingQuerySinceReadTimeAndDocumentKey () {
219
- Map <String , Object > docData = map ("data" , 2 );
220
226
addTestDocumentAtPath ("b/a" , /* updateTime= */ 1 , /* readTime= */ 11 );
221
227
addTestDocumentAtPath ("b/b" , /* updateTime= */ 2 , /* readTime= = */ 11 );
222
228
addTestDocumentAtPath ("b/c" , /* updateTime= */ 3 , /* readTime= = */ 11 );
@@ -226,21 +232,18 @@ public void testDocumentsMatchingQuerySinceReadTimeAndDocumentKey() {
226
232
ImmutableSortedMap <DocumentKey , MutableDocument > results =
227
233
remoteDocumentCache .getAllDocumentsMatchingQuery (
228
234
query , IndexOffset .create (version (11 ), key ("b/b" )));
229
- List <MutableDocument > expected = asList (doc ("b/c" , 3 , docData ), doc ("b/d" , 4 , docData ));
230
- assertEquals (expected , values (results ));
235
+ assertThat (values (results )).containsExactly (doc ("b/c" , 3 , DOC_DATA ), doc ("b/d" , 4 , DOC_DATA ));
231
236
}
232
237
233
238
@ Test
234
239
public void testDocumentsMatchingUsesReadTimeNotUpdateTime () {
235
- Map <String , Object > docData = map ("data" , 2 );
236
240
addTestDocumentAtPath ("b/old" , /* updateTime= */ 1 , /* readTime= */ 2 );
237
241
addTestDocumentAtPath ("b/new" , /* updateTime= */ 2 , /* readTime= */ 1 );
238
242
239
243
Query query = Query .atPath (path ("b" ));
240
244
ImmutableSortedMap <DocumentKey , MutableDocument > results =
241
245
remoteDocumentCache .getAllDocumentsMatchingQuery (query , IndexOffset .create (version (1 )));
242
- List <MutableDocument > expected = asList (doc ("b/old" , 1 , docData ));
243
- assertEquals (expected , values (results ));
246
+ assertThat (values (results )).containsExactly (doc ("b/old" , 1 , DOC_DATA ));
244
247
}
245
248
246
249
@ Test
0 commit comments