use of org.qi4j.api.structure.Application in project qi4j-sdk by Qi4j.
the class ApplicationModelFactoryImpl method newApplicationModel.
@Override
public ApplicationDescriptor newApplicationModel(ApplicationAssembly assembly) throws AssemblyException {
AssemblyHelper helper = new AssemblyHelper();
ApplicationAssemblyImpl applicationAssembly = (ApplicationAssemblyImpl) assembly;
ActivatorsModel<Application> applicationActivators = new ActivatorsModel<>(applicationAssembly.activators());
List<LayerModel> layerModels = new ArrayList<>();
final ApplicationModel applicationModel = new ApplicationModel(applicationAssembly.name(), applicationAssembly.version(), applicationAssembly.mode(), applicationAssembly.metaInfo(), applicationActivators, layerModels);
Map<LayerAssembly, LayerModel> mapAssemblyModel = new HashMap<>();
Map<LayerAssembly, List<LayerModel>> mapUsedLayers = new HashMap<>();
// Build all layers
List<LayerAssemblyImpl> layerAssemblies = new ArrayList<>(applicationAssembly.layerAssemblies());
for (LayerAssemblyImpl layerAssembly : layerAssemblies) {
List<LayerModel> usedLayers = new ArrayList<>();
mapUsedLayers.put(layerAssembly, usedLayers);
UsedLayersModel usedLayersModel = new UsedLayersModel(usedLayers);
List<ModuleModel> moduleModels = new ArrayList<>();
String name = layerAssembly.name();
if (name == null) {
throw new AssemblyException("Layer must have name set");
}
ActivatorsModel<Layer> layerActivators = new ActivatorsModel<>(layerAssembly.activators());
LayerModel layerModel = new LayerModel(name, layerAssembly.metaInfo(), usedLayersModel, layerActivators, moduleModels);
for (ModuleAssemblyImpl moduleAssembly : layerAssembly.moduleAssemblies()) {
moduleModels.add(moduleAssembly.assembleModule(helper));
}
mapAssemblyModel.put(layerAssembly, layerModel);
layerModels.add(layerModel);
}
// Populate used layer lists
for (LayerAssemblyImpl layerAssembly : layerAssemblies) {
Set<LayerAssembly> usesLayers = layerAssembly.uses();
List<LayerModel> usedLayers = mapUsedLayers.get(layerAssembly);
for (LayerAssembly usesLayer : usesLayers) {
LayerModel layerModel = mapAssemblyModel.get(usesLayer);
usedLayers.add(layerModel);
}
}
// This will resolve all dependencies
try {
// applicationModel.bind();
applicationModel.accept(new BindingVisitor(applicationModel));
} catch (BindingException e) {
throw new AssemblyException("Unable to bind: " + applicationModel, e);
}
return applicationModel;
}
use of org.qi4j.api.structure.Application in project qi4j-sdk by Qi4j.
the class PluginTest method testPlugins.
@Test
@Ignore("Must fix the TODOs below. This example relied on ability to set Service MetaInfo at runtime, it seems it's not possible anymore.")
public void testPlugins() throws Exception {
Energy4Java runtime = new Energy4Java();
Application app = runtime.newApplication(new MainApplicationAssembler());
app.activate();
}
use of org.qi4j.api.structure.Application in project qi4j-sdk by Qi4j.
the class ApplicationActivationTest method testApplicationActivator.
@Test
public void testApplicationActivator() throws Exception {
SingletonAssembler assembly = new SingletonAssembler() {
public void assemble(ModuleAssembly module) throws AssemblyException {
module.layer().application().withActivators(TestedActivator.class);
}
};
// Activate
Application application = assembly.application();
// Assert activated
Assert.assertEquals("Activation Level", 2, activationLevel);
// Passivate
application.passivate();
// Assert passivated
Assert.assertEquals("Passivation Level", 2, passivationLevel);
}
use of org.qi4j.api.structure.Application 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.api.structure.Application 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());
}
Aggregations