Axon 3 fixture.given is throwing Aggregate Identifier must be non-null after applying an event

Currently when I try to configure my fixture so I can send a test prior events my tests fail (testDeleteSort). Currently the testCreateSort method works like a charm. Just a note the “delete” is only toggling a boolean in the aggregate. I currently believe that I must have configured my fixture incorrectly. Is this how I should properly configure it in Axon 3?

@Before
public void setup() throws Exception {
    fixture = new AggregateTestFixture<>(Sort.class);

    //TODO look into initializing testing with eventStores in Axon 3
    AggregateAnnotationCommandHandler commandHandler = new AggregateAnnotationCommandHandler<>(Sort.class, fixture.getRepository());
    fixture.registerAnnotatedCommandHandler(commandHandler);
}

//Success
@Test
public void testCreateSort() throws Exception {
    CreateSortCommand createSortCommand = new CreateSortCommand("operationTypeId", SortType.LOCAL_SORT, new SortName("My Local Sort"));
    fixture.givenNoPriorActivity()
            .when(createSortCommand)
            .expectEvents(new CreateSortEvent(createSortCommand.getId(), "operationTypeId", SortType.LOCAL_SORT, new SortName("My Local Sort")));
}

//Fail
@Test
public void testDeleteSort() throws Exception {
    CreateSortCommand createSortCommand = new CreateSortCommand("operationTypeId", SortType.LOCAL_SORT, new SortName("My Local Sort"));
    fixture.given(createSortCommand)
            .when(new DeleteSortCommand(createSortCommand.getId()))
            .expectEvents(new DeleteSortEvent(createSortCommand.getId()));
}

Also wanted to note that my missing aggregate is being caused by:

org.axonframework.commandhandling.model.LockingRepository - Exception occurred while trying to load an aggregate. Releasing lock.

Hi Matthew,

in your fixture.given() method, make sure you enter events, not commands. If you want to use commands instead, consider using the fixture.givenCommands() method.

The reason for the exception is that the first event (which was actually a command) supplied, did not set the aggregate identifier to a non-null value. Which makes sense, as you won’t have an EventHandler for that command.

Also, you don’t need the boilerplate configuration after your //TODO. Just using new AggregateTestFixture<>(Sort.class) is enough.

Cheers,

Allard