@Test @SuppressWarnings({"unchecked"}) void testCreateSnapshot_AggregateMarkedDeletedWillNotGenerateSnapshot() { String aggregateIdentifier = UUID.randomUUID().toString(); DomainEventMessage firstEvent = new GenericDomainEventMessage<>("type", aggregateIdentifier, (long) 0, "Mock contents", MetaData.emptyInstance()); DomainEventMessage secondEvent = new GenericDomainEventMessage<>("type", aggregateIdentifier, (long) 0, "deleted", MetaData.emptyInstance()); DomainEventStream eventStream = DomainEventStream.of(firstEvent, secondEvent); StubAggregate aggregate = new StubAggregate(aggregateIdentifier); when(mockAggregateFactory.createAggregateRoot(aggregateIdentifier, firstEvent)).thenReturn(aggregate); DomainEventMessage snapshot = testSubject.createSnapshot(StubAggregate.class, aggregateIdentifier, eventStream); verify(mockAggregateFactory).createAggregateRoot(aggregateIdentifier, firstEvent); assertNull(snapshot, "Snapshotter shouldn't have created snapshot of deleted aggregate"); }
@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();  }