From 3970984edb315efea4ecdbae8b1d8188bbfa8c7d Mon Sep 17 00:00:00 2001 From: Simon Zambrovski Date: Tue, 11 Jul 2023 17:16:52 +0200 Subject: [PATCH 1/6] init axon assert --- extension/extension-assert/pom.xml | 28 +++ .../src/main/kotlin/AxonAssertions.kt | 28 +++ .../IntermediateEventRepresentationAssert.kt | 162 ++++++++++++++++++ ...rmediateEventRepresentationStreamAssert.kt | 44 +++++ extension/pom.xml | 1 + 5 files changed, 263 insertions(+) create mode 100644 extension/extension-assert/pom.xml create mode 100644 extension/extension-assert/src/main/kotlin/AxonAssertions.kt create mode 100644 extension/extension-assert/src/main/kotlin/IntermediateEventRepresentationAssert.kt create mode 100644 extension/extension-assert/src/main/kotlin/IntermediateEventRepresentationStreamAssert.kt diff --git a/extension/extension-assert/pom.xml b/extension/extension-assert/pom.xml new file mode 100644 index 0000000..90774fb --- /dev/null +++ b/extension/extension-assert/pom.xml @@ -0,0 +1,28 @@ + + + 4.0.0 + + io.holixon.axon.testing._ + extension + 4.7.4.1-SNAPSHOT + + + extension-assert + + + + + + + org.assertj + assertj-core + ${assertj.version} + + + org.axonframework + axon-messaging + + + diff --git a/extension/extension-assert/src/main/kotlin/AxonAssertions.kt b/extension/extension-assert/src/main/kotlin/AxonAssertions.kt new file mode 100644 index 0000000..97c5c45 --- /dev/null +++ b/extension/extension-assert/src/main/kotlin/AxonAssertions.kt @@ -0,0 +1,28 @@ +package io.holixon.axon.testing.assert + +import org.axonframework.serialization.Serializer +import org.axonframework.serialization.upcasting.event.IntermediateEventRepresentation +import java.util.stream.Stream + +class AxonAssertions private constructor() { + companion object { + /** + * Creates the assert for given intermediate representation serialized using given serializer. + * @param actual current intermediate representation. + * @param serializer serializer in use. + * @return the asserting anchor for checks. + */ + @JvmStatic + fun assertThat(actual: IntermediateEventRepresentation, serializer: Serializer) = IntermediateEventRepresentationAssert.assertThat(actual, serializer) + + /** + * Creates the assert for given stream of intermediate representations serialized using given serializer. + * @param actual current intermediate representation. + * @param serializer serializer in use. + * @return the asserting anchor for checks. + */ + @JvmStatic + fun assertThat(actual: Stream, serializer: Serializer) = + IntermediateEventRepresentationStreamAssert.assertThat(actual, serializer) + } +} diff --git a/extension/extension-assert/src/main/kotlin/IntermediateEventRepresentationAssert.kt b/extension/extension-assert/src/main/kotlin/IntermediateEventRepresentationAssert.kt new file mode 100644 index 0000000..2fb18fa --- /dev/null +++ b/extension/extension-assert/src/main/kotlin/IntermediateEventRepresentationAssert.kt @@ -0,0 +1,162 @@ +package io.holixon.axon.testing.assert + +import org.assertj.core.api.AbstractAssert +import org.assertj.core.api.ObjectAssert +import org.axonframework.serialization.SerializedObject +import org.axonframework.serialization.SerializedType +import org.axonframework.serialization.Serializer +import org.axonframework.serialization.upcasting.event.IntermediateEventRepresentation + +/** + * Asserts intermediate representation. + */ +class IntermediateEventRepresentationAssert(actual: IntermediateEventRepresentation, private val serializer: Serializer) : + AbstractAssert(actual, IntermediateEventRepresentationAssert::class.java) { + + + companion object { + /** + * Creates the assert for given intermediate representation serialized using given serializer. + * @param actual current intermediate representation. + * @param serializer serializer in use. + * @return the asserting anchor for checks. + */ + @JvmStatic + fun assertThat(actual: IntermediateEventRepresentation, serializer: Serializer) = IntermediateEventRepresentationAssert(actual, serializer) + } + + /** + * Asserts that the de-serialized data is equals to the given. + * @param expected expected data. + * @param T type of the data. + * @return object assert. + */ + fun hasDeserializedData(expected: T): ObjectAssert { + isNotNull + val event: T = serializer.deserialize(actual.data) + if (event != expected) { + failWithMessage("Expected the event to be <%s> but it was <%s>", expected, event) + } + return ObjectAssert(event) + } + + /** + * Asserts that the serialized data is equals to the given. + * @param expected expected data. + * @return object assert. + */ + fun hasData(expected: SerializedObject<*>): ObjectAssert> { + isNotNull + val so: SerializedObject<*> = actual.data + if (so != expected) { + failWithMessage("Expected the serialized object to be <%s> but it was <%s>", expected, so) + } + return ObjectAssert(so) + } + + /** + * Asserts that the aggregate identifier is equals to the given. + * @param expected aggregate identifier. + */ + fun hasAggregateIdentifier(expected: String): IntermediateEventRepresentationAssert { + isNotNull + val aggregateIdentifier = actual.aggregateIdentifier.orElse(null) + if (aggregateIdentifier != expected) { + failWithMessage("Expected the aggregate identifier to be <%s> but it was <%s>", expected, aggregateIdentifier) + } + return this + } + + /** + * Asserts that the message identifier is equals to the given. + * @param expected message identifier. + */ + fun hasMessageIdentifier(expected: String): IntermediateEventRepresentationAssert { + isNotNull + val messageIdentifier = actual.messageIdentifier + if (messageIdentifier != expected) { + failWithMessage("Expected the message identifier to be <%s> but it was <%s>", expected, messageIdentifier) + } + return this + } + + /** + * Asserts that the aggregate type is equals to the given. + * @param expected aggregate type. + */ + fun hasAggregateType(expected: String): IntermediateEventRepresentationAssert { + isNotNull + val aggregateType = actual.aggregateType.orElseGet(null) + if (aggregateType != expected) { + failWithMessage("Expected the aggregate type to be <%s> but it was <%s>", expected, aggregateType) + } + return this + } + + /** + * Asserts that the content type is equals to the given. + * @param expected content type. + */ + fun hasAggregateType(expected: Class<*>): IntermediateEventRepresentationAssert { + isNotNull + val contentType = actual.contentType + if (contentType != expected) { + failWithMessage("Expected the content type to be <%s> but it was <%s>", expected, contentType) + } + return this + } + + /** + * Asserts that the type is equals to the given. + * @param expected type. + */ + fun hasType(expected: SerializedType): IntermediateEventRepresentationAssert { + isNotNull + val type = actual.type + if (type != expected) { + failWithMessage("Expected the content type to be <%s> but it was <%s>", expected, type) + } + return this + } + + /** + * Asserts that the type name is equals to the given. + * @param expected type. + */ + fun hasTypeName(expected: String): IntermediateEventRepresentationAssert { + isNotNull + val typeName = actual.type.name + if (typeName != expected) { + failWithMessage("Expected the content type name to be <%s> but it was <%s>", expected, typeName) + } + return this + } + + /** + * Asserts that the type name is equals to the given. + * @param expected type. + */ + fun hasTypeRevision(expected: String?): IntermediateEventRepresentationAssert { + isNotNull + val typeName = actual.type.revision + if (typeName != expected) { + failWithMessage("Expected the content type name to be <%s> but it was <%s>", expected, typeName) + } + return this + } + + /** + * Asserts that the deserialized version of data is equals to deserialized version of given. + * @param expected intermediate representation. + * @param T type of the payload. + */ + fun isEqualsTo(expected: IntermediateEventRepresentation): IntermediateEventRepresentationAssert { + isNotNull + val deserialized: T = serializer.deserialize(actual.data) + val deserializedExpected: T = serializer.deserialize(actual.data) + if (deserialized != deserializedExpected) { + failWithMessage("Expected the content type name to be <%s> but it was <%s>", deserializedExpected, deserialized) + } + return this + } +} diff --git a/extension/extension-assert/src/main/kotlin/IntermediateEventRepresentationStreamAssert.kt b/extension/extension-assert/src/main/kotlin/IntermediateEventRepresentationStreamAssert.kt new file mode 100644 index 0000000..058cce3 --- /dev/null +++ b/extension/extension-assert/src/main/kotlin/IntermediateEventRepresentationStreamAssert.kt @@ -0,0 +1,44 @@ +package io.holixon.axon.testing.assert + +import org.assertj.core.api.AbstractAssert +import org.axonframework.serialization.Serializer +import org.axonframework.serialization.upcasting.event.IntermediateEventRepresentation +import java.util.stream.Collectors +import java.util.stream.Stream + +/** + * Asserts intermediate representation. + */ +class IntermediateEventRepresentationStreamAssert(actual: Stream, private val serializer: Serializer) : + AbstractAssert>( + actual, + IntermediateEventRepresentationStreamAssert::class.java + ) { + + + companion object { + /** + * Creates the assert for given stream of intermediate representations serialized using given serializer. + * @param actual current intermediate representation. + * @param serializer serializer in use. + * @return the asserting anchor for checks. + */ + @JvmStatic + fun assertThat(actual: Stream, serializer: Serializer) = IntermediateEventRepresentationStreamAssert(actual, serializer) + } + + /** + * Asserts that the deserialized version of data is element-wise equal to deserialized version of given. + * @param expected intermediate representation. + * @param T type of the payload. + */ + fun isContainsExactlyElementsOf(expected: Stream): IntermediateEventRepresentationStreamAssert { + isNotNull + val deserialized: List = actual.collect(Collectors.toList()).map { ier -> serializer.deserialize(ier.data) } + val deserializedExpected: List = expected.collect(Collectors.toList()).map { ier -> serializer.deserialize(ier.data) } + if (deserialized != deserializedExpected) { + failWithMessage("Expected the deserialized data to be <%s> but it was <%s>", deserializedExpected, deserialized) + } + return this + } +} diff --git a/extension/pom.xml b/extension/pom.xml index 1cdaf1c..75e918f 100644 --- a/extension/pom.xml +++ b/extension/pom.xml @@ -15,6 +15,7 @@ jgiven upcaster + extension-assert From 2658045898114b9c89e48429ee39e5f59a3138fd Mon Sep 17 00:00:00 2001 From: Simon Zambrovski Date: Thu, 21 Sep 2023 23:05:00 +0200 Subject: [PATCH 2/6] implemented asserts for element, list and stream --- examples/bankaccount-upcaster-junit5/pom.xml | 5 +++ .../AccountCreatedEventUpcastingKotlinTest.kt | 31 +++++++++---------- .../{extension-assert => assert}/pom.xml | 13 +++++++- .../src/main/kotlin/AxonAssertions.kt | 11 +++++++ .../IntermediateEventRepresentationAssert.kt | 29 ++++++++++++++--- ...rmediateEventRepresentationStreamAssert.kt | 4 ++- extension/pom.xml | 2 +- pom.xml | 6 +++- 8 files changed, 76 insertions(+), 25 deletions(-) rename extension/{extension-assert => assert}/pom.xml (66%) rename extension/{extension-assert => assert}/src/main/kotlin/AxonAssertions.kt (71%) rename extension/{extension-assert => assert}/src/main/kotlin/IntermediateEventRepresentationAssert.kt (80%) rename extension/{extension-assert => assert}/src/main/kotlin/IntermediateEventRepresentationStreamAssert.kt (91%) diff --git a/examples/bankaccount-upcaster-junit5/pom.xml b/examples/bankaccount-upcaster-junit5/pom.xml index 8133f00..e3ca6b3 100644 --- a/examples/bankaccount-upcaster-junit5/pom.xml +++ b/examples/bankaccount-upcaster-junit5/pom.xml @@ -18,6 +18,11 @@ axon-testing-upcaster-junit5 test + + io.holixon.axon.testing + axon-testing-assert + test + com.fasterxml.jackson.module diff --git a/examples/bankaccount-upcaster-junit5/src/test/kotlin/AccountCreatedEventUpcastingKotlinTest.kt b/examples/bankaccount-upcaster-junit5/src/test/kotlin/AccountCreatedEventUpcastingKotlinTest.kt index 0fc0926..3a20b3b 100644 --- a/examples/bankaccount-upcaster-junit5/src/test/kotlin/AccountCreatedEventUpcastingKotlinTest.kt +++ b/examples/bankaccount-upcaster-junit5/src/test/kotlin/AccountCreatedEventUpcastingKotlinTest.kt @@ -5,19 +5,16 @@ import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper import com.thoughtworks.xstream.XStream import com.thoughtworks.xstream.security.AnyTypePermission import fixture.bankaccount.event.AccountCreatedEvent +import io.holixon.axon.testing.assert.AxonAssertions import io.holixon.axon.testing.upcaster.MessageEncoding import io.holixon.axon.testing.upcaster.UpcasterTest -import io.holixon.axon.testing.upcaster.UpcasterTestSupport.Companion.deserializeEvents import io.holixon.axon.testing.upcaster.UpcasterTestSupport.Companion.jsonNodeUpcaster import io.holixon.axon.testing.upcaster.UpcasterTestSupport.Companion.xmlDocumentUpcaster -import org.assertj.core.api.Assertions.assertThat import org.axonframework.serialization.json.JacksonSerializer import org.axonframework.serialization.upcasting.event.IntermediateEventRepresentation import org.axonframework.serialization.xml.XStreamSerializer -import org.dom4j.Document import org.dom4j.Element import java.util.stream.Collectors -import java.util.stream.Stream class AccountCreatedEventUpcastingKotlinTest { @@ -61,33 +58,35 @@ class AccountCreatedEventUpcastingKotlinTest { } + /** + * This method demonstrates usage of input events provided to the test method, + * usage of the list assert and element assert for intermediate representation. + */ @UpcasterTest( messageEncoding = MessageEncoding.XSTREAM ) fun upcasts_account_created_xstream(events: List) { val upcastedStream = xmlUpcaster.upcast(events.stream()) - val upcastedEvents = deserializeEvents(upcastedStream, xmlSerializer) - // FIXME: build better assertions - - assertThat(upcastedEvents) + AxonAssertions + .assertThat(upcastedStream.collect(Collectors.toList()), xmlSerializer) .hasSize(1) .element(0) - .isEqualTo(accountEvent) + .hasDeserializedData(accountEvent) } + /** + * This method demonstrates usage of input events and resulting provided to the test method, + * and usage of the stream assert. + */ @UpcasterTest( messageEncoding = MessageEncoding.JACKSON ) fun `upcasts account created jackson`(events: List, result: List) { - val upcastedStream = jsonUpcaster.upcast(events.stream()) - - // FIXME: build better assertions - val upcastedEvents = deserializeEvents(stream = upcastedStream, serializer = jacksonSerializer).collect(Collectors.toList()) - val deserializedResult = deserializeEvents(list = result, serializer = jacksonSerializer) - - assertThat(upcastedEvents).containsExactlyElementsOf(deserializedResult) + AxonAssertions.assertThat(upcastedStream, jacksonSerializer) + .containsExactlyDeserializedElementsOf(result.stream(), AccountCreatedEvent::class.java) } } + diff --git a/extension/extension-assert/pom.xml b/extension/assert/pom.xml similarity index 66% rename from extension/extension-assert/pom.xml rename to extension/assert/pom.xml index 90774fb..9764cf9 100644 --- a/extension/extension-assert/pom.xml +++ b/extension/assert/pom.xml @@ -9,12 +9,23 @@ 4.7.4.1-SNAPSHOT - extension-assert + io.holixon.axon.testing + axon-testing-assert + Axon Testing - Assert + + com.fasterxml.jackson.core + jackson-databind + + + org.dom4j + dom4j + ${dom4j.version} + org.assertj assertj-core diff --git a/extension/extension-assert/src/main/kotlin/AxonAssertions.kt b/extension/assert/src/main/kotlin/AxonAssertions.kt similarity index 71% rename from extension/extension-assert/src/main/kotlin/AxonAssertions.kt rename to extension/assert/src/main/kotlin/AxonAssertions.kt index 97c5c45..d00bd2b 100644 --- a/extension/extension-assert/src/main/kotlin/AxonAssertions.kt +++ b/extension/assert/src/main/kotlin/AxonAssertions.kt @@ -24,5 +24,16 @@ class AxonAssertions private constructor() { @JvmStatic fun assertThat(actual: Stream, serializer: Serializer) = IntermediateEventRepresentationStreamAssert.assertThat(actual, serializer) + + /** + * Creates the assert for given list of intermediate representation serialized using given serializer. + * @param actual list of current intermediate representations. + * @param serializer serializer in use. + * @return the asserting anchor for checks. + */ + @JvmStatic + fun assertThat(actual: List, serializer: Serializer) = + IntermediateEventRepresentationListAssert.assertThat(actual, serializer) + } } diff --git a/extension/extension-assert/src/main/kotlin/IntermediateEventRepresentationAssert.kt b/extension/assert/src/main/kotlin/IntermediateEventRepresentationAssert.kt similarity index 80% rename from extension/extension-assert/src/main/kotlin/IntermediateEventRepresentationAssert.kt rename to extension/assert/src/main/kotlin/IntermediateEventRepresentationAssert.kt index 2fb18fa..f0f22ed 100644 --- a/extension/extension-assert/src/main/kotlin/IntermediateEventRepresentationAssert.kt +++ b/extension/assert/src/main/kotlin/IntermediateEventRepresentationAssert.kt @@ -1,17 +1,32 @@ package io.holixon.axon.testing.assert +import com.fasterxml.jackson.databind.JsonNode import org.assertj.core.api.AbstractAssert import org.assertj.core.api.ObjectAssert import org.axonframework.serialization.SerializedObject import org.axonframework.serialization.SerializedType import org.axonframework.serialization.Serializer +import org.axonframework.serialization.json.JacksonSerializer import org.axonframework.serialization.upcasting.event.IntermediateEventRepresentation +import org.axonframework.serialization.xml.XStreamSerializer +import org.dom4j.Document + /** * Asserts intermediate representation. */ -class IntermediateEventRepresentationAssert(actual: IntermediateEventRepresentation, private val serializer: Serializer) : - AbstractAssert(actual, IntermediateEventRepresentationAssert::class.java) { +class IntermediateEventRepresentationAssert( + actual: IntermediateEventRepresentation, + private val serializer: Serializer, + private val intermediateRepresentationTypeResolver: (serializer: Serializer) -> Class<*> = + { + when (it) { + is XStreamSerializer -> Document::class.java + is JacksonSerializer -> JsonNode::class.java + else -> throw IllegalArgumentException("Unknown serializer type ${serializer::class.java}") + } + } +) : AbstractAssert(actual, IntermediateEventRepresentationAssert::class.java) { companion object { @@ -33,7 +48,9 @@ class IntermediateEventRepresentationAssert(actual: IntermediateEventRepresentat */ fun hasDeserializedData(expected: T): ObjectAssert { isNotNull - val event: T = serializer.deserialize(actual.data) + val intermediateRepresentationType = intermediateRepresentationTypeResolver.invoke(serializer) + val data = actual.getData(intermediateRepresentationType) + val event: T = serializer.deserialize(data) if (event != expected) { failWithMessage("Expected the event to be <%s> but it was <%s>", expected, event) } @@ -150,13 +167,15 @@ class IntermediateEventRepresentationAssert(actual: IntermediateEventRepresentat * @param expected intermediate representation. * @param T type of the payload. */ - fun isEqualsTo(expected: IntermediateEventRepresentation): IntermediateEventRepresentationAssert { + fun isEqualDeserializedTo(expected: IntermediateEventRepresentation): IntermediateEventRepresentationAssert { isNotNull val deserialized: T = serializer.deserialize(actual.data) - val deserializedExpected: T = serializer.deserialize(actual.data) + val deserializedExpected: T = serializer.deserialize(expected.data) if (deserialized != deserializedExpected) { failWithMessage("Expected the content type name to be <%s> but it was <%s>", deserializedExpected, deserialized) } return this } + + } diff --git a/extension/extension-assert/src/main/kotlin/IntermediateEventRepresentationStreamAssert.kt b/extension/assert/src/main/kotlin/IntermediateEventRepresentationStreamAssert.kt similarity index 91% rename from extension/extension-assert/src/main/kotlin/IntermediateEventRepresentationStreamAssert.kt rename to extension/assert/src/main/kotlin/IntermediateEventRepresentationStreamAssert.kt index 058cce3..3ff3482 100644 --- a/extension/extension-assert/src/main/kotlin/IntermediateEventRepresentationStreamAssert.kt +++ b/extension/assert/src/main/kotlin/IntermediateEventRepresentationStreamAssert.kt @@ -32,7 +32,7 @@ class IntermediateEventRepresentationStreamAssert(actual: Stream isContainsExactlyElementsOf(expected: Stream): IntermediateEventRepresentationStreamAssert { + fun containsExactlyDeserializedElementsOf(expected: Stream, clazz: Class): IntermediateEventRepresentationStreamAssert { isNotNull val deserialized: List = actual.collect(Collectors.toList()).map { ier -> serializer.deserialize(ier.data) } val deserializedExpected: List = expected.collect(Collectors.toList()).map { ier -> serializer.deserialize(ier.data) } @@ -41,4 +41,6 @@ class IntermediateEventRepresentationStreamAssert(actual: Stream jgiven upcaster - extension-assert + assert diff --git a/pom.xml b/pom.xml index af29abe..a8df0c4 100644 --- a/pom.xml +++ b/pom.xml @@ -103,7 +103,11 @@ axon-testing-upcaster-junit5 ${project.version} - + + io.holixon.axon.testing + axon-testing-assert + ${project.version} + From 6fa9fbfea72983882c0a20b418d6de900b483172 Mon Sep 17 00:00:00 2001 From: Simon Zambrovski Date: Thu, 21 Sep 2023 23:05:10 +0200 Subject: [PATCH 3/6] implemented asserts for element, list and stream --- ...termediateEventRepresentationListAssert.kt | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 extension/assert/src/main/kotlin/IntermediateEventRepresentationListAssert.kt diff --git a/extension/assert/src/main/kotlin/IntermediateEventRepresentationListAssert.kt b/extension/assert/src/main/kotlin/IntermediateEventRepresentationListAssert.kt new file mode 100644 index 0000000..a5ef61a --- /dev/null +++ b/extension/assert/src/main/kotlin/IntermediateEventRepresentationListAssert.kt @@ -0,0 +1,26 @@ +package io.holixon.axon.testing.assert + +import org.assertj.core.api.AbstractListAssert +import org.axonframework.serialization.Serializer +import org.axonframework.serialization.upcasting.event.IntermediateEventRepresentation + +class IntermediateEventRepresentationListAssert( + actual: List, + private val serializer: Serializer +) : AbstractListAssert +, IntermediateEventRepresentation, IntermediateEventRepresentationAssert>( + actual, IntermediateEventRepresentationListAssert::class.java +) { + companion object { + fun assertThat(actual: List, serializer: Serializer): IntermediateEventRepresentationListAssert = + IntermediateEventRepresentationListAssert(actual, serializer) + } + + override fun toAssert(value: IntermediateEventRepresentation, description: String): IntermediateEventRepresentationAssert = + IntermediateEventRepresentationAssert(value, serializer).`as`(description) + + + override fun newAbstractIterableAssert(iterable: MutableIterable): IntermediateEventRepresentationListAssert = + IntermediateEventRepresentationListAssert(iterable.toList(), serializer) + +} From 9ae925b510e81fb32d9091d73e75487c012f3f0f Mon Sep 17 00:00:00 2001 From: Simon Zambrovski Date: Fri, 22 Sep 2023 00:56:02 +0200 Subject: [PATCH 4/6] bugfix: remove quotes for commands and events allowing vargs to work in reporting, fix #334 --- .../core/src/main/kotlin/AxonJGivenStage.kt | 4 +++- .../kotlin/aggregate/AggregateFixtureGiven.kt | 23 ++++++++++++++----- .../kotlin/aggregate/AggregateFixtureThen.kt | 15 +++++------- .../kotlin/aggregate/AggregateFixtureWhen.kt | 4 ++-- 4 files changed, 28 insertions(+), 18 deletions(-) diff --git a/extension/jgiven/core/src/main/kotlin/AxonJGivenStage.kt b/extension/jgiven/core/src/main/kotlin/AxonJGivenStage.kt index aba64ea..117d957 100644 --- a/extension/jgiven/core/src/main/kotlin/AxonJGivenStage.kt +++ b/extension/jgiven/core/src/main/kotlin/AxonJGivenStage.kt @@ -1,11 +1,13 @@ package io.holixon.axon.testing.jgiven import com.tngtech.jgiven.Stage -import org.axonframework.test.aggregate.ResultValidator /** * Marker annotation to identify Axon JGiven Stages. */ annotation class AxonJGivenStage +/** + * Step function to create JGiven stage steps easily. + */ internal inline fun > Stage.step(block: X.() -> Unit) = self().apply(block) diff --git a/extension/jgiven/core/src/main/kotlin/aggregate/AggregateFixtureGiven.kt b/extension/jgiven/core/src/main/kotlin/aggregate/AggregateFixtureGiven.kt index 9f8045e..57f801a 100644 --- a/extension/jgiven/core/src/main/kotlin/aggregate/AggregateFixtureGiven.kt +++ b/extension/jgiven/core/src/main/kotlin/aggregate/AggregateFixtureGiven.kt @@ -40,21 +40,25 @@ class AggregateFixtureGiven : Stage>() { * @param command dispatched command. */ @As("command:") - fun command(@Quoted command: Any): AggregateFixtureGiven = this.commands(command) + fun command(command: Any): AggregateFixtureGiven = this.commandsInternal(listOf(command)) /** * One or several commands has been dispatched. * @param commands dispatched commands. */ @As("commands:") - fun commands(@Quoted vararg commands: Any): AggregateFixtureGiven = this.commands(commands.toList()) + fun commands(vararg commands: Any): AggregateFixtureGiven = this.commandsInternal(commands.toList()) /** * One or several commands has been dispatched. * @param commands dispatched commands. */ @As("commands:") - fun commands(@Quoted commands: List): AggregateFixtureGiven = execute { + fun commands(commands: List): AggregateFixtureGiven = this.commandsInternal(commands) + + + private fun commandsInternal(commands: List): AggregateFixtureGiven = execute { + if (context.isFirstGiven) { context.isFirstGiven = false context.fixture!!.givenCommands(commands) @@ -68,21 +72,27 @@ class AggregateFixtureGiven : Stage>() { * @param event published event. */ @As("event:") - fun event(@Quoted event: Any): AggregateFixtureGiven = this.events(event) + fun event(event: Any): AggregateFixtureGiven = this.eventsInternal(listOf(event)) /** * One or several events has been published. * @param events published events. */ @As("events:") - fun events(@Quoted vararg events: Any): AggregateFixtureGiven = this.events(events.toList()) + fun events(vararg events: Any): AggregateFixtureGiven = this.eventsInternal(events.toList()) /** * One or several events has been published. * @param events published events. */ @As("events:") - fun events(@Quoted events: List): AggregateFixtureGiven = execute { + fun events(events: List): AggregateFixtureGiven = this.eventsInternal(events) + + + /* + * Private method to avoid duplications in report. + */ + private fun eventsInternal(events: List) = execute { if (context.isFirstGiven) { context.isFirstGiven = false context.fixture!!.given(events) @@ -91,6 +101,7 @@ class AggregateFixtureGiven : Stage>() { } } + /** * Sets the time. * @param instant new time. diff --git a/extension/jgiven/core/src/main/kotlin/aggregate/AggregateFixtureThen.kt b/extension/jgiven/core/src/main/kotlin/aggregate/AggregateFixtureThen.kt index 481ab63..269e3a4 100644 --- a/extension/jgiven/core/src/main/kotlin/aggregate/AggregateFixtureThen.kt +++ b/extension/jgiven/core/src/main/kotlin/aggregate/AggregateFixtureThen.kt @@ -3,10 +3,7 @@ package io.holixon.axon.testing.jgiven.aggregate import com.tngtech.jgiven.Stage -import com.tngtech.jgiven.annotation.As -import com.tngtech.jgiven.annotation.Hidden -import com.tngtech.jgiven.annotation.ProvidedScenarioState -import com.tngtech.jgiven.annotation.Quoted +import com.tngtech.jgiven.annotation.* import io.holixon.axon.testing.jgiven.AxonJGivenStage import io.holixon.axon.testing.jgiven.step import org.axonframework.commandhandling.CommandResultMessage @@ -35,14 +32,14 @@ class AggregateFixtureThen : Stage>() { * @param event expected event. */ @As("expect event:") - fun expectEvent(@Quoted event: Any) = this.expectEvents(event) + fun expectEvent(event: Any) = this.expectEvents(event) /** * Expect a series of events. * @param events events to expect. */ @As("expect events:") - fun expectEvents(@Quoted vararg events: Any) = execute { + fun expectEvents(vararg events: Any) = execute { expectEvents(*events) } @@ -51,7 +48,7 @@ class AggregateFixtureThen : Stage>() { * @param events events to expect. */ @As("expect events:") - fun expectEvents(@Quoted vararg events: EventMessage<*>) = execute { + fun expectEvents(vararg events: EventMessage<*>) = execute { expectEvents(*events) } @@ -121,7 +118,7 @@ class AggregateFixtureThen : Stage>() { } /** - * Expects an exception of provided type to be thrown. + * Expects an exception of the provided type to be thrown. * @param clazz type of exception. */ @As("expect exception: $") @@ -130,7 +127,7 @@ class AggregateFixtureThen : Stage>() { } /** - * Expects an exception of provided type to be thrown. + * Expects an exception of the provided type to be thrown. * @param clazz type of exception. */ @As("expect exception: $") diff --git a/extension/jgiven/core/src/main/kotlin/aggregate/AggregateFixtureWhen.kt b/extension/jgiven/core/src/main/kotlin/aggregate/AggregateFixtureWhen.kt index 301328c..d488cda 100644 --- a/extension/jgiven/core/src/main/kotlin/aggregate/AggregateFixtureWhen.kt +++ b/extension/jgiven/core/src/main/kotlin/aggregate/AggregateFixtureWhen.kt @@ -29,7 +29,7 @@ class AggregateFixtureWhen : Stage>() { * @param cmd command to dispatch. */ @As("command: \$cmd") - fun command(@Quoted cmd: Any): AggregateFixtureWhen = command(cmd, MetaData.emptyInstance()) + fun command(cmd: Any): AggregateFixtureWhen = command(cmd, MetaData.emptyInstance()) /** * Dispatches a command. @@ -37,7 +37,7 @@ class AggregateFixtureWhen : Stage>() { * @param metadata metadata to include into command message. */ @As("command: \$cmd, metadata: \$metadata") - fun command(@Quoted cmd: Any, metadata: Map): AggregateFixtureWhen = execute { context.testExecutor!!.`when`(cmd, metadata) } + fun command(cmd: Any, metadata: Map): AggregateFixtureWhen = execute { context.testExecutor!!.`when`(cmd, metadata) } /** * Moves time to new value. From ffbee041eb4899cbc13a21d8ae80e6575c664153 Mon Sep 17 00:00:00 2001 From: Simon Zambrovski Date: Fri, 22 Sep 2023 00:56:44 +0200 Subject: [PATCH 5/6] chore: update axon version to 4.7.6, kotlin to 1.9.10 --- examples/bankaccount-jgiven-junit4/pom.xml | 2 +- examples/bankaccount-jgiven-junit5/pom.xml | 2 +- examples/bankaccount-upcaster-junit5/pom.xml | 2 +- examples/pom.xml | 11 ++++++- extension/assert/pom.xml | 2 +- extension/jgiven/core/pom.xml | 2 +- extension/jgiven/junit/pom.xml | 2 +- extension/jgiven/junit5/pom.xml | 2 +- extension/jgiven/pom.xml | 2 +- extension/pom.xml | 2 +- extension/upcaster/core/pom.xml | 2 +- extension/upcaster/junit5/pom.xml | 2 +- extension/upcaster/pom.xml | 2 +- lib/fixtures/bankaccount/pom.xml | 2 +- lib/fixtures/giftcard/pom.xml | 2 +- lib/fixtures/pom.xml | 2 +- lib/pom.xml | 2 +- pom.xml | 30 +++++++++++++++----- 18 files changed, 49 insertions(+), 24 deletions(-) diff --git a/examples/bankaccount-jgiven-junit4/pom.xml b/examples/bankaccount-jgiven-junit4/pom.xml index 0f45af6..4d53cc9 100644 --- a/examples/bankaccount-jgiven-junit4/pom.xml +++ b/examples/bankaccount-jgiven-junit4/pom.xml @@ -6,7 +6,7 @@ io.holixon.axon.testing._ examples - 4.7.4.1-SNAPSHOT + 4.7.6.0 io.holixon.axon.testing.examples diff --git a/examples/bankaccount-jgiven-junit5/pom.xml b/examples/bankaccount-jgiven-junit5/pom.xml index 4b95cc9..102e479 100644 --- a/examples/bankaccount-jgiven-junit5/pom.xml +++ b/examples/bankaccount-jgiven-junit5/pom.xml @@ -6,7 +6,7 @@ io.holixon.axon.testing._ examples - 4.7.4.1-SNAPSHOT + 4.7.6.0 io.holixon.axon.testing.examples diff --git a/examples/bankaccount-upcaster-junit5/pom.xml b/examples/bankaccount-upcaster-junit5/pom.xml index e3ca6b3..77fae30 100644 --- a/examples/bankaccount-upcaster-junit5/pom.xml +++ b/examples/bankaccount-upcaster-junit5/pom.xml @@ -6,7 +6,7 @@ io.holixon.axon.testing._ examples - 4.7.4.1-SNAPSHOT + 4.7.6.0 io.holixon.axon.testing.examples diff --git a/examples/pom.xml b/examples/pom.xml index 576ffa2..b6d7ccd 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -6,7 +6,7 @@ io.holixon.axon.testing._ axon-testing_ - 4.7.4.1-SNAPSHOT + 4.7.6.0 examples @@ -33,4 +33,13 @@ + + + + com.tngtech.jgiven + jgiven-maven-plugin + + + + diff --git a/extension/assert/pom.xml b/extension/assert/pom.xml index 9764cf9..49d56ab 100644 --- a/extension/assert/pom.xml +++ b/extension/assert/pom.xml @@ -6,7 +6,7 @@ io.holixon.axon.testing._ extension - 4.7.4.1-SNAPSHOT + 4.7.6.0 io.holixon.axon.testing diff --git a/extension/jgiven/core/pom.xml b/extension/jgiven/core/pom.xml index e17f539..c20def6 100644 --- a/extension/jgiven/core/pom.xml +++ b/extension/jgiven/core/pom.xml @@ -7,7 +7,7 @@ io.holixon.axon.testing._ extension-jgiven - 4.7.4.1-SNAPSHOT + 4.7.6.0 io.holixon.axon.testing diff --git a/extension/jgiven/junit/pom.xml b/extension/jgiven/junit/pom.xml index 3a7c815..5386567 100644 --- a/extension/jgiven/junit/pom.xml +++ b/extension/jgiven/junit/pom.xml @@ -7,7 +7,7 @@ io.holixon.axon.testing._ extension-jgiven - 4.7.4.1-SNAPSHOT + 4.7.6.0 io.holixon.axon.testing diff --git a/extension/jgiven/junit5/pom.xml b/extension/jgiven/junit5/pom.xml index a405810..2509ee2 100644 --- a/extension/jgiven/junit5/pom.xml +++ b/extension/jgiven/junit5/pom.xml @@ -7,7 +7,7 @@ io.holixon.axon.testing._ extension-jgiven - 4.7.4.1-SNAPSHOT + 4.7.6.0 io.holixon.axon.testing diff --git a/extension/jgiven/pom.xml b/extension/jgiven/pom.xml index 8c5efe8..0ee7578 100644 --- a/extension/jgiven/pom.xml +++ b/extension/jgiven/pom.xml @@ -6,7 +6,7 @@ io.holixon.axon.testing._ extension - 4.7.4.1-SNAPSHOT + 4.7.6.0 extension-jgiven diff --git a/extension/pom.xml b/extension/pom.xml index 7119945..39a9ba7 100644 --- a/extension/pom.xml +++ b/extension/pom.xml @@ -6,7 +6,7 @@ io.holixon.axon.testing._ axon-testing_ - 4.7.4.1-SNAPSHOT + 4.7.6.0 extension diff --git a/extension/upcaster/core/pom.xml b/extension/upcaster/core/pom.xml index aa5fccb..5f48b63 100644 --- a/extension/upcaster/core/pom.xml +++ b/extension/upcaster/core/pom.xml @@ -7,7 +7,7 @@ io.holixon.axon.testing._ extension-upcaster - 4.7.4.1-SNAPSHOT + 4.7.6.0 io.holixon.axon.testing diff --git a/extension/upcaster/junit5/pom.xml b/extension/upcaster/junit5/pom.xml index 4d41c86..c0ac5a9 100644 --- a/extension/upcaster/junit5/pom.xml +++ b/extension/upcaster/junit5/pom.xml @@ -7,7 +7,7 @@ io.holixon.axon.testing._ extension-upcaster - 4.7.4.1-SNAPSHOT + 4.7.6.0 io.holixon.axon.testing diff --git a/extension/upcaster/pom.xml b/extension/upcaster/pom.xml index f4b910a..87b4faa 100644 --- a/extension/upcaster/pom.xml +++ b/extension/upcaster/pom.xml @@ -6,7 +6,7 @@ io.holixon.axon.testing._ extension - 4.7.4.1-SNAPSHOT + 4.7.6.0 extension-upcaster diff --git a/lib/fixtures/bankaccount/pom.xml b/lib/fixtures/bankaccount/pom.xml index f254323..23a065c 100644 --- a/lib/fixtures/bankaccount/pom.xml +++ b/lib/fixtures/bankaccount/pom.xml @@ -6,7 +6,7 @@ io.holixon.axon.testing._ fixtures - 4.7.4.1-SNAPSHOT + 4.7.6.0 io.holixon.axon.testing.lib diff --git a/lib/fixtures/giftcard/pom.xml b/lib/fixtures/giftcard/pom.xml index eeefd16..7ca1506 100644 --- a/lib/fixtures/giftcard/pom.xml +++ b/lib/fixtures/giftcard/pom.xml @@ -6,7 +6,7 @@ io.holixon.axon.testing._ fixtures - 4.7.4.1-SNAPSHOT + 4.7.6.0 io.holixon.axon.testing.lib diff --git a/lib/fixtures/pom.xml b/lib/fixtures/pom.xml index 65acac5..2e4ef65 100644 --- a/lib/fixtures/pom.xml +++ b/lib/fixtures/pom.xml @@ -6,7 +6,7 @@ io.holixon.axon.testing._ lib - 4.7.4.1-SNAPSHOT + 4.7.6.0 fixtures diff --git a/lib/pom.xml b/lib/pom.xml index ffdafa6..e6cdec2 100644 --- a/lib/pom.xml +++ b/lib/pom.xml @@ -6,7 +6,7 @@ io.holixon.axon.testing._ axon-testing_ - 4.7.4.1-SNAPSHOT + 4.7.6.0 lib diff --git a/pom.xml b/pom.xml index a8df0c4..32eabe6 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ io.holixon.axon.testing._ axon-testing_ - 4.7.4.1-SNAPSHOT + 4.7.6.0 pom @@ -19,10 +19,10 @@ 11 - 1.8.22 + 1.9.10 - 4.8.0 + 4.7.4 1.2.5 1.2.5.0 @@ -325,6 +325,22 @@ + + com.tngtech.jgiven + jgiven-maven-plugin + ${jgiven.version} + + + + report + + + + + html + + + org.apache.maven.plugins @@ -336,7 +352,7 @@ org.jetbrains.dokka dokka-maven-plugin - 1.8.20 + 1.9.10 ${dokka.skip} @@ -632,9 +648,9 @@ - + 2021 From e4d53aa399c5a53dced7e020fae6542a4c555d59 Mon Sep 17 00:00:00 2001 From: Simon Zambrovski Date: Fri, 22 Sep 2023 01:09:04 +0200 Subject: [PATCH 6/6] chore: corrected version of the artifact --- examples/bankaccount-jgiven-junit4/pom.xml | 2 +- examples/bankaccount-jgiven-junit5/pom.xml | 2 +- examples/bankaccount-upcaster-junit5/pom.xml | 2 +- examples/pom.xml | 2 +- extension/assert/pom.xml | 2 +- extension/jgiven/core/pom.xml | 2 +- extension/jgiven/junit/pom.xml | 2 +- extension/jgiven/junit5/pom.xml | 2 +- extension/jgiven/pom.xml | 2 +- extension/pom.xml | 2 +- extension/upcaster/core/pom.xml | 2 +- extension/upcaster/junit5/pom.xml | 2 +- extension/upcaster/pom.xml | 2 +- lib/fixtures/bankaccount/pom.xml | 2 +- lib/fixtures/giftcard/pom.xml | 2 +- lib/fixtures/pom.xml | 2 +- lib/pom.xml | 2 +- pom.xml | 2 +- 18 files changed, 18 insertions(+), 18 deletions(-) diff --git a/examples/bankaccount-jgiven-junit4/pom.xml b/examples/bankaccount-jgiven-junit4/pom.xml index cf5603b..73fe6f7 100644 --- a/examples/bankaccount-jgiven-junit4/pom.xml +++ b/examples/bankaccount-jgiven-junit4/pom.xml @@ -6,7 +6,7 @@ io.holixon.axon.testing._ examples - 4.7.6.0 + 4.7.6.0-SNAPSHOT io.holixon.axon.testing.examples diff --git a/examples/bankaccount-jgiven-junit5/pom.xml b/examples/bankaccount-jgiven-junit5/pom.xml index 49811c3..d69ccc2 100644 --- a/examples/bankaccount-jgiven-junit5/pom.xml +++ b/examples/bankaccount-jgiven-junit5/pom.xml @@ -6,7 +6,7 @@ io.holixon.axon.testing._ examples - 4.7.6.0 + 4.7.6.0-SNAPSHOT io.holixon.axon.testing.examples diff --git a/examples/bankaccount-upcaster-junit5/pom.xml b/examples/bankaccount-upcaster-junit5/pom.xml index 74269e1..54cb8dc 100644 --- a/examples/bankaccount-upcaster-junit5/pom.xml +++ b/examples/bankaccount-upcaster-junit5/pom.xml @@ -6,7 +6,7 @@ io.holixon.axon.testing._ examples - 4.7.6.0 + 4.7.6.0-SNAPSHOT io.holixon.axon.testing.examples diff --git a/examples/pom.xml b/examples/pom.xml index b6d7ccd..94ee9d8 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -6,7 +6,7 @@ io.holixon.axon.testing._ axon-testing_ - 4.7.6.0 + 4.7.6.0-SNAPSHOT examples diff --git a/extension/assert/pom.xml b/extension/assert/pom.xml index 49d56ab..1c7d76a 100644 --- a/extension/assert/pom.xml +++ b/extension/assert/pom.xml @@ -6,7 +6,7 @@ io.holixon.axon.testing._ extension - 4.7.6.0 + 4.7.6.0-SNAPSHOT io.holixon.axon.testing diff --git a/extension/jgiven/core/pom.xml b/extension/jgiven/core/pom.xml index 7220f95..3515161 100644 --- a/extension/jgiven/core/pom.xml +++ b/extension/jgiven/core/pom.xml @@ -7,7 +7,7 @@ io.holixon.axon.testing._ extension-jgiven - 4.7.6.0 + 4.7.6.0-SNAPSHOT io.holixon.axon.testing diff --git a/extension/jgiven/junit/pom.xml b/extension/jgiven/junit/pom.xml index 5386567..6149da0 100644 --- a/extension/jgiven/junit/pom.xml +++ b/extension/jgiven/junit/pom.xml @@ -7,7 +7,7 @@ io.holixon.axon.testing._ extension-jgiven - 4.7.6.0 + 4.7.6.0-SNAPSHOT io.holixon.axon.testing diff --git a/extension/jgiven/junit5/pom.xml b/extension/jgiven/junit5/pom.xml index 55cd241..7e045a9 100644 --- a/extension/jgiven/junit5/pom.xml +++ b/extension/jgiven/junit5/pom.xml @@ -7,7 +7,7 @@ io.holixon.axon.testing._ extension-jgiven - 4.7.6.0 + 4.7.6.0-SNAPSHOT io.holixon.axon.testing diff --git a/extension/jgiven/pom.xml b/extension/jgiven/pom.xml index 0ee7578..3809362 100644 --- a/extension/jgiven/pom.xml +++ b/extension/jgiven/pom.xml @@ -6,7 +6,7 @@ io.holixon.axon.testing._ extension - 4.7.6.0 + 4.7.6.0-SNAPSHOT extension-jgiven diff --git a/extension/pom.xml b/extension/pom.xml index 39a9ba7..26a0543 100644 --- a/extension/pom.xml +++ b/extension/pom.xml @@ -6,7 +6,7 @@ io.holixon.axon.testing._ axon-testing_ - 4.7.6.0 + 4.7.6.0-SNAPSHOT extension diff --git a/extension/upcaster/core/pom.xml b/extension/upcaster/core/pom.xml index 49ea9c2..7a4123c 100644 --- a/extension/upcaster/core/pom.xml +++ b/extension/upcaster/core/pom.xml @@ -7,7 +7,7 @@ io.holixon.axon.testing._ extension-upcaster - 4.7.6.0 + 4.7.6.0-SNAPSHOT io.holixon.axon.testing diff --git a/extension/upcaster/junit5/pom.xml b/extension/upcaster/junit5/pom.xml index a738a93..8d5442d 100644 --- a/extension/upcaster/junit5/pom.xml +++ b/extension/upcaster/junit5/pom.xml @@ -7,7 +7,7 @@ io.holixon.axon.testing._ extension-upcaster - 4.7.6.0 + 4.7.6.0-SNAPSHOT io.holixon.axon.testing diff --git a/extension/upcaster/pom.xml b/extension/upcaster/pom.xml index 87b4faa..a87469c 100644 --- a/extension/upcaster/pom.xml +++ b/extension/upcaster/pom.xml @@ -6,7 +6,7 @@ io.holixon.axon.testing._ extension - 4.7.6.0 + 4.7.6.0-SNAPSHOT extension-upcaster diff --git a/lib/fixtures/bankaccount/pom.xml b/lib/fixtures/bankaccount/pom.xml index 23a065c..87f3fb0 100644 --- a/lib/fixtures/bankaccount/pom.xml +++ b/lib/fixtures/bankaccount/pom.xml @@ -6,7 +6,7 @@ io.holixon.axon.testing._ fixtures - 4.7.6.0 + 4.7.6.0-SNAPSHOT io.holixon.axon.testing.lib diff --git a/lib/fixtures/giftcard/pom.xml b/lib/fixtures/giftcard/pom.xml index cb716b9..f3d3faf 100644 --- a/lib/fixtures/giftcard/pom.xml +++ b/lib/fixtures/giftcard/pom.xml @@ -6,7 +6,7 @@ io.holixon.axon.testing._ fixtures - 4.7.6.0 + 4.7.6.0-SNAPSHOT io.holixon.axon.testing.lib diff --git a/lib/fixtures/pom.xml b/lib/fixtures/pom.xml index 8d413e8..95e432c 100644 --- a/lib/fixtures/pom.xml +++ b/lib/fixtures/pom.xml @@ -6,7 +6,7 @@ io.holixon.axon.testing._ lib - 4.7.6.0 + 4.7.6.0-SNAPSHOT fixtures diff --git a/lib/pom.xml b/lib/pom.xml index e6cdec2..d5ab558 100644 --- a/lib/pom.xml +++ b/lib/pom.xml @@ -6,7 +6,7 @@ io.holixon.axon.testing._ axon-testing_ - 4.7.6.0 + 4.7.6.0-SNAPSHOT lib diff --git a/pom.xml b/pom.xml index 82abc9a..0cd2ed9 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ io.holixon.axon.testing._ axon-testing_ - 4.7.6.0 + 4.7.6.0-SNAPSHOT pom