Skip to content

Commit

Permalink
Adding test for refreshing started modules when a new one is installed -
Browse files Browse the repository at this point in the history
TRUNK-4134
  • Loading branch information
dkayiwa committed Nov 13, 2013
1 parent 0d1b89a commit ce227b2
Showing 1 changed file with 51 additions and 2 deletions.
53 changes: 51 additions & 2 deletions web/src/test/java/org/openmrs/web/test/WebModuleActivatorTest.java
Expand Up @@ -15,12 +15,16 @@

import static org.junit.Assert.assertTrue;

import java.io.File;
import java.net.URL;

import org.junit.Test;
import org.openmrs.module.BaseModuleActivatorTest;
import org.openmrs.module.Module;
import org.openmrs.module.ModuleFactory;
import org.openmrs.module.ModuleUtil;
import org.openmrs.module.web.WebModuleUtil;
import org.openmrs.util.OpenmrsClassLoader;
import org.openmrs.web.Listener;
import org.springframework.context.support.AbstractRefreshableApplicationContext;
import org.springframework.test.annotation.NotTransactional;
Expand Down Expand Up @@ -96,7 +100,7 @@ public void shouldRefreshOtherModulesOnStartingStoppedModule() {

//When OpenMRS is running and you start a stopped module:
// willRefreshContext() and contextRefreshed() methods get called for all started modules' activators (including the newly started module)
// started() method gets called for ONLY the newly started module's activator
// willStart() and started() methods get called for ONLY the newly started module's activator

//start module3 which was previously stopped
ModuleFactory.startModule(module);
Expand All @@ -113,7 +117,10 @@ public void shouldRefreshOtherModulesOnStartingStoppedModule() {
assertTrue(moduleTestData.getContextRefreshedCallCount(MODULE2_ID) == 1);
assertTrue(moduleTestData.getContextRefreshedCallCount(MODULE3_ID) == 1);

//started() method gets called for ONLY the newly started module's activator
//willStart() and started() methods get called for ONLY the newly started module's activator
assertTrue(moduleTestData.getWillStartCallCount(MODULE1_ID) == 0);
assertTrue(moduleTestData.getWillStartCallCount(MODULE2_ID) == 0);
assertTrue(moduleTestData.getWillStartCallCount(MODULE3_ID) == 1);
assertTrue(moduleTestData.getStartedCallCount(MODULE1_ID) == 0);
assertTrue(moduleTestData.getStartedCallCount(MODULE2_ID) == 0);
assertTrue(moduleTestData.getStartedCallCount(MODULE3_ID) == 1);
Expand Down Expand Up @@ -143,4 +150,46 @@ public void shouldRefreshContextForAllStartedModulesOnWebStartup() throws Throwa
assertTrue(moduleTestData.getStartedCallCount(MODULE2_ID) == 1);
assertTrue(moduleTestData.getStartedCallCount(MODULE3_ID) == 1);
}

@Test
@NotTransactional
public void shouldRefreshOtherModulesOnInstallingNewModule() throws Exception {
//first completely remove module3
Module module = ModuleFactory.getModuleById(MODULE3_ID);
ModuleFactory.stopModule(module);
WebModuleUtil.stopModule(module, ((XmlWebApplicationContext) applicationContext).getServletContext());
ModuleFactory.unloadModule(module);

init(); //to initialize for the condition below:

//When OpenMRS is running and you install a new module:
// willRefreshContext() and contextRefreshed() methods get called for all started modules' activators (including the newly installed module)
// willStart() and started() methods get called for ONLY the newly installed module's activator

//install a new module3
URL url = OpenmrsClassLoader.getInstance().getResource("org/openmrs/module/include/test3-1.0-SNAPSHOT.omod");
File file = new File(url.getFile());
module = ModuleFactory.loadModule(file);
ModuleFactory.startModule(module);
WebModuleUtil.startModule(module, ((XmlWebApplicationContext) applicationContext).getServletContext(), false);

assertTrue(module.isStarted());
assertTrue(ModuleFactory.isModuleStarted(module));

//module1, module2 and module3 should refresh
assertTrue(moduleTestData.getWillRefreshContextCallCount(MODULE1_ID) == 1);
assertTrue(moduleTestData.getWillRefreshContextCallCount(MODULE2_ID) == 1);
assertTrue(moduleTestData.getWillRefreshContextCallCount(MODULE3_ID) == 1);
assertTrue(moduleTestData.getContextRefreshedCallCount(MODULE1_ID) == 1);
assertTrue(moduleTestData.getContextRefreshedCallCount(MODULE2_ID) == 1);
assertTrue(moduleTestData.getContextRefreshedCallCount(MODULE3_ID) == 1);

//willStart() and started() methods get called for ONLY the newly installed module's activator
assertTrue(moduleTestData.getWillStartCallCount(MODULE1_ID) == 0);
assertTrue(moduleTestData.getWillStartCallCount(MODULE2_ID) == 0);
assertTrue(moduleTestData.getWillStartCallCount(MODULE3_ID) == 1);
assertTrue(moduleTestData.getStartedCallCount(MODULE1_ID) == 0);
assertTrue(moduleTestData.getStartedCallCount(MODULE2_ID) == 0);
assertTrue(moduleTestData.getStartedCallCount(MODULE3_ID) == 1);
}
}

0 comments on commit ce227b2

Please sign in to comment.