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);
}
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());
}
}
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();
}
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);
}
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);
}
Aggregations