Search in sources :

Example 1 with EventSource

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()));
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) Function(org.qi4j.functional.Function) EventSource(org.qi4j.library.eventsourcing.domain.source.EventSource) Principal(java.security.Principal) CurrentUserUoWPrincipal(org.qi4j.library.eventsourcing.domain.factory.CurrentUserUoWPrincipal) UnitOfWorkDomainEventsValue(org.qi4j.library.eventsourcing.domain.api.UnitOfWorkDomainEventsValue) AbstractQi4jTest(org.qi4j.test.AbstractQi4jTest) Test(org.junit.Test)

Example 2 with EventSource

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()));
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) Function(org.qi4j.functional.Function) EventSource(org.qi4j.library.eventsourcing.domain.source.EventSource) Principal(java.security.Principal) CurrentUserUoWPrincipal(org.qi4j.library.eventsourcing.domain.factory.CurrentUserUoWPrincipal) UnitOfWorkDomainEventsValue(org.qi4j.library.eventsourcing.domain.api.UnitOfWorkDomainEventsValue) AbstractQi4jTest(org.qi4j.test.AbstractQi4jTest) Test(org.junit.Test)

Aggregations

Principal (java.security.Principal)2 Test (org.junit.Test)2 UnitOfWork (org.qi4j.api.unitofwork.UnitOfWork)2 Function (org.qi4j.functional.Function)2 UnitOfWorkDomainEventsValue (org.qi4j.library.eventsourcing.domain.api.UnitOfWorkDomainEventsValue)2 CurrentUserUoWPrincipal (org.qi4j.library.eventsourcing.domain.factory.CurrentUserUoWPrincipal)2 EventSource (org.qi4j.library.eventsourcing.domain.source.EventSource)2 AbstractQi4jTest (org.qi4j.test.AbstractQi4jTest)2