use of org.qi4j.bootstrap.ModuleAssembly in project qi4j-sdk by Qi4j.
the class ImportedServiceActivationTest method testServiceImporterImportedServiceActivators.
@Test
public void testServiceImporterImportedServiceActivators() throws Exception {
SingletonAssembler assembler = new SingletonAssembler() {
public void assemble(ModuleAssembly module) throws AssemblyException {
module.importedServices(TestedService.class).importedBy(ImportedServiceDeclaration.SERVICE_IMPORTER).setMetaInfo("testimporter").withActivators(TestedActivator.class).importOnStartup();
module.services(TestedServiceImporterService.class).identifiedBy("testimporter");
}
};
Application application = assembler.application();
assertEquals("Activation Level", 2, activationLevel);
application.passivate();
assertEquals("Passivation Level", 2, passivationLevel);
}
use of org.qi4j.bootstrap.ModuleAssembly in project qi4j-sdk by Qi4j.
the class InvocationInjectionTest method whenInvocationInjectionWithMethodWhenInjectedThenInjectMethod.
@Test
public void whenInvocationInjectionWithMethodWhenInjectedThenInjectMethod() throws Exception {
SingletonAssembler assembly = new SingletonAssembler() {
public void assemble(ModuleAssembly module) throws AssemblyException {
module.transients(MyComposite.class);
}
};
MyComposite composite = assembly.module().newTransient(MyComposite.class);
composite.doStuff();
composite.doStuff();
composite.doStuff2();
composite.doStuff3();
}
use of org.qi4j.bootstrap.ModuleAssembly in project qi4j-sdk by Qi4j.
the class ServiceInjectionTest method testInjectService.
@Test
public void testInjectService() throws Exception {
SingletonAssembler assembly = new SingletonAssembler() {
public void assemble(ModuleAssembly module) throws AssemblyException {
module.services(MyServiceComposite.class).identifiedBy("Foo").setMetaInfo(new ServiceName("Foo"));
module.services(MyServiceComposite2.class).identifiedBy("Bar").setMetaInfo(new ServiceName("Bar"));
module.services(StringService.class, LongService.class);
module.objects(ServiceUser.class);
}
};
testInjection(assembly);
}
use of org.qi4j.bootstrap.ModuleAssembly in project qi4j-sdk by Qi4j.
the class MixinVisibilityTest method testMixinInLowerLayerIsVisible.
@Test
public void testMixinInLowerLayerIsVisible() throws Exception {
Energy4Java boot = new Energy4Java();
Assembler[][][] assemblers = new Assembler[][][] { { // Layer 1
{ new Assembler() {
public void assemble(ModuleAssembly module) throws AssemblyException {
module.setName("Module A");
module.objects(ObjectA.class);
}
} } }, { // Layer 2
{ new Assembler() {
public void assemble(ModuleAssembly module) throws AssemblyException {
module.setName("Module B");
module.transients(B1Composite.class).visibleIn(Visibility.application);
}
} } } };
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 MixinVisibilityTest method testMultipleMixinsInLayerWillFailSameModule.
@Test(expected = AmbiguousTypeException.class)
public void testMultipleMixinsInLayerWillFailSameModule() throws Exception {
Energy4Java boot = new Energy4Java();
Assembler[][][] assemblers = new Assembler[][][] { { // Layer
{ new Assembler() {
public void assemble(ModuleAssembly module) throws AssemblyException {
module.setName("Module A");
module.objects(ObjectA.class);
}
} }, { new Assembler() {
public void assemble(ModuleAssembly module) throws AssemblyException {
module.setName("Module B");
module.transients(B1Composite.class, 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());
}
Aggregations