Skip to content

Commit

Permalink
Merge branch 'release/4.8.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
zambrovski committed Oct 12, 2023
2 parents d2e1433 + e7b8cf3 commit 5d1345f
Show file tree
Hide file tree
Showing 20 changed files with 196 additions and 38 deletions.
2 changes: 1 addition & 1 deletion examples/bankaccount-jgiven-junit5/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.holixon.axon.testing._</groupId>
<artifactId>examples</artifactId>
<version>4.8.0.1</version>
<version>4.8.0.2</version>
</parent>

<groupId>io.holixon.axon.testing.examples</groupId>
Expand Down
2 changes: 1 addition & 1 deletion examples/bankaccount-upcaster-junit5/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.holixon.axon.testing._</groupId>
<artifactId>examples</artifactId>
<version>4.8.0.1</version>
<version>4.8.0.2</version>
</parent>

<groupId>io.holixon.axon.testing.examples</groupId>
Expand Down
2 changes: 1 addition & 1 deletion examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.holixon.axon.testing._</groupId>
<artifactId>axon-testing_</artifactId>
<version>4.8.0.1</version>
<version>4.8.0.2</version>
</parent>

<artifactId>examples</artifactId>
Expand Down
17 changes: 16 additions & 1 deletion extension/assert/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.holixon.axon.testing._</groupId>
<artifactId>extension</artifactId>
<version>4.8.0.1</version>
<version>4.8.0.2</version>
</parent>

<groupId>io.holixon.axon.testing</groupId>
Expand Down Expand Up @@ -36,6 +36,21 @@
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
</dependency>
<dependency>
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-core</artifactId>
<version>${xmlunit.version}</version>
</dependency>
<dependency>
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-assertj3</artifactId>
<version>${xmlunit.version}</version>
</dependency>
<dependency>
<groupId>org.skyscreamer</groupId>
<artifactId>jsonassert</artifactId>
<version>${jsonassert.verision}</version>
</dependency>
<dependency>
<groupId>org.axonframework</groupId>
<artifactId>axon-messaging</artifactId>
Expand Down
22 changes: 22 additions & 0 deletions extension/assert/src/main/kotlin/AxonAssertions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ class AxonAssertions private constructor() {
@JvmStatic
fun assertThat(actual: IntermediateEventRepresentation, serializer: Serializer) = IntermediateEventRepresentationAssert.assertThat(actual, serializer)

/**
* Creates the assert for given intermediate representation serialized using given serializer.
* @param actual current intermediate representation.
* @param serializer serializer in use.
* @param strictComparison if true equality instead of similarity is applied where possible. Defaults to false.
* @return the asserting anchor for checks.
*/
@JvmStatic
fun assertThat(actual: IntermediateEventRepresentation, serializer: Serializer, strictComparison: Boolean) = IntermediateEventRepresentationAssert
.assertThat(actual, serializer, strictComparison)

/**
* Creates the assert for given stream of intermediate representations serialized using given serializer.
* @param actual current intermediate representation.
Expand All @@ -35,5 +46,16 @@ class AxonAssertions private constructor() {
fun assertThat(actual: List<IntermediateEventRepresentation>, serializer: Serializer) =
IntermediateEventRepresentationListAssert.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.
* @param strictComparison if true equality instead of similarity is applied where possible. Defaults to false.
* @return the asserting anchor for checks.
*/
@JvmStatic
fun assertThat(actual: List<IntermediateEventRepresentation>, serializer: Serializer, strictComparison: Boolean) =
IntermediateEventRepresentationListAssert.assertThat(actual, serializer, strictComparison)

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ 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.io.DOMWriter
import org.json.JSONObject
import org.skyscreamer.jsonassert.JSONAssert
import org.skyscreamer.jsonassert.JSONCompareMode
import org.xmlunit.assertj3.XmlAssert
import org.xmlunit.builder.Input


/**
Expand All @@ -18,13 +24,63 @@ import org.dom4j.Document
class IntermediateEventRepresentationAssert(
actual: IntermediateEventRepresentation,
private val serializer: Serializer,
/**
* Parameter controlling if the strict serialized data check is executed. Defaults to false.
*/
private val strictSerializedComparison: Boolean = false,
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}")
}
},
private val intermediateRepresentationObjectAssertResolver: (serializer: Serializer, strict: Boolean) -> (expected: Any, actual: Any) -> Unit =
{ it: Serializer, strict: Boolean ->
when (it) {
is XStreamSerializer -> { expected: Any, actual: Any ->
require(expected is Document) { "The expected intermediate representation must be a Document, but it was of type ${expected::class.java.name}" }
require(actual is Document) { "The actual intermediate representation must be a Document, but it was of type ${expected::class.java.name}" }
XmlAssert
.assertThat(
Input.fromDocument(
DOMWriter().write(actual)
)
).and(
Input.fromDocument(
DOMWriter().write(expected)
)
)
.apply {
if (strict) {
this.areIdentical()
} else {
this
.ignoreWhitespace() // ignore empty lines and other empty text nodes
.ignoreChildNodesOrder() // child order doesn't matter
.areSimilar() // just be similar
}
}
}

is JacksonSerializer -> { expected: Any, actual: Any ->
require(expected is JSONObject) { "The expected intermediate representation must be a JSONObject, but it was of type ${expected::class.java.name}" }
require(actual is JSONObject) { "The actual intermediate representation must be a JSONObject, but it was of type ${expected::class.java.name}" }
JSONAssert.assertEquals(
expected,
actual,
if (strict) {
JSONCompareMode.STRICT
} else {
JSONCompareMode.LENIENT
}
)
}

else -> throw IllegalArgumentException("Unknown serializer type ${serializer::class.java}")
}

}
) : AbstractAssert<IntermediateEventRepresentationAssert, IntermediateEventRepresentation>(actual, IntermediateEventRepresentationAssert::class.java) {

Expand All @@ -37,7 +93,61 @@ class IntermediateEventRepresentationAssert(
* @return the asserting anchor for checks.
*/
@JvmStatic
fun assertThat(actual: IntermediateEventRepresentation, serializer: Serializer) = IntermediateEventRepresentationAssert(actual, serializer)
fun assertThat(actual: IntermediateEventRepresentation, serializer: Serializer) = assertThat(actual, serializer, false)

/**
* Creates the assert for given intermediate representation serialized using given serializer.
* @param actual current intermediate representation.
* @param serializer serializer in use.
* @param strictSerializedComparison controlling if the strict serialized data check is executed.
* @return the asserting anchor for checks.
*/
@JvmStatic
fun assertThat(actual: IntermediateEventRepresentation, serializer: Serializer, strictSerializedComparison: Boolean) =
IntermediateEventRepresentationAssert(actual, serializer, strictSerializedComparison)
}

/**
* Asserts that the deserialized version of data is equals to deserialized version of given.
* We are comparing on the level of deserialized target type.
*
* @param expected intermediate representation.
* @param T type of the payload.
*/
fun <T : Any> isEqualDeserializedTo(expected: IntermediateEventRepresentation): IntermediateEventRepresentationAssert {
isNotNull
val intermediateRepresentationType = intermediateRepresentationTypeResolver.invoke(serializer)
val deserialized: T = serializer.deserialize(actual.getData(intermediateRepresentationType))
val deserializedExpected: T = serializer.deserialize(expected.getData(intermediateRepresentationType))
if (deserialized != deserializedExpected) {
failWithMessage("Expected the deserialized content to be <%s> but it was <%s>", deserializedExpected, deserialized)
}
return this
}

/**
* Asserts equality of type and data in the intermediate form (will compare Document, JsonNode, ...).
* @param expected intermediate or initial representation of expected event.
* @return object assert.
*/
override fun isEqualTo(expected: Any): IntermediateEventRepresentationAssert {
isNotNull
when (expected) {
is IntermediateEventRepresentation -> {
hasType(expected.type)
val intermediateRepresentationType = intermediateRepresentationTypeResolver.invoke(serializer)
val expectedData = expected.getData(intermediateRepresentationType)
val actualData = actual.getData(intermediateRepresentationType)
val objectAssertFunction = intermediateRepresentationObjectAssertResolver.invoke(serializer, strictSerializedComparison)
objectAssertFunction.invoke(expectedData.data, actualData.data) // comparing intermediate representation data (Document, JsonNode, ...)
}

else -> failWithMessage(
"Expected to compare current expected representation with an instance of IntermediateEventRepresentation, but it was an instance of <%s>",
expected.javaClass
)
}
return this
}

/**
Expand All @@ -49,7 +159,7 @@ class IntermediateEventRepresentationAssert(
fun <T : Any> hasDeserializedData(expected: T): ObjectAssert<T> {
isNotNull
val intermediateRepresentationType = intermediateRepresentationTypeResolver.invoke(serializer)
val data = actual.getData(intermediateRepresentationType)
val data = actual.getData(intermediateRepresentationType) // type is the type of intermediate data
val event: T = serializer.deserialize(data)
if (event != expected) {
failWithMessage("Expected the event to be <%s> but it was <%s>", expected, event)
Expand Down Expand Up @@ -131,7 +241,7 @@ class IntermediateEventRepresentationAssert(
isNotNull
val type = actual.type
if (type != expected) {
failWithMessage("Expected the content type to be <%s> but it was <%s>", expected, type)
failWithMessage("Expected the type to be <%s> but it was <%s>", expected, type)
}
return this
}
Expand All @@ -157,22 +267,7 @@ class 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 <T : Any> isEqualDeserializedTo(expected: IntermediateEventRepresentation): IntermediateEventRepresentationAssert {
isNotNull
val deserialized: 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)
failWithMessage("Expected the content type revision to be <%s> but it was <%s>", expected, typeName)
}
return this
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,42 @@ import org.axonframework.serialization.upcasting.event.IntermediateEventRepresen

class IntermediateEventRepresentationListAssert(
actual: List<IntermediateEventRepresentation>,
private val serializer: Serializer
private val serializer: Serializer,
private val strictComparison: Boolean = false
) : AbstractListAssert
<IntermediateEventRepresentationListAssert, List<IntermediateEventRepresentation>, IntermediateEventRepresentation, IntermediateEventRepresentationAssert>(
actual, IntermediateEventRepresentationListAssert::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: List<IntermediateEventRepresentation>, serializer: Serializer): IntermediateEventRepresentationListAssert =
IntermediateEventRepresentationListAssert(actual, serializer)

/**
* Creates the assert for given intermediate representation serialized using given serializer.
* @param actual current intermediate representation.
* @param serializer serializer in use.
* @param strictComparison if true equality instead of similarity is applied where possible. Defaults to false.
* @return the asserting anchor for checks.
*/
@JvmStatic
fun assertThat(
actual: List<IntermediateEventRepresentation>,
serializer: Serializer,
strictComparison: Boolean
): IntermediateEventRepresentationListAssert {
return IntermediateEventRepresentationListAssert(actual, serializer, strictComparison)
}
}

override fun toAssert(value: IntermediateEventRepresentation, description: String): IntermediateEventRepresentationAssert =
IntermediateEventRepresentationAssert(value, serializer).`as`(description)
IntermediateEventRepresentationAssert(value, serializer, strictComparison).`as`(description)


override fun newAbstractIterableAssert(iterable: MutableIterable<IntermediateEventRepresentation>): IntermediateEventRepresentationListAssert =
Expand Down
2 changes: 1 addition & 1 deletion extension/jgiven/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>io.holixon.axon.testing._</groupId>
<artifactId>extension-jgiven</artifactId>
<version>4.8.0.1</version>
<version>4.8.0.2</version>
</parent>

<groupId>io.holixon.axon.testing</groupId>
Expand Down
2 changes: 1 addition & 1 deletion extension/jgiven/junit5/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>io.holixon.axon.testing._</groupId>
<artifactId>extension-jgiven</artifactId>
<version>4.8.0.1</version>
<version>4.8.0.2</version>
</parent>

<groupId>io.holixon.axon.testing</groupId>
Expand Down
2 changes: 1 addition & 1 deletion extension/jgiven/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.holixon.axon.testing._</groupId>
<artifactId>extension</artifactId>
<version>4.8.0.1</version>
<version>4.8.0.2</version>
</parent>

<artifactId>extension-jgiven</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion extension/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.holixon.axon.testing._</groupId>
<artifactId>axon-testing_</artifactId>
<version>4.8.0.1</version>
<version>4.8.0.2</version>
</parent>

<artifactId>extension</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion extension/upcaster/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>io.holixon.axon.testing._</groupId>
<artifactId>extension-upcaster</artifactId>
<version>4.8.0.1</version>
<version>4.8.0.2</version>
</parent>

<groupId>io.holixon.axon.testing</groupId>
Expand Down
2 changes: 1 addition & 1 deletion extension/upcaster/junit5/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>io.holixon.axon.testing._</groupId>
<artifactId>extension-upcaster</artifactId>
<version>4.8.0.1</version>
<version>4.8.0.2</version>
</parent>

<groupId>io.holixon.axon.testing</groupId>
Expand Down
2 changes: 1 addition & 1 deletion extension/upcaster/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.holixon.axon.testing._</groupId>
<artifactId>extension</artifactId>
<version>4.8.0.1</version>
<version>4.8.0.2</version>
</parent>

<artifactId>extension-upcaster</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion lib/fixtures/bankaccount/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.holixon.axon.testing._</groupId>
<artifactId>fixtures</artifactId>
<version>4.8.0.1</version>
<version>4.8.0.2</version>
</parent>

<groupId>io.holixon.axon.testing.lib</groupId>
Expand Down
Loading

0 comments on commit 5d1345f

Please sign in to comment.