@Override public <R> R invoke(Function<AR, R> invocation) { return wrappedAggregate.invoke(invocation); }
private void assertValidWorkingAggregateState(Aggregate<T> eventSourcedAggregate, MatchAllFieldFilter fieldFilter, Aggregate<T> workingAggregate) { HashSet<ComparationEntry> comparedEntries = new HashSet<>(); if (!workingAggregate.rootType().equals(eventSourcedAggregate.rootType())) { throw new AxonAssertionError(String.format("The aggregate loaded based on the generated events seems to " + "be of another type than the original.\n" + "Working type: <%s>\nEvent Sourced type: <%s>", workingAggregate.rootType().getName(), eventSourcedAggregate.rootType().getName())); } ensureValuesEqual(workingAggregate.invoke(Function.identity()), eventSourcedAggregate.invoke(Function.identity()), eventSourcedAggregate.rootType().getName(), comparedEntries, fieldFilter); }
@CommandHandler public MyAggregate handle(MyCommand command) throws Exception { Aggregate<MyAggregate> aggregate; try { aggregate = repository.load(command.getAggregateIdentifier()); } catch (AggregateNotFoundException e) { aggregate = repository.newInstance(() -> new MyAggregate(command.getAggregateIdentifier())); } aggregate.execute(a -> a.handle(command, commandGateway)); return aggregate.invoke(Function.identity()); } }
@Test public void orderInEventSourcedAggregate() { Repository<MyAggregate> repository = configuration.repository(MyAggregate.class); configuration.commandGateway().sendAndWait(command); UnitOfWork unitOfWork = DefaultUnitOfWork.startAndGet(GenericCommandMessage.asCommandMessage("loading")); MyAggregate loadedAggregate = repository.load(aggregateIdentifier).invoke(Function.identity()); unitOfWork.commit(); assertEquals(expectedDescriptions(command), loadedAggregate.getHandledCommands()); }
@Override public <R> R invoke(Function<AR, R> invocation) { return wrappedAggregate.invoke(invocation); }