Search in sources :

Example 41 with SingletonAssembler

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

the class ConstructorInjectionOfThisTest method givenConcernWithThisInConstructorWhenCreatingModelExpectException.

@Test
public void givenConcernWithThisInConstructorWhenCreatingModelExpectException() throws ActivationException, AssemblyException {
    SingletonAssembler singletonAssembler = new SingletonAssembler() {

        @Override
        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.values(Does.class).withConcerns(DoesConcern.class);
        }
    };
    Module module = singletonAssembler.application().findModule("Layer 1", "Module 1");
    Does does = module.newValue(Does.class);
    does.doSomething();
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) Module(org.qi4j.api.structure.Module) Test(org.junit.Test)

Example 42 with SingletonAssembler

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

the class ConstructorInjectionOfThisTest method givenSideEffectWithThisInConstructorWhenCreatingModelExpectException.

@Test
public void givenSideEffectWithThisInConstructorWhenCreatingModelExpectException() throws ActivationException, AssemblyException {
    SingletonAssembler singletonAssembler = new SingletonAssembler() {

        @Override
        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.values(Does.class).withSideEffects(DoesSideEffect.class);
        }
    };
    Module module = singletonAssembler.application().findModule("Layer 1", "Module 1");
    Does does = module.newValue(Does.class);
    does.doSomething();
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) Module(org.qi4j.api.structure.Module) Test(org.junit.Test)

Example 43 with SingletonAssembler

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

the class ServiceInjectionTest method testInjectionServiceBetweenLayers.

@Test
public void testInjectionServiceBetweenLayers() throws ActivationException, AssemblyException {
    SingletonAssembler assembly = new SingletonAssembler() {

        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.services(MyServiceComposite.class).identifiedBy("Foo").setMetaInfo(new ServiceName("Foo"));
            module.services(StringService.class, LongService.class);
            LayerAssembly layerAssembly = module.layer();
            module.objects(ServiceUser.class);
            ApplicationAssembly applicationAssembly = layerAssembly.application();
            LayerAssembly layer2Assembly = applicationAssembly.layer("Other layer");
            layerAssembly.uses(layer2Assembly);
            ModuleAssembly module2 = layer2Assembly.module("Other module");
            ServiceDeclaration service2Decl = module2.services(MyServiceComposite2.class);
            service2Decl.identifiedBy("Bar").setMetaInfo(new ServiceName("Bar")).visibleIn(application);
        }
    };
    testInjection(assembly);
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) ServiceDeclaration(org.qi4j.bootstrap.ServiceDeclaration) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) ApplicationAssembly(org.qi4j.bootstrap.ApplicationAssembly) LayerAssembly(org.qi4j.bootstrap.LayerAssembly) Test(org.junit.Test)

Example 44 with SingletonAssembler

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

the class ServiceInjectionTest method testInjectionServiceBetweenModules.

@Test
public void testInjectionServiceBetweenModules() throws ActivationException, AssemblyException {
    SingletonAssembler assembly = new SingletonAssembler() {

        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.services(MyServiceComposite.class).identifiedBy("Foo").setMetaInfo(new ServiceName("Foo"));
            module.services(StringService.class, LongService.class);
            module.objects(ServiceUser.class);
            ModuleAssembly module2 = module.layer().module("Other module");
            ServiceDeclaration service2Decl = module2.services(MyServiceComposite.class);
            service2Decl.identifiedBy("Bar").setMetaInfo(new ServiceName("Bar")).visibleIn(layer);
            ServiceDeclaration service3Decl = module2.services(MyServiceComposite2.class);
            service3Decl.identifiedBy("Boo").setMetaInfo(new ServiceName("Boo"));
        }
    };
    testInjection(assembly);
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) ServiceDeclaration(org.qi4j.bootstrap.ServiceDeclaration) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) Test(org.junit.Test)

Example 45 with SingletonAssembler

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

the class ImportedServiceActivationTest method testNewObjectImportedServiceActivators.

@Test
public void testNewObjectImportedServiceActivators() throws Exception {
    SingletonAssembler assembler = new SingletonAssembler() {

        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.importedServices(TestedService.class).importedBy(ImportedServiceDeclaration.NEW_OBJECT).withActivators(TestedActivator.class).importOnStartup();
            module.objects(TestedServiceInstance.class);
        }
    };
    Application application = assembler.application();
    assertEquals("Activation Level", 2, activationLevel);
    application.passivate();
    assertEquals("Passivation Level", 2, passivationLevel);
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) Application(org.qi4j.api.structure.Application) Test(org.junit.Test)

Aggregations

ModuleAssembly (org.qi4j.bootstrap.ModuleAssembly)87 SingletonAssembler (org.qi4j.bootstrap.SingletonAssembler)87 Test (org.junit.Test)65 Module (org.qi4j.api.structure.Module)15 AssemblyException (org.qi4j.bootstrap.AssemblyException)14 EntityTestAssembler (org.qi4j.test.EntityTestAssembler)13 Before (org.junit.Before)11 Application (org.qi4j.api.structure.Application)10 UnitOfWork (org.qi4j.api.unitofwork.UnitOfWork)5 AmbiguousTypeException (org.qi4j.api.composite.AmbiguousTypeException)4 ServiceReference (org.qi4j.api.service.ServiceReference)4 ArrayList (java.util.ArrayList)3 TransientBuilderFactory (org.qi4j.api.composite.TransientBuilderFactory)3 ObjectFactory (org.qi4j.api.object.ObjectFactory)3 ValueBuilder (org.qi4j.api.value.ValueBuilder)3 UnitOfWorkDomainEventsValue (org.qi4j.library.eventsourcing.domain.api.UnitOfWorkDomainEventsValue)3 File (java.io.File)2 BeforeClass (org.junit.BeforeClass)2 Ignore (org.junit.Ignore)2 ServiceDeclaration (org.qi4j.bootstrap.ServiceDeclaration)2