Search in sources :

Example 56 with SingletonAssembler

use of org.qi4j.bootstrap.SingletonAssembler in project qi4j-sdk by Qi4j.

the class PassivationTest method givenSuccessPassivationWhenPassivatingExpectNoExceptions.

@Test
public void givenSuccessPassivationWhenPassivatingExpectNoExceptions() throws Throwable {
    SingletonAssembler assembly = new SingletonAssembler() {

        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.addServices(DataAccessService.class).withActivators(PassivationSuccessActivator.class);
            module.addServices(DataAccessService.class).withActivators(PassivationSuccessActivator.class);
        }
    };
    Iterable<ServiceReference<DataAccess>> iterable = assembly.module().findServices(DataAccess.class);
    for (ServiceReference<DataAccess> service : iterable) {
        assertTrue("Service should not be Active before accessed", !service.isActive());
        assertTrue(service.get().data().activated);
        assertTrue("Service should be Active after access.", service.isActive());
    }
    assembly.application().passivate();
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) ServiceReference(org.qi4j.api.service.ServiceReference) Test(org.junit.Test)

Example 57 with SingletonAssembler

use of org.qi4j.bootstrap.SingletonAssembler in project qi4j-sdk by Qi4j.

the class ServiceIdSelectorTest method givenManyServicesWhenInjectServiceThenGetSelectedOne.

@Test
public void givenManyServicesWhenInjectServiceThenGetSelectedOne() throws ActivationException, AssemblyException {
    SingletonAssembler assembler = new SingletonAssembler() {

        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.objects(ServiceConsumer.class);
            module.services(TestServiceComposite1.class, TestServiceComposite2.class);
        }
    };
    ObjectFactory obf = assembler.module();
    ServiceConsumer consumer = obf.newObject(ServiceConsumer.class, TestServiceComposite2.class.getSimpleName());
    TestService service = consumer.getService();
    assertThat("service is selected one", service.test(), equalTo("mixin2"));
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) ObjectFactory(org.qi4j.api.object.ObjectFactory) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) Test(org.junit.Test)

Example 58 with SingletonAssembler

use of org.qi4j.bootstrap.SingletonAssembler in project qi4j-sdk by Qi4j.

the class IterableQuerySourceTest method setUp.

@Before
public void setUp() throws UnitOfWorkCompletionException, ActivationException, AssemblyException {
    SingletonAssembler assembler = new SingletonAssembler() {

        public void assemble(ModuleAssembly module) throws AssemblyException {
            Iterable<Class<?>> entities = ClassScanner.findClasses(DomainEntity.class);
            for (Class entity : entities) {
                module.entities(entity);
            }
            module.values(ContactsValue.class, ContactValue.class);
            new EntityTestAssembler().assemble(module);
        }
    };
    uow = assembler.module().newUnitOfWork();
    Network.populate(uow, assembler.module());
    uow.complete();
    uow = assembler.module().newUnitOfWork();
    Network.refresh(uow);
    qbf = assembler.module();
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) EntityTestAssembler(org.qi4j.test.EntityTestAssembler) Before(org.junit.Before)

Example 59 with SingletonAssembler

use of org.qi4j.bootstrap.SingletonAssembler in project qi4j-sdk by Qi4j.

the class ValueComposite2Test method testServiceAndStructureInjectionsAllowedInValueComposite.

@Test
public void testServiceAndStructureInjectionsAllowedInValueComposite() throws ActivationException, AssemblyException {
    SingletonAssembler app = new SingletonAssembler() {

        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.values(SomeValue.class);
            module.services(DummyService.class);
        }
    };
    ValueBuilder<Some> builder = app.module().newValueBuilder(Some.class);
    Some prototype = builder.prototype();
    Property<String> otherProperty = prototype.other();
    otherProperty.set("Abc");
    Some value = builder.newInstance();
    Assert.assertEquals(value.other().get(), "Abc");
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) Test(org.junit.Test)

Example 60 with SingletonAssembler

use of org.qi4j.bootstrap.SingletonAssembler in project qi4j-sdk by Qi4j.

the class TypeToCompositeLookupTest method entities.

@Test
public void entities() throws UnitOfWorkCompletionException, ActivationException, AssemblyException {
    Module module = new SingletonAssembler() {

        @Override
        public void assemble(ModuleAssembly module) throws AssemblyException {
            new EntityTestAssembler().assemble(module);
            module.entities(SomeOtherFoo.class);
        }
    }.module();
    UnitOfWork uow = module.newUnitOfWork();
    SomeOtherFoo someOtherFoo = uow.newEntityBuilder(SomeOtherFoo.class).newInstance();
    BasicFoo basicFoo = uow.newEntityBuilder(BasicFoo.class).newInstance();
    Foo foo = uow.newEntityBuilder(Foo.class).newInstance();
    assertEquals(CATHEDRAL, someOtherFoo.bar());
    assertEquals(CATHEDRAL, basicFoo.bar());
    assertEquals(CATHEDRAL, foo.bar());
    String someOtherFooIdentity = ((Identity) someOtherFoo).identity().get();
    String basicFooIdentity = ((Identity) basicFoo).identity().get();
    String fooIdentity = ((Identity) foo).identity().get();
    uow.complete();
    uow = module.newUnitOfWork();
    uow.get(SomeOtherFoo.class, someOtherFooIdentity);
    uow.get(BasicFoo.class, basicFooIdentity);
    uow.get(Foo.class, fooIdentity);
    uow.discard();
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) AssemblyException(org.qi4j.bootstrap.AssemblyException) UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) EntityTestAssembler(org.qi4j.test.EntityTestAssembler) Module(org.qi4j.api.structure.Module) Test(org.junit.Test)

Aggregations

ModuleAssembly (org.qi4j.bootstrap.ModuleAssembly)87 SingletonAssembler (org.qi4j.bootstrap.SingletonAssembler)87 Test (org.junit.Test)65 Module (org.qi4j.api.structure.Module)15 AssemblyException (org.qi4j.bootstrap.AssemblyException)14 EntityTestAssembler (org.qi4j.test.EntityTestAssembler)13 Before (org.junit.Before)11 Application (org.qi4j.api.structure.Application)10 UnitOfWork (org.qi4j.api.unitofwork.UnitOfWork)5 AmbiguousTypeException (org.qi4j.api.composite.AmbiguousTypeException)4 ServiceReference (org.qi4j.api.service.ServiceReference)4 ArrayList (java.util.ArrayList)3 TransientBuilderFactory (org.qi4j.api.composite.TransientBuilderFactory)3 ObjectFactory (org.qi4j.api.object.ObjectFactory)3 ValueBuilder (org.qi4j.api.value.ValueBuilder)3 UnitOfWorkDomainEventsValue (org.qi4j.library.eventsourcing.domain.api.UnitOfWorkDomainEventsValue)3 File (java.io.File)2 BeforeClass (org.junit.BeforeClass)2 Ignore (org.junit.Ignore)2 ServiceDeclaration (org.qi4j.bootstrap.ServiceDeclaration)2