@Componentpublic class MyFirstCommandHandler{ private final CommandGateway commandGateway;
public MyFirstCommandHandler(CommandGateway commandGateway) { this.commandGateway = commandGateway; }
@CommandHandler public void handle( final InitCommand initCommand) { // for example call external api that returns a list of objects to create List<String> response = asList("a", "b"); response.forEach(s -> commandGateway.send(new CreateMyAggregateCommand(new MyAggregateId(), s))); }}@Aggregate@NoArgsConstructorpublic class MyAggregate{ @AggregateIdentifier private MyAggregateId id;
private String something;
@CommandHandler public MyAggregate(final CreateMyAggregateCommand command) { apply(new MyAggregateCreatedEvent(command.getId(), command.getSomething())); }
@EventSourcingHandler public void on(final MyAggregateCreatedEvent event) { this.id = event.getId(); this.something = event.getSomething(); System.out.println(event); }}public class MyFirstCommandHandlerTest{ private FixtureConfiguration fixture;
@Before public void setUp() throws Exception { fixture = new AggregateTestFixture<>(MyAggregate.class); CommandBus commandBus = fixture.getCommandBus(); DefaultCommandGateway commandGateway = new DefaultCommandGateway(commandBus); fixture.registerAnnotatedCommandHandler(new MyFirstCommandHandler(commandGateway)); }
@Test public void testMigrateStream() throws Exception { fixture .givenNoPriorActivity() .when(new InitCommand()) .expectSuccessfulHandlerExecution(); }
}org.axonframework.test.AxonAssertionError: Illegal state change detected! Property "test.onecommandtwoevents.domain.MyAggregate.id.identifier" has different value when sourcing events.Working aggregate value: <8802e90d-2764-4daa-97c5-d661ba38918e>Value after applying events: <f34ebebe-dcf2-495b-9700-433385b9ed9f>
--
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.