|
| 1 | +package com.paypal.messages.logger |
| 2 | + |
| 3 | +import com.google.gson.Gson |
| 4 | +import org.junit.jupiter.api.Assertions.assertEquals |
| 5 | +import org.junit.jupiter.api.Test |
| 6 | + |
| 7 | +class CloudEventTest { |
| 8 | + private val clientId = "test_client_id" |
| 9 | + private val merchantId = "test_merchant_id" |
| 10 | + private val partnerAttributionId = "test_partner_attribution_id" |
| 11 | + private val merchantProfileHash = "test_merchant_profile_hash" |
| 12 | + private val deviceId = "test_device_id" |
| 13 | + private val sessionId = "test_session_id" |
| 14 | + private val instanceId = "test_instance_id" |
| 15 | + private val integrationName = "test_integration_name" |
| 16 | + private val integrationType = "test_integration_type" |
| 17 | + private val integrationVersion = "test_integration_version" |
| 18 | + private val libraryVersion = "test_library_version" |
| 19 | + private val components = mutableListOf<TrackingComponent>() |
| 20 | + private val specVersion = "1.0" |
| 21 | + private val type = "com.paypal.credit.upstream-presentment.v1" |
| 22 | + private val source = "urn:paypal:event-src:v1:android:messages" |
| 23 | + private val dataContentType = "application/json" |
| 24 | + |
| 25 | + @Suppress("ktlint:standard:max-line-length") |
| 26 | + private val dataSchema = "ppaas:events.credit.FinancingPresentmentAsyncAPISpecification/v1/schema/json/credit_upstream_presentment_event.json" |
| 27 | + |
| 28 | + private val data = TrackingPayload( |
| 29 | + clientId = clientId, |
| 30 | + merchantId = merchantId, |
| 31 | + partnerAttributionId = partnerAttributionId, |
| 32 | + merchantProfileHash = merchantProfileHash, |
| 33 | + deviceId = deviceId, |
| 34 | + sessionId = sessionId, |
| 35 | + instanceId = instanceId, |
| 36 | + integrationName = integrationName, |
| 37 | + integrationType = integrationType, |
| 38 | + integrationVersion = integrationVersion, |
| 39 | + libraryVersion = libraryVersion, |
| 40 | + components = components, |
| 41 | + ) |
| 42 | + |
| 43 | + private val cloudWrappedEvent = CloudEvent( |
| 44 | + specVersion = specVersion, |
| 45 | + type = type, |
| 46 | + source = source, |
| 47 | + dataContentType = dataContentType, |
| 48 | + dataSchema = dataSchema, |
| 49 | + data = data, |
| 50 | + ) |
| 51 | + |
| 52 | + @Test |
| 53 | + fun testConstructor() { |
| 54 | + assertEquals(cloudWrappedEvent.specVersion, specVersion) |
| 55 | + assertEquals(cloudWrappedEvent.type, type) |
| 56 | + assertEquals(cloudWrappedEvent.source, source) |
| 57 | + assertEquals(cloudWrappedEvent.dataContentType, dataContentType) |
| 58 | + assertEquals(cloudWrappedEvent.dataSchema, dataSchema) |
| 59 | + assertEquals(cloudWrappedEvent.data, data) |
| 60 | + } |
| 61 | + |
| 62 | + @Test |
| 63 | + fun testSerialization() { |
| 64 | + val gson = Gson() |
| 65 | + val json = gson.toJson(cloudWrappedEvent) |
| 66 | + |
| 67 | + @Suppress("ktlint:standard:max-line-length") |
| 68 | + val expectedJson = """{"specversion":"1.0","id":"${cloudWrappedEvent.id}","type":"com.paypal.credit.upstream-presentment.v1","source":"urn:paypal:event-src:v1:android:messages","datacontenttype":"application/json","dataschema":"ppaas:events.credit.FinancingPresentmentAsyncAPISpecification/v1/schema/json/credit_upstream_presentment_event.json","time":"${cloudWrappedEvent.time}","data":{"client_id":"test_client_id","merchant_id":"test_merchant_id","partner_attribution_id":"test_partner_attribution_id","merchant_profile_hash":"test_merchant_profile_hash","device_id":"test_device_id","session_id":"test_session_id","instance_id":"test_instance_id","integration_name":"test_integration_name","integration_type":"test_integration_type","integration_version":"test_integration_version","lib_version":"test_library_version","components":[]}}""" |
| 69 | + assertEquals(expectedJson, json) |
| 70 | + } |
| 71 | +} |
0 commit comments