Skip to content

Commit

Permalink
Merge branch 'release/0.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
jangalinski committed Jan 9, 2023
2 parents fe9b87f + 622b23c commit 070658b
Show file tree
Hide file tree
Showing 24 changed files with 307 additions and 132 deletions.
10 changes: 5 additions & 5 deletions examples/bankaccount-jgiven-junit4/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>0.2.1</version>
<version>0.3.0</version>
</parent>

<groupId>io.holixon.axon.testing.examples</groupId>
Expand All @@ -27,7 +27,7 @@
<dependency>
<groupId>io.toolisticon.testing</groupId>
<artifactId>jgiven-kotlin</artifactId>
<version>1.2.2</version>
<version>1.2.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -38,19 +38,19 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.36</version>
<version>2.0.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.23.1</version>
<version>3.24.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>4.6.1</version>
<version>4.11.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
8 changes: 4 additions & 4 deletions 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>0.2.1</version>
<version>0.3.0</version>
</parent>

<groupId>io.holixon.axon.testing.examples</groupId>
Expand All @@ -29,7 +29,7 @@
<dependency>
<groupId>io.toolisticon.testing</groupId>
<artifactId>jgiven-kotlin</artifactId>
<version>1.2.2</version>
<version>1.2.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -40,13 +40,13 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.36</version>
<version>2.0.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.23.1</version>
<version>3.24.1</version>
<scope>test</scope>
</dependency>
</dependencies>
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>0.2.1</version>
<version>0.3.0</version>
</parent>

<artifactId>examples</artifactId>
Expand Down
31 changes: 27 additions & 4 deletions extension/jgiven/core/pom.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?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">
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 Testing - JGiven Core</name>

<parent>
<groupId>io.holixon.axon.testing._</groupId>
<artifactId>extension-jgiven</artifactId>
<version>0.2.1</version>
<version>0.3.0</version>
</parent>

<groupId>io.holixon.axon.testing</groupId>
Expand All @@ -17,12 +17,13 @@
<dependency>
<groupId>org.axonframework</groupId>
<artifactId>axon-configuration</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>org.axonframework</groupId>
<artifactId>axon-test</artifactId>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>com.tngtech.jgiven</groupId>
<artifactId>jgiven-core</artifactId>
Expand All @@ -34,6 +35,28 @@
<version>2.2</version>
</dependency>

<!-- TEST -->

<dependency>
<groupId>io.github.microutils</groupId>
<artifactId>kotlin-logging-jvm</artifactId>
<version>3.0.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.toolisticon.testing</groupId>
<artifactId>jgiven-kotlin</artifactId>
<version>${jgiven-kotlin.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.tngtech.jgiven</groupId>
<artifactId>jgiven-junit5</artifactId>
<version>${jgiven.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
Expand All @@ -43,7 +66,7 @@
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.11</version>
<version>1.4.5</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
5 changes: 2 additions & 3 deletions extension/jgiven/core/src/main/kotlin/AxonJGiven.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@ import io.holixon.axon.testing.jgiven.saga.SagaFixtureGiven
import io.holixon.axon.testing.jgiven.saga.SagaFixtureThen
import io.holixon.axon.testing.jgiven.saga.SagaFixtureWhen
import io.holixon.axon.testing.jgiven.saga.SagaTestFixtureBuilder
import org.axonframework.test.aggregate.AggregateTestFixture
import org.axonframework.test.saga.SagaTestFixture
import kotlin.reflect.KClass

/**
* Base class for scenario aggregate tests.
*/
@Suppress("UNUSED")
abstract class AggregateFixtureScenarioTestBase<T> : ScenarioTestBase<AggregateFixtureGiven<T>, AggregateFixtureWhen<T>, AggregateFixtureThen<T>>()

/**
* Base class for scenario saga tests.
*/
@Suppress("UNUSED")
abstract class SagaFixtureScenarioTestBase<T> : ScenarioTestBase<SagaFixtureGiven<T>, SagaFixtureWhen<T>, SagaFixtureThen<T>>()

object AxonJGiven {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,14 @@
package io.holixon.axon.testing.jgiven.aggregate

import com.tngtech.jgiven.Stage
import com.tngtech.jgiven.annotation.As
import com.tngtech.jgiven.annotation.ExpectedScenarioState
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.test.aggregate.AggregateTestFixture
import org.axonframework.test.aggregate.TestExecutor
import java.time.Duration
import java.time.Instant
import java.util.function.Supplier


/**
* Given stage for aggregate fixture.
* @param T aggregate type.
Expand All @@ -27,7 +22,12 @@ class AggregateFixtureGiven<T> : Stage<AggregateFixtureGiven<T>>() {
private lateinit var fixture: AggregateTestFixture<T>

@ProvidedScenarioState
private lateinit var testExecutor: TestExecutor<T>
private lateinit var context: AggregateTestFixtureContext<T>

@BeforeStage
internal fun initStage() {
context = AggregateTestFixtureContext(fixture)
}

/**
* Nothing happens before.
Expand All @@ -40,104 +40,82 @@ class AggregateFixtureGiven<T> : Stage<AggregateFixtureGiven<T>>() {
* @param command dispatched command.
*/
@As("command:")
fun command(@Quoted command: Any) = this.commands(command)
fun command(@Quoted command: Any): AggregateFixtureGiven<T> = this.commands(command)

/**
* One or several commands has been dispatched.
* @param commands dispatched commands.
*/
@As("commands:")
fun commands(@Quoted vararg commands: Any) = this.commands(commands.toList())
fun commands(@Quoted vararg commands: Any): AggregateFixtureGiven<T> = this.commands(commands.toList())

/**
* One or several commands has been dispatched.
* @param commands dispatched commands.
*/
@As("commands:")
fun commands(@Quoted commands: List<Any>) = execute {
if (!::testExecutor.isInitialized)
fixture.givenCommands(commands)
else
testExecutor.andGivenCommands(commands)
fun commands(@Quoted commands: List<Any>): AggregateFixtureGiven<T> = execute {
if (context.isFirstGiven) {
context.isFirstGiven = false
context.fixture!!.givenCommands(commands)
} else {
context.testExecutor!!.andGivenCommands(commands)
}
}

/**
* An event has been published.
* @param event published event.
*/
@As("event:")
fun event(@Quoted event: Any) = this.events(event)
fun event(@Quoted event: Any): AggregateFixtureGiven<T> = this.events(event)

/**
* One or several events has been published.
* @param events published events.
*/
@As("events:")
fun events(@Quoted vararg events: Any) = this.events(events.toList())
fun events(@Quoted vararg events: Any): AggregateFixtureGiven<T> = this.events(events.toList())

/**
* One or several events has been published.
* @param events published events.
*/
@As("events:")
fun events(@Quoted events: List<Any>) = execute {
if (!::testExecutor.isInitialized)
fixture.given(events)
else
testExecutor.andGiven(events)
fun events(@Quoted events: List<Any>): AggregateFixtureGiven<T> = execute {
if (context.isFirstGiven) {
context.isFirstGiven = false
context.fixture!!.given(events)
} else {
context.testExecutor!!.andGiven(events)
}
}

/**
* Sets the time.
* @param instant new time.
*/
fun currentTime(instant: Instant) = execute {
if (!::testExecutor.isInitialized)
fixture.givenCurrentTime(instant)
else
testExecutor.andGivenCurrentTime(instant)
fun currentTime(instant: Instant): AggregateFixtureGiven<T> = execute {
context.testExecutor!!.andGivenCurrentTime(instant)
}

/**
* Sets the state of the aggregate.
* @param aggregate aggregate state supplier.
*/
fun state(aggregate: Supplier<T>) = execute {
fun state(aggregate: Supplier<T>): AggregateFixtureGiven<T> = execute {
fixture.givenState(aggregate)
}

/**
* Sets the state of the aggregate.
* @param aggregate aggregate state providing function..
*/
fun state(aggregate: () -> T) = execute {
fun state(aggregate: () -> T): AggregateFixtureGiven<T> = execute {
fixture.givenState(aggregate)
}

/**
* Moves time to new value.
* @param instant new time to set.
*/
fun timeAdvancesTo(instant: Instant) {
if (!::testExecutor.isInitialized)
fixture.whenThenTimeAdvancesTo(instant)
else
testExecutor.whenThenTimeAdvancesTo(instant)
}

/**
* Moves time to new value.
* @param duration timespan to move time to.
*/
fun timeElapses(duration: Duration) {
if (!::testExecutor.isInitialized)
fixture.whenThenTimeElapses(duration)
else
testExecutor.whenThenTimeElapses(duration)
}

private fun execute(block: () -> TestExecutor<T>) = step {
testExecutor = block.invoke()
context.testExecutor = block.invoke()
}

}
Loading

0 comments on commit 070658b

Please sign in to comment.