use of com.google.firebase.firestore.remote.WatchChange in project firebase-android-sdk by firebase.
the class SpecTestCase method doWatchReset.
private void doWatchReset(JSONArray targetIds) throws Exception {
List<Integer> targets = parseIntList(targetIds);
WatchChange change = new WatchTargetChange(WatchTargetChangeType.Reset, targets);
writeWatchChange(change, SnapshotVersion.NONE);
}
use of com.google.firebase.firestore.remote.WatchChange in project firebase-android-sdk by firebase.
the class SpecTestCase method doWatchEntity.
private void doWatchEntity(JSONObject watchEntity) throws Exception {
if (watchEntity.has("docs")) {
Assert.hardAssert(!watchEntity.has("doc"), "Exactly one of |doc| or |docs| needs to be set.");
JSONArray docs = watchEntity.getJSONArray("docs");
for (int i = 0; i < docs.length(); ++i) {
JSONObject doc = docs.getJSONObject(i);
JSONObject watchSpec = new JSONObject();
watchSpec.put("doc", doc);
if (watchEntity.has("targets")) {
watchSpec.put("targets", watchEntity.get("targets"));
}
if (watchEntity.has("removedTargets")) {
watchSpec.put("removedTargets", watchEntity.get("removedTargets"));
}
doWatchEntity(watchSpec);
}
} else if (watchEntity.has("doc")) {
JSONObject docSpec = watchEntity.getJSONObject("doc");
String key = docSpec.getString("key");
@Nullable Map<String, Object> value = !docSpec.isNull("value") ? parseMap(docSpec.getJSONObject("value")) : null;
long version = docSpec.getLong("version");
MutableDocument doc = value != null ? doc(key, version, value) : deletedDoc(key, version);
List<Integer> updated = parseIntList(watchEntity.optJSONArray("targets"));
List<Integer> removed = parseIntList(watchEntity.optJSONArray("removedTargets"));
WatchChange change = new DocumentChange(updated, removed, doc.getKey(), doc);
writeWatchChange(change, SnapshotVersion.NONE);
} else if (watchEntity.has("key")) {
String key = watchEntity.getString("key");
List<Integer> removed = parseIntList(watchEntity.optJSONArray("removedTargets"));
WatchChange change = new DocumentChange(Collections.emptyList(), removed, key(key), null);
writeWatchChange(change, SnapshotVersion.NONE);
} else {
throw Assert.fail("Either key, doc or docs must be set.");
}
}
use of com.google.firebase.firestore.remote.WatchChange in project firebase-android-sdk by firebase.
the class SpecTestCase method doWatchSnapshot.
private void doWatchSnapshot(JSONObject watchSnapshot) throws Exception {
// The client will only respond to watchSnapshots if they are on a target change with an empty
// set of target IDs.
List<Integer> targets = watchSnapshot.has("targetIds") ? parseIntList(watchSnapshot.getJSONArray("targetIds")) : Collections.emptyList();
String resumeToken = watchSnapshot.optString("resumeToken");
WatchChange change = new WatchTargetChange(WatchTargetChangeType.NoChange, targets, ByteString.copyFromUtf8(resumeToken));
writeWatchChange(change, version(watchSnapshot.getLong("version")));
}
use of com.google.firebase.firestore.remote.WatchChange in project firebase-android-sdk by firebase.
the class TestUtil method noChangeEvent.
public static RemoteEvent noChangeEvent(int targetId, int version, ByteString resumeToken) {
TargetData targetData = TestUtil.targetData(targetId, QueryPurpose.LISTEN, "foo/bar");
TestTargetMetadataProvider testTargetMetadataProvider = new TestTargetMetadataProvider();
testTargetMetadataProvider.setSyncedKeys(targetData, DocumentKey.emptyKeySet());
WatchChangeAggregator aggregator = new WatchChangeAggregator(testTargetMetadataProvider);
WatchChange.WatchTargetChange watchChange = new WatchChange.WatchTargetChange(WatchChange.WatchTargetChangeType.NoChange, asList(targetId), resumeToken);
aggregator.handleTargetChange(watchChange);
return aggregator.createRemoteEvent(version(version));
}
Aggregations