use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.
the class MutationTest method testOverlayWithFieldDeletionOfNestedField.
@Test
public void testOverlayWithFieldDeletionOfNestedField() {
MutableDocument doc = doc("collection/key", 1, map("foo", 1));
Mutation patch1 = patchMutation("collection/key", map("foo", "foo-patched-value", "bar.baz", FieldValue.increment(1)));
Mutation patch2 = patchMutation("collection/key", map("foo", "foo-patched-value", "bar.baz", FieldValue.serverTimestamp()));
Mutation patch3 = patchMutation("collection/key", map("foo", "foo-patched-value", "bar.baz", FieldValue.delete()));
verifyOverlayRoundTrips(doc, patch1, patch2, patch3);
}
use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.
the class MutationTest method testTransitions.
@Test
public void testTransitions() {
MutableDocument docV3 = doc("collection/key", 3, map());
MutableDocument deletedV3 = deletedDoc("collection/key", 3);
Mutation set = setMutation("collection/key", map());
Mutation patch = patchMutation("collection/key", map());
Mutation delete = deleteMutation("collection/key");
MutableDocument docV7Deleted = deletedDoc("collection/key", 7).setHasCommittedMutations();
MutableDocument docV7Committed = doc("collection/key", 7, map()).setHasCommittedMutations();
MutableDocument docV7Unknown = unknownDoc("collection/key", 7);
MutationResult mutationResult = new MutationResult(version(7), /*transformResults=*/
Collections.emptyList());
assertVersionTransitions(set, docV3, mutationResult, docV7Committed);
assertVersionTransitions(set, deletedV3, mutationResult, docV7Committed);
assertVersionTransitions(set, MutableDocument.newInvalidDocument(key("collection/key")), mutationResult, docV7Committed);
assertVersionTransitions(patch, docV3, mutationResult, docV7Committed);
assertVersionTransitions(patch, deletedV3, mutationResult, docV7Unknown);
assertVersionTransitions(patch, MutableDocument.newInvalidDocument(key("collection/key")), mutationResult, docV7Unknown);
assertVersionTransitions(delete, docV3, mutationResult, docV7Deleted);
assertVersionTransitions(delete, deletedV3, mutationResult, docV7Deleted);
assertVersionTransitions(delete, MutableDocument.newInvalidDocument(key("collection/key")), mutationResult, docV7Deleted);
}
use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.
the class MutationTest method runPermutationTests.
/**
* For each document in {@code docs}, calculate the overlay mutations of each possible
* permutation, check whether this holds: document + overlay_mutation = document + mutation_list
* Returns how many cases it has run.
*/
private int runPermutationTests(List<MutableDocument> docs, List<Mutation> mutations) {
int testCases = 0;
Collection<List<Mutation>> permutations = Collections2.permutations(Lists.newArrayList(mutations));
for (MutableDocument doc : docs) {
for (List<Mutation> permutation : permutations) {
verifyOverlayRoundTrips(doc, permutation.toArray(new Mutation[] {}));
testCases += 1;
}
}
return testCases;
}
use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.
the class MutationTest method testAppliesLocalServerTimestampTransformsToDocuments.
@Test
public void testAppliesLocalServerTimestampTransformsToDocuments() {
Map<String, Object> data = map("foo", map("bar", "bar-value"), "baz", "baz-value");
MutableDocument transformedDoc = doc("collection/key", 1, data);
Timestamp timestamp = Timestamp.now();
Mutation transform = patchMutation("collection/key", map("foo.bar", FieldValue.serverTimestamp()));
transform.applyToLocalView(transformedDoc, /* previousMask= */
null, timestamp);
// Server timestamps aren't parsed, so we manually insert it.
ObjectValue expectedData = wrapObject(map("foo", map("bar", "<server-timestamp>"), "baz", "baz-value"));
Value fieldValue = ServerTimestamps.valueOf(timestamp, wrap("bar-value"));
expectedData.set(field("foo.bar"), fieldValue);
MutableDocument expectedDoc = doc("collection/key", 1, expectedData).setHasLocalMutations();
assertEquals(expectedDoc, transformedDoc);
}
use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.
the class MutationTest method testOverlayWithPatchThenMergeWithArrayUnion.
@Test
public void testOverlayWithPatchThenMergeWithArrayUnion() {
MutableDocument doc = doc("collection/key", 1, map("foo", 1));
Mutation patch = patchMutation("collection/key", map("foo", "foo-patched-value", "bar.baz", FieldValue.increment(1)));
Mutation merge = mergeMutation("collection/key", map("arrays", FieldValue.arrayUnion(1, 2, 3)), Arrays.asList(field("arrays")));
verifyOverlayRoundTrips(doc, patch, merge);
}
Aggregations