use of org.qi4j.bootstrap.ApplicationAssembler in project qi4j-sdk by Qi4j.
the class WicketQi4jApplication method getAssembler.
/**
* Qi4j Assembler
*
* To let the custom application class (DCISampleApplication_x) focus on starting up the
* Wicket environment, I made a convention of having Qi4j Assembler files in an 'assembly'
* folder beside the custom application class.
*
* There's always only one application file, but we could split the assemblage into several
* files ie. one for each layer. In that case, the Assembler file would be distributing to
* the individual LayerXAssembler classes.
*
* If you like, you can also override this method in the custom application class and simply
* return an instance of YourAssembler:
*
* @Override protected ApplicationAssembler getAssembler() {
* return new YourAssemblerInAnyPath();
* }
*/
protected ApplicationAssembler getAssembler() throws Exception {
String appPath = getClass().getCanonicalName();
String expectedPathFromApplication = ".assembly.Assembler";
String assemblerPath = appPath.substring(0, appPath.lastIndexOf(".")) + expectedPathFromApplication;
try {
return (ApplicationAssembler) Class.forName(assemblerPath).newInstance();
} catch (ClassNotFoundException e) {
throw new Exception("Couldn't find Qi4j assembler in path '" + assemblerPath + "'");
}
}
use of org.qi4j.bootstrap.ApplicationAssembler in project qi4j-sdk by Qi4j.
the class DocumentationSupport method assembledWithValuesModuleSerialization.
// END SNIPPET: io
@Test
public // TODO Include in each ValueSerialization extensions documentation
void assembledWithValuesModuleSerialization() throws Exception {
Application app = new Energy4Java().newApplication(new ApplicationAssembler() {
@Override
public ApplicationAssembly assemble(ApplicationAssemblyFactory applicationFactory) throws AssemblyException {
Assembler[][][] pancakes = new Assembler[][][] { { { new Assembler() {
@Override
public void assemble(ModuleAssembly valuesModule) throws AssemblyException {
valuesModule.layer().setName("SINGLE-Layer");
valuesModule.setName("VALUES-Module");
valuesModule.values(SomeValue.class);
}
} }, { new Assembler() {
@Override
public void assemble(ModuleAssembly servicesModule) throws AssemblyException {
servicesModule.setName("SERVICES-Module");
Function<Application, Module> valuesModuleFinder = new Function<Application, Module>() {
@Override
public Module map(Application app) {
return app.findModule("SINGLE-Layer", "VALUES-Module");
}
};
new OrgJsonValueSerializationAssembler().withValuesModuleFinder(valuesModuleFinder).assemble(servicesModule);
}
} } } };
return applicationFactory.newApplicationAssembly(pancakes);
}
});
app.activate();
try {
Module valuesModule = app.findModule("SINGLE-Layer", "VALUES-Module");
SomeValue someValue = someNewValueInstance(valuesModule);
Module servicesModule = app.findModule("SINGLE-Layer", "SERVICES-Module");
ValueSerialization valueSerialization = servicesModule.findService(ValueSerialization.class).get();
String json = valueSerialization.serialize(someValue);
assertThat(json, equalTo("{\"foo\":\"bar\"}"));
SomeValue someNewValue = valueSerialization.deserialize(SomeValue.class, json);
assertThat(someNewValue, equalTo(someValue));
} finally {
app.passivate();
}
}
use of org.qi4j.bootstrap.ApplicationAssembler 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.ApplicationAssembler 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.ApplicationAssembler in project qi4j-sdk by Qi4j.
the class Qi4jApplicationBootstrapListener method createNewApplication.
private Application createNewApplication(ServletContext context) {
Energy4Java qi4j = new Energy4Java();
// Try create assembler
final ApplicationAssembler assembler = createAssembler();
if (assembler != null) {
try {
return qi4j.newApplication(assembler);
} catch (AssemblyException e) {
throw new IllegalStateException(e);
}
}
return null;
}
Aggregations