diff --git a/firebase-firestore/src/test/java/com/google/firebase/firestore/spec/SpecTestCase.java b/firebase-firestore/src/test/java/com/google/firebase/firestore/spec/SpecTestCase.java index 8fa7375ebeb..1b2dcc4c66e 100644 --- a/firebase-firestore/src/test/java/com/google/firebase/firestore/spec/SpecTestCase.java +++ b/firebase-firestore/src/test/java/com/google/firebase/firestore/spec/SpecTestCase.java @@ -478,6 +478,18 @@ private List parseIntList(@Nullable JSONArray arr) throws JSONException return result; } + /** Deeply parses a JSONArray into a List. */ + private List parseStringList(@Nullable JSONArray arr) throws JSONException { + List result = new ArrayList<>(); + if (arr == null) { + return result; + } + for (int i = 0; i < arr.length(); ++i) { + result.add(arr.getString(i)); + } + return result; + } + // // Methods for doing the steps of the spec test. // @@ -665,15 +677,14 @@ private void doWatchEntity(JSONObject watchEntity) throws Exception { } } - private void doWatchFilter(JSONArray watchFilter) throws Exception { - List targets = parseIntList(watchFilter.getJSONArray(0)); + private void doWatchFilter(JSONObject watchFilter) throws Exception { + List keys = parseStringList(watchFilter.getJSONArray("keys")); + List targets = parseIntList(watchFilter.getJSONArray("targetIds")); Assert.hardAssert( targets.size() == 1, "ExistenceFilters currently support exactly one target only."); - int keyCount = watchFilter.length() == 0 ? 0 : watchFilter.length() - 1; - // TODO: extend this with different existence filters over time. - ExistenceFilter filter = new ExistenceFilter(keyCount); + ExistenceFilter filter = new ExistenceFilter(keys.size()); ExistenceFilterWatchChange change = new ExistenceFilterWatchChange(targets.get(0), filter); writeWatchChange(change, SnapshotVersion.NONE); } @@ -850,7 +861,7 @@ private void doStep(JSONObject step) throws Exception { } else if (step.has("watchEntity")) { doWatchEntity(step.getJSONObject("watchEntity")); } else if (step.has("watchFilter")) { - doWatchFilter(step.getJSONArray("watchFilter")); + doWatchFilter(step.getJSONObject("watchFilter")); } else if (step.has("watchReset")) { doWatchReset(step.getJSONArray("watchReset")); } else if (step.has("watchSnapshot")) { diff --git a/firebase-firestore/src/test/resources/json/existence_filter_spec_test.json b/firebase-firestore/src/test/resources/json/existence_filter_spec_test.json index c0be6b22cfb..0a4ecb48201 100644 --- a/firebase-firestore/src/test/resources/json/existence_filter_spec_test.json +++ b/firebase-firestore/src/test/resources/json/existence_filter_spec_test.json @@ -132,12 +132,14 @@ ] }, { - "watchFilter": [ - [ - 2 + "watchFilter": { + "keys": [ + "collection/1" ], - "collection/1" - ] + "targetIds": [ + 2 + ] + } }, { "watchSnapshot": { @@ -366,13 +368,15 @@ ] }, { - "watchFilter": [ - [ - 2 + "watchFilter": { + "keys": [ + "collection/1", + "collection/2" ], - "collection/1", - "collection/2" - ] + "targetIds": [ + 2 + ] + } }, { "watchEntity": { @@ -729,11 +733,13 @@ } }, { - "watchFilter": [ - [ + "watchFilter": { + "keys": [ + ], + "targetIds": [ 2 ] - ] + } }, { "watchRemove": { @@ -910,12 +916,14 @@ ] }, { - "watchFilter": [ - [ - 2 + "watchFilter": { + "keys": [ + "collection/1" ], - "collection/1" - ] + "targetIds": [ + 2 + ] + } }, { "watchSnapshot": { @@ -1203,12 +1211,14 @@ ] }, { - "watchFilter": [ - [ - 2 + "watchFilter": { + "keys": [ + "collection/1" ], - "collection/1" - ] + "targetIds": [ + 2 + ] + } }, { "watchSnapshot": { @@ -1313,12 +1323,14 @@ } }, { - "watchFilter": [ - [ - 2 + "watchFilter": { + "keys": [ + "collection/1" ], - "collection/1" - ] + "targetIds": [ + 2 + ] + } }, { "watchSnapshot": { @@ -1489,12 +1501,14 @@ ] }, { - "watchFilter": [ - [ - 2 + "watchFilter": { + "keys": [ + "collection/1" ], - "collection/1" - ] + "targetIds": [ + 2 + ] + } }, { "watchSnapshot": { @@ -1846,12 +1860,14 @@ ] }, { - "watchFilter": [ - [ - 2 + "watchFilter": { + "keys": [ + "collection/1" ], - "collection/1" - ] + "targetIds": [ + 2 + ] + } }, { "watchSnapshot": { @@ -2149,11 +2165,13 @@ ] }, { - "watchFilter": [ - [ + "watchFilter": { + "keys": [ + ], + "targetIds": [ 2 ] - ] + } }, { "watchSnapshot": { @@ -2265,12 +2283,14 @@ ] }, { - "watchFilter": [ - [ - 2 + "watchFilter": { + "keys": [ + "collection/1" ], - "collection/1" - ] + "targetIds": [ + 2 + ] + } }, { "watchSnapshot": { diff --git a/firebase-firestore/src/test/resources/json/limbo_spec_test.json b/firebase-firestore/src/test/resources/json/limbo_spec_test.json index c4c179fd8ba..8172a189689 100644 --- a/firebase-firestore/src/test/resources/json/limbo_spec_test.json +++ b/firebase-firestore/src/test/resources/json/limbo_spec_test.json @@ -3445,11 +3445,13 @@ ] }, { - "watchFilter": [ - [ + "watchFilter": { + "keys": [ + ], + "targetIds": [ 1 ] - ] + } }, { "watchCurrent": [ @@ -8201,15 +8203,16 @@ } }, { - "watchFilter": [ - [ - 2 + "watchFilter": { + "keys": [ + "collection/b1", + "collection/b2", + "collection/b3" ], - "collection/b1", - "collection/b2", - "collection/b3" - ] - + "targetIds": [ + 2 + ] + } }, { "watchSnapshot": { diff --git a/firebase-firestore/src/test/resources/json/limit_spec_test.json b/firebase-firestore/src/test/resources/json/limit_spec_test.json index 37ec88b11c0..257c53eeb4c 100644 --- a/firebase-firestore/src/test/resources/json/limit_spec_test.json +++ b/firebase-firestore/src/test/resources/json/limit_spec_test.json @@ -5611,12 +5611,14 @@ } }, { - "watchFilter": [ - [ - 2 + "watchFilter": { + "keys": [ + "collection/b" ], - "collection/b" - ] + "targetIds": [ + 2 + ] + } }, { "watchSnapshot": {