protected abstract String getFactoryClassName();
public void testLazy() throws Throwable
{
Kernel kernel = bootstrap();
KernelController controller = kernel.getController();
try
{
AbstractBeanMetaData bean = new AbstractBeanMetaData("bean", RareBean.class.getName());
bean.setMode(ControllerMode.MANUAL);
DemandMetaData demand = new AbstractDemandMetaData("foobar");
((AbstractDemandMetaData)demand).setWhenRequired(ControllerState.INSTANTIATED);
bean.setDemands(Collections.singleton(demand));
KernelControllerContext beanContext = controller.install(bean);
controller.change(beanContext, ControllerState.NOT_INSTALLED);
ModifiedLazyMetaData lazy = new ModifiedLazyMetaData("bean", getFactoryClassName());
lazy.setInterfaces(Collections.singleton(IRare.class.getName()));
KernelControllerContext lazyContext = controller.install(lazy);
assertNotNull(lazyContext);
assertEquals(ControllerState.INSTALLED, lazyContext.getState());
controller.change(beanContext, ControllerState.DESCRIBED);
controller.change(lazyContext, ControllerState.INSTALLED);
IRare lazyRare = (IRare)lazyContext.getTarget();
assertNotNull(lazyRare);
try
{
lazyRare.getHits();
throw new RuntimeException("Should not be here.");
}
catch(Throwable t)
{
assertInstanceOf(t, IllegalArgumentException.class);
}
controller.install(new AbstractBeanMetaData("foobar", Object.class.getName()));
controller.change(beanContext, ControllerState.INSTALLED);
assertEquals(0, lazyRare.getHits());
lazyRare.setHits(10);
assertEquals(5, lazyRare.checkHits(15));
controller.uninstall(beanContext.getName());
assertEquals(ControllerState.DESCRIBED, lazyContext.getState());
}
finally
{
controller.shutdown();
}
}