Hi,
I’ve run into problems using given-when-then fixtures with AggregateFActory. Details follow but tl;dr version is - fixture too eagerly checks class name of the aggreate.
Inside @Before method:
`
ProductAggregateFactory factory = new ProductAggregateFactory();
EventSourcingRepository repository = new EventSourcingRepository<>(factory, fixture.getEventStore());
fixture.registerRepository(repository);
fixture.registerAnnotatedCommandHandler(productCommandHandler);
fixture.registerAggregateFactory(factory);
`
Working test:
`
fixture.getCommandBus().dispatch(new GenericCommandMessage<>(createProductCmd));
fixture.getCommandBus().dispatch(new GenericCommandMessage<>(commandInstanceOne));
fixture.getCommandBus().dispatch(new GenericCommandMessage<>(commandInstanceTwo));
try (CloseableUnitOfWork ignored = CloseableUnitOfWork.startAndGet()) {
BaseProduct product = fixture.getRepository().load(intId);
// assert that commandOne and Two had effects
}
`
Failing test:
`
fixture.givenCommands(createProductCmd, commandInstanceOne)
.when(commandInstanceTwo)
.expectEvents(new eventTwo());
`
And the exception I get:
`
ProductEventTests.testAdditionalInfoWithFixture:161 The aggregate loaded based on the generated events seems to be of another type than the original.
Working type: <pl.example.project.BaseProduct>
Event Sourced type: <pl.example.project.ChildClass>
`
ChildClass extends BaseProduct.
Exception comes from method org.axonframework.test.GivenWhenThenTestFixture#assertValidWorkingAggregateState, maybe it should test isAssignable>From instead of .equals?