use of com.google.firebase.firestore.model.SnapshotVersion in project firebase-android-sdk by firebase.
the class BundleSerializerTest method testDecodesBundledDocumentMetadata.
// BundledDocumentMetadata tests
@Test
public void testDecodesBundledDocumentMetadata() throws JSONException {
String json = "{\n" + "name: '" + TEST_DOCUMENT + "',\n" + "readTime: '2020-01-01T00:00:01.000000001Z',\n" + "exists: true,\n" + "queries: [ 'query-1', 'query-2' ]\n" + "}";
BundledDocumentMetadata expectedMetadata = new BundledDocumentMetadata(key("coll/doc"), new SnapshotVersion(new com.google.firebase.Timestamp(1577836801, 1)), true, Arrays.asList("query-1", "query-2"));
BundledDocumentMetadata actualMetadata = serializer.decodeBundledDocumentMetadata(new JSONObject(json));
assertEquals(expectedMetadata, actualMetadata);
}
use of com.google.firebase.firestore.model.SnapshotVersion in project firebase-android-sdk by firebase.
the class BundleSerializerTest method testDecodesBundleMetadata.
// BundleMetadata tests
@Test
public void testDecodesBundleMetadata() throws JSONException {
String json = "{\n" + "id: 'bundle-1',\n" + "version: 1,\n" + "createTime: { seconds: 2, nanos: 3 },\n" + "totalDocuments: 4,\n" + "totalBytes: 5\n" + "}";
BundleMetadata expectedMetadata = new BundleMetadata("bundle-1", /* schemaVersion= */
1, new SnapshotVersion(new com.google.firebase.Timestamp(2, 3)), /* totalDocuments= */
4, /* totalBytes= */
5);
BundleMetadata actualMetadata = serializer.decodeBundleMetadata(new JSONObject(json));
assertEquals(expectedMetadata, actualMetadata);
}
use of com.google.firebase.firestore.model.SnapshotVersion in project firebase-android-sdk by firebase.
the class BundleSerializerTest method assertDecodesValue.
private void assertDecodesValue(String json, Value proto) throws JSONException {
String documentJson = "{\n" + " name: '" + TEST_DOCUMENT + "',\n" + " fields: {\n" + " foo:\n" + json + "\n" + " },\n" + " crateTime: '2020-01-01T00:00:01.000000001Z',\n" + " updateTime: '2020-01-01T00:00:02.000000002Z'\n" + "}";
BundleDocument actualDocument = serializer.decodeDocument(new JSONObject(documentJson));
BundleDocument expectedDocument = new BundleDocument(MutableDocument.newFoundDocument(DocumentKey.fromName(TEST_DOCUMENT), new SnapshotVersion(new com.google.firebase.Timestamp(1577836802, 2)), new ObjectValue(Value.newBuilder().setMapValue(MapValue.newBuilder().putFields("foo", proto)).build())));
assertEquals(expectedDocument, actualDocument);
}
use of com.google.firebase.firestore.model.SnapshotVersion in project firebase-android-sdk by firebase.
the class RemoteSerializer method decodeMutationResult.
public MutationResult decodeMutationResult(com.google.firestore.v1.WriteResult proto, SnapshotVersion commitVersion) {
// NOTE: Deletes don't have an updateTime but the commit timestamp from the containing
// CommitResponse or WriteResponse indicates essentially that the delete happened no later than
// that. For our purposes we don't care exactly when the delete happened so long as we can tell
// when an update on the watch stream is at or later than that change.
SnapshotVersion version = decodeVersion(proto.getUpdateTime());
if (SnapshotVersion.NONE.equals(version)) {
version = commitVersion;
}
int transformResultsCount = proto.getTransformResultsCount();
List<Value> transformResults = new ArrayList<>(transformResultsCount);
for (int i = 0; i < transformResultsCount; i++) {
transformResults.add(proto.getTransformResults(i));
}
return new MutationResult(version, transformResults);
}
use of com.google.firebase.firestore.model.SnapshotVersion in project firebase-android-sdk by firebase.
the class RemoteSerializer method decodeFoundDocument.
private MutableDocument decodeFoundDocument(BatchGetDocumentsResponse response) {
Assert.hardAssert(response.getResultCase().equals(ResultCase.FOUND), "Tried to deserialize a found document from a missing document.");
DocumentKey key = decodeKey(response.getFound().getName());
ObjectValue value = ObjectValue.fromMap(response.getFound().getFieldsMap());
SnapshotVersion version = decodeVersion(response.getFound().getUpdateTime());
hardAssert(!version.equals(SnapshotVersion.NONE), "Got a document response with no snapshot version");
return MutableDocument.newFoundDocument(key, version, value);
}
Aggregations