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());
}
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);
}
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();
}
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());
}
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"));
}
Aggregations