/** * Creates a new immutable aggregate from the given projection, initialized with the empty * value as defined by the projection, no events, and a "not created" version. * * @param projection The projection used to apply events to the state of the aggregate. * @param id The id of the aggregate. * @return A new immutable aggregate with empty state and "not created" version. */ public static <TState, TEvent> DefaultImmutableAggregate<TState, TEvent> createNew( final AggregateProjection<TState, TEvent> projection, final String id) { return new DefaultImmutableAggregate<>( projection, id, Aggregate.VERSION_NOT_CREATED, projection.empty(), ImmutableList.of()); }
/** * Creates a new immutable aggregate from the given projection, initialized with the empty * value as defined by the projection, no events, and a "not created" version. * * @param projection The projection used to apply events to the state of the aggregate. * @param id The id of the aggregate. * @return A new immutable aggregate with empty state and "not created" version. */ public static <TState, TEvent> DefaultImmutableAggregate<TState, TEvent> createNew( final AggregateProjection<TState, TEvent> projection, final String id) { return new DefaultImmutableAggregate<>( projection, id, Aggregate.VERSION_NOT_CREATED, projection.empty(), ImmutableList.of()); }
/** * Creates a new mutable aggregate from the given projection, initialized with the empty * value as defined by the projection, no events, and a "not created" version. * * @param projection The projection used to apply events to the state of the aggregate. * @param id The id of the aggregate. * @return A new mutable aggregate with empty state and "not created" version. */ public static <TState, TEvent> DefaultMutableAggregate<TState, TEvent> createNew( final AggregateProjection<TState, TEvent> projection, final String id) { return new DefaultMutableAggregate<>( projection, id, Aggregate.VERSION_NOT_CREATED, projection.empty(), ImmutableList.of()); }
/** * Creates a new mutable aggregate from the given projection, initialized with the empty * value as defined by the projection, no events, and a "not created" version. * * @param projection The projection used to apply events to the state of the aggregate. * @param id The id of the aggregate. * @return A new mutable aggregate with empty state and "not created" version. */ public static <TState, TEvent> DefaultMutableAggregate<TState, TEvent> createNew( final AggregateProjection<TState, TEvent> projection, final String id) { return new DefaultMutableAggregate<>( projection, id, Aggregate.VERSION_NOT_CREATED, projection.empty(), ImmutableList.of()); }
@Before @SuppressWarnings("unchecked") public void setUpRepository() { eventRepository = mock(EventRepository.class); aggregateProjection = mock(AggregateProjection.class); when(aggregateProjection.empty()).thenReturn(new TestState("empty")); repository = new DefaultAggregateRepository<>(eventRepository, aggregateProjection); }
@Override public ImmutableAggregate<TState, TEvent> load(final String aggregateId) { TState state = projection.empty(); int currentStreamPosition = 0; try {
@Override public ImmutableAggregate<TState, TEvent> load(final String aggregateId) { TState state = projection.empty(); int currentStreamPosition = 0; try {
ArgumentCaptor<Iterable<TestEvent>> passedEvents = ArgumentCaptor.forClass((Class) Iterable.class); verify(aggregateProjection).empty(); verify(aggregateProjection).apply( eq(AGGREGATE_ID_1),
verify(aggregateProjection).empty(); verify(aggregateProjection, times(2)).apply(any(), any(), (Iterable) any()); verify(eventRepository).read(eq(AGGREGATE_ID_1), eq(0), anyInt());
ExpectedVersion.any()); AggregateProjection projection = mock(AggregateProjection.class); when(projection.empty()).thenReturn(new TestState(null)); DefaultImmutableAggregate sourceAggregate = DefaultImmutableAggregate.createNew(projection, AGGREGATE_ID);