use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.
the class TestUtil method addedRemoteEvent.
public static RemoteEvent addedRemoteEvent(List<MutableDocument> docs, List<Integer> updatedInTargets, List<Integer> removedFromTargets) {
Preconditions.checkArgument(!docs.isEmpty(), "Cannot pass empty docs array");
WatchChangeAggregator aggregator = new WatchChangeAggregator(new WatchChangeAggregator.TargetMetadataProvider() {
@Override
public ImmutableSortedSet<DocumentKey> getRemoteKeysForTarget(int targetId) {
return DocumentKey.emptyKeySet();
}
@Override
public TargetData getTargetDataForTarget(int targetId) {
ResourcePath collectionPath = docs.get(0).getKey().getCollectionPath();
return targetData(targetId, QueryPurpose.LISTEN, collectionPath.toString());
}
});
SnapshotVersion version = SnapshotVersion.NONE;
for (MutableDocument doc : docs) {
DocumentChange change = new DocumentChange(updatedInTargets, removedFromTargets, doc.getKey(), doc);
aggregator.handleDocumentChange(change);
version = doc.getVersion().compareTo(version) > 0 ? doc.getVersion() : version;
}
return aggregator.createRemoteEvent(version);
}
use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.
the class MutationTest method assertVersionTransitions.
private void assertVersionTransitions(Mutation mutation, MutableDocument base, MutationResult mutationResult, MutableDocument expected) {
MutableDocument clone = base.mutableCopy();
mutation.applyToRemoteDocument(clone, mutationResult);
assertEquals(expected, clone);
}
use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.
the class MutationTest method testPatchWithMutationResult.
@Test
public void testPatchWithMutationResult() {
Map<String, Object> data = map("foo", "bar");
MutableDocument patchDoc = doc("collection/key", 1, data);
Mutation patch = patchMutation("collection/key", map("foo", "new-bar"));
patch.applyToRemoteDocument(patchDoc, mutationResult(4));
assertEquals(doc("collection/key", 4, map("foo", "new-bar")).setHasCommittedMutations(), patchDoc);
}
use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.
the class MutationTest method testAppliesPatchToNullDocWithMergeToDocuments.
@Test
public void testAppliesPatchToNullDocWithMergeToDocuments() {
MutableDocument mergeDoc = MutableDocument.newInvalidDocument(key("collection/key"));
Mutation upsert = mergeMutation("collection/key", map("foo.bar", "new-bar-value"), Arrays.asList(field("foo.bar")));
upsert.applyToLocalView(mergeDoc, /* previousMask= */
null, Timestamp.now());
Map<String, Object> expectedData = map("foo", map("bar", "new-bar-value"));
assertEquals(doc("collection/key", 0, expectedData).setHasLocalMutations(), mergeDoc);
}
use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.
the class MutationTest method testAppliesServerAckedArrayTransformsToDocuments.
@Test
public void testAppliesServerAckedArrayTransformsToDocuments() {
Map<String, Object> data = map("array1", Arrays.asList(1, 2), "array2", Arrays.asList("a", "b"));
MutableDocument transformedDoc = doc("collection/key", 1, data);
Mutation transform = setMutation("collection/key", map("array1", FieldValue.arrayUnion(2, 3), "array2", FieldValue.arrayRemove("a", "c")));
// Server just sends null transform results for array operations.
MutationResult mutationResult = new MutationResult(version(1), Arrays.asList(wrap(null), wrap(null)));
transform.applyToRemoteDocument(transformedDoc, mutationResult);
Map<String, Object> expectedData = map("array1", Arrays.asList(1, 2, 3), "array2", Arrays.asList("b"));
assertEquals(doc("collection/key", 1, expectedData).setHasCommittedMutations(), transformedDoc);
}
Aggregations