diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/capture/envelope/LogEnvelopeSource.kt b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/capture/envelope/LogEnvelopeSource.kt new file mode 100644 index 0000000000..f385ff1a3b --- /dev/null +++ b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/capture/envelope/LogEnvelopeSource.kt @@ -0,0 +1,23 @@ +package io.embrace.android.embracesdk.capture.envelope + +import io.embrace.android.embracesdk.capture.envelope.log.LogSource +import io.embrace.android.embracesdk.capture.envelope.metadata.EnvelopeMetadataSource +import io.embrace.android.embracesdk.capture.envelope.resource.EnvelopeResourceSource +import io.embrace.android.embracesdk.internal.payload.Envelope +import io.embrace.android.embracesdk.internal.payload.Log +import io.embrace.android.embracesdk.session.orchestrator.SessionSnapshotType + +internal class LogEnvelopeSource( + private val metadataSource: EnvelopeMetadataSource, + private val resourceSource: EnvelopeResourceSource, + private val logSource: LogSource, +) : EnvelopeSource { + + override fun getEnvelope(endType: SessionSnapshotType) = Envelope( + resourceSource.getEnvelopeResource(), + metadataSource.getEnvelopeMetadata(), + null, + null, + logSource.getLogPayload() + ) +} diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/capture/envelope/SessionEnvelopeSource.kt b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/capture/envelope/SessionEnvelopeSource.kt index 806bef6310..aeca90a192 100644 --- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/capture/envelope/SessionEnvelopeSource.kt +++ b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/capture/envelope/SessionEnvelopeSource.kt @@ -1,16 +1,25 @@ package io.embrace.android.embracesdk.capture.envelope +import io.embrace.android.embracesdk.capture.envelope.metadata.EnvelopeMetadataSource +import io.embrace.android.embracesdk.capture.envelope.resource.EnvelopeResourceSource import io.embrace.android.embracesdk.capture.envelope.session.SessionPayloadSource import io.embrace.android.embracesdk.internal.payload.Envelope import io.embrace.android.embracesdk.internal.payload.SessionPayload import io.embrace.android.embracesdk.session.orchestrator.SessionSnapshotType internal class SessionEnvelopeSource( - private val sessionPayloadSource: SessionPayloadSource + private val metadataSource: EnvelopeMetadataSource, + private val resourceSource: EnvelopeResourceSource, + private val sessionPayloadSource: SessionPayloadSource, ) : EnvelopeSource { override fun getEnvelope(endType: SessionSnapshotType): Envelope { - sessionPayloadSource.getSessionPayload(endType) - throw NotImplementedError("Not yet implemented") + return Envelope( + resourceSource.getEnvelopeResource(), + metadataSource.getEnvelopeMetadata(), + null, + null, + sessionPayloadSource.getSessionPayload(endType) + ) } } diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/capture/envelope/log/LogSource.kt b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/capture/envelope/log/LogSource.kt new file mode 100644 index 0000000000..13377b0f8b --- /dev/null +++ b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/capture/envelope/log/LogSource.kt @@ -0,0 +1,7 @@ +package io.embrace.android.embracesdk.capture.envelope.log + +import io.embrace.android.embracesdk.internal.payload.Log + +internal interface LogSource { + fun getLogPayload(): Log +} diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/capture/envelope/log/LogSourceImpl.kt b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/capture/envelope/log/LogSourceImpl.kt new file mode 100644 index 0000000000..ea8e80f2f0 --- /dev/null +++ b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/capture/envelope/log/LogSourceImpl.kt @@ -0,0 +1,9 @@ +package io.embrace.android.embracesdk.capture.envelope.log + +import io.embrace.android.embracesdk.internal.payload.Log + +internal class LogSourceImpl : LogSource { + override fun getLogPayload(): Log { + throw NotImplementedError("Not implemented yet") + } +} diff --git a/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/capture/envelope/LogEnvelopeSourceTest.kt b/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/capture/envelope/LogEnvelopeSourceTest.kt new file mode 100644 index 0000000000..9cfe34831b --- /dev/null +++ b/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/capture/envelope/LogEnvelopeSourceTest.kt @@ -0,0 +1,32 @@ +package io.embrace.android.embracesdk.capture.envelope + +import io.embrace.android.embracesdk.fakes.FakeEnvelopeMetadataSource +import io.embrace.android.embracesdk.fakes.FakeEnvelopeResourceSource +import io.embrace.android.embracesdk.fakes.FakeLogSource +import io.embrace.android.embracesdk.session.orchestrator.SessionSnapshotType +import org.junit.Assert.assertEquals +import org.junit.Assert.assertNull +import org.junit.Test + +internal class LogEnvelopeSourceTest { + + @Test + fun getEnvelope() { + val metadataSource = FakeEnvelopeMetadataSource() + val resourceSource = FakeEnvelopeResourceSource() + val logSource = FakeLogSource() + val source = LogEnvelopeSource( + metadataSource, + resourceSource, + logSource, + ) + val payload = source.getEnvelope(SessionSnapshotType.NORMAL_END) + assertEquals(metadataSource.metadata, payload.metadata) + assertEquals(resourceSource.resource, payload.resource) + assertEquals(logSource.log, payload.data) + + // future fields that need populating: + assertNull(payload.type) + assertNull(payload.version) + } +} diff --git a/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/capture/envelope/SessionEnvelopeSourceTest.kt b/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/capture/envelope/SessionEnvelopeSourceTest.kt index 995788b271..053cfa34bf 100644 --- a/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/capture/envelope/SessionEnvelopeSourceTest.kt +++ b/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/capture/envelope/SessionEnvelopeSourceTest.kt @@ -1,24 +1,32 @@ package io.embrace.android.embracesdk.capture.envelope -import io.embrace.android.embracesdk.capture.envelope.session.SessionPayloadSourceImpl -import io.embrace.android.embracesdk.fakes.FakeCurrentSessionSpan -import io.embrace.android.embracesdk.fakes.FakeInternalErrorService -import io.embrace.android.embracesdk.fakes.FakeNativeThreadSamplerService -import io.embrace.android.embracesdk.internal.spans.SpanSinkImpl +import io.embrace.android.embracesdk.fakes.FakeEnvelopeMetadataSource +import io.embrace.android.embracesdk.fakes.FakeEnvelopeResourceSource +import io.embrace.android.embracesdk.fakes.FakeSessionPayloadSource import io.embrace.android.embracesdk.session.orchestrator.SessionSnapshotType +import org.junit.Assert.assertEquals +import org.junit.Assert.assertNull import org.junit.Test internal class SessionEnvelopeSourceTest { - @Test(expected = NotImplementedError::class) + @Test fun getEnvelope() { - SessionEnvelopeSource( - SessionPayloadSourceImpl( - FakeInternalErrorService(), - FakeNativeThreadSamplerService(), - SpanSinkImpl(), - FakeCurrentSessionSpan() - ) - ).getEnvelope(SessionSnapshotType.NORMAL_END) + val metadataSource = FakeEnvelopeMetadataSource() + val resourceSource = FakeEnvelopeResourceSource() + val sessionPayloadSource = FakeSessionPayloadSource() + val source = SessionEnvelopeSource( + metadataSource, + resourceSource, + sessionPayloadSource, + ) + val payload = source.getEnvelope(SessionSnapshotType.NORMAL_END) + assertEquals(metadataSource.metadata, payload.metadata) + assertEquals(resourceSource.resource, payload.resource) + assertEquals(sessionPayloadSource.sessionPayload, payload.data) + + // future fields that need populating: + assertNull(payload.type) + assertNull(payload.version) } } diff --git a/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/fakes/FakeEnvelopeMetadataSource.kt b/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/fakes/FakeEnvelopeMetadataSource.kt new file mode 100644 index 0000000000..c795be2a9a --- /dev/null +++ b/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/fakes/FakeEnvelopeMetadataSource.kt @@ -0,0 +1,11 @@ +package io.embrace.android.embracesdk.fakes + +import io.embrace.android.embracesdk.capture.envelope.metadata.EnvelopeMetadataSource +import io.embrace.android.embracesdk.internal.payload.EnvelopeMetadata + +internal class FakeEnvelopeMetadataSource : EnvelopeMetadataSource { + + var metadata: EnvelopeMetadata = EnvelopeMetadata() + + override fun getEnvelopeMetadata(): EnvelopeMetadata = metadata +} diff --git a/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/fakes/FakeEnvelopeResourceSource.kt b/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/fakes/FakeEnvelopeResourceSource.kt new file mode 100644 index 0000000000..474d84dc4e --- /dev/null +++ b/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/fakes/FakeEnvelopeResourceSource.kt @@ -0,0 +1,11 @@ +package io.embrace.android.embracesdk.fakes + +import io.embrace.android.embracesdk.capture.envelope.resource.EnvelopeResourceSource +import io.embrace.android.embracesdk.internal.payload.EnvelopeResource + +internal class FakeEnvelopeResourceSource : EnvelopeResourceSource { + + var resource: EnvelopeResource = EnvelopeResource() + + override fun getEnvelopeResource(): EnvelopeResource = resource +} diff --git a/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/fakes/FakeLogSource.kt b/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/fakes/FakeLogSource.kt new file mode 100644 index 0000000000..faca31ca67 --- /dev/null +++ b/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/fakes/FakeLogSource.kt @@ -0,0 +1,11 @@ +package io.embrace.android.embracesdk.fakes + +import io.embrace.android.embracesdk.capture.envelope.log.LogSource +import io.embrace.android.embracesdk.internal.payload.Log + +internal class FakeLogSource : LogSource { + + var log: Log = Log() + + override fun getLogPayload(): Log = log +} diff --git a/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/fakes/FakeSessionPayloadSource.kt b/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/fakes/FakeSessionPayloadSource.kt new file mode 100644 index 0000000000..13bde75a77 --- /dev/null +++ b/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/fakes/FakeSessionPayloadSource.kt @@ -0,0 +1,11 @@ +package io.embrace.android.embracesdk.fakes + +import io.embrace.android.embracesdk.capture.envelope.session.SessionPayloadSource +import io.embrace.android.embracesdk.internal.payload.SessionPayload +import io.embrace.android.embracesdk.session.orchestrator.SessionSnapshotType + +internal class FakeSessionPayloadSource : SessionPayloadSource { + + var sessionPayload: SessionPayload = SessionPayload() + override fun getSessionPayload(endType: SessionSnapshotType) = sessionPayload +}