Search in sources :

Example 21 with Module

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);
}
Also used : Module(org.openmrs.module.Module) Test(org.junit.Test) BaseModuleActivatorTest(org.openmrs.module.BaseModuleActivatorTest)

Example 22 with Module

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);
}
Also used : Module(org.openmrs.module.Module) URL(java.net.URL) Test(org.junit.Test) BaseModuleActivatorTest(org.openmrs.module.BaseModuleActivatorTest)

Aggregations

Module (org.openmrs.module.Module)22 File (java.io.File)8 Test (org.junit.Test)7 BaseModuleActivatorTest (org.openmrs.module.BaseModuleActivatorTest)5 IOException (java.io.IOException)3 URL (java.net.URL)3 Properties (java.util.Properties)3 JarFile (java.util.jar.JarFile)2 ServletContext (javax.servlet.ServletContext)2 ServletException (javax.servlet.ServletException)2 AdministrationService (org.openmrs.api.AdministrationService)2 MandatoryModuleException (org.openmrs.module.MandatoryModuleException)2 ModuleMustStartException (org.openmrs.module.ModuleMustStartException)2 OpenmrsCoreModuleException (org.openmrs.module.OpenmrsCoreModuleException)2 Config (org.openmrs.module.pihcore.config.Config)2 DatabaseUpdateException (org.openmrs.util.DatabaseUpdateException)2 InputRequiredException (org.openmrs.util.InputRequiredException)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 BeanCreationException (org.springframework.beans.factory.BeanCreationException)2 FileInputStream (java.io.FileInputStream)1