Skip to content

Commit

Permalink
Adding a unit test for: ModuleActivator.started()/.contextRefreshed()
Browse files Browse the repository at this point in the history
not called when module is stopped/restarted or newly uploaded -
TRUNK-4134
  • Loading branch information
dkayiwa committed Nov 13, 2013
1 parent 0d4d58d commit f0b8379
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions web/src/test/java/org/openmrs/web/test/WebModuleActivatorTest.java
Expand Up @@ -84,4 +84,37 @@ public void shouldRefreshOtherModulesOnStoppingModule() {
assertTrue(moduleTestData.getContextRefreshedCallCount(MODULE1_ID) == 1);
assertTrue(moduleTestData.getContextRefreshedCallCount(MODULE2_ID) == 1);
}

@Test
@NotTransactional
public void shouldRefreshOtherModulesOnStartingStoppedModule() {
Module module = ModuleFactory.getModuleById(MODULE3_ID);
ModuleFactory.stopModule(module);

This comment has been minimized.

Copy link
@wluyima

wluyima Nov 18, 2013

Member

I feel that calling init() spoils the test here, you shouldn't have to reset things within the same test since other activator methods have been called, aren't you supposed to be testing against the call count instead?

This comment has been minimized.

Copy link
@dkayiwa

dkayiwa Nov 18, 2013

Author Member

init just resets all counters to zero and for only this test. Do you see any danger with that?

This comment has been minimized.

Copy link
@wluyima

wluyima Nov 19, 2013

Member

It might be fine, i was just assuming you would know what the expected count is since you can predict the invocation count like you are doing in some other tests

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

//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

//start module3 which was previously stopped
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);

//started() method gets called for ONLY the newly started module's activator
assertTrue(moduleTestData.getStartedCallCount(MODULE1_ID) == 0);
assertTrue(moduleTestData.getStartedCallCount(MODULE2_ID) == 0);
assertTrue(moduleTestData.getStartedCallCount(MODULE3_ID) == 1);
}
}

0 comments on commit f0b8379

Please sign in to comment.