assertNotNull(p11);
noServiceException(plugin2);
noServiceException(plugin3);
FileMonitor f1 = (FileMonitor) context1.getBean("bean1");
FileMonitor f2 = (FileMonitor) context1.getBean("bean2");
FileMonitor f3 = (FileMonitor) context1.getBean("bean3");
FileMonitor pluginBean = Impala.getModuleBean(plugin1, "bean1", FileMonitor.class);
assertEquals("classes.FileMonitorBean1", pluginBean.getClass().getName());
noServiceException("unknownPlugin");
service(f1);
noService(f2);
noService(f3);
final Test2 test2 = new Test2();
Impala.init(test2);
assertEquals(test2.getModuleDefinition(), Impala.getRootModuleDefinition());
assertTrue(Impala.hasModule(plugin1));
assertTrue(Impala.hasModule(plugin2));
final ApplicationContext context2 = SpringModuleUtils.getModuleSpringContext(Impala.getRootRuntimeModule());
final ConfigurableApplicationContext p12 = getModule(plugin1);
assertNotNull(p12);
assertSame(p11, p12);
final ConfigurableApplicationContext p22 = getModule(plugin2);
assertNotNull(p22);
noServiceException(plugin3);
f1 = (FileMonitor) context2.getBean("bean1");
f2 = (FileMonitor) context2.getBean("bean2");
f3 = (FileMonitor) context2.getBean("bean3");
service(f1);
service(f2);
noService(f3);
// context still same
assertSame(context1, context2);
assertTrue(Impala.hasModule(plugin1));
assertTrue(Impala.hasModule(plugin2));
// now load plugin 3 as well
final Test3 test3 = new Test3();
Impala.init(test3);
assertEquals(test3.getModuleDefinition(), Impala.getRootModuleDefinition());
final ApplicationContext context3 = SpringModuleUtils.getModuleSpringContext(Impala.getRootRuntimeModule());
final ConfigurableApplicationContext p13 = getModule(plugin1);
assertSame(p11, p13);
final ConfigurableApplicationContext p23 = getModule(plugin2);
assertSame(p22, p23);
final ConfigurableApplicationContext p33 = getModule(plugin3);
assertNotNull(p33);
f1 = (FileMonitor) context3.getBean("bean1");
f2 = (FileMonitor) context3.getBean("bean2");
f3 = (FileMonitor) context3.getBean("bean3");
FileMonitor f3PluginBean = Impala.getModuleBean(plugin1, "bean3", FileMonitor.class);
assertSame(f3, f3PluginBean);
// context still same
assertSame(context1, context3);
service(f3);
assertTrue(Impala.hasModule(plugin1));
assertTrue(Impala.hasModule(plugin2));
assertTrue(Impala.hasModule(plugin3));
assertTrue(Impala.hasModule(plugin1));
assertTrue(Impala.hasModule(plugin2));
assertTrue(Impala.hasModule(plugin3));
// show that this will return false
assertFalse(Impala.reloadModule("unknown"));
// now reload plugin1
assertTrue(Impala.reloadModule(plugin1));
assertTrue(Impala.hasModule(plugin1));
final ConfigurableApplicationContext p13reloaded = getModule(plugin1);
assertNotSame(p13reloaded, p13);
FileMonitor f1reloaded = (FileMonitor) context3.getBean("bean1");
assertEquals(f1.lastModified((File) null), f1reloaded.lastModified((File) null));
service(f1reloaded);
assertSame(f1reloaded, f1);
// now reload plugin2, which will also reload plugin3
assertTrue(Impala.reloadModule(plugin2));
assertTrue(Impala.hasModule(plugin2));
final ConfigurableApplicationContext p23reloaded = getModule(plugin2);
assertNotSame(p23reloaded, p23);
final ConfigurableApplicationContext p33reloaded = getModule(plugin3);
assertNotSame(p33reloaded, p33);
FileMonitor f3reloaded = (FileMonitor) context3.getBean("bean3");
assertEquals(f3.lastModified((File) null), f3reloaded.lastModified((File) null));
service(f3reloaded);
assertSame(f3reloaded, f3);
// show that this will return null
assertNull(Impala.reloadModuleLike("unknown"));
// now test reloadLike
assertEquals(plugin2, Impala.reloadModuleLike("module2"));
f3reloaded = (FileMonitor) context3.getBean("bean3");
service(f3reloaded);
// now remove plugin2 (and by implication, child plugin3)
assertFalse(Impala.removeModule("unknown"));
assertTrue(Impala.removeModule(plugin2));
assertFalse(Impala.hasModule(plugin2));
// check that the child is gone too
assertFalse(Impala.hasModule(plugin3));
final ModuleDefinition test3RootDefinition = Impala.getRootModuleDefinition();
assertTrue(test3RootDefinition.hasChildModuleDefinition(plugin1));
assertFalse(test3RootDefinition.hasChildModuleDefinition(plugin2));
f3reloaded = (FileMonitor) context3.getBean("bean3");
FileMonitor f2reloaded = (FileMonitor) context3.getBean("bean2");
noService(f3reloaded);
noService(f2reloaded);
}