Search in sources :

Example 11 with SingletonAssembler

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

the class PassivationTest method givenMultipleFailingPassivationWhenPassivatingExpectPassivationExceptionToBubbleUp.

@Test(expected = PassivationException.class)
public void givenMultipleFailingPassivationWhenPassivatingExpectPassivationExceptionToBubbleUp() throws Exception {
    SingletonAssembler assembly = new SingletonAssembler() {

        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.addServices(DataAccessService.class).withActivators(PassivationFailureActivator.class);
            module.addServices(DataAccessService.class).withActivators(PassivationFailureActivator.class);
        }
    };
    Iterable<ServiceReference<DataAccess>> iterable = assembly.module().findServices(DataAccess.class);
    for (ServiceReference<DataAccess> service : iterable) {
        assertTrue("Service should not be Active before accessed", !service.isActive());
        assertTrue(service.get().data().activated);
        assertTrue("Service should be Active after access.", service.isActive());
    }
    assembly.application().passivate();
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) ServiceReference(org.qi4j.api.service.ServiceReference) Test(org.junit.Test)

Example 12 with SingletonAssembler

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

the class ObjectBuilderFactoryTest method newBuilderForUnregisteredObject.

/**
     * Tests that an object builder cannot be created for an unregistered object.
     *
     * @throws Exception expected
     */
@Test(expected = NoSuchObjectException.class)
public void newBuilderForUnregisteredObject() throws Exception {
    SingletonAssembler assembler = new SingletonAssembler() {

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

Example 13 with SingletonAssembler

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

the class ObjectBuilderFactoryTest method newBuilderForNullType.

/**
     * Tests that an object builder cannot be created for a 'null' type.
     *
     * @throws Exception expected
     */
@Test(expected = NullArgumentException.class)
public void newBuilderForNullType() throws Exception {
    SingletonAssembler assembler = new SingletonAssembler() {

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

Example 14 with SingletonAssembler

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

the class ObjectBuilderFactoryTest method givenManyConstructorsWhenInstantiateThenChooseCorrectConstructor.

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

        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.objects(ManyConstructorObject.class);
        }
    };
    ManyConstructorObject object = assembler.module().newObject(ManyConstructorObject.class);
    Assert.assertThat("ref is not null", object.anyObject, notNullValue());
    object = assembler.module().newObject(ManyConstructorObject.class, new AnyObject());
    Assert.assertThat("ref is not null", object.anyObject, notNullValue());
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) Test(org.junit.Test)

Example 15 with SingletonAssembler

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

the class ObjectBuilderFactoryTest method newObjectInstanceForNullType.

/**
     * Tests that an object builder cannot be created for a 'null' type.
     *
     * @throws Exception expected
     */
@Test(expected = NullArgumentException.class)
public void newObjectInstanceForNullType() throws Exception {
    SingletonAssembler assembler = new SingletonAssembler() {

        public void assemble(ModuleAssembly module) throws AssemblyException {
        }
    };
    assembler.module().newObject(null);
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) 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