Search in sources :

Example 6 with ApplicationAssemblyFactory

use of org.qi4j.bootstrap.ApplicationAssemblyFactory 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;
        }
    });
}
Also used : ApplicationAssemblyFactory(org.qi4j.bootstrap.ApplicationAssemblyFactory) ApplicationAssembly(org.qi4j.bootstrap.ApplicationAssembly) LayerAssembly(org.qi4j.bootstrap.LayerAssembly) ApplicationDescriptor(org.qi4j.api.structure.ApplicationDescriptor) AssemblyException(org.qi4j.bootstrap.AssemblyException) ApplicationAssembler(org.qi4j.bootstrap.ApplicationAssembler) Energy4Java(org.qi4j.bootstrap.Energy4Java) Application(org.qi4j.api.structure.Application) LayerDescriptor(org.qi4j.api.structure.LayerDescriptor) Test(org.junit.Test)

Example 7 with ApplicationAssemblyFactory

use of org.qi4j.bootstrap.ApplicationAssemblyFactory 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();
    }
}
Also used : ApplicationAssemblyFactory(org.qi4j.bootstrap.ApplicationAssemblyFactory) UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) EntityTypeNotFoundException(org.qi4j.api.unitofwork.EntityTypeNotFoundException) ApplicationAssembly(org.qi4j.bootstrap.ApplicationAssembly) AssemblyException(org.qi4j.bootstrap.AssemblyException) ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) ApplicationAssembler(org.qi4j.bootstrap.ApplicationAssembler) EntityTestAssembler(org.qi4j.test.EntityTestAssembler) Energy4Java(org.qi4j.bootstrap.Energy4Java) Assembler(org.qi4j.bootstrap.Assembler) ApplicationAssembler(org.qi4j.bootstrap.ApplicationAssembler) EntityTestAssembler(org.qi4j.test.EntityTestAssembler) Module(org.qi4j.api.structure.Module) Identity(org.qi4j.api.entity.Identity) Application(org.qi4j.api.structure.Application) Test(org.junit.Test)

Example 8 with ApplicationAssemblyFactory

use of org.qi4j.bootstrap.ApplicationAssemblyFactory 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;
    }
}
Also used : ApplicationAssemblyFactory(org.qi4j.bootstrap.ApplicationAssemblyFactory) AssemblyException(org.qi4j.bootstrap.AssemblyException) ApplicationAssembler(org.qi4j.bootstrap.ApplicationAssembler) ApplicationAssembly(org.qi4j.bootstrap.ApplicationAssembly)

Example 9 with ApplicationAssemblyFactory

use of org.qi4j.bootstrap.ApplicationAssemblyFactory in project qi4j-sdk by Qi4j.

the class AbstractQi4jScenarioTest method newApplication.

protected static ApplicationDescriptor newApplication() throws AssemblyException {
    final Assembler asm = assembler;
    ApplicationAssembler assembler = new ApplicationAssembler() {

        @Override
        public ApplicationAssembly assemble(ApplicationAssemblyFactory applicationFactory) throws AssemblyException {
            return applicationFactory.newApplicationAssembly(asm);
        }
    };
    try {
        return qi4j.newApplicationModel(assembler);
    } catch (AssemblyException e) {
        assemblyException(e);
        return null;
    }
}
Also used : ApplicationAssemblyFactory(org.qi4j.bootstrap.ApplicationAssemblyFactory) AssemblyException(org.qi4j.bootstrap.AssemblyException) ApplicationAssembler(org.qi4j.bootstrap.ApplicationAssembler) ApplicationAssembler(org.qi4j.bootstrap.ApplicationAssembler) Assembler(org.qi4j.bootstrap.Assembler)

Aggregations

ApplicationAssembler (org.qi4j.bootstrap.ApplicationAssembler)9 ApplicationAssemblyFactory (org.qi4j.bootstrap.ApplicationAssemblyFactory)9 AssemblyException (org.qi4j.bootstrap.AssemblyException)9 ApplicationAssembly (org.qi4j.bootstrap.ApplicationAssembly)8 Energy4Java (org.qi4j.bootstrap.Energy4Java)7 Test (org.junit.Test)5 Application (org.qi4j.api.structure.Application)5 ApplicationDescriptor (org.qi4j.api.structure.ApplicationDescriptor)4 LayerAssembly (org.qi4j.bootstrap.LayerAssembly)4 ModuleAssembly (org.qi4j.bootstrap.ModuleAssembly)4 Assembler (org.qi4j.bootstrap.Assembler)3 Module (org.qi4j.api.structure.Module)2 HashMap (java.util.HashMap)1 ActivationEventListener (org.qi4j.api.activation.ActivationEventListener)1 Identity (org.qi4j.api.entity.Identity)1 LayerDescriptor (org.qi4j.api.structure.LayerDescriptor)1 EntityTypeNotFoundException (org.qi4j.api.unitofwork.EntityTypeNotFoundException)1 UnitOfWork (org.qi4j.api.unitofwork.UnitOfWork)1 Function (org.qi4j.functional.Function)1 HierarchicalVisitor (org.qi4j.functional.HierarchicalVisitor)1