use of org.qi4j.bootstrap.ApplicationAssembly in project qi4j-sdk by Qi4j.
the class IssueTest method testLayersCanBeCreatedInOrderDifferentFromTheirDependency.
@Test
public void testLayersCanBeCreatedInOrderDifferentFromTheirDependency() throws AssemblyException {
Energy4Java qi4j = new Energy4Java();
Application app = qi4j.newApplication(new ApplicationAssembler() {
public ApplicationAssembly assemble(ApplicationAssemblyFactory applicationFactory) throws AssemblyException {
ApplicationAssembly assembly = applicationFactory.newApplicationAssembly();
LayerAssembly domainLayer = assembly.layer(null);
domainLayer.setName("Domain");
LayerAssembly infrastructureLayer = assembly.layer(null);
infrastructureLayer.setName("Infrastructure");
domainLayer.uses(infrastructureLayer);
return assembly;
}
});
ApplicationDescriptor model = app.descriptor();
model.accept(new HierarchicalVisitorAdapter<Object, Object, RuntimeException>() {
@Override
public boolean visitEnter(Object visited) throws RuntimeException {
return visited instanceof ApplicationDescriptor;
}
@Override
public boolean visitLeave(Object visited) throws RuntimeException {
return visited instanceof LayerDescriptor;
}
@Override
public boolean visit(Object visited) throws RuntimeException {
if (visited instanceof LayerDescriptor) {
Iterable<? extends LayerDescriptor> usedLayers = ((LayerDescriptor) visited).usedLayers().layers();
for (LayerDescriptor usedLayerModel : usedLayers) {
Assert.assertNotNull("Used layer model is null", usedLayerModel);
}
}
return false;
}
});
}
use of org.qi4j.bootstrap.ApplicationAssembly in project qi4j-sdk by Qi4j.
the class PrivateEntityUnitOfWorkTest method givenAppWithPrivateEntityWhenUnitOfWorkCanSeeItThenCanCommit.
@Test
public void givenAppWithPrivateEntityWhenUnitOfWorkCanSeeItThenCanCommit() throws Exception {
System.setProperty("qi4j.compacttrace", "off");
Energy4Java is = new Energy4Java();
Application app = is.newApplication(new ApplicationAssembler() {
public ApplicationAssembly assemble(ApplicationAssemblyFactory applicationFactory) throws AssemblyException {
return applicationFactory.newApplicationAssembly(new Assembler[][][] { { { new Assembler() {
public void assemble(ModuleAssembly module) throws AssemblyException {
module.objects(PrivateEntityUnitOfWorkTest.class);
}
} } }, { { new Assembler() {
public void assemble(ModuleAssembly module) throws AssemblyException {
module.entities(ProductEntity.class);
module.entities(ProductCatalogEntity.class).visibleIn(application);
module.values(ProductInfo.class);
new EntityTestAssembler().assemble(module);
}
} } } });
}
});
app.activate();
Module module = app.findModule("Layer 1", "Module 1");
module.injectTo(this);
UnitOfWork unitOfWork = uowf.newUnitOfWork();
try {
unitOfWork.newEntity(ProductEntity.class);
fail("Should not be able to create product here");
} catch (EntityTypeNotFoundException e) {
// Ok
ProductCatalog catalog = unitOfWork.newEntity(ProductCatalog.class, "1");
unitOfWork.complete();
}
unitOfWork = uowf.newUnitOfWork();
String id;
try {
ProductCatalog catalog = unitOfWork.get(ProductCatalog.class, "1");
id = ((Identity) catalog.newProduct()).identity().get();
unitOfWork.complete();
} finally {
unitOfWork.discard();
}
unitOfWork = module.newUnitOfWork();
try {
ProductCatalog catalog = unitOfWork.get(ProductCatalog.class, "1");
Product product = catalog.findProduct(id);
product.price().set(100);
unitOfWork.complete();
} finally {
unitOfWork.discard();
}
}
use of org.qi4j.bootstrap.ApplicationAssembly in project qi4j-sdk by Qi4j.
the class AbstractQi4jBaseTest method newApplication.
protected ApplicationDescriptor newApplication() throws AssemblyException {
ApplicationAssembler assembler = new ApplicationAssembler() {
@Override
public ApplicationAssembly assemble(ApplicationAssemblyFactory applicationFactory) throws AssemblyException {
ApplicationAssembly applicationAssembly = applicationFactory.newApplicationAssembly();
applicationAssembly.setMode(Application.Mode.test);
defineApplication(applicationAssembly);
return applicationAssembly;
}
};
try {
return qi4j.newApplicationModel(assembler);
} catch (AssemblyException e) {
assemblyException(e);
return null;
}
}
use of org.qi4j.bootstrap.ApplicationAssembly in project qi4j-sdk by Qi4j.
the class Assembler method assemble.
@Override
public ApplicationAssembly assemble(ApplicationAssemblyFactory applicationFactory) throws AssemblyException {
// Application assembly
ApplicationAssembly assembly = applicationFactory.newApplicationAssembly();
assembly.setName("DCI Sample (version B)");
assembly.setVersion("B.1.0");
assembly.setMode(development);
// Layers (adding bottom-up - will be assembled in this order)
LayerAssembly infrastructureLayer = assembly.layer("INFRASTRUCTURE");
LayerAssembly dataLayer = assembly.layer("DATA");
LayerAssembly contextLayer = assembly.layer("CONTEXT");
LayerAssembly communicationLayer = assembly.layer("COMMUNICATION");
LayerAssembly bootstrapLayer = assembly.layer("BOOTSTRAP");
// Layer dependencies
bootstrapLayer.uses(communicationLayer, contextLayer, dataLayer, infrastructureLayer);
communicationLayer.uses(contextLayer, dataLayer, infrastructureLayer);
contextLayer.uses(dataLayer, infrastructureLayer);
dataLayer.uses(infrastructureLayer);
// Assemble
assembleBootstrapLayer(bootstrapLayer);
assembleCommunicationLayer(communicationLayer);
assembleContextLayer(contextLayer);
assembleDataLayer(dataLayer);
assembleInfrastructureLayer(infrastructureLayer);
return assembly;
}
use of org.qi4j.bootstrap.ApplicationAssembly in project qi4j-sdk by Qi4j.
the class TestAssembler method assemble.
public ApplicationAssembly assemble(ApplicationAssemblyFactory applicationFactory) throws AssemblyException {
// Application assembly
ApplicationAssembly assembly = applicationFactory.newApplicationAssembly();
assembly.setName("DCI Sample (version A) - TEST");
assembly.setVersion("A.1.0");
assembly.setMode(test);
// Layers
LayerAssembly infrastructureLayer = assembly.layer("INFRASTRUCTURE");
LayerAssembly domainLayer = assembly.layer("DOMAIN");
LayerAssembly contextLayer = assembly.layer("CONTEXT");
LayerAssembly bootstrapLayer = assembly.layer("BOOTSTRAP");
// Layer dependencies
bootstrapLayer.uses(contextLayer, domainLayer, infrastructureLayer);
contextLayer.uses(domainLayer, infrastructureLayer);
domainLayer.uses(contextLayer, infrastructureLayer);
// Assemble
assembleDomainLayer(domainLayer);
assembleContextLayer(contextLayer);
assembleBootstrapLayer(bootstrapLayer);
assembleInfrastructureLayer(infrastructureLayer);
return assembly;
}
Aggregations