use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.
the class MutationTest method testSetWithMutationResult.
@Test
public void testSetWithMutationResult() {
Map<String, Object> data = map("foo", "bar");
MutableDocument setDoc = doc("collection/key", 1, data);
Mutation set = setMutation("collection/key", map("foo", "new-bar"));
set.applyToRemoteDocument(setDoc, mutationResult(4));
assertEquals(doc("collection/key", 4, map("foo", "new-bar")).setHasCommittedMutations(), setDoc);
}
use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.
the class MutationTest method testAppliesPatchWithMergeToDocuments.
@Test
public void testAppliesPatchWithMergeToDocuments() {
MutableDocument mergeDoc = deletedDoc("collection/key", 2);
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", 2, expectedData).setHasLocalMutations(), mergeDoc);
}
use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.
the class RemoteEventTest method testTargetAddedChangeWillResetPreviousState.
@Test
public void testTargetAddedChangeWillResetPreviousState() {
Map<Integer, TargetData> targetMap = activeQueries(1, 3);
MutableDocument doc1 = doc("docs/1", 1, map("value", 1));
MutableDocument doc2 = doc("docs/2", 2, map("value", 2));
WatchChange change1 = new DocumentChange(asList(1, 3), asList(2), doc1.getKey(), doc1);
WatchChange change2 = new WatchTargetChange(WatchTargetChangeType.Current, asList(1, 2, 3));
WatchChange change3 = new WatchTargetChange(WatchTargetChangeType.Removed, asList(1));
WatchChange change4 = new WatchTargetChange(WatchTargetChangeType.Removed, asList(2));
WatchChange change5 = new WatchTargetChange(WatchTargetChangeType.Added, asList(1));
WatchChange change6 = new DocumentChange(asList(1), asList(3), doc2.getKey(), doc2);
Map<Integer, Integer> outstanding = new HashMap<>();
outstanding.put(1, 2);
outstanding.put(2, 1);
RemoteEvent event = createRemoteEvent(3, targetMap, outstanding, keySet(doc2.getKey()), change1, change2, change3, change4, change5, change6);
assertEquals(version(3), event.getSnapshotVersion());
assertEquals(2, event.getDocumentUpdates().size());
assertEquals(doc1, event.getDocumentUpdates().get(doc1.getKey()));
assertEquals(doc2, event.getDocumentUpdates().get(doc2.getKey()));
// target 1 and 3 are affected (1 because of re-add), target 2 is not because of remove.
assertEquals(2, event.getTargetChanges().size());
// doc1 was before the remove, so it does not show up in the mapping.
// Current was before the remove.
TargetChange mapping1 = targetChange(resumeToken, false, null, asList(doc2), null);
assertEquals(mapping1, event.getTargetChanges().get(1));
// Doc1 was before the remove.
// Current was after the remove
TargetChange mapping3 = targetChange(resumeToken, true, asList(doc1), null, asList(doc2));
assertEquals(mapping3, event.getTargetChanges().get(3));
}
use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.
the class RemoteEventTest method testWillHandleTargetAddAndRemovalInSameBatch.
@Test
public void testWillHandleTargetAddAndRemovalInSameBatch() {
Map<Integer, TargetData> targetMap = activeQueries(1, 2);
MutableDocument doc1a = doc("docs/1", 1, map("value", 1));
MutableDocument doc1b = doc("docs/1", 1, map("value", 2));
WatchChange change1 = new DocumentChange(asList(1), asList(2), doc1a.getKey(), doc1a);
WatchChange change2 = new DocumentChange(asList(2), asList(1), doc1b.getKey(), doc1b);
RemoteEvent event = createRemoteEvent(3, targetMap, noOutstandingResponses, keySet(doc1a.getKey()), change1, change2);
assertEquals(version(3), event.getSnapshotVersion());
assertEquals(1, event.getDocumentUpdates().size());
assertEquals(doc1b, event.getDocumentUpdates().get(doc1b.getKey()));
assertEquals(2, event.getTargetChanges().size());
TargetChange mapping1 = targetChange(resumeToken, false, null, null, asList(doc1b));
assertEquals(mapping1, event.getTargetChanges().get(1));
TargetChange mapping2 = targetChange(resumeToken, false, null, asList(doc1b), null);
assertEquals(mapping2, event.getTargetChanges().get(2));
}
use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.
the class RemoteEventTest method testSeparatesUpdates.
@Test
public void testSeparatesUpdates() {
Map<Integer, TargetData> targetMap = activeQueries(1);
MutableDocument newDoc = doc("docs/new", 1, map("key", "value"));
DocumentChange newDocChange = new DocumentChange(asList(1), emptyList(), newDoc.getKey(), newDoc);
MutableDocument existingDoc = doc("docs/existing", 1, map("some", "data"));
DocumentChange existingDocChange = new DocumentChange(asList(1), emptyList(), existingDoc.getKey(), existingDoc);
MutableDocument deletedDoc = deletedDoc("docs/deleted", 1);
DocumentChange deletedDocChange = new DocumentChange(asList(1), emptyList(), deletedDoc.getKey(), deletedDoc);
MutableDocument missingDoc = deletedDoc("docs/missing ", 1);
DocumentChange missingDocChange = new DocumentChange(asList(1), emptyList(), missingDoc.getKey(), missingDoc);
RemoteEvent event = createRemoteEvent(3, targetMap, noOutstandingResponses, keySet(existingDoc.getKey(), deletedDoc.getKey()), newDocChange, existingDocChange, deletedDocChange, missingDocChange);
TargetChange mapping = targetChange(resumeToken, false, asList(newDoc), asList(existingDoc), asList(deletedDoc));
assertEquals(mapping, event.getTargetChanges().get(1));
}
Aggregations