Search in sources :

Example 16 with ModuleAssembly

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

the class LazyActivatedServiceTest method testActivatable.

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

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

Example 17 with ModuleAssembly

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

the class PassivationTest method givenMixedSuccessFailurePassivationWhenPassivatingExpectAllPassivateMethodsToBeCalled.

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

        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.addServices(DataAccessService.class).withActivators(PassivationSuccessActivator.class);
            module.addServices(DataAccessService.class).withActivators(PassivationSuccessActivator.class);
            module.addServices(DataAccessService.class).withActivators(PassivationSuccessActivator.class);
            module.addServices(DataAccessService.class).withActivators(PassivationFailureActivator.class);
            module.addServices(DataAccessService.class).withActivators(PassivationSuccessActivator.class);
            module.addServices(DataAccessService.class).withActivators(PassivationSuccessActivator.class);
            module.addServices(DataAccessService.class).withActivators(PassivationFailureActivator.class);
            module.addServices(DataAccessService.class).withActivators(PassivationSuccessActivator.class);
            module.addServices(DataAccessService.class).withActivators(PassivationSuccessActivator.class);
            module.addServices(DataAccessService.class).withActivators(PassivationFailureActivator.class);
            module.addServices(DataAccessService.class).withActivators(PassivationSuccessActivator.class);
            module.addServices(DataAccessService.class).withActivators(PassivationSuccessActivator.class);
            module.addServices(DataAccessService.class).withActivators(PassivationFailureActivator.class);
        }
    };
    ArrayList<Data> datas = new ArrayList<Data>();
    Iterable<ServiceReference<DataAccess>> iterable = assembly.module().findServices(DataAccess.class);
    for (ServiceReference<DataAccess> service : iterable) {
        assertTrue("Service should not be Active before accessed", !service.isActive());
        Data data = service.get().data();
        if (DataAccessService.class.isInstance(service.get())) {
            // Collect the expected successes.
            datas.add(data);
        }
        assertTrue("Data should indicate that the service is activated", data.activated);
        assertTrue("Service should be Active after access.", service.isActive());
    }
    try {
        assembly.application().passivate();
        fail("PassivationException should have been thrown.");
    } catch (PassivationException e) {
    // Expected
    }
    // Still ensure that all services have been shutdown.
    for (ServiceReference<DataAccess> service : iterable) {
        assertFalse("All services should have been shutdown", service.isActive());
    }
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) PassivationException(org.qi4j.api.activation.PassivationException) ArrayList(java.util.ArrayList) ServiceReference(org.qi4j.api.service.ServiceReference) Test(org.junit.Test)

Example 18 with ModuleAssembly

use of org.qi4j.bootstrap.ModuleAssembly 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 19 with ModuleAssembly

use of org.qi4j.bootstrap.ModuleAssembly 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 20 with ModuleAssembly

use of org.qi4j.bootstrap.ModuleAssembly 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)

Aggregations

ModuleAssembly (org.qi4j.bootstrap.ModuleAssembly)191 SingletonAssembler (org.qi4j.bootstrap.SingletonAssembler)87 Test (org.junit.Test)82 EntityTestAssembler (org.qi4j.test.EntityTestAssembler)59 AssemblyException (org.qi4j.bootstrap.AssemblyException)27 Application (org.qi4j.api.structure.Application)26 OrgJsonValueSerializationAssembler (org.qi4j.valueserialization.orgjson.OrgJsonValueSerializationAssembler)24 Assembler (org.qi4j.bootstrap.Assembler)23 Module (org.qi4j.api.structure.Module)19 LayerAssembly (org.qi4j.bootstrap.LayerAssembly)15 Before (org.junit.Before)12 UnitOfWork (org.qi4j.api.unitofwork.UnitOfWork)12 Energy4Java (org.qi4j.bootstrap.Energy4Java)12 DataSourceAssembler (org.qi4j.library.sql.assembly.DataSourceAssembler)11 DBCPDataSourceServiceAssembler (org.qi4j.library.sql.dbcp.DBCPDataSourceServiceAssembler)9 IOException (java.io.IOException)8 ApplicationAssemblerAdapter (org.qi4j.bootstrap.ApplicationAssemblerAdapter)8 ApplicationAssembly (org.qi4j.bootstrap.ApplicationAssembly)8 File (java.io.File)7 OrgJsonValueSerializationService (org.qi4j.valueserialization.orgjson.OrgJsonValueSerializationService)7