-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
141 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
library/src/main/java/com/paypal/messages/logger/CloudEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.paypal.messages.logger | ||
|
||
import com.google.gson.annotations.SerializedName | ||
import java.text.SimpleDateFormat | ||
import java.util.Date | ||
import java.util.UUID | ||
|
||
data class CloudEvent( | ||
@SerializedName("specversion") | ||
val specVersion: String = "1.0", | ||
val id: UUID = UUID.randomUUID(), | ||
val type: String = "com.paypal.credit.upstream-presentment.v1", | ||
val source: String = "urn:paypal:event-src:v1:android:messages", | ||
@SerializedName("datacontenttype") | ||
val dataContentType: String = "application/json", | ||
@Suppress("ktlint:standard:max-line-length") | ||
@SerializedName("dataschema") | ||
val dataSchema: String = "ppaas:events.credit.FinancingPresentmentAsyncAPISpecification/v1/schema/json/credit_upstream_presentment_event.json", | ||
var time: String = "", | ||
val data: TrackingPayload, | ||
) { | ||
init { | ||
val dateFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ") | ||
val currentDate = Date() | ||
|
||
val formattedDate = dateFormat.format(currentDate) | ||
time = formattedDate | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
library/src/test/java/com/paypal/messages/logger/CloudEventTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.paypal.messages.logger | ||
|
||
import com.google.gson.Gson | ||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.Test | ||
|
||
class CloudEventTest { | ||
private val clientId = "test_client_id" | ||
private val merchantId = "test_merchant_id" | ||
private val partnerAttributionId = "test_partner_attribution_id" | ||
private val merchantProfileHash = "test_merchant_profile_hash" | ||
private val deviceId = "test_device_id" | ||
private val sessionId = "test_session_id" | ||
private val instanceId = "test_instance_id" | ||
private val integrationName = "test_integration_name" | ||
private val integrationType = "test_integration_type" | ||
private val integrationVersion = "test_integration_version" | ||
private val libraryVersion = "test_library_version" | ||
private val components = mutableListOf<TrackingComponent>() | ||
private val specVersion = "1.0" | ||
private val type = "com.paypal.credit.upstream-presentment.v1" | ||
private val source = "urn:paypal:event-src:v1:android:messages" | ||
private val dataContentType = "application/json" | ||
|
||
@Suppress("ktlint:standard:max-line-length") | ||
private val dataSchema = "ppaas:events.credit.FinancingPresentmentAsyncAPISpecification/v1/schema/json/credit_upstream_presentment_event.json" | ||
|
||
private val data = TrackingPayload( | ||
clientId = clientId, | ||
merchantId = merchantId, | ||
partnerAttributionId = partnerAttributionId, | ||
merchantProfileHash = merchantProfileHash, | ||
deviceId = deviceId, | ||
sessionId = sessionId, | ||
instanceId = instanceId, | ||
integrationName = integrationName, | ||
integrationType = integrationType, | ||
integrationVersion = integrationVersion, | ||
libraryVersion = libraryVersion, | ||
components = components, | ||
) | ||
|
||
private val cloudWrappedEvent = CloudEvent( | ||
specVersion = specVersion, | ||
type = type, | ||
source = source, | ||
dataContentType = dataContentType, | ||
dataSchema = dataSchema, | ||
data = data, | ||
) | ||
|
||
@Test | ||
fun testConstructor() { | ||
assertEquals(cloudWrappedEvent.specVersion, specVersion) | ||
assertEquals(cloudWrappedEvent.type, type) | ||
assertEquals(cloudWrappedEvent.source, source) | ||
assertEquals(cloudWrappedEvent.dataContentType, dataContentType) | ||
assertEquals(cloudWrappedEvent.dataSchema, dataSchema) | ||
assertEquals(cloudWrappedEvent.data, data) | ||
} | ||
|
||
@Test | ||
fun testSerialization() { | ||
val gson = Gson() | ||
val json = gson.toJson(cloudWrappedEvent) | ||
|
||
@Suppress("ktlint:standard:max-line-length") | ||
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":[]}}""" | ||
assertEquals(expectedJson, json) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters