Search in sources :

Example 51 with SingletonAssembler

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

the class ObjectBuilderFactoryTest method givenClassWithInnerClassesWhenInstantiateThenInstantiateInnerClass.

@Test
public void givenClassWithInnerClassesWhenInstantiateThenInstantiateInnerClass() throws ActivationException, AssemblyException {
    SingletonAssembler assembler = new SingletonAssembler() {

        @Override
        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.objects(OuterClass.class);
        }
    };
    Assert.assertThat("inner class has been injected", assembler.module().newObject(OuterClass.class).name(), equalTo("Module 1"));
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) Test(org.junit.Test)

Example 52 with SingletonAssembler

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

the class ObjectBuilderFactoryTest method newInstanceForRegisteredObject.

/**
     * Tests that an object can be created for an registered object class.
     */
@Test
public void newInstanceForRegisteredObject() throws ActivationException, AssemblyException {
    SingletonAssembler assembler = new SingletonAssembler() {

        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.objects(AnyObject.class);
        }
    };
    assembler.module().newObject(AnyObject.class);
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) Test(org.junit.Test)

Example 53 with SingletonAssembler

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

the class ActivatableServiceTest method testActivatable.

@Test
public void testActivatable() throws Exception {
    SingletonAssembler assembly = new SingletonAssembler() {

        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.objects(ActivatableServiceTest.class);
            module.services(ActivatableComposite.class).withActivators(TestActivator.class).instantiateOnStartup();
        }
    };
    assertTrue(isActive);
    assembly.module().injectTo(this);
    assertTrue(isActive);
    service.get();
    assertTrue(isActive);
    assembly.application().passivate();
    assertFalse(isActive);
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) Test(org.junit.Test)

Example 54 with SingletonAssembler

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

the class AvailableServiceTest method givenAvailableServiceWhenCheckServiceReferenceThenReturnTrue.

@Test
public void givenAvailableServiceWhenCheckServiceReferenceThenReturnTrue() throws ActivationException, AssemblyException {
    SingletonAssembler assembler = new SingletonAssembler() {

        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.services(TestServiceComposite1.class);
        }
    };
    ServiceReference<TestServiceComposite1> serviceRef = assembler.module().findService(TestServiceComposite1.class);
    assertThat("service is available", serviceRef.isAvailable(), equalTo(true));
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) Test(org.junit.Test)

Example 55 with SingletonAssembler

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

the class AvailableServiceTest method givenEnablableServiceWhenCheckAvailableThenReturnEnabledStatus.

@Test
public void givenEnablableServiceWhenCheckAvailableThenReturnEnabledStatus() throws ActivationException, AssemblyException {
    SingletonAssembler assembler = new SingletonAssembler() {

        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.services(TestServiceComposite2.class);
            module.entities(TestServiceConfiguration.class);
            new EntityTestAssembler().assemble(module);
        }
    };
    ServiceReference<TestServiceComposite2> serviceRef = assembler.module().findService(TestServiceComposite2.class);
    assertThat("service is unavailable", serviceRef.isAvailable(), equalTo(false));
    serviceRef.get().get().enabled().set(true);
    serviceRef.get().save();
    assertThat("service is available", serviceRef.isAvailable(), equalTo(true));
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) EntityTestAssembler(org.qi4j.test.EntityTestAssembler) 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