@Override public void apply(@NotNull final Iterable<? extends TEvent> events) { Preconditions.checkNotNull(events); state = projection.apply(id, state, events); events.forEach(appliedEvents::add); }
/** * 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()); }
repositoryResult1, repositoryResult2); when(aggregateProjection.apply(any(), any(), (Iterable) any())).thenReturn(expectedState); verify(aggregateProjection).empty(); verify(aggregateProjection, times(2)).apply(any(), any(), (Iterable) any()); verify(eventRepository).read(eq(AGGREGATE_ID_1), eq(0), anyInt()); verify(eventRepository).read(eq(AGGREGATE_ID_1), eq(2), anyInt());
@Override public void apply(@NotNull final TEvent event) { Preconditions.checkNotNull(event); state = projection.apply(id, state, event); appliedEvents.add(event); }
/** * 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()); }
when(aggregateProjection.apply(any(), any(), (Iterable) any())).thenReturn(expectedState); ArgumentCaptor<Iterable<TestEvent>> passedEvents = ArgumentCaptor.forClass((Class) Iterable.class); verify(aggregateProjection).empty(); verify(aggregateProjection).apply( eq(AGGREGATE_ID_1), eq(new TestState("empty")),
@Override public void apply(@NotNull final Iterable<? extends TEvent> events) { Preconditions.checkNotNull(events); state = projection.apply(id, state, events); events.forEach(appliedEvents::add); }
/** * 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()); }
@Override public void apply(@NotNull final TEvent event) { Preconditions.checkNotNull(event); state = projection.apply(id, state, event); appliedEvents.add(event); }
/** * 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()); }
@NotNull @Override public ImmutableAggregate<TState, TEvent> apply(@NotNull final TEvent event) { Preconditions.checkNotNull(event); @NotNull TState newState = projection.apply(id, state, event); return new DefaultImmutableAggregate<>( projection, id, sourceVersion, newState, ImmutableList.<TEvent>builder().addAll(appliedEvents).add(event).build()); }
@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); }
@NotNull @Override public ImmutableAggregate<TState, TEvent> apply( @NotNull final Iterable<? extends TEvent> events) { Preconditions.checkNotNull(events); @NotNull TState newState = projection.apply(id, state, events); return new DefaultImmutableAggregate<>( projection, id, sourceVersion, newState, ImmutableList.<TEvent>builder().addAll(appliedEvents).addAll(events).build()); }
ExpectedVersion.any()); AggregateProjection projection = mock(AggregateProjection.class); when(projection.empty()).thenReturn(new TestState(null)); DefaultImmutableAggregate sourceAggregate = DefaultImmutableAggregate.createNew(projection, AGGREGATE_ID);
@NotNull @Override public ImmutableAggregate<TState, TEvent> apply(@NotNull final TEvent event) { Preconditions.checkNotNull(event); @NotNull TState newState = projection.apply(id, state, event); return new DefaultImmutableAggregate<>( projection, id, sourceVersion, newState, ImmutableList.<TEvent>builder().addAll(appliedEvents).add(event).build()); }
@NotNull @Override public ImmutableAggregate<TState, TEvent> apply( @NotNull final Iterable<? extends TEvent> events) { Preconditions.checkNotNull(events); @NotNull TState newState = projection.apply(id, state, events); return new DefaultImmutableAggregate<>( projection, id, sourceVersion, newState, ImmutableList.<TEvent>builder().addAll(appliedEvents).addAll(events).build()); }
TState updatedState = state; for (TEvent e : events) { updatedState = apply(id, updatedState, e);
TState updatedState = state; for (TEvent e : events) { updatedState = apply(id, updatedState, e);