use of org.qi4j.api.structure.Application in project qi4j-sdk by Qi4j.
the class ImportedServiceActivationTest method testNewInstanceImportedServiceActivators.
@Test
public void testNewInstanceImportedServiceActivators() throws Exception {
SingletonAssembler assembler = new SingletonAssembler() {
public void assemble(ModuleAssembly module) throws AssemblyException {
module.importedServices(TestedService.class).withActivators(TestedActivator.class).setMetaInfo(new TestedServiceInstance()).importOnStartup();
}
};
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 LayerActivationTest method testLayersActivators.
@Test
public void testLayersActivators() throws Exception {
SingletonAssembler assembly = new SingletonAssembler() {
public void assemble(ModuleAssembly module) throws AssemblyException {
module.layer().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 ModuleActivationTest method testModulesActivators.
@Test
public void testModulesActivators() throws Exception {
SingletonAssembler assembly = new SingletonAssembler() {
public void assemble(ModuleAssembly module) throws AssemblyException {
module.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 ServiceActivationTest method testServicesActivators.
@Test
public void testServicesActivators() throws Exception {
SingletonAssembler assembly = new SingletonAssembler() {
public void assemble(ModuleAssembly module) throws AssemblyException {
module.addServices(TestedServiceComposite.class).withActivators(TestedActivator.class).instantiateOnStartup();
module.addServices(TestedServiceComposite2.class).withActivators(TestedActivator.class).instantiateOnStartup();
}
};
// Activate
Application application = assembly.application();
// Assert activated
Assert.assertEquals("Activation Level", 4, activationLevel);
// Passivate
application.passivate();
// Assert passivated
Assert.assertEquals("Passivation Level", 4, passivationLevel);
}
use of org.qi4j.api.structure.Application 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();
}
}
Aggregations