@Test @SuppressWarnings({"unchecked"}) void testCreateSnapshot_FirstEventLoadedIsSnapshotEvent() { UUID aggregateIdentifier = UUID.randomUUID(); StubAggregate aggregate = new StubAggregate(aggregateIdentifier); DomainEventMessage<StubAggregate> first = new GenericDomainEventMessage<>("type", aggregate.getIdentifier(), 0, aggregate); DomainEventMessage second = new GenericDomainEventMessage<>( "type", aggregateIdentifier.toString(), 0, "Mock contents", MetaData.emptyInstance()); DomainEventStream eventStream = DomainEventStream.of(first, second); when(mockAggregateFactory.createAggregateRoot(any(), any(DomainEventMessage.class))) .thenAnswer(invocation -> ((DomainEventMessage) invocation.getArguments()[1]).getPayload()); DomainEventMessage snapshot = testSubject.createSnapshot(StubAggregate.class, aggregateIdentifier.toString(), eventStream); assertSame(aggregate, snapshot.getPayload(), "Snapshotter did not recognize the aggregate snapshot"); verify(mockAggregateFactory).createAggregateRoot(any(), any(DomainEventMessage.class)); }
@SuppressWarnings("unchecked") @Override protected DomainEventMessage createSnapshot(Class<?> aggregateType, String aggregateIdentifier, DomainEventStream eventStream) { DomainEventMessage firstEvent = eventStream.peek(); AggregateFactory<?> aggregateFactory = getAggregateFactory(aggregateType); if (aggregateFactory == null) { throw new IllegalArgumentException( "Aggregate Type is unknown in this snapshotter: " + aggregateType.getName() ); } aggregateModels.computeIfAbsent(aggregateType, k -> AnnotatedAggregateMetaModelFactory .inspectAggregate(k, parameterResolverFactory, handlerDefinition)); Object aggregateRoot = aggregateFactory.createAggregateRoot(aggregateIdentifier, firstEvent); SnapshotAggregate<Object> aggregate = new SnapshotAggregate(aggregateRoot, aggregateModels.get(aggregateType), repositoryProvider); aggregate.initializeState(eventStream); if (aggregate.isDeleted()) { return null; } return new GenericDomainEventMessage<>(aggregate.type(), aggregate.identifierAsString(), aggregate.version(), aggregate.getAggregateRoot()); }
AggregateSnapshotter extends AbstractSnapshotter { @SuppressWarnings("unchecked") @Override protected DomainEventMessage createSnapshot(Class<?> aggregateType, String aggregateIdentifier, DomainEventStream eventStream) { DomainEventMessage firstEvent = eventStream.peek(); AggregateFactory<?> aggregateFactory = getAggregateFactory(aggregateType); if (aggregateFactory == null) { throw new IllegalArgumentException( "Aggregate Type is unknown in this snapshotter: " + aggregateType.getName() ); } aggregateModels.computeIfAbsent(aggregateType, k -> AnnotatedAggregateMetaModelFactory .inspectAggregate(k, parameterResolverFactory, handlerDefinition)); Object aggregateRoot = aggregateFactory.createAggregateRoot(aggregateIdentifier, firstEvent); SnapshotAggregate<Object> aggregate = new SnapshotAggregate(aggregateRoot, aggregateModels.get(aggregateType), repositoryProvider); aggregate.initializeState(eventStream); if (aggregate.isDeleted()) { return null; } return new GenericDomainEventMessage<>(aggregate.type(), aggregate.identifierAsString(), aggregate.version(), aggregate.getAggregateRoot()); } }
AggregateSnapshotter extends AbstractSnapshotter { @SuppressWarnings("unchecked") @Override protected DomainEventMessage createSnapshot(Class<?> aggregateType, String aggregateIdentifier, DomainEventStream eventStream) { DomainEventMessage firstEvent = eventStream.peek(); AggregateFactory<?> aggregateFactory = getAggregateFactory(aggregateType); if (aggregateFactory == null) { throw new IllegalArgumentException( "Aggregate Type is unknown in this snapshotter: " + aggregateType.getName() ); } aggregateModels.computeIfAbsent(aggregateType, k -> AnnotatedAggregateMetaModelFactory .inspectAggregate(k, parameterResolverFactory, handlerDefinition)); Object aggregateRoot = aggregateFactory.createAggregateRoot(aggregateIdentifier, firstEvent); SnapshotAggregate<Object> aggregate = new SnapshotAggregate(aggregateRoot, aggregateModels.get(aggregateType), repositoryProvider); aggregate.initializeState(eventStream); if (aggregate.isDeleted()) { return null; } return new GenericDomainEventMessage<>(aggregate.type(), aggregate.identifierAsString(), aggregate.version(), aggregate.getAggregateRoot()); } protected  AggregateSnapshotter(Builder builder); }
AggregateSnapshotter extends AbstractSnapshotter { @SuppressWarnings("unchecked") @Override protected DomainEventMessage createSnapshot(Class<?> aggregateType, String aggregateIdentifier, DomainEventStream eventStream) { DomainEventMessage firstEvent = eventStream.peek(); AggregateFactory<?> aggregateFactory = getAggregateFactory(aggregateType); if (aggregateFactory == null) { throw new IllegalArgumentException( "Aggregate Type is unknown in this snapshotter: " + aggregateType.getName() ); } aggregateModels.computeIfAbsent(aggregateType, k -> AnnotatedAggregateMetaModelFactory .inspectAggregate(k, parameterResolverFactory, handlerDefinition)); Object aggregateRoot = aggregateFactory.createAggregateRoot(aggregateIdentifier, firstEvent); SnapshotAggregate<Object> aggregate = new SnapshotAggregate(aggregateRoot, aggregateModels.get(aggregateType), repositoryProvider); aggregate.initializeState(eventStream); if (aggregate.isDeleted()) { return null; } return new GenericDomainEventMessage<>(aggregate.type(), aggregate.identifierAsString(), aggregate.version(), aggregate.getAggregateRoot()); } protected  AggregateSnapshotter(Builder builder); static Builder builder(); }
AggregateSnapshotter extends AbstractSnapshotter { @SuppressWarnings("unchecked") @Override protected DomainEventMessage createSnapshot(Class<?> aggregateType, String aggregateIdentifier, DomainEventStream eventStream) { DomainEventMessage firstEvent = eventStream.peek(); AggregateFactory<?> aggregateFactory = getAggregateFactory(aggregateType); if (aggregateFactory == null) { throw new IllegalArgumentException( "Aggregate Type is unknown in this snapshotter: " + aggregateType.getName() ); } aggregateModels.computeIfAbsent(aggregateType, k -> AnnotatedAggregateMetaModelFactory .inspectAggregate(k, parameterResolverFactory, handlerDefinition)); Object aggregateRoot = aggregateFactory.createAggregateRoot(aggregateIdentifier, firstEvent); SnapshotAggregate<Object> aggregate = new SnapshotAggregate(aggregateRoot, aggregateModels.get(aggregateType), repositoryProvider); aggregate.initializeState(eventStream); if (aggregate.isDeleted()) { return null; } return new GenericDomainEventMessage<>(aggregate.type(), aggregate.identifierAsString(), aggregate.version(), aggregate.getAggregateRoot()); } protected  AggregateSnapshotter(Builder builder); static Builder builder();  }