Search in sources :

Example 16 with SingletonAssembler

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

the class ObjectConcernTest method testConcernOnObject.

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

        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.objects(TestObject.class);
        }
    };
    TestObject object = assembler.module().newObject(TestObject.class);
    object.doStuff();
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) Test(org.junit.Test)

Example 17 with SingletonAssembler

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

the class ServiceSelectorImporterTest method givenManyServicesAndSelectFirstWhenInjectServiceThenDontGetSelf.

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

        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.objects(ServiceConsumer.class);
            module.importedServices(TestService.class).importedBy(SERVICE_SELECTOR).setMetaInfo(ServiceQualifier.withId("TestServiceComposite2_1"));
            ModuleAssembly module2 = module.layer().module("Other module");
            module2.addServices(TestServiceComposite2.class, TestServiceComposite2.class).visibleIn(Visibility.layer);
        }
    };
    TestService service = assembler.module().newObject(ServiceConsumer.class).getService();
    assertThat("service is specified one", service.test(), equalTo("mixin2"));
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) Test(org.junit.Test)

Example 18 with SingletonAssembler

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

the class ServiceSelectorImporterTest method givenManyServicesWhenInjectServiceThenGetFirstOne.

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

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

Example 19 with SingletonAssembler

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

the class TypeToCompositeLookupTest method values.

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

        @Override
        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.values(SomeOtherFoo.class);
        }
    }.module();
    assertEquals(CATHEDRAL, module.newValueBuilder(SomeOtherFoo.class).newInstance().bar());
    assertEquals(CATHEDRAL, module.newValueBuilder(BasicFoo.class).newInstance().bar());
    assertEquals(CATHEDRAL, module.newValueBuilder(Foo.class).newInstance().bar());
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) AssemblyException(org.qi4j.bootstrap.AssemblyException) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) Module(org.qi4j.api.structure.Module) Test(org.junit.Test)

Example 20 with SingletonAssembler

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

the class TypeToCompositeLookupTest method objects.

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

        @Override
        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.objects(SomeOtherFooImpl.class);
        }
    }.module();
    assertEquals(CATHEDRAL, module.newObject(SomeOtherFooImpl.class).bar());
    assertEquals(CATHEDRAL, module.newObject(BasicFooImpl.class).bar());
    assertEquals(CATHEDRAL, module.newObject(Foo.class).bar());
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) AssemblyException(org.qi4j.bootstrap.AssemblyException) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) 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