@Test void testAggregateCreatesSequenceNumbersForNewAggregatesWhenUsingDomainEventSequenceAwareEventBus() { DomainSequenceAwareEventBus testEventBus = new DomainSequenceAwareEventBus(); testSubject = GenericJpaRepository.builder(StubJpaAggregate.class) .entityManagerProvider(new SimpleEntityManagerProvider(mockEntityManager)) .eventBus(testEventBus) .identifierConverter(identifierConverter) .build(); DefaultUnitOfWork.startAndGet(null).executeWithResult(() -> { Aggregate<StubJpaAggregate> agg = testSubject.newInstance(() -> new StubJpaAggregate("id", "test1", "test2")); agg.execute(e -> e.doSomething("test3")); return null; }); CurrentUnitOfWork.commit(); List<EventMessage> publishedEvents = testEventBus.getPublishedEvents(); assertEquals(3, publishedEvents.size()); EventMessage eventOne = publishedEvents.get(0); assertTrue(eventOne instanceof DomainEventMessage); DomainEventMessage domainEventOne = (DomainEventMessage) eventOne; assertEquals("test1", domainEventOne.getPayload()); assertEquals(0, domainEventOne.getSequenceNumber()); assertEquals("id", domainEventOne.getAggregateIdentifier()); EventMessage eventTwo = publishedEvents.get(1); assertTrue(eventTwo instanceof DomainEventMessage); DomainEventMessage domainEventTwo = (DomainEventMessage) eventTwo; assertEquals("test2", domainEventTwo.getPayload()); assertEquals(1, domainEventTwo.getSequenceNumber()); assertEquals("id", domainEventTwo.getAggregateIdentifier()); EventMessage eventThree = publishedEvents.get(2); assertTrue(eventThree instanceof DomainEventMessage); DomainEventMessage domainEventThree = (DomainEventMessage) eventThree; assertEquals("test3", domainEventThree.getPayload()); assertEquals(2, domainEventThree.getSequenceNumber()); assertEquals("id", domainEventThree.getAggregateIdentifier()); }
public static <T> Builder<T> builder(Class<T> aggregateType) { return new Builder<>(aggregateType); }
GenericJpaRepository extends LockingRepository<T, AnnotatedAggregate<T>> { public static <T> Builder<T> builder(Class<T> aggregateType) { return new Builder<>(aggregateType); } }
GenericJpaRepository extends LockingRepository<T, AnnotatedAggregate<T>> { public static <T> Builder<T> builder(Class<T> aggregateType) { return new Builder<>(aggregateType); } protected  GenericJpaRepository(Builder<T> builder); }
GenericJpaRepository extends LockingRepository<T, AnnotatedAggregate<T>> { public static <T> Builder<T> builder(Class<T> aggregateType) { return new Builder<>(aggregateType); } protected  GenericJpaRepository(Builder<T> builder); static Builder<T> builder(Class<T> aggregateType); void setForceFlushOnSave(boolean forceFlushOnSave); }
GenericJpaRepository extends LockingRepository<T, AnnotatedAggregate<T>> { public static <T> Builder<T> builder(Class<T> aggregateType) { return new Builder<>(aggregateType); } protected  GenericJpaRepository(Builder<T> builder); static Builder<T> builder(Class<T> aggregateType); void setForceFlushOnSave(boolean forceFlushOnSave);  }