Hi All,
When testing simple aggreate creation command I always encounter the following error:
java.lang.AssertionError: The aggregate used in this fixture was initialized with an identifier different than the one used to load it. Loaded [0], but actual identifier is [10000].
Make sure the identifier passed in the Command matches that of the given Events.
at org.axonframework.test.GivenWhenThenTestFixture$IdentifierValidatingRepository.validateIdentifier(GivenWhenThenTestFixture.java:435)
at org.axonframework.test.GivenWhenThenTestFixture$IdentifierValidatingRepository.load(GivenWhenThenTestFixture.java:429)
at org.axonframework.test.GivenWhenThenTestFixture$IdentifierValidatingRepository.load(GivenWhenThenTestFixture.java:411)
at org.axonframework.test.GivenWhenThenTestFixture.detectIllegalStateChanges(GivenWhenThenTestFixture.java:271)
at org.axonframework.test.GivenWhenThenTestFixture.when(GivenWhenThenTestFixture.java:236)
at org.axonframework.test.GivenWhenThenTestFixture.when(GivenWhenThenTestFixture.java:223)
…
I can get rid of above error by invoking FixtureConfiguration#setReportIllegalStateChange(false) but it seems wrong to do so since my aggregate is simple.
Below is the test code:
`
fixture.givenNoPriorActivity().when(new CreateEmployeeCommand(name, contact, joinedDate))
.expectVoidReturnType()
.expectEvents(new EmployeeCreatedEvent(10000, name,contact, joinedDate));
`
And below is the Aggregate:
`
class Employee extends AbstractAnnotatedAggregateRoot
{
private static final long serialVersionUID = 7125543543552936997L;
private final LongIdentifierGenerator GENERATOR = new LongGenerator(false, 10000);
@AggregateIdentifier
private long id;
@CommandHandler
public Employee(CreateEmployeeCommand command)
{
apply(new EmployeeCreatedEvent(GENERATOR.nextLongIdentifier(), command.getName(), command.getContact(), command.getJoinDate()));
}
@EventSourcingHandler
private void handleEmployeeCreatedEvent(EmployeeCreatedEvent event)
{
this.id = event.getId();
}
}
`
Any help would be greatly appreciated.
Thanks & Regards,
Setya