@@ -2,11 +2,9 @@ package io.holunda.polyflow.datapool.core.business
22
33import com.fasterxml.jackson.databind.ObjectMapper
44import io.holunda.camunda.taskpool.api.business.*
5- import io.holunda.polyflow.bus.jackson.JsonAutoDetectAnyVisibility
65import io.holunda.polyflow.bus.jackson.configurePolyflowJacksonObjectMapper
76import io.holunda.polyflow.datapool.core.DeletionStrategy
87import io.holunda.polyflow.datapool.core.configurePolyflowJacksonObjectMapperForDatapool
9- import org.assertj.core.api.Assertions
108import org.assertj.core.api.Assertions.assertThat
119import org.axonframework.eventsourcing.AggregateDeletedException
1210import org.axonframework.test.aggregate.AggregateTestFixture
@@ -164,6 +162,113 @@ class DataEntryAggregateTest {
164162 )
165163 }
166164
165+ @Test
166+ fun `should anonymize aggregate` () {
167+
168+ val dataEntryChange = DataEntryChange (
169+ entryType = " io.holunda.My" ,
170+ entryId = UUID .randomUUID().toString(),
171+ applicationName = " myApp" ,
172+ name = " My Entry 4711" ,
173+ type = " My" ,
174+ payload = Variables .createVariables(),
175+ correlations = newCorrelations()
176+ )
177+
178+ val command = AnonymizeDataEntryCommand (
179+ entryType = dataEntryChange.entryType,
180+ entryId = dataEntryChange.entryId,
181+ anonymizedUsername = " ANONYMOUS" ,
182+ excludedUsernames = listOf (" SYSTEM" ),
183+ anonymizeModification = Modification (OffsetDateTime .now(), " kermit" , " kermit decided to anonymize" , logNotes = " Let us anonymize this item" )
184+ )
185+
186+ fixture
187+ .registerInjectableResource(LAX_POLICY )
188+ .given(
189+ DataEntryCreatedEvent (
190+ entryId = dataEntryChange.entryId,
191+ entryType = dataEntryChange.entryType,
192+ name = " Some name" ,
193+ type = " Another" ,
194+ applicationName = " Different application" ,
195+ state = dataEntryChange.state,
196+ description = dataEntryChange.description,
197+ payload = dataEntryChange.payload,
198+ correlations = dataEntryChange.correlations,
199+ createModification = dataEntryChange.modification,
200+ authorizations = dataEntryChange.authorizationChanges,
201+ formKey = dataEntryChange.formKey
202+ )
203+ )
204+ .`when `(command)
205+ .expectEvents(
206+ DataEntryAnonymizedEvent (
207+ entryId = command.entryId,
208+ entryType = command.entryType,
209+ anonymizedUsername = command.anonymizedUsername,
210+ excludedUsernames = command.excludedUsernames,
211+ anonymizeModification = command.anonymizeModification,
212+ )
213+ )
214+ }
215+
216+ @Test
217+ fun `should not anonymize deleted aggregate in strict mode` () {
218+
219+ val dataEntryChange = DataEntryChange (
220+ entryType = " io.holunda.My" ,
221+ entryId = UUID .randomUUID().toString(),
222+ applicationName = " myApp" ,
223+ name = " My Entry 4711" ,
224+ type = " My" ,
225+ payload = Variables .createVariables(),
226+ correlations = newCorrelations()
227+ )
228+
229+ val deleteCommand = DeleteDataEntryCommand (
230+ entryType = dataEntryChange.entryType,
231+ entryId = dataEntryChange.entryId,
232+ modification = Modification (OffsetDateTime .now(), " kermit" , " kermit decided to delete" , logNotes = " Let us delete this item" ),
233+ state = ProcessingType .DELETED .of(" deleted as irrelevant" )
234+ )
235+
236+ val anonymizeCommand = AnonymizeDataEntryCommand (
237+ entryType = dataEntryChange.entryType,
238+ entryId = dataEntryChange.entryId,
239+ anonymizedUsername = " ANONYMOUS" ,
240+ excludedUsernames = listOf (" SYSTEM" ),
241+ anonymizeModification = Modification (OffsetDateTime .now(), " kermit" , " kermit decided to anonymize" , logNotes = " Let us anonymize this item" )
242+ )
243+
244+ fixture
245+ .registerInjectableResource(STRICT_POLICY )
246+ .given(
247+ DataEntryCreatedEvent (
248+ entryId = dataEntryChange.entryId,
249+ entryType = dataEntryChange.entryType,
250+ name = " Some name" ,
251+ type = " Another" ,
252+ applicationName = " Different application" ,
253+ state = dataEntryChange.state,
254+ description = dataEntryChange.description,
255+ payload = dataEntryChange.payload,
256+ correlations = dataEntryChange.correlations,
257+ createModification = dataEntryChange.modification,
258+ authorizations = dataEntryChange.authorizationChanges,
259+ formKey = dataEntryChange.formKey
260+ ),
261+ DataEntryDeletedEvent (
262+ entryId = deleteCommand.entryId,
263+ entryType = deleteCommand.entryType,
264+ deleteModification = deleteCommand.modification,
265+ state = deleteCommand.state
266+ )
267+ )
268+ .`when `(anonymizeCommand)
269+ .expectException(AggregateDeletedException ::class .java)
270+ }
271+
167272 @Test
168273 fun `should not delete deleted aggregate in strict mode` () {
169274
0 commit comments