Axon 3 M5.

Hello everyone

We are still working with M5. I know there is a new version, but still we need work on M5 before refactor the whole thing. Saying that we got the following problem.

We have a command in kotlin

class UpdatePasswordTokenCommand(@TargetAggregateIdentifier override val accountId: String, override val firstName: String,
override val lastName: String, override val email: String, override val phone: String,
override val companyNumber: String, override val type: String, override val password: String, override val active: Boolean,
val passwordResetToken: String)

And an event

class AccountUpdatedPasswordTokenEvent(val accountId: String, val password: String, val passwordResetToken: String)

We are using the commandGateway to raise a command handler and this is our handler

public void handle(UpdatePasswordTokenCommand command) {
AccountUpdatedPasswordTokenEvent updateEvent = new AccountUpdatedPasswordTokenEvent(command.getAccountId(),command.getPassword(),command.getPasswordResetToken());

and this is our event

public void on(AccountUpdatedPasswordTokenEvent event) {
    this.accountId = event.getAccountId();
    this.password = event.getPassword();
    this.passwordResetToken = event.getPasswordResetToken();

This is our test:

public class AccountTest {
    private FixtureConfiguration fixture;

    public void setUp() throws Exception {

        fixture = Fixtures.newGivenWhenThenFixture(Account.class);
        Account account = new Account();
    public void testUpdateToken() {
                .when(new UpdatePasswordTokenCommand("1","firstName","lastName","com",
                .expectEvents(new AccountUpdatedPasswordTokenEvent("1","mypassword","1234@"));

However we are getting the following error:

Expected Actual
com.myapp.coreapi.AccountUpdatedPasswordTokenEvent < >

A probable cause for the wrong chain of events is an exception that occurred while handling the command.
java.lang.IllegalStateException: Cannot retrieve current AggregateLifecycle; none is yet defined

Could you please someone help us?



A couple observations. But before we start I’m assuming the command handler is a method in your Account class. You didn’t make that clear.

Your aggregate class needs an @CommandHandler annotated constructor. Right now you’re testing an update command on an aggregate that hasn’t even been created yet. More likely you want your test to read:

givenCommands(new CreateAccountCommand(…)).when(new UpdatePasswordTokenCommand(…)).expect(…)

Also, in your setUp method you’re registering an Account instance as an AnnotatedCommandHandler. As Account is your aggregate and you’re handling commands from within the aggregate this is not correct.