Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package org.openmrs.module; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
import org.junit.Before; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
import org.openmrs.test.BaseContextSensitiveTest; | ||
import org.openmrs.test.SkipBaseSetup; | ||
import org.openmrs.test.StartModule; | ||
|
||
@SkipBaseSetup | ||
@StartModule({ "org/openmrs/module/include/test3-1.0-SNAPSHOT.omod", "org/openmrs/module/include/test1-1.0-SNAPSHOT.omod", | ||
"org/openmrs/module/include/test2-1.0-SNAPSHOT.omod" }) | ||
public class ModuleActivatorTest extends BaseContextSensitiveTest { | ||
|
||
private static final String MODULE1_ID = "test1"; | ||
|
||
private static final String MODULE2_ID = "test2"; | ||
|
||
private static final String MODULE3_ID = "test3"; | ||
|
||
ModuleTestData moduleTestData; | ||
|
||
@Before | ||
public void beforeEachTest() { | ||
moduleTestData = ModuleTestData.getInstance(); | ||
} | ||
|
||
@Test | ||
public void shouldCallWillStartOnStartup() throws Exception { | ||
assertTrue(moduleTestData.getWillStartCallCount(MODULE1_ID) == 1); | ||
assertTrue(moduleTestData.getWillStartCallCount(MODULE2_ID) == 1); | ||
assertTrue(moduleTestData.getWillStartCallCount(MODULE3_ID) == 1); | ||
} | ||
|
||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
dkayiwa
Author
Member
|
||
@Test | ||
@Ignore("This is work in progress. So not yet finished this") | ||
public void shouldCallWillRefreshContextOnStartup() throws Exception { | ||
assertTrue(moduleTestData.getWillRefreshContextCallCount(MODULE1_ID) == 1); | ||
assertTrue(moduleTestData.getWillRefreshContextCallCount(MODULE2_ID) == 1); | ||
assertTrue(moduleTestData.getWillRefreshContextCallCount(MODULE3_ID) == 1); | ||
} | ||
|
||
@Test | ||
@Ignore("This is work in progress. So not yet looked into why this fails") | ||
public void shouldCallStartedOnStartup() throws Exception { | ||
assertTrue(moduleTestData.getStartedCallCount(MODULE1_ID) == 1); | ||
assertTrue(moduleTestData.getStartedCallCount(MODULE2_ID) == 1); | ||
assertTrue(moduleTestData.getStartedCallCount(MODULE3_ID) == 1); | ||
} | ||
|
||
@Test | ||
public void shouldStartModulesInOrder() throws Exception { | ||
//module test2 depends on test1 | ||
//while test3 depends on test2 | ||
assertTrue(moduleTestData.getWillStartCallTime(MODULE1_ID) <= moduleTestData.getWillStartCallTime(MODULE2_ID)); | ||
This comment has been minimized.
Sorry, something went wrong.
wluyima
Member
|
||
assertTrue(moduleTestData.getWillStartCallTime(MODULE2_ID) <= moduleTestData.getWillStartCallTime(MODULE3_ID)); | ||
} | ||
|
||
@Test | ||
public void shouldCallWillStopAndStoppedOnlyForStoppedModule() throws Exception { | ||
ModuleFactory.stopModule(ModuleFactory.getModuleById(MODULE3_ID)); | ||
|
||
//should have called willStop() for only module test3 | ||
assertTrue(moduleTestData.getWillStopCallCount(MODULE3_ID) == 1); | ||
assertTrue(moduleTestData.getWillStopCallCount(MODULE1_ID) == 0); | ||
assertTrue(moduleTestData.getWillStopCallCount(MODULE2_ID) == 0); | ||
|
||
//should have called stopped() for only module test3 | ||
assertTrue(moduleTestData.getStoppedCallCount(MODULE3_ID) == 1); | ||
assertTrue(moduleTestData.getStoppedCallCount(MODULE1_ID) == 0); | ||
assertTrue(moduleTestData.getStoppedCallCount(MODULE2_ID) == 0); | ||
This comment has been minimized.
Sorry, something went wrong.
wluyima
Member
|
||
} | ||
|
||
@Test | ||
public void shouldCallWillStopAndStoppedOnShutdown() throws Exception { | ||
ModuleUtil.shutdown(); | ||
|
||
//should have called willStop() | ||
assertTrue(moduleTestData.getWillStopCallCount(MODULE1_ID) == 1); | ||
assertTrue(moduleTestData.getWillStopCallCount(MODULE2_ID) == 1); | ||
assertTrue(moduleTestData.getWillStopCallCount(MODULE3_ID) == 1); | ||
|
||
//should have called stopped() | ||
assertTrue(moduleTestData.getStoppedCallCount(MODULE1_ID) == 1); | ||
assertTrue(moduleTestData.getStoppedCallCount(MODULE2_ID) == 1); | ||
assertTrue(moduleTestData.getStoppedCallCount(MODULE3_ID) == 1); | ||
|
||
//willStop() should have been called before stopped() | ||
assertTrue(moduleTestData.getWillStopCallTime(MODULE1_ID) <= moduleTestData.getStoppedCallTime(MODULE1_ID)); | ||
assertTrue(moduleTestData.getWillStopCallTime(MODULE2_ID) <= moduleTestData.getStoppedCallTime(MODULE2_ID)); | ||
assertTrue(moduleTestData.getWillStopCallTime(MODULE3_ID) <= moduleTestData.getStoppedCallTime(MODULE3_ID)); | ||
} | ||
|
||
private void init() { | ||
moduleTestData.init(MODULE1_ID); | ||
moduleTestData.init(MODULE2_ID); | ||
moduleTestData.init(MODULE3_ID); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
package org.openmrs.module; | ||
|
||
import java.util.Date; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class ModuleTestData { | ||
This comment has been minimized.
Sorry, something went wrong.
wluyima
Member
|
||
|
||
private Map<String, Integer> willRefreshContextCallCount = new HashMap<String, Integer>(); | ||
|
||
private Map<String, Integer> contextRefreshedCallCount = new HashMap<String, Integer>(); | ||
|
||
private Map<String, Integer> willStartCallCount = new HashMap<String, Integer>(); | ||
|
||
private Map<String, Integer> startedCallCount = new HashMap<String, Integer>(); | ||
|
||
private Map<String, Integer> willStopCallCount = new HashMap<String, Integer>(); | ||
|
||
private Map<String, Integer> stoppedCallCount = new HashMap<String, Integer>(); | ||
|
||
private Map<String, Long> willRefreshContextCallTime = new HashMap<String, Long>(); | ||
|
||
private Map<String, Long> contextRefreshedCallTime = new HashMap<String, Long>(); | ||
This comment has been minimized.
Sorry, something went wrong.
wluyima
Member
|
||
|
||
private Map<String, Long> willStartCallTime = new HashMap<String, Long>(); | ||
|
||
private Map<String, Long> startedCallTime = new HashMap<String, Long>(); | ||
|
||
private Map<String, Long> willStopCallTime = new HashMap<String, Long>(); | ||
|
||
private Map<String, Long> stoppedCallTime = new HashMap<String, Long>(); | ||
|
||
private ModuleTestData() { | ||
|
||
} | ||
|
||
private static class ModuleTestDataHolder { | ||
|
||
private static ModuleTestData INSTANCE = null; | ||
} | ||
|
||
public static ModuleTestData getInstance() { | ||
if (ModuleTestDataHolder.INSTANCE == null) | ||
ModuleTestDataHolder.INSTANCE = new ModuleTestData(); | ||
|
||
return ModuleTestDataHolder.INSTANCE; | ||
} | ||
|
||
public void init(String moduleId) { | ||
willRefreshContextCallCount.put(moduleId, 0); | ||
contextRefreshedCallCount.put(moduleId, 0); | ||
willStartCallCount.put(moduleId, 0); | ||
startedCallCount.put(moduleId, 0); | ||
willStopCallCount.put(moduleId, 0); | ||
stoppedCallCount.put(moduleId, 0); | ||
|
||
willRefreshContextCallTime.put(moduleId, 0l); | ||
contextRefreshedCallTime.put(moduleId, 0l); | ||
willStartCallTime.put(moduleId, 0l); | ||
startedCallTime.put(moduleId, 0l); | ||
willStopCallTime.put(moduleId, 0l); | ||
stoppedCallTime.put(moduleId, 0l); | ||
} | ||
|
||
public Integer getWillRefreshContextCallCount(String moduleId) { | ||
Integer count = willRefreshContextCallCount.get(moduleId); | ||
if (count == null) { | ||
count = 0; | ||
} | ||
return count; | ||
} | ||
|
||
public Integer getContextRefreshedCallCount(String moduleId) { | ||
Integer count = contextRefreshedCallCount.get(moduleId); | ||
if (count == null) { | ||
count = 0; | ||
} | ||
return count; | ||
} | ||
|
||
public Integer getWillStartCallCount(String moduleId) { | ||
Integer count = willStartCallCount.get(moduleId); | ||
if (count == null) { | ||
count = 0; | ||
} | ||
return count; | ||
} | ||
|
||
public Integer getStartedCallCount(String moduleId) { | ||
Integer count = startedCallCount.get(moduleId); | ||
if (count == null) { | ||
count = 0; | ||
} | ||
return count; | ||
} | ||
|
||
public Integer getWillStopCallCount(String moduleId) { | ||
Integer count = willStopCallCount.get(moduleId); | ||
if (count == null) { | ||
count = 0; | ||
} | ||
return count; | ||
} | ||
|
||
public Integer getStoppedCallCount(String moduleId) { | ||
Integer count = stoppedCallCount.get(moduleId); | ||
if (count == null) { | ||
count = 0; | ||
} | ||
return count; | ||
} | ||
|
||
public void willRefreshContext(String moduleId) { | ||
willRefreshContextCallTime.put(moduleId, new Date().getTime()); | ||
|
||
Integer count = willRefreshContextCallCount.get(moduleId); | ||
if (count == null) { | ||
count = 0; | ||
} | ||
willRefreshContextCallCount.put(moduleId, count + 1); | ||
} | ||
|
||
public void contextRefreshed(String moduleId) { | ||
contextRefreshedCallTime.put(moduleId, new Date().getTime()); | ||
|
||
Integer count = contextRefreshedCallCount.get(moduleId); | ||
if (count == null) { | ||
count = 0; | ||
} | ||
contextRefreshedCallCount.put(moduleId, count + 1); | ||
} | ||
|
||
public void willStart(String moduleId) { | ||
willStartCallTime.put(moduleId, new Date().getTime()); | ||
|
||
Integer count = willStartCallCount.get(moduleId); | ||
if (count == null) { | ||
count = 0; | ||
} | ||
willStartCallCount.put(moduleId, count + 1); | ||
} | ||
|
||
public void started(String moduleId) { | ||
startedCallTime.put(moduleId, new Date().getTime()); | ||
|
||
Integer count = startedCallCount.get(moduleId); | ||
if (count == null) { | ||
count = 0; | ||
} | ||
startedCallCount.put(moduleId, count + 1); | ||
} | ||
|
||
public void willStop(String moduleId) { | ||
willStopCallTime.put(moduleId, new Date().getTime()); | ||
|
||
Integer count = willStopCallCount.get(moduleId); | ||
if (count == null) { | ||
count = 0; | ||
} | ||
willStopCallCount.put(moduleId, count + 1); | ||
} | ||
|
||
public void stopped(String moduleId) { | ||
stoppedCallTime.put(moduleId, new Date().getTime()); | ||
|
||
Integer count = stoppedCallCount.get(moduleId); | ||
if (count == null) { | ||
count = 0; | ||
} | ||
stoppedCallCount.put(moduleId, count + 1); | ||
} | ||
|
||
public Long getWillRefreshContextCallTime(String moduleId) { | ||
return willRefreshContextCallTime.get(moduleId); | ||
} | ||
|
||
public Long getContextRefreshedCallTime(String moduleId) { | ||
return contextRefreshedCallTime.get(moduleId); | ||
} | ||
|
||
public Long getWillStartCallTime(String moduleId) { | ||
return willStartCallTime.get(moduleId); | ||
} | ||
|
||
public Long getStartedCallTime(String moduleId) { | ||
return startedCallTime.get(moduleId); | ||
} | ||
|
||
public Long getWillStopCallTime(String moduleId) { | ||
return willStopCallTime.get(moduleId); | ||
} | ||
|
||
public Long getStoppedCallTime(String moduleId) { | ||
return stoppedCallTime.get(moduleId); | ||
} | ||
} |
I also you are missing tests for when you start a module that is previously stopped