use of org.qi4j.library.eventsourcing.domain.source.EventSource in project qi4j-sdk by Qi4j.
the class JdbmEventStoreServiceTest method testDomainEvent.
@Test
public void testDomainEvent() throws UnitOfWorkCompletionException, IOException {
UnitOfWork uow = module.newUnitOfWork(UsecaseBuilder.newUsecase("Create entity"));
TestEntity entity = uow.newEntity(TestEntity.class);
uow.complete();
int count = 10;
for (int i = 0; i < count; i++) {
uow = module.newUnitOfWork(UsecaseBuilder.newUsecase("Change description"));
uow.setMetaInfo(new Principal() {
public String getName() {
return "administrator";
}
});
entity = uow.get(entity);
entity.changeDescription("New description");
uow.complete();
}
EventSource source = (EventSource) module.findService(EventSource.class).get();
source.events(0, Long.MAX_VALUE).transferTo(Transforms.map(new Function<UnitOfWorkDomainEventsValue, String>() {
public String map(UnitOfWorkDomainEventsValue unitOfWorkDomainEventsValue) {
return unitOfWorkDomainEventsValue.toString();
}
}, Outputs.systemOut()));
}
use of org.qi4j.library.eventsourcing.domain.source.EventSource in project qi4j-sdk by Qi4j.
the class DomainEventTest method testDomainEvent.
@Test
public void testDomainEvent() throws UnitOfWorkCompletionException, IOException {
// Set principal for the UoW
Principal administratorPrincipal = new Principal() {
public String getName() {
return "administrator";
}
};
// Perform UoW with usecase defined
UnitOfWork uow = module.newUnitOfWork(UsecaseBuilder.newUsecase("Change description"));
uow.setMetaInfo(administratorPrincipal);
TestEntity entity = uow.newEntity(TestEntity.class);
entity.changedDescription("New description");
uow.complete();
// Print events
EventSource source = (EventSource) module.findService(EventSource.class).get();
source.events(0, Long.MAX_VALUE).transferTo(Transforms.map(new Function<UnitOfWorkDomainEventsValue, String>() {
public String map(UnitOfWorkDomainEventsValue unitOfWorkDomainEventsValue) {
return unitOfWorkDomainEventsValue.toString();
}
}, Outputs.systemOut()));
}
Aggregations