org.axonframework.test.AxonAssertionError: Illegal state change detected! Property "com.example.domain.model.Letter.imported" has different value when sourcing events.
Working aggregate value: <2014-10-22T12:57:08.572+02:00>
Value after applying events: <2014-10-22T12:57:10.670+02:00> @Test
public void lettersCanBeCreated(){
final LetterId letterId = new LetterId(UUID.randomUUID().toString());
final LetterFileRef letterRef = mock(LetterFileRef.class);
fixture.given()
.when(new CreateLetterCommand(letterId, letterRef))
.expectReturnValue(letterId)
.expectEvents(new LetterImportedEvent(letterId, letterRef));
}public class Letter extends AbstractAnnotatedAggregateRoot {
@AggregateIdentifier
private LetterId id;
@Version
private Long version;
private LetterFileRef fileRef;
private DateTime imported = null;
// constructor needed for reconstruction
protected Letter() {
}
@CommandHandler
public Letter(@NotNull CreateLetterCommand command) {
apply(new LetterImportedEvent(command.getLetterId(), command.getFileRef()));
}
@EventSourcingHandler
private void handleCreation(@NotNull LetterImportedEvent event, @Timestamp eventTime) {
this.id = event.getLetterId();
this.fileRef = event.getFileRef();
this.imported = eventTime;
}
}handleRecursively(new GenericDomainEventMessage<Object>(null, 0, eventPayload, metaData));
registerEvent(metaData, eventPayload)workaround for aggregates that set the aggregate identifier in an Event Handler
public class MyAggregateRoot extends AbstractAnnotatedAggregateRoot {
@AggregateIdentifier
private String aggregateIdentifier;
private String someProperty;
public MyAggregateRoot(String id) {
apply(new MyAggregateCreatedEvent(id));
}
// constructor needed for reconstruction
protected MyAggregateRoot() {
}
@EventSourcingHandler
private void handleMyAggregateCreatedEvent(MyAggregateCreatedEvent event) {
// make sure identifier is always initialized properly
this.aggregateIdentifier = event.getMyAggregateIdentifier();
// do something with someProperty
}
}--
You received this message because you are subscribed to the Google Groups "Axon Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to axonframewor...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
The problem does seem to be in the Event that is applied during the creation of the aggregate. That one is handled slightly differently, as Axon cannot create an instance of the definitive event right away. It simply doesn't have an identifier yet. However, it seems that this code should be modified so that the timestamp (and most likely also the identifier) should remain identical.
--
--