use of org.openmrs.module.Module in project openmrs-core by openmrs.
the class WebModuleActivatorTest method shouldRefreshOtherModulesOnStoppingModule.
@Test
public void shouldRefreshOtherModulesOnStoppingModule() {
// When OpenMRS is running and you stop a module:
// willRefreshContext() and contextRefreshed() methods get called for ONLY the started modules' activators EXCLUDING the stopped module
// willStop() and stopped() methods get called for ONLY the stopped module's activator
Module module = ModuleFactory.getModuleById(MODULE3_ID);
ModuleFactory.stopModule(module);
WebModuleUtil.stopModule(module, ((XmlWebApplicationContext) applicationContext).getServletContext());
// module3 should have stopped
assertTrue(moduleTestData.getWillStopCallCount(MODULE3_ID) == 1);
assertTrue(moduleTestData.getStoppedCallCount(MODULE3_ID) == 1);
// module1 and module2 should not stop
assertTrue(moduleTestData.getWillStopCallCount(MODULE1_ID) == 0);
assertTrue(moduleTestData.getStoppedCallCount(MODULE1_ID) == 0);
assertTrue(moduleTestData.getWillStopCallCount(MODULE2_ID) == 0);
assertTrue(moduleTestData.getStoppedCallCount(MODULE2_ID) == 0);
// module3 should not refresh
assertTrue(moduleTestData.getWillRefreshContextCallCount(MODULE3_ID) == 0);
assertTrue(moduleTestData.getContextRefreshedCallCount(MODULE3_ID) == 0);
// module1 and module2 should refresh
assertTrue(moduleTestData.getWillRefreshContextCallCount(MODULE1_ID) == 1);
assertTrue(moduleTestData.getWillRefreshContextCallCount(MODULE2_ID) == 1);
assertTrue(moduleTestData.getContextRefreshedCallCount(MODULE1_ID) == 1);
assertTrue(moduleTestData.getContextRefreshedCallCount(MODULE2_ID) == 1);
}
use of org.openmrs.module.Module in project openmrs-core by openmrs.
the class WebModuleActivatorTest method shouldUpgradeModuleWithDependents.
@Test
public void shouldUpgradeModuleWithDependents() {
Module module = ModuleFactory.getModuleById(MODULE1_ID);
assertTrue(module.getVersion().equals("1.0-SNAPSHOT"));
URL url = OpenmrsClassLoader.getInstance().getResource("org/openmrs/module/include/test1-2.0-SNAPSHOT.omod");
module.setDownloadURL("file:" + url.getFile());
createWebInfFolderIfNotExist();
// all the modules should be started
assertTrue(ModuleFactory.getModuleById(MODULE1_ID).isStarted());
assertTrue(ModuleFactory.getModuleById(MODULE2_ID).isStarted());
assertTrue(ModuleFactory.getModuleById(MODULE3_ID).isStarted());
// and they should be only 3
assertTrue(ModuleFactory.getLoadedModules().size() == 3);
assertTrue(ModuleFactory.getStartedModules().size() == 3);
// now stop module1
// stop the module with these parameters so that mandatory modules can be upgraded
ModuleFactory.stopModule(module, false, true);
WebModuleUtil.stopModule(module, ((XmlWebApplicationContext) applicationContext).getServletContext());
// module2 and module3 should have stopped since they depend on module1
assertTrue(!ModuleFactory.getModuleById(MODULE1_ID).isStarted());
assertTrue(!ModuleFactory.getModuleById(MODULE2_ID).isStarted());
assertTrue(!ModuleFactory.getModuleById(MODULE3_ID).isStarted());
// upgrade module1
Module newModule = ModuleFactory.updateModule(module);
// web start the upgraded module1
WebModuleUtil.startModule(newModule, ((XmlWebApplicationContext) applicationContext).getServletContext(), false);
// module1 should have upgraded from version 1.0 to 2.0
module = ModuleFactory.getModuleById(MODULE1_ID);
assertTrue(module.isStarted());
assertTrue(module.getVersion().equals("2.0-SNAPSHOT"));
// now try start module2 and module3
ModuleFactory.startModule(ModuleFactory.getModuleById(MODULE2_ID));
ModuleFactory.startModule(ModuleFactory.getModuleById(MODULE3_ID));
// module2 and module3 should have started
assertTrue(ModuleFactory.getModuleById(MODULE2_ID).isStarted());
assertTrue(ModuleFactory.getModuleById(MODULE3_ID).isStarted());
// we should have 3 modules instead of 4
assertTrue(ModuleFactory.getLoadedModules().size() == 3);
assertTrue(ModuleFactory.getStartedModules().size() == 3);
}
Aggregations