Search in sources :

Example 11 with ModuleAssembly

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

the class MixinVisibilityTest method testMixinInModuleIsVisible.

@Test
public void testMixinInModuleIsVisible() throws Exception {
    Energy4Java boot = new Energy4Java();
    Assembler[][][] assemblers = new Assembler[][][] { { // Layer
    { // Module 1
    new Assembler() {

        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.setName("Module A");
            module.transients(B1Composite.class);
            module.objects(ObjectA.class);
        }
    } } } };
    Application app = boot.newApplication(new ApplicationAssemblerAdapter(assemblers) {
    });
    app.activate();
    ObjectA object = app.findModule("Layer 1", "Module A").newObject(ObjectA.class);
    assertEquals("ok", object.test1());
    assertEquals("abc", object.test2());
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) Energy4Java(org.qi4j.bootstrap.Energy4Java) Assembler(org.qi4j.bootstrap.Assembler) Application(org.qi4j.api.structure.Application) ApplicationAssemblerAdapter(org.qi4j.bootstrap.ApplicationAssemblerAdapter) Test(org.junit.Test)

Example 12 with ModuleAssembly

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

the class StructureTest method createApplicationUsingApplicationAssembly.

@Test
public void createApplicationUsingApplicationAssembly() throws AssemblyException {
    Energy4Java boot = new Energy4Java();
    boot.newApplication(new ApplicationAssembler() {

        public ApplicationAssembly assemble(ApplicationAssemblyFactory applicationFactory) throws AssemblyException {
            ApplicationAssembly applicationAssembly = applicationFactory.newApplicationAssembly();
            // Application Layer
            LayerAssembly applicationLayer = applicationAssembly.layer("Application");
            ModuleAssembly applicationModule = applicationLayer.module("Application");
            new DomainApplicationAssembler().assemble(applicationModule);
            // View Layer
            LayerAssembly viewLayer = applicationAssembly.layer("View");
            ModuleAssembly viewModule = viewLayer.module("View");
            new ViewAssembler().assemble(viewModule);
            viewLayer.uses(applicationLayer);
            return applicationAssembly;
        }
    });
}
Also used : ApplicationAssemblyFactory(org.qi4j.bootstrap.ApplicationAssemblyFactory) AssemblyException(org.qi4j.bootstrap.AssemblyException) ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) ApplicationAssembler(org.qi4j.bootstrap.ApplicationAssembler) ApplicationAssembly(org.qi4j.bootstrap.ApplicationAssembly) Energy4Java(org.qi4j.bootstrap.Energy4Java) LayerAssembly(org.qi4j.bootstrap.LayerAssembly) Test(org.junit.Test)

Example 13 with ModuleAssembly

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

the class TypeToCompositeLookupTest method objectsAmbiguousDeclaration.

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

        @Override
        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.objects(SomeOtherFooImpl.class, BasicFooImpl.class);
        }
    }.module();
    assertEquals(CATHEDRAL, module.newObject(SomeOtherFooImpl.class).bar());
    assertEquals(BAZAR, module.newObject(BasicFooImpl.class).bar());
    try {
        module.newObject(Foo.class);
        fail("Ambiguous type exception not detected for Objects");
    } catch (AmbiguousTypeException expected) {
    }
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) AssemblyException(org.qi4j.bootstrap.AssemblyException) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) Module(org.qi4j.api.structure.Module) AmbiguousTypeException(org.qi4j.api.composite.AmbiguousTypeException) Test(org.junit.Test)

Example 14 with ModuleAssembly

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

the class TypeToCompositeLookupTest method transientsAmbiguousDeclaration.

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

        @Override
        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.transients(SomeOtherFoo.class, BasicFoo.class);
        }
    }.module();
    assertEquals(CATHEDRAL, module.newTransientBuilder(SomeOtherFoo.class).newInstance().bar());
    assertEquals(BAZAR, module.newTransientBuilder(BasicFoo.class).newInstance().bar());
    try {
        module.newTransientBuilder(Foo.class);
        fail("Ambiguous type exception not detected for Transients");
    } catch (AmbiguousTypeException expected) {
    }
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) AssemblyException(org.qi4j.bootstrap.AssemblyException) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) Module(org.qi4j.api.structure.Module) AmbiguousTypeException(org.qi4j.api.composite.AmbiguousTypeException) Test(org.junit.Test)

Example 15 with ModuleAssembly

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

the class AvailableServiceTest method givenEnablableServiceWhenInjectWithAvailableQualifierThenInjectCorrectly.

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

        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.objects(TestObject.class);
            module.services(TestServiceComposite2.class);
            module.entities(TestServiceConfiguration.class);
            new EntityTestAssembler().assemble(module);
        }
    };
    TestObject object = assembler.module().newObject(TestObject.class);
    assertThat("service is unavailable", object.getService(), nullValue());
    ServiceReference<TestServiceComposite2> serviceRef = assembler.module().findService(TestServiceComposite2.class);
    serviceRef.get().get().enabled().set(true);
    serviceRef.get().save();
    object = assembler.module().newObject(TestObject.class);
    assertThat("service is available", object.getService(), notNullValue());
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) EntityTestAssembler(org.qi4j.test.EntityTestAssembler) Test(org.junit.Test)

Aggregations

ModuleAssembly (org.qi4j.bootstrap.ModuleAssembly)191 SingletonAssembler (org.qi4j.bootstrap.SingletonAssembler)87 Test (org.junit.Test)82 EntityTestAssembler (org.qi4j.test.EntityTestAssembler)59 AssemblyException (org.qi4j.bootstrap.AssemblyException)27 Application (org.qi4j.api.structure.Application)26 OrgJsonValueSerializationAssembler (org.qi4j.valueserialization.orgjson.OrgJsonValueSerializationAssembler)24 Assembler (org.qi4j.bootstrap.Assembler)23 Module (org.qi4j.api.structure.Module)19 LayerAssembly (org.qi4j.bootstrap.LayerAssembly)15 Before (org.junit.Before)12 UnitOfWork (org.qi4j.api.unitofwork.UnitOfWork)12 Energy4Java (org.qi4j.bootstrap.Energy4Java)12 DataSourceAssembler (org.qi4j.library.sql.assembly.DataSourceAssembler)11 DBCPDataSourceServiceAssembler (org.qi4j.library.sql.dbcp.DBCPDataSourceServiceAssembler)9 IOException (java.io.IOException)8 ApplicationAssemblerAdapter (org.qi4j.bootstrap.ApplicationAssemblerAdapter)8 ApplicationAssembly (org.qi4j.bootstrap.ApplicationAssembly)8 File (java.io.File)7 OrgJsonValueSerializationService (org.qi4j.valueserialization.orgjson.OrgJsonValueSerializationService)7