Hello,
I am testing the effect (expected events) when I execute a command on my aggregate root (Album, extends AbstractAnnotatedAggregateRoot). I provide the initial event (which should set the aggregateRootId) but still getting an AggregateIdentifierNotInitializedException.
The test code is:
`
@Test
public void voegFotoToe() {
AlbumId albumId = AlbumId.create();
BestandId bestandId = BestandId.create();
VoegFotoToeCommand voegFotoToe = VoegFotoToeCommand.voegFotoToe(
albumId,
BestandId.create(),
Paths.get("albumdir/foto"));
FixtureConfiguration fixture = newGivenWhenThenFixture(Album.class);
fixture.given(albumCreatedEvent(albumId))
.when(voegFotoToe)
.expectEvents(new FotoToegevoegdEvent(albumId, bestandId, Paths.get("albumdir/foto")));
}
`
albumCreatedEvent returns an event normally apply by the command passed in in the aggregate constructor. When albumCreatedEvent is applied, the aggregateRootId is set.
As I am testing “VoegFotoToeCommand”, the creation event should already be there and applied. But the fixture does return the AggregateIdentifierNotInitializedException… why?
The following is the a part of the error stacktrace:
`
org.axonframework.test.AxonAssertionError: The published events do not match the expected events
Expected | Actual |
---|---|
be.haezebrouck.triptrap.foto.domain.album.FotoToegevoegdEvent < | > |
A probable cause for the wrong chain of events is an exception that occurred while handling the command.
org.axonframework.domain.AggregateIdentifierNotInitializedException: AggregateIdentifier is unknown in [be.haezebrouck.triptrap.foto.domain.album.Album]. Make sure the Aggregate Identifier is initialized before registering events.
at org.axonframework.domain.AbstractAggregateRoot.getEventContainer(AbstractAggregateRoot.java:174)
org.axonframework.test.AxonAssertionError: The published events do not match the expected events
`