Search in sources :

Example 36 with SingletonAssembler

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

the class HelloWorldTest method setUp.

@Before
public void setUp() throws Exception {
    SingletonAssembler assembly = new SingletonAssembler() {

        @Override
        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.transients(HelloWorldComposite.class);
        }
    };
    helloWorld = assembly.module().newTransientBuilder(HelloWorldComposite.class).newInstance();
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) Before(org.junit.Before)

Example 37 with SingletonAssembler

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

the class HelloWorldTest method setUp.

@Before
public void setUp() throws Exception {
    SingletonAssembler assembly = new SingletonAssembler() {

        @Override
        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.transients(HelloWorldComposite.class);
        }
    };
    helloWorld = assembly.module().newTransient(HelloWorldComposite.class);
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) Before(org.junit.Before)

Example 38 with SingletonAssembler

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

the class HelloWorldTest method setUp.

@Before
public void setUp() throws Exception {
    SingletonAssembler assembly = new SingletonAssembler() {

        @Override
        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.transients(HelloWorldComposite.class);
        }
    };
    helloWorld = assembly.module().newTransientBuilder(HelloWorldComposite.class).newInstance();
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) Before(org.junit.Before)

Example 39 with SingletonAssembler

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

the class Main method main.

public static void main(String[] args) throws Exception {
    SingletonAssembler assembler = new // <1>
    SingletonAssembler() {

        @Override
        public void assemble(ModuleAssembly assembly) throws AssemblyException {
            // <2>
            assembly.transients(Speaker.class);
        }
    };
    // <3>
    Speaker speaker = assembler.module().newTransient(Speaker.class);
    System.out.println(speaker.sayHello());
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler)

Example 40 with SingletonAssembler

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

the class ActivationEventsTest method testSingleModuleSingleLazyService.

@Test
public void testSingleModuleSingleLazyService() throws Exception {
    final List<ActivationEvent> events = new ArrayList<>();
    SingletonAssembler assembler = new SingletonAssembler() {

        @Override
        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.services(TestServiceComposite.class);
        }

        @Override
        protected void beforeActivation(Application application) {
            application.registerActivationEventListener(new EventsRecorder(events));
        }
    };
    Application application = assembler.application();
    application.passivate();
    Iterator<ActivationEvent> it = events.iterator();
    // Activation
    assertEvent(it.next(), ACTIVATING, "Application");
    assertEvent(it.next(), ACTIVATING, "Layer");
    assertEvent(it.next(), ACTIVATING, "Module");
    // Lazy Service NOT activated
    assertEvent(it.next(), ACTIVATED, "Module");
    assertEvent(it.next(), ACTIVATED, "Layer");
    assertEvent(it.next(), ACTIVATED, "Application");
    // Passivation
    assertEvent(it.next(), PASSIVATING, "Application");
    assertEvent(it.next(), PASSIVATING, "Layer");
    assertEvent(it.next(), PASSIVATING, "Module");
    // Lazy Service NOT passivated
    assertEvent(it.next(), PASSIVATED, "Module");
    assertEvent(it.next(), PASSIVATED, "Layer");
    assertEvent(it.next(), PASSIVATED, "Application");
    assertFalse(it.hasNext());
    events.clear();
    application.activate();
    Module module = assembler.module();
    module.findService(TestService.class).get().test();
    application.passivate();
    for (ActivationEvent event : events) {
        System.out.println(event);
    }
    it = events.iterator();
    // Activation
    assertEvent(it.next(), ACTIVATING, "Application");
    assertEvent(it.next(), ACTIVATING, "Layer");
    assertEvent(it.next(), ACTIVATING, "Module");
    assertEvent(it.next(), ACTIVATED, "Module");
    assertEvent(it.next(), ACTIVATED, "Layer");
    assertEvent(it.next(), ACTIVATED, "Application");
    // Lazy Service Activation
    assertEvent(it.next(), ACTIVATING, "TestService");
    assertEvent(it.next(), ACTIVATED, "TestService");
    // Passivation
    assertEvent(it.next(), PASSIVATING, "Application");
    assertEvent(it.next(), PASSIVATING, "Layer");
    assertEvent(it.next(), PASSIVATING, "Module");
    assertEvent(it.next(), PASSIVATING, "TestService");
    assertEvent(it.next(), PASSIVATED, "TestService");
    assertEvent(it.next(), PASSIVATED, "Module");
    assertEvent(it.next(), PASSIVATED, "Layer");
    assertEvent(it.next(), PASSIVATED, "Application");
    assertFalse(it.hasNext());
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) ArrayList(java.util.ArrayList) Module(org.qi4j.api.structure.Module) 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