Search in sources :

Example 21 with ModuleAssembly

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

the class ObjectBuilderFactoryTest method givenManyConstructorsWhenInstantiateThenChooseCorrectConstructor.

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

        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.objects(ManyConstructorObject.class);
        }
    };
    ManyConstructorObject object = assembler.module().newObject(ManyConstructorObject.class);
    Assert.assertThat("ref is not null", object.anyObject, notNullValue());
    object = assembler.module().newObject(ManyConstructorObject.class, new AnyObject());
    Assert.assertThat("ref is not null", object.anyObject, notNullValue());
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) Test(org.junit.Test)

Example 22 with ModuleAssembly

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

the class ObjectBuilderFactoryTest method newObjectInstanceForNullType.

/**
     * Tests that an object builder cannot be created for a 'null' type.
     *
     * @throws Exception expected
     */
@Test(expected = NullArgumentException.class)
public void newObjectInstanceForNullType() throws Exception {
    SingletonAssembler assembler = new SingletonAssembler() {

        public void assemble(ModuleAssembly module) throws AssemblyException {
        }
    };
    assembler.module().newObject(null);
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) Test(org.junit.Test)

Example 23 with ModuleAssembly

use of org.qi4j.bootstrap.ModuleAssembly 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 24 with ModuleAssembly

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

the class MixinVisibilityTest method testMultipleMixinsInLayerWillFailDiffModule.

@Test(expected = AmbiguousTypeException.class)
public void testMultipleMixinsInLayerWillFailDiffModule() 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.objects(ObjectA.class);
        }
    } }, { // Module 2
    new Assembler() {

        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.setName("Module B");
            module.transients(B1Composite.class).visibleIn(Visibility.layer);
        }
    } }, { // Module 3
    new Assembler() {

        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.setName("Module C");
            module.transients(B2Composite.class).visibleIn(Visibility.layer);
        }
    } } } };
    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 25 with ModuleAssembly

use of org.qi4j.bootstrap.ModuleAssembly 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)

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