Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding unit test to ensure that other modules are refreshed on stopping
a module - TRUNK-4134
- Loading branch information
Showing
2 changed files
with
49 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,17 +17,22 @@ | |
|
||
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.springframework.context.support.AbstractRefreshableApplicationContext; | ||
import org.springframework.test.annotation.NotTransactional; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.web.context.support.XmlWebApplicationContext; | ||
|
||
/** | ||
* ModuleActivator tests that need refreshing the spring application context. The only reason why i | ||
* did not put these in the api projects's ModuleActivatorTest is because when the spring | ||
* application context is refreshed, classes that the module references which are not in the api but | ||
* web, will lead to ClassNotFoundException s, hence preventing the refresh. If you want to try this | ||
* out, just put these tests in ModuleActivatorTest | ||
* out, just put these tests in ModuleActivatorTest NOTE: The way we start, stop, unload, etc, | ||
* modules is copied from ModuleListController | ||
*/ | ||
@ContextConfiguration(locations = { "classpath*:webModuleApplicationContext.xml" }, inheritLocations = true, loader = TestContextLoader.class) | ||
public class WebModuleActivatorTest extends BaseModuleActivatorTest { | ||
|
@@ -46,4 +51,37 @@ public void shouldCallWillRefreshContextAndContextRefreshedOnRefresh() throws Ex | |
assertTrue(moduleTestData.getContextRefreshedCallCount(MODULE2_ID) == 1); | ||
assertTrue(moduleTestData.getContextRefreshedCallCount(MODULE3_ID) == 1); | ||
} | ||
|
||
@Test | ||
@NotTransactional | ||
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()); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
dkayiwa
Author
Member
|
||
|
||
//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); | ||
} | ||
} |
Why are you calling stopModule here twice? WebModuleUtil.stopModule should be enough