From 0441eec02af205083e74320e75641bde2d37e06f Mon Sep 17 00:00:00 2001 From: Simon Zambrovski Date: Mon, 19 Oct 2020 12:07:44 +0200 Subject: [PATCH 1/4] feature: implement aggregate fixture and saga fixture extensions, fix #67 --- kotlin-test/pom.xml | 59 +++++++++++++++++++ .../kotlin/AggregateFixtureExtensions.kt | 57 ++++++++++++++++++ .../kotlin/FixtureConfigurationExtensions.kt | 31 ++++++++++ .../extension/kotlin/SagaFixtureExtensions.kt | 47 +++++++++++++++ pom.xml | 1 + 5 files changed, 195 insertions(+) create mode 100644 kotlin-test/pom.xml create mode 100644 kotlin-test/src/main/kotlin/org/axonframework/extension/kotlin/AggregateFixtureExtensions.kt create mode 100644 kotlin-test/src/main/kotlin/org/axonframework/extension/kotlin/FixtureConfigurationExtensions.kt create mode 100644 kotlin-test/src/main/kotlin/org/axonframework/extension/kotlin/SagaFixtureExtensions.kt diff --git a/kotlin-test/pom.xml b/kotlin-test/pom.xml new file mode 100644 index 0000000..5d94eb2 --- /dev/null +++ b/kotlin-test/pom.xml @@ -0,0 +1,59 @@ + + + 4.0.0 + + Axon Framework - Kotlin Extension Test + Module for the Kotlin Test Extension of Axon Framework + + + axon-kotlin-parent + org.axonframework.extensions.kotlin + 0.2.0-SNAPSHOT + + + axon-kotlin-test + + + + org.axonframework + axon-test + provided + + + + + + + org.jetbrains.kotlin + kotlin-maven-plugin + + + + + + + javadoc-and-sources + + + performRelease + true + + + + + + org.jetbrains.dokka + dokka-maven-plugin + + + maven-source-plugin + 3.0.1 + + + + + + + \ No newline at end of file diff --git a/kotlin-test/src/main/kotlin/org/axonframework/extension/kotlin/AggregateFixtureExtensions.kt b/kotlin-test/src/main/kotlin/org/axonframework/extension/kotlin/AggregateFixtureExtensions.kt new file mode 100644 index 0000000..01757a3 --- /dev/null +++ b/kotlin-test/src/main/kotlin/org/axonframework/extension/kotlin/AggregateFixtureExtensions.kt @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2010-2020. Axon Framework + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.axonframework.extension.kotlin + +import org.axonframework.test.aggregate.AggregateTestFixture +import org.axonframework.test.aggregate.FixtureConfiguration +import org.axonframework.test.aggregate.ResultValidator +import kotlin.reflect.KClass + +/** + * Creates an aggregate test fixture for aggregate [T]. + * @param [T] reified type of the aggregate. + * @return aggregate test fixture. + */ +inline fun AggregateTestFixture.aggregateTestFixture() = + AggregateTestFixture(T::class.java) + +/** + * Alias for the `when` method to avoid name clash with Kotlin's `when`. + * @param command command to pass to the when method. + * @param [T] aggregate type. + * @return result validator. + */ +fun AggregateTestFixture.whenever(command: Any): ResultValidator = this.`when`(command) + +/** + * Alias for the `when` method to avoid name clash with Kotlin's `when`. + * @param command command to pass to the when method. + * @param metaData metadata map. + * @param [T] aggregate type. + * @return result validator. + */ +fun AggregateTestFixture.whenever(command: Any, metaData: Map): ResultValidator = this.`when`(command, metaData) + +/** + * Registers subtypes of this aggregate to support aggregate polymorphism. Command Handlers defined on this subtype + * will be considered part of this aggregate's handlers. + * + * @param subtypes subtypes in this polymorphic hierarchy + * @return the current FixtureConfiguration, for fluent interfacing + */ +fun AggregateTestFixture.withSubtypes(vararg subtypes: KClass) = + this.withSubtypes(* subtypes.map { it.java }.toTypedArray()) diff --git a/kotlin-test/src/main/kotlin/org/axonframework/extension/kotlin/FixtureConfigurationExtensions.kt b/kotlin-test/src/main/kotlin/org/axonframework/extension/kotlin/FixtureConfigurationExtensions.kt new file mode 100644 index 0000000..25b7b4d --- /dev/null +++ b/kotlin-test/src/main/kotlin/org/axonframework/extension/kotlin/FixtureConfigurationExtensions.kt @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2010-2020. Axon Framework + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.axonframework.extension.kotlin + +import org.axonframework.test.aggregate.FixtureConfiguration + +/** + * Indicates that a field with given {@code fieldName}, which is declared in given {@code declaringClass} + * is ignored when performing deep equality checks. + * + * @param [T] type of fixture target. + * @param [F] filed type. + * @param fieldName The name of the field + * @return the current FixtureConfiguration, for fluent interfacing + */ +inline fun FixtureConfiguration.registerIgnoredField(fieldName: String): FixtureConfiguration = + this.registerIgnoredField(F::class.java, fieldName) \ No newline at end of file diff --git a/kotlin-test/src/main/kotlin/org/axonframework/extension/kotlin/SagaFixtureExtensions.kt b/kotlin-test/src/main/kotlin/org/axonframework/extension/kotlin/SagaFixtureExtensions.kt new file mode 100644 index 0000000..4f5563d --- /dev/null +++ b/kotlin-test/src/main/kotlin/org/axonframework/extension/kotlin/SagaFixtureExtensions.kt @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2010-2020. Axon Framework + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.axonframework.extension.kotlin + +import org.axonframework.test.saga.SagaTestFixture + +/** + * Creates a saga test fixture for saga [T]. + * @param [T] reified type of the saga. + * @return saga test fixture. + */ +inline fun SagaTestFixture.sagaTestFixture() = + SagaTestFixture(T::class.java) + +/** + * Reified version of command gateway registration. + * @param [T] saga type + * @param [I] command gateway type. + * @return registered command gateway instance. + */ +inline fun SagaTestFixture.registerCommandGateway(): I = + this.registerCommandGateway(I::class.java) + +/** + * Reified version of command gateway registration. + * @param [T] saga type + * @param [I] command gateway type. + * @param stubImplementation stub implementation. + * @return registered command gateway instance. + */ +inline fun SagaTestFixture.registerCommandGateway(stubImplementation: I): I = + this.registerCommandGateway(I::class.java, stubImplementation) + diff --git a/pom.xml b/pom.xml index 65c13a7..48c4d13 100644 --- a/pom.xml +++ b/pom.xml @@ -28,6 +28,7 @@ kotlin + kotlin-test From 711ad7db0f62da54200232c04f313bb3dfbbfbb7 Mon Sep 17 00:00:00 2001 From: Simon Zambrovski Date: Mon, 19 Oct 2020 12:11:07 +0200 Subject: [PATCH 2/4] renaming --- kotlin-test/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kotlin-test/pom.xml b/kotlin-test/pom.xml index 5d94eb2..5dcd4f8 100644 --- a/kotlin-test/pom.xml +++ b/kotlin-test/pom.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - Axon Framework - Kotlin Extension Test + Axon Framework - Kotlin Extension - Test Module for the Kotlin Test Extension of Axon Framework From 611046243620a4d6df3185b866abedd4fdb6b5f5 Mon Sep 17 00:00:00 2001 From: Simon Zambrovski Date: Mon, 19 Oct 2020 12:41:18 +0200 Subject: [PATCH 3/4] docs: kdocs improvements --- .../extension/kotlin/AggregateFixtureExtensions.kt | 11 +++++++---- .../kotlin/FixtureConfigurationExtensions.kt | 5 +++-- .../extension/kotlin/SagaFixtureExtensions.kt | 13 ++++++++----- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/kotlin-test/src/main/kotlin/org/axonframework/extension/kotlin/AggregateFixtureExtensions.kt b/kotlin-test/src/main/kotlin/org/axonframework/extension/kotlin/AggregateFixtureExtensions.kt index 01757a3..446f961 100644 --- a/kotlin-test/src/main/kotlin/org/axonframework/extension/kotlin/AggregateFixtureExtensions.kt +++ b/kotlin-test/src/main/kotlin/org/axonframework/extension/kotlin/AggregateFixtureExtensions.kt @@ -17,14 +17,14 @@ package org.axonframework.extension.kotlin import org.axonframework.test.aggregate.AggregateTestFixture -import org.axonframework.test.aggregate.FixtureConfiguration import org.axonframework.test.aggregate.ResultValidator import kotlin.reflect.KClass /** * Creates an aggregate test fixture for aggregate [T]. - * @param [T] reified type of the aggregate. + * @param T reified type of the aggregate. * @return aggregate test fixture. + * @since 0.2.0 */ inline fun AggregateTestFixture.aggregateTestFixture() = AggregateTestFixture(T::class.java) @@ -32,8 +32,9 @@ inline fun AggregateTestFixture.aggregateTestFixture() = /** * Alias for the `when` method to avoid name clash with Kotlin's `when`. * @param command command to pass to the when method. - * @param [T] aggregate type. + * @param T aggregate type. * @return result validator. + * @since 0.2.0 */ fun AggregateTestFixture.whenever(command: Any): ResultValidator = this.`when`(command) @@ -41,8 +42,9 @@ fun AggregateTestFixture.whenever(command: Any): ResultValidator * Alias for the `when` method to avoid name clash with Kotlin's `when`. * @param command command to pass to the when method. * @param metaData metadata map. - * @param [T] aggregate type. + * @param T aggregate type. * @return result validator. + * @since 0.2.0 */ fun AggregateTestFixture.whenever(command: Any, metaData: Map): ResultValidator = this.`when`(command, metaData) @@ -52,6 +54,7 @@ fun AggregateTestFixture.whenever(command: Any, metaData: Map AggregateTestFixture.withSubtypes(vararg subtypes: KClass) = this.withSubtypes(* subtypes.map { it.java }.toTypedArray()) diff --git a/kotlin-test/src/main/kotlin/org/axonframework/extension/kotlin/FixtureConfigurationExtensions.kt b/kotlin-test/src/main/kotlin/org/axonframework/extension/kotlin/FixtureConfigurationExtensions.kt index 25b7b4d..e2aa888 100644 --- a/kotlin-test/src/main/kotlin/org/axonframework/extension/kotlin/FixtureConfigurationExtensions.kt +++ b/kotlin-test/src/main/kotlin/org/axonframework/extension/kotlin/FixtureConfigurationExtensions.kt @@ -22,10 +22,11 @@ import org.axonframework.test.aggregate.FixtureConfiguration * Indicates that a field with given {@code fieldName}, which is declared in given {@code declaringClass} * is ignored when performing deep equality checks. * - * @param [T] type of fixture target. - * @param [F] filed type. + * @param T type of fixture target. + * @param F filed type. * @param fieldName The name of the field * @return the current FixtureConfiguration, for fluent interfacing + * @since 0.2.0 */ inline fun FixtureConfiguration.registerIgnoredField(fieldName: String): FixtureConfiguration = this.registerIgnoredField(F::class.java, fieldName) \ No newline at end of file diff --git a/kotlin-test/src/main/kotlin/org/axonframework/extension/kotlin/SagaFixtureExtensions.kt b/kotlin-test/src/main/kotlin/org/axonframework/extension/kotlin/SagaFixtureExtensions.kt index 4f5563d..8d62074 100644 --- a/kotlin-test/src/main/kotlin/org/axonframework/extension/kotlin/SagaFixtureExtensions.kt +++ b/kotlin-test/src/main/kotlin/org/axonframework/extension/kotlin/SagaFixtureExtensions.kt @@ -20,27 +20,30 @@ import org.axonframework.test.saga.SagaTestFixture /** * Creates a saga test fixture for saga [T]. - * @param [T] reified type of the saga. + * @param T reified type of the saga. * @return saga test fixture. + * @since 0.2.0 */ inline fun SagaTestFixture.sagaTestFixture() = SagaTestFixture(T::class.java) /** * Reified version of command gateway registration. - * @param [T] saga type - * @param [I] command gateway type. + * @param T saga type + * @param I command gateway type. * @return registered command gateway instance. + * @since 0.2.0 */ inline fun SagaTestFixture.registerCommandGateway(): I = this.registerCommandGateway(I::class.java) /** * Reified version of command gateway registration. - * @param [T] saga type - * @param [I] command gateway type. + * @param T saga type + * @param I command gateway type. * @param stubImplementation stub implementation. * @return registered command gateway instance. + * @since 0.2.0 */ inline fun SagaTestFixture.registerCommandGateway(stubImplementation: I): I = this.registerCommandGateway(I::class.java, stubImplementation) From ae7ba7b9e9c7e7b664396773f571fc7679b0961b Mon Sep 17 00:00:00 2001 From: Simon Zambrovski Date: Tue, 3 Nov 2020 11:22:50 +0100 Subject: [PATCH 4/4] worked on comments from @sandjelkovic --- .../kotlin/FixtureConfigurationExtensions.kt | 32 ------------ .../extension/kotlin/SagaFixtureExtensions.kt | 50 ------------------- .../FixtureExtensions.kt} | 48 +++++++++++++++++- 3 files changed, 47 insertions(+), 83 deletions(-) delete mode 100644 kotlin-test/src/main/kotlin/org/axonframework/extension/kotlin/FixtureConfigurationExtensions.kt delete mode 100644 kotlin-test/src/main/kotlin/org/axonframework/extension/kotlin/SagaFixtureExtensions.kt rename kotlin-test/src/main/kotlin/org/axonframework/extension/kotlin/{AggregateFixtureExtensions.kt => test/FixtureExtensions.kt} (56%) diff --git a/kotlin-test/src/main/kotlin/org/axonframework/extension/kotlin/FixtureConfigurationExtensions.kt b/kotlin-test/src/main/kotlin/org/axonframework/extension/kotlin/FixtureConfigurationExtensions.kt deleted file mode 100644 index e2aa888..0000000 --- a/kotlin-test/src/main/kotlin/org/axonframework/extension/kotlin/FixtureConfigurationExtensions.kt +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2010-2020. Axon Framework - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.axonframework.extension.kotlin - -import org.axonframework.test.aggregate.FixtureConfiguration - -/** - * Indicates that a field with given {@code fieldName}, which is declared in given {@code declaringClass} - * is ignored when performing deep equality checks. - * - * @param T type of fixture target. - * @param F filed type. - * @param fieldName The name of the field - * @return the current FixtureConfiguration, for fluent interfacing - * @since 0.2.0 - */ -inline fun FixtureConfiguration.registerIgnoredField(fieldName: String): FixtureConfiguration = - this.registerIgnoredField(F::class.java, fieldName) \ No newline at end of file diff --git a/kotlin-test/src/main/kotlin/org/axonframework/extension/kotlin/SagaFixtureExtensions.kt b/kotlin-test/src/main/kotlin/org/axonframework/extension/kotlin/SagaFixtureExtensions.kt deleted file mode 100644 index 8d62074..0000000 --- a/kotlin-test/src/main/kotlin/org/axonframework/extension/kotlin/SagaFixtureExtensions.kt +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2010-2020. Axon Framework - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.axonframework.extension.kotlin - -import org.axonframework.test.saga.SagaTestFixture - -/** - * Creates a saga test fixture for saga [T]. - * @param T reified type of the saga. - * @return saga test fixture. - * @since 0.2.0 - */ -inline fun SagaTestFixture.sagaTestFixture() = - SagaTestFixture(T::class.java) - -/** - * Reified version of command gateway registration. - * @param T saga type - * @param I command gateway type. - * @return registered command gateway instance. - * @since 0.2.0 - */ -inline fun SagaTestFixture.registerCommandGateway(): I = - this.registerCommandGateway(I::class.java) - -/** - * Reified version of command gateway registration. - * @param T saga type - * @param I command gateway type. - * @param stubImplementation stub implementation. - * @return registered command gateway instance. - * @since 0.2.0 - */ -inline fun SagaTestFixture.registerCommandGateway(stubImplementation: I): I = - this.registerCommandGateway(I::class.java, stubImplementation) - diff --git a/kotlin-test/src/main/kotlin/org/axonframework/extension/kotlin/AggregateFixtureExtensions.kt b/kotlin-test/src/main/kotlin/org/axonframework/extension/kotlin/test/FixtureExtensions.kt similarity index 56% rename from kotlin-test/src/main/kotlin/org/axonframework/extension/kotlin/AggregateFixtureExtensions.kt rename to kotlin-test/src/main/kotlin/org/axonframework/extension/kotlin/test/FixtureExtensions.kt index 446f961..092c810 100644 --- a/kotlin-test/src/main/kotlin/org/axonframework/extension/kotlin/AggregateFixtureExtensions.kt +++ b/kotlin-test/src/main/kotlin/org/axonframework/extension/kotlin/test/FixtureExtensions.kt @@ -14,10 +14,12 @@ * limitations under the License. */ -package org.axonframework.extension.kotlin +package org.axonframework.extension.kotlin.test import org.axonframework.test.aggregate.AggregateTestFixture +import org.axonframework.test.aggregate.FixtureConfiguration import org.axonframework.test.aggregate.ResultValidator +import org.axonframework.test.saga.SagaTestFixture import kotlin.reflect.KClass /** @@ -58,3 +60,47 @@ fun AggregateTestFixture.whenever(command: Any, metaData: Map AggregateTestFixture.withSubtypes(vararg subtypes: KClass) = this.withSubtypes(* subtypes.map { it.java }.toTypedArray()) + +/** + * Indicates that a field with given {@code fieldName}, which is declared in given {@code declaringClass} + * is ignored when performing deep equality checks. + * + * @param T type of fixture target. + * @param F filed type. + * @param fieldName The name of the field + * @return the current FixtureConfiguration, for fluent interfacing + * @since 0.2.0 + */ +inline fun FixtureConfiguration.registerIgnoredField(fieldName: String): FixtureConfiguration = + this.registerIgnoredField(F::class.java, fieldName) + +/** + * Creates a saga test fixture for saga [T]. + * @param T reified type of the saga. + * @return saga test fixture. + * @since 0.2.0 + */ +inline fun SagaTestFixture.sagaTestFixture() = + SagaTestFixture(T::class.java) + +/** + * Reified version of command gateway registration. + * @param T saga type + * @param I command gateway type. + * @return registered command gateway instance. + * @since 0.2.0 + */ +inline fun SagaTestFixture.registerCommandGateway(): I = + this.registerCommandGateway(I::class.java) + +/** + * Reified version of command gateway registration. + * @param T saga type + * @param I command gateway type. + * @param stubImplementation stub implementation. + * @return registered command gateway instance. + * @since 0.2.0 + */ +inline fun SagaTestFixture.registerCommandGateway(stubImplementation: I): I = + this.registerCommandGateway(I::class.java, stubImplementation) +