package org.qi4j.library.eventsourcing.domain.source.helper; import org.junit.Before; import org.junit.Test; import org.qi4j.api.activation.ActivationException; import org.qi4j.api.value.ValueBuilder; import org.qi4j.bootstrap.AssemblyException; import org.qi4j.bootstrap.ModuleAssembly; import org.qi4j.bootstrap.SingletonAssembler; import org.qi4j.library.eventsourcing.domain.api.DomainEventValue; import org.qi4j.library.eventsourcing.domain.api.UnitOfWorkDomainEventsValue; import java.util.ArrayList; import java.util.List; import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertThat; import static org.qi4j.functional.Iterables.count; import static org.qi4j.io.Inputs.iterable; import static org.qi4j.io.Outputs.systemOut; import static org.qi4j.library.eventsourcing.domain.source.helper.Events.events; /** * TODO */ public class EventsTest { private List<UnitOfWorkDomainEventsValue> list; @Before public void testData() throws ActivationException, AssemblyException { SingletonAssembler assembler = new SingletonAssembler() { @Override public void assemble( ModuleAssembly module ) throws AssemblyException { module.values( UnitOfWorkDomainEventsValue.class, DomainEventValue.class ); } }; list = new ArrayList<UnitOfWorkDomainEventsValue>( ); { ValueBuilder<UnitOfWorkDomainEventsValue> builder = assembler.module().newValueBuilder( UnitOfWorkDomainEventsValue.class ); builder.prototype().events().get().add( newDomainEvent( assembler, "Test1" ) ); builder.prototype().events().get().add( newDomainEvent( assembler, "Test2" ) ); builder.prototype().events().get().add( newDomainEvent( assembler, "Test3" ) ); builder.prototype().version().set( "1.0" ); builder.prototype().timestamp().set( System.currentTimeMillis() ); builder.prototype().usecase().set( "Test" ); list.add( builder.newInstance() ); } { ValueBuilder<UnitOfWorkDomainEventsValue> builder = assembler.module().newValueBuilder( UnitOfWorkDomainEventsValue.class ); builder.prototype().events().get().add( newDomainEvent( assembler, "Test4" ) ); builder.prototype().events().get().add( newDomainEvent( assembler, "Test5" ) ); builder.prototype().events().get().add( newDomainEvent( assembler, "Test6" ) ); builder.prototype().version().set( "1.0" ); builder.prototype().timestamp().set( System.currentTimeMillis() ); builder.prototype().usecase().set( "Test2" ); list.add( builder.newInstance() ); } } private DomainEventValue newDomainEvent( SingletonAssembler assembler, String name ) { ValueBuilder<DomainEventValue> eventBuilder = assembler.module().newValueBuilder( DomainEventValue.class ); eventBuilder.prototype().entityId().set( "123" ); eventBuilder.prototype().entityType().set( "Foo" ); eventBuilder.prototype().parameters().set( "{}" ); eventBuilder.prototype().name().set( name ); return eventBuilder.newInstance(); } @Test public void testIterablesEvents() { assertThat( count( events( list ) ), equalTo( 6L ) ); iterable( events( list ) ).transferTo( systemOut() ); } }