|
5 | 5 | */ |
6 | 6 | package com.datadog.android.rum.assertj |
7 | 7 |
|
| 8 | +import com.datadog.android.api.context.AccountInfo |
| 9 | +import com.datadog.android.api.context.NetworkInfo |
| 10 | +import com.datadog.android.api.context.UserInfo |
8 | 11 | import com.datadog.android.rum.featureoperations.FailureReason |
9 | 12 | import com.datadog.android.rum.internal.domain.scope.RumSessionScope |
| 13 | +import com.datadog.android.rum.internal.domain.scope.isConnected |
10 | 14 | import com.datadog.android.rum.internal.domain.scope.toSchemaFailureReason |
11 | 15 | import com.datadog.android.rum.internal.domain.scope.toVitalSessionPrecondition |
12 | 16 | import com.datadog.android.rum.model.VitalEvent |
@@ -180,6 +184,207 @@ internal class VitalEventAssert(actual: VitalEvent) : AbstractObjectAssert<Vital |
180 | 184 | ).isEqualTo(resultId) |
181 | 185 | } |
182 | 186 |
|
| 187 | + fun hasSource(source: VitalEvent.VitalEventSource?) = apply { |
| 188 | + assertThat(actual.source) |
| 189 | + .overridingErrorMessage( |
| 190 | + "Expected event to have a source %s" + |
| 191 | + " instead it was %s", |
| 192 | + actual.source ?: "null", |
| 193 | + source ?: "null" |
| 194 | + ) |
| 195 | + .isEqualTo(source) |
| 196 | + return this |
| 197 | + } |
| 198 | + |
| 199 | + fun hasAccountInfo(expected: AccountInfo?) = apply { |
| 200 | + assertThat(actual.account?.id) |
| 201 | + .overridingErrorMessage( |
| 202 | + "Expected RUM event to have account.id ${expected?.id} " + |
| 203 | + "but was ${actual.account?.id}" |
| 204 | + ) |
| 205 | + .isEqualTo(expected?.id) |
| 206 | + assertThat(actual.account?.name) |
| 207 | + .overridingErrorMessage( |
| 208 | + "Expected RUM event to have account.name ${expected?.name} " + |
| 209 | + "but was ${actual.account?.name}" |
| 210 | + ) |
| 211 | + .isEqualTo(expected?.name) |
| 212 | + assertThat(actual.account?.additionalProperties) |
| 213 | + .overridingErrorMessage( |
| 214 | + "Expected event to have account additional " + |
| 215 | + "properties ${expected?.extraInfo} " + |
| 216 | + "but was ${actual.account?.additionalProperties}" |
| 217 | + ) |
| 218 | + .containsExactlyInAnyOrderEntriesOf(expected?.extraInfo) |
| 219 | + } |
| 220 | + |
| 221 | + fun hasUserInfo(expected: UserInfo?) = apply { |
| 222 | + assertThat(actual.usr?.id) |
| 223 | + .overridingErrorMessage( |
| 224 | + "Expected event to have usr.id ${expected?.id} " + |
| 225 | + "but was ${actual.usr?.id}" |
| 226 | + ) |
| 227 | + .isEqualTo(expected?.id) |
| 228 | + assertThat(actual.usr?.name) |
| 229 | + .overridingErrorMessage( |
| 230 | + "Expected event to have usr.name ${expected?.name} " + |
| 231 | + "but was ${actual.usr?.name}" |
| 232 | + ) |
| 233 | + .isEqualTo(expected?.name) |
| 234 | + assertThat(actual.usr?.email) |
| 235 | + .overridingErrorMessage( |
| 236 | + "Expected event to have usr.email ${expected?.email} " + |
| 237 | + "but was ${actual.usr?.email}" |
| 238 | + ) |
| 239 | + .isEqualTo(expected?.email) |
| 240 | + assertThat(actual.usr?.additionalProperties) |
| 241 | + .overridingErrorMessage( |
| 242 | + "Expected event to have user additional" + |
| 243 | + " properties ${expected?.additionalProperties} " + |
| 244 | + "but was ${actual.usr?.additionalProperties}" |
| 245 | + ) |
| 246 | + .containsExactlyInAnyOrderEntriesOf(expected?.additionalProperties) |
| 247 | + } |
| 248 | + |
| 249 | + fun hasDeviceInfo( |
| 250 | + name: String, |
| 251 | + model: String, |
| 252 | + brand: String, |
| 253 | + type: VitalEvent.DeviceType, |
| 254 | + architecture: String |
| 255 | + ) = apply { |
| 256 | + assertThat(actual.device?.name) |
| 257 | + .overridingErrorMessage( |
| 258 | + "Expected event data to have device.name $name but was ${actual.device?.name}" |
| 259 | + ) |
| 260 | + .isEqualTo(name) |
| 261 | + assertThat(actual.device?.model) |
| 262 | + .overridingErrorMessage( |
| 263 | + "Expected event data to have device.model $model but was ${actual.device?.model}" |
| 264 | + ) |
| 265 | + .isEqualTo(model) |
| 266 | + assertThat(actual.device?.brand) |
| 267 | + .overridingErrorMessage( |
| 268 | + "Expected event data to have device.brand $brand but was ${actual.device?.brand}" |
| 269 | + ) |
| 270 | + .isEqualTo(brand) |
| 271 | + assertThat(actual.device?.type) |
| 272 | + .overridingErrorMessage( |
| 273 | + "Expected event data to have device.type $type but was ${actual.device?.type}" |
| 274 | + ) |
| 275 | + .isEqualTo(type) |
| 276 | + assertThat(actual.device?.architecture) |
| 277 | + .overridingErrorMessage( |
| 278 | + "Expected event data to have device.architecture $architecture" + |
| 279 | + " but was ${actual.device?.architecture}" |
| 280 | + ) |
| 281 | + .isEqualTo(architecture) |
| 282 | + } |
| 283 | + |
| 284 | + fun hasOsInfo( |
| 285 | + name: String, |
| 286 | + version: String, |
| 287 | + versionMajor: String |
| 288 | + ) = apply { |
| 289 | + assertThat(actual.os?.name) |
| 290 | + .overridingErrorMessage( |
| 291 | + "Expected event data to have os.name $name but was ${actual.os?.name}" |
| 292 | + ) |
| 293 | + .isEqualTo(name) |
| 294 | + assertThat(actual.os?.version) |
| 295 | + .overridingErrorMessage( |
| 296 | + "Expected event data to have os.version $version but was ${actual.os?.version}" |
| 297 | + ) |
| 298 | + .isEqualTo(version) |
| 299 | + assertThat(actual.os?.versionMajor) |
| 300 | + .overridingErrorMessage( |
| 301 | + "Expected event data to have os.version_major $versionMajor" + |
| 302 | + " but was ${actual.os?.versionMajor}" |
| 303 | + ) |
| 304 | + .isEqualTo(versionMajor) |
| 305 | + } |
| 306 | + |
| 307 | + fun hasConnectivityInfo(expected: NetworkInfo?) = apply { |
| 308 | + val expectedStatus = if (expected?.isConnected() == true) { |
| 309 | + VitalEvent.Status.CONNECTED |
| 310 | + } else { |
| 311 | + VitalEvent.Status.NOT_CONNECTED |
| 312 | + } |
| 313 | + val expectedInterfaces = when (expected?.connectivity) { |
| 314 | + NetworkInfo.Connectivity.NETWORK_ETHERNET -> listOf(VitalEvent.Interface.ETHERNET) |
| 315 | + NetworkInfo.Connectivity.NETWORK_WIFI -> listOf(VitalEvent.Interface.WIFI) |
| 316 | + NetworkInfo.Connectivity.NETWORK_WIMAX -> listOf(VitalEvent.Interface.WIMAX) |
| 317 | + NetworkInfo.Connectivity.NETWORK_BLUETOOTH -> listOf(VitalEvent.Interface.BLUETOOTH) |
| 318 | + NetworkInfo.Connectivity.NETWORK_2G, |
| 319 | + NetworkInfo.Connectivity.NETWORK_3G, |
| 320 | + NetworkInfo.Connectivity.NETWORK_4G, |
| 321 | + NetworkInfo.Connectivity.NETWORK_5G, |
| 322 | + NetworkInfo.Connectivity.NETWORK_MOBILE_OTHER, |
| 323 | + NetworkInfo.Connectivity.NETWORK_CELLULAR -> listOf(VitalEvent.Interface.CELLULAR) |
| 324 | + |
| 325 | + NetworkInfo.Connectivity.NETWORK_OTHER -> listOf(VitalEvent.Interface.OTHER) |
| 326 | + NetworkInfo.Connectivity.NETWORK_NOT_CONNECTED -> emptyList() |
| 327 | + null -> null |
| 328 | + } |
| 329 | + |
| 330 | + assertThat(actual.connectivity?.status) |
| 331 | + .overridingErrorMessage( |
| 332 | + "Expected RUM event to have connectivity.status $expectedStatus " + |
| 333 | + "but was ${actual.connectivity?.status}" |
| 334 | + ) |
| 335 | + .isEqualTo(expectedStatus) |
| 336 | + |
| 337 | + assertThat(actual.connectivity?.cellular?.technology) |
| 338 | + .overridingErrorMessage( |
| 339 | + "Expected RUM event to connectivity usr.cellular.technology " + |
| 340 | + "${expected?.cellularTechnology} " + |
| 341 | + "but was ${actual.connectivity?.cellular?.technology}" |
| 342 | + ) |
| 343 | + .isEqualTo(expected?.cellularTechnology) |
| 344 | + |
| 345 | + assertThat(actual.connectivity?.cellular?.carrierName) |
| 346 | + .overridingErrorMessage( |
| 347 | + "Expected RUM event to connectivity usr.cellular.carrierName " + |
| 348 | + "${expected?.carrierName} " + |
| 349 | + "but was ${actual.connectivity?.cellular?.carrierName}" |
| 350 | + ) |
| 351 | + .isEqualTo(expected?.carrierName) |
| 352 | + |
| 353 | + assertThat(actual.connectivity?.interfaces) |
| 354 | + .overridingErrorMessage( |
| 355 | + "Expected RUM event to have connectivity.interfaces $expectedInterfaces " + |
| 356 | + "but was ${actual.connectivity?.interfaces}" |
| 357 | + ) |
| 358 | + .isEqualTo(expectedInterfaces) |
| 359 | + } |
| 360 | + |
| 361 | + fun hasVersion(version: String?) = apply { |
| 362 | + assertThat(actual.version) |
| 363 | + .overridingErrorMessage( |
| 364 | + "Expected RUM event to have version: $version" + |
| 365 | + " but instead was: ${actual.version}" |
| 366 | + ) |
| 367 | + .isEqualTo(version) |
| 368 | + } |
| 369 | + |
| 370 | + fun hasServiceName(serviceName: String?) = apply { |
| 371 | + assertThat(actual.service) |
| 372 | + .overridingErrorMessage( |
| 373 | + "Expected RUM event to have serviceName: $serviceName" + |
| 374 | + " but instead was: ${actual.service}" |
| 375 | + ) |
| 376 | + .isEqualTo(serviceName) |
| 377 | + } |
| 378 | + |
| 379 | + fun hasDDTags(ddTags: String) = apply { |
| 380 | + assertThat(actual.ddtags) |
| 381 | + .overridingErrorMessage( |
| 382 | + "Expected RUM event to have ddTags: $ddTags" + |
| 383 | + " but instead was: ${actual.ddtags}" |
| 384 | + ) |
| 385 | + .isEqualTo(ddTags) |
| 386 | + } |
| 387 | + |
183 | 388 | companion object { |
184 | 389 | internal fun assertThat(actual: VitalEvent): VitalEventAssert = VitalEventAssert(actual) |
185 | 390 | } |
|
0 commit comments