|
| 1 | +package io.ably.lib.objects.unit.fixtures |
| 2 | + |
| 3 | +import com.google.gson.JsonArray |
| 4 | +import com.google.gson.JsonObject |
| 5 | +import io.ably.lib.objects.* |
| 6 | +import io.ably.lib.objects.Binary |
| 7 | +import io.ably.lib.objects.ObjectData |
| 8 | +import io.ably.lib.objects.ObjectMessage |
| 9 | +import io.ably.lib.objects.ObjectState |
| 10 | +import io.ably.lib.objects.ObjectValue |
| 11 | + |
| 12 | +internal val dummyObjectDataStringValue = ObjectData(objectId = "object-id", ObjectValue("dummy string")) |
| 13 | + |
| 14 | +internal val dummyBinaryObjectValue = ObjectData(objectId = "object-id", ObjectValue(Binary(byteArrayOf(1, 2, 3)))) |
| 15 | + |
| 16 | +internal val dummyNumberObjectValue = ObjectData(objectId = "object-id", ObjectValue(42.0)) |
| 17 | + |
| 18 | +internal val dummyBooleanObjectValue = ObjectData(objectId = "object-id", ObjectValue(true)) |
| 19 | + |
| 20 | +val dummyJsonObject = JsonObject().apply { addProperty("foo", "bar") } |
| 21 | +internal val dummyJsonObjectValue = ObjectData(objectId = "object-id", ObjectValue(dummyJsonObject)) |
| 22 | + |
| 23 | +val dummyJsonArray = JsonArray().apply { add(1); add(2); add(3) } |
| 24 | +internal val dummyJsonArrayValue = ObjectData(objectId = "object-id", ObjectValue(dummyJsonArray)) |
| 25 | + |
| 26 | +internal val dummyObjectMapEntry = ObjectMapEntry( |
| 27 | + tombstone = false, |
| 28 | + timeserial = "dummy-timeserial", |
| 29 | + data = dummyObjectDataStringValue |
| 30 | +) |
| 31 | + |
| 32 | +internal val dummyObjectMap = ObjectMap( |
| 33 | + semantics = MapSemantics.LWW, |
| 34 | + entries = mapOf("dummy-key" to dummyObjectMapEntry) |
| 35 | +) |
| 36 | + |
| 37 | +internal val dummyObjectCounter = ObjectCounter( |
| 38 | + count = 123.0 |
| 39 | +) |
| 40 | + |
| 41 | +internal val dummyObjectMapOp = ObjectMapOp( |
| 42 | + key = "dummy-key", |
| 43 | + data = dummyObjectDataStringValue |
| 44 | +) |
| 45 | + |
| 46 | +internal val dummyObjectCounterOp = ObjectCounterOp( |
| 47 | + amount = 10.0 |
| 48 | +) |
| 49 | + |
| 50 | +internal val dummyObjectOperation = ObjectOperation( |
| 51 | + action = ObjectOperationAction.MapCreate, |
| 52 | + objectId = "dummy-object-id", |
| 53 | + mapOp = dummyObjectMapOp, |
| 54 | + counterOp = dummyObjectCounterOp, |
| 55 | + map = dummyObjectMap, |
| 56 | + counter = dummyObjectCounter, |
| 57 | + nonce = "dummy-nonce", |
| 58 | + initialValue = "{\"foo\":\"bar\"}" |
| 59 | +) |
| 60 | + |
| 61 | +internal val dummyObjectState = ObjectState( |
| 62 | + objectId = "dummy-object-id", |
| 63 | + siteTimeserials = mapOf("site1" to "serial1"), |
| 64 | + tombstone = false, |
| 65 | + createOp = dummyObjectOperation, |
| 66 | + map = dummyObjectMap, |
| 67 | + counter = dummyObjectCounter |
| 68 | +) |
| 69 | + |
| 70 | +internal val dummyObjectMessage = ObjectMessage( |
| 71 | + id = "dummy-id", |
| 72 | + timestamp = 1234567890L, |
| 73 | + clientId = "dummy-client-id", |
| 74 | + connectionId = "dummy-connection-id", |
| 75 | + extras = mapOf("meta" to "data"), |
| 76 | + operation = dummyObjectOperation, |
| 77 | + objectState = dummyObjectState, |
| 78 | + serial = "dummy-serial", |
| 79 | + siteCode = "dummy-site-code" |
| 80 | +) |
| 81 | + |
| 82 | +internal fun dummyObjectMessageWithStringData(): ObjectMessage { |
| 83 | + return dummyObjectMessage |
| 84 | +} |
| 85 | + |
| 86 | +internal fun dummyObjectMessageWithBinaryData(): ObjectMessage { |
| 87 | + val binaryObjectMapEntry = dummyObjectMapEntry.copy(data = dummyBinaryObjectValue) |
| 88 | + val binaryObjectMap = dummyObjectMap.copy(entries = mapOf("dummy-key" to binaryObjectMapEntry)) |
| 89 | + val binaryObjectMapOp = dummyObjectMapOp.copy(data = dummyBinaryObjectValue) |
| 90 | + val binaryObjectOperation = dummyObjectOperation.copy( |
| 91 | + mapOp = binaryObjectMapOp, |
| 92 | + map = binaryObjectMap |
| 93 | + ) |
| 94 | + val binaryObjectState = dummyObjectState.copy( |
| 95 | + map = binaryObjectMap, |
| 96 | + createOp = binaryObjectOperation |
| 97 | + ) |
| 98 | + return dummyObjectMessage.copy( |
| 99 | + operation = binaryObjectOperation, |
| 100 | + objectState = binaryObjectState |
| 101 | + ) |
| 102 | +} |
| 103 | + |
| 104 | +internal fun dummyObjectMessageWithNumberData(): ObjectMessage { |
| 105 | + val numberObjectMapEntry = dummyObjectMapEntry.copy(data = dummyNumberObjectValue) |
| 106 | + val numberObjectMap = dummyObjectMap.copy(entries = mapOf("dummy-key" to numberObjectMapEntry)) |
| 107 | + val numberObjectMapOp = dummyObjectMapOp.copy(data = dummyNumberObjectValue) |
| 108 | + val numberObjectOperation = dummyObjectOperation.copy( |
| 109 | + mapOp = numberObjectMapOp, |
| 110 | + map = numberObjectMap |
| 111 | + ) |
| 112 | + val numberObjectState = dummyObjectState.copy( |
| 113 | + map = numberObjectMap, |
| 114 | + createOp = numberObjectOperation |
| 115 | + ) |
| 116 | + return dummyObjectMessage.copy( |
| 117 | + operation = numberObjectOperation, |
| 118 | + objectState = numberObjectState |
| 119 | + ) |
| 120 | +} |
| 121 | + |
| 122 | +internal fun dummyObjectMessageWithBooleanData(): ObjectMessage { |
| 123 | + val booleanObjectMapEntry = dummyObjectMapEntry.copy(data = dummyBooleanObjectValue) |
| 124 | + val booleanObjectMap = dummyObjectMap.copy(entries = mapOf("dummy-key" to booleanObjectMapEntry)) |
| 125 | + val booleanObjectMapOp = dummyObjectMapOp.copy(data = dummyBooleanObjectValue) |
| 126 | + val booleanObjectOperation = dummyObjectOperation.copy( |
| 127 | + mapOp = booleanObjectMapOp, |
| 128 | + map = booleanObjectMap |
| 129 | + ) |
| 130 | + val booleanObjectState = dummyObjectState.copy( |
| 131 | + map = booleanObjectMap, |
| 132 | + createOp = booleanObjectOperation |
| 133 | + ) |
| 134 | + return dummyObjectMessage.copy( |
| 135 | + operation = booleanObjectOperation, |
| 136 | + objectState = booleanObjectState |
| 137 | + ) |
| 138 | +} |
| 139 | + |
| 140 | +internal fun dummyObjectMessageWithJsonObjectData(): ObjectMessage { |
| 141 | + val jsonObjectMapEntry = dummyObjectMapEntry.copy(data = dummyJsonObjectValue) |
| 142 | + val jsonObjectMap = dummyObjectMap.copy(entries = mapOf("dummy-key" to jsonObjectMapEntry)) |
| 143 | + val jsonObjectMapOp = dummyObjectMapOp.copy(data = dummyJsonObjectValue) |
| 144 | + val jsonObjectOperation = dummyObjectOperation.copy( |
| 145 | + mapOp = jsonObjectMapOp, |
| 146 | + map = jsonObjectMap |
| 147 | + ) |
| 148 | + val jsonObjectState = dummyObjectState.copy( |
| 149 | + map = jsonObjectMap, |
| 150 | + createOp = jsonObjectOperation |
| 151 | + ) |
| 152 | + return dummyObjectMessage.copy( |
| 153 | + operation = jsonObjectOperation, |
| 154 | + objectState = jsonObjectState |
| 155 | + ) |
| 156 | +} |
| 157 | + |
| 158 | +internal fun dummyObjectMessageWithJsonArrayData(): ObjectMessage { |
| 159 | + val jsonArrayMapEntry = dummyObjectMapEntry.copy(data = dummyJsonArrayValue) |
| 160 | + val jsonArrayMap = dummyObjectMap.copy(entries = mapOf("dummy-key" to jsonArrayMapEntry)) |
| 161 | + val jsonArrayMapOp = dummyObjectMapOp.copy(data = dummyJsonArrayValue) |
| 162 | + val jsonArrayOperation = dummyObjectOperation.copy( |
| 163 | + mapOp = jsonArrayMapOp, |
| 164 | + map = jsonArrayMap |
| 165 | + ) |
| 166 | + val jsonArrayState = dummyObjectState.copy( |
| 167 | + map = jsonArrayMap, |
| 168 | + createOp = jsonArrayOperation |
| 169 | + ) |
| 170 | + return dummyObjectMessage.copy( |
| 171 | + operation = jsonArrayOperation, |
| 172 | + objectState = jsonArrayState |
| 173 | + ) |
| 174 | +} |
0 commit comments