Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/axon kotlin test #73

Merged
merged 6 commits into from
Nov 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions kotlin-test/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<name>Axon Framework - Kotlin Extension - Test</name>
<description>Module for the Kotlin Test Extension of Axon Framework</description>

<parent>
<artifactId>axon-kotlin-parent</artifactId>
<groupId>org.axonframework.extensions.kotlin</groupId>
<version>0.2.0-SNAPSHOT</version>
</parent>

<artifactId>axon-kotlin-test</artifactId>

<dependencies>
<dependency>
<groupId>org.axonframework</groupId>
<artifactId>axon-test</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>javadoc-and-sources</id>
<activation>
<property>
<name>performRelease</name>
<value>true</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.jetbrains.dokka</groupId>
<artifactId>dokka-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* 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.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

/**
* Creates an aggregate test fixture for aggregate [T].
* @param T reified type of the aggregate.
* @return aggregate test fixture.
* @since 0.2.0
*/
inline fun <reified T : Any> AggregateTestFixture<T>.aggregateTestFixture() =
smcvb marked this conversation as resolved.
Show resolved Hide resolved
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.
* @since 0.2.0
*/
fun <T : Any> AggregateTestFixture<T>.whenever(command: Any): ResultValidator<T> = this.`when`(command)
smcvb marked this conversation as resolved.
Show resolved Hide resolved

/**
* 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.
* @since 0.2.0
*/
fun <T : Any> AggregateTestFixture<T>.whenever(command: Any, metaData: Map<String, Any>): ResultValidator<T> = 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
* @since 0.2.0
*/
fun <T : Any> AggregateTestFixture<T>.withSubtypes(vararg subtypes: KClass<out T>) =
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 <T : Any, reified F : Any> FixtureConfiguration<T>.registerIgnoredField(fieldName: String): FixtureConfiguration<T> =
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 <reified T : Any> SagaTestFixture<T>.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 <T : Any, reified I : Any> SagaTestFixture<T>.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 <T : Any, reified I : Any> SagaTestFixture<T>.registerCommandGateway(stubImplementation: I): I =
this.registerCommandGateway(I::class.java, stubImplementation)

1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

<modules>
<module>kotlin</module>
<module>kotlin-test</module>
</modules>

<properties>
Expand Down