use of com.google.firebase.firestore.model.mutation.Mutation in project firebase-android-sdk by firebase.
the class DocumentOverlayCacheTestCase method saveOverlays.
void saveOverlays(int largestBatch, Mutation... mutations) {
Map<DocumentKey, Mutation> data = new HashMap<>();
for (Mutation mutation : mutations) {
data.put(mutation.getKey(), mutation);
}
cache.saveOverlays(largestBatch, data);
}
use of com.google.firebase.firestore.model.mutation.Mutation in project firebase-android-sdk by firebase.
the class DocumentOverlayCacheTestCase method testSaveOverlaysThrowsNullPointerExceptionOnNullMapValue.
@Test
public void testSaveOverlaysThrowsNullPointerExceptionOnNullMapValue() {
Map<DocumentKey, Mutation> data = new HashMap<>();
data.put(key("coll/doc"), null);
NullPointerException e = assertThrows(NullPointerException.class, new ThrowingRunnable() {
@Override
public void run() {
cache.saveOverlays(1, data);
}
});
assertThat(e.getMessage()).contains("coll/doc");
}
use of com.google.firebase.firestore.model.mutation.Mutation in project firebase-android-sdk by firebase.
the class DocumentOverlayCacheTestCase method testCanReadSavedOverlays.
@Test
public void testCanReadSavedOverlays() {
Mutation m1 = patchMutation("coll/doc1", map("foo", "bar"));
Mutation m2 = setMutation("coll/doc2", map("foo", "bar"));
Mutation m3 = deleteMutation("coll/doc3");
saveOverlays(3, m1, m2, m3);
assertEquals(m1, cache.getOverlay(key("coll/doc1")).getMutation());
assertEquals(m2, cache.getOverlay(key("coll/doc2")).getMutation());
assertEquals(m3, cache.getOverlay(key("coll/doc3")).getMutation());
}
use of com.google.firebase.firestore.model.mutation.Mutation in project firebase-android-sdk by firebase.
the class DocumentOverlayCacheTestCase method testGetAllOverlaysForCollection.
@Test
public void testGetAllOverlaysForCollection() {
Mutation m1 = patchMutation("coll/doc1", map("foo", "bar"));
Mutation m2 = setMutation("coll/doc2", map("foo", "bar"));
Mutation m3 = deleteMutation("coll/doc3");
// m4 and m5 are not under "coll"
Mutation m4 = setMutation("coll/doc1/sub/sub_doc", map("foo", "bar"));
Mutation m5 = setMutation("other/doc1", map("foo", "bar"));
saveOverlays(3, m1, m2, m3, m4, m5);
Map<DocumentKey, Overlay> overlays = cache.getOverlays(path("coll"), -1);
verifyOverlayContains(overlays, "coll/doc1", "coll/doc2", "coll/doc3");
}
use of com.google.firebase.firestore.model.mutation.Mutation in project firebase-android-sdk by firebase.
the class LocalSerializerTest method testEncodesMutationBatch.
@Test
public void testEncodesMutationBatch() {
Mutation baseWrite = new PatchMutation(key("foo/bar"), TestUtil.wrapObject(map("a", "b")), FieldMask.fromSet(Collections.singleton(field("a"))), com.google.firebase.firestore.model.mutation.Precondition.NONE);
Mutation set = setMutation("foo/bar", map("a", "b", "num", 1));
Mutation patch = new PatchMutation(key("bar/baz"), TestUtil.wrapObject(map("a", "b", "num", 1)), fieldMask("a"), com.google.firebase.firestore.model.mutation.Precondition.exists(true));
Mutation del = deleteMutation("baz/quux");
MutationBatch model = new MutationBatch(42, writeTime, Collections.singletonList(baseWrite), asList(set, patch, del));
Write baseWriteProto = Write.newBuilder().setUpdate(com.google.firestore.v1.Document.newBuilder().setName("projects/p/databases/d/documents/foo/bar").putFields("a", Value.newBuilder().setStringValue("b").build())).setUpdateMask(DocumentMask.newBuilder().addFieldPaths("a")).build();
com.google.firebase.firestore.proto.WriteBatch batchProto = com.google.firebase.firestore.proto.WriteBatch.newBuilder().setBatchId(42).addBaseWrites(baseWriteProto).addAllWrites(asList(setProto, patchProto, deleteProto)).setLocalWriteTime(writeTimeProto).build();
assertEquals(batchProto, serializer.encodeMutationBatch(model));
MutationBatch decoded = serializer.decodeMutationBatch(batchProto);
assertEquals(model.getBatchId(), decoded.getBatchId());
assertEquals(model.getLocalWriteTime(), decoded.getLocalWriteTime());
assertEquals(model.getMutations(), decoded.getMutations());
assertEquals(model.getBaseMutations(), decoded.getBaseMutations());
assertEquals(model.getKeys(), decoded.getKeys());
}
Aggregations