From 1c4908ebe5655685a9c2cf93b2f225b5712ee4e5 Mon Sep 17 00:00:00 2001 From: Patrick Schalk Date: Fri, 19 Apr 2024 14:38:35 +0200 Subject: [PATCH] Add serialization test for data entry aggregate #978 --- .../core/business/DataEntryAggregateTest.kt | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/core/datapool/datapool-core/src/test/kotlin/io/holunda/polyflow/datapool/core/business/DataEntryAggregateTest.kt b/core/datapool/datapool-core/src/test/kotlin/io/holunda/polyflow/datapool/core/business/DataEntryAggregateTest.kt index 262004518..054d9933b 100644 --- a/core/datapool/datapool-core/src/test/kotlin/io/holunda/polyflow/datapool/core/business/DataEntryAggregateTest.kt +++ b/core/datapool/datapool-core/src/test/kotlin/io/holunda/polyflow/datapool/core/business/DataEntryAggregateTest.kt @@ -1,7 +1,11 @@ package io.holunda.polyflow.datapool.core.business +import com.fasterxml.jackson.databind.ObjectMapper import io.holunda.camunda.taskpool.api.business.* +import io.holunda.polyflow.bus.jackson.configurePolyflowJacksonObjectMapper import io.holunda.polyflow.datapool.core.DeletionStrategy +import org.assertj.core.api.Assertions +import org.assertj.core.api.Assertions.assertThat import org.axonframework.eventsourcing.AggregateDeletedException import org.axonframework.test.aggregate.AggregateTestFixture import org.camunda.bpm.engine.variable.Variables @@ -353,5 +357,51 @@ class DataEntryAggregateTest { ) } + @Test + fun `should serialize and deserialize an empty aggregate`() { + // GIVEN a object mapper and an empty aggregate + val objectMapper = ObjectMapper().configurePolyflowJacksonObjectMapper() + val dataEntryAggregate = DataEntryAggregate() + + // WHEN we serialize and deserialize it + val serializedObj = objectMapper.writeValueAsString(dataEntryAggregate) + val deserializedObj = objectMapper.readValue(serializedObj, DataEntryAggregate::class.java) + + // THEN no problem should occur + } + + @Test + fun `should serialize and deserialize an aggregate with data`() { + // GIVEN a object mapper and a filled aggregate + val objectMapper = ObjectMapper().configurePolyflowJacksonObjectMapper() + + val dataEntryAggregate = DataEntryAggregate().apply { + on( + DataEntryCreatedEvent( + entryId = UUID.randomUUID().toString(), + entryType = "io.holunda.My", + name = "Some name", + type = "Another", + applicationName = "Different application", + ) + ) + } + val dataIdentityValue = dataEntryAggregate.getDataIdentityValueForTest() + + // WHEN we serialize and deserialize it + val serializedObj = objectMapper.writeValueAsString(dataEntryAggregate) + val deserializedObj = objectMapper.readValue(serializedObj, DataEntryAggregate::class.java) + // THEN no problem should occur + assertThat(deserializedObj.getDataIdentityValueForTest()).isEqualTo(dataIdentityValue) + } + +} + +private fun DataEntryAggregate.getDataIdentityValueForTest(): String? { + return javaClass.getDeclaredField("dataIdentity").let { + it.isAccessible = true + val value = it.get(this) as String? + return@let value + } }