17
17
18
18
import org .junit .Test ;
19
19
import org .openmrs .module .BaseModuleActivatorTest ;
20
+ import org .openmrs .module .Module ;
21
+ import org .openmrs .module .ModuleFactory ;
20
22
import org .openmrs .module .ModuleUtil ;
23
+ import org .openmrs .module .web .WebModuleUtil ;
21
24
import org .springframework .context .support .AbstractRefreshableApplicationContext ;
22
25
import org .springframework .test .annotation .NotTransactional ;
23
26
import org .springframework .test .context .ContextConfiguration ;
27
+ import org .springframework .web .context .support .XmlWebApplicationContext ;
24
28
25
29
/**
26
30
* ModuleActivator tests that need refreshing the spring application context. The only reason why i
27
31
* did not put these in the api projects's ModuleActivatorTest is because when the spring
28
32
* application context is refreshed, classes that the module references which are not in the api but
29
33
* web, will lead to ClassNotFoundException s, hence preventing the refresh. If you want to try this
30
- * out, just put these tests in ModuleActivatorTest
34
+ * out, just put these tests in ModuleActivatorTest NOTE: The way we start, stop, unload, etc,
35
+ * modules is copied from ModuleListController
31
36
*/
32
37
@ ContextConfiguration (locations = { "classpath*:webModuleApplicationContext.xml" }, inheritLocations = true , loader = TestContextLoader .class )
33
38
public class WebModuleActivatorTest extends BaseModuleActivatorTest {
@@ -46,4 +51,37 @@ public void shouldCallWillRefreshContextAndContextRefreshedOnRefresh() throws Ex
46
51
assertTrue (moduleTestData .getContextRefreshedCallCount (MODULE2_ID ) == 1 );
47
52
assertTrue (moduleTestData .getContextRefreshedCallCount (MODULE3_ID ) == 1 );
48
53
}
54
+
55
+ @ Test
56
+ @ NotTransactional
57
+ public void shouldRefreshOtherModulesOnStoppingModule () {
58
+
59
+ //When OpenMRS is running and you stop a module:
60
+ // willRefreshContext() and contextRefreshed() methods get called for ONLY the started modules' activators EXCLUDING the stopped module
61
+ // willStop() and stopped() methods get called for ONLY the stopped module's activator
62
+
63
+ Module module = ModuleFactory .getModuleById (MODULE3_ID );
64
+ ModuleFactory .stopModule (module );
65
+ WebModuleUtil .stopModule (module , ((XmlWebApplicationContext ) applicationContext ).getServletContext ());
Has conversations. Original line has conversations.
66
+
67
+ //module3 should have stopped
68
+ assertTrue (moduleTestData .getWillStopCallCount (MODULE3_ID ) == 1 );
69
+ assertTrue (moduleTestData .getStoppedCallCount (MODULE3_ID ) == 1 );
70
+
71
+ //module1 and module2 should not stop
72
+ assertTrue (moduleTestData .getWillStopCallCount (MODULE1_ID ) == 0 );
73
+ assertTrue (moduleTestData .getStoppedCallCount (MODULE1_ID ) == 0 );
74
+ assertTrue (moduleTestData .getWillStopCallCount (MODULE2_ID ) == 0 );
75
+ assertTrue (moduleTestData .getStoppedCallCount (MODULE2_ID ) == 0 );
76
+
77
+ //module3 should not refresh
78
+ assertTrue (moduleTestData .getWillRefreshContextCallCount (MODULE3_ID ) == 0 );
79
+ assertTrue (moduleTestData .getContextRefreshedCallCount (MODULE3_ID ) == 0 );
80
+
81
+ //module1 and module2 should refresh
82
+ assertTrue (moduleTestData .getWillRefreshContextCallCount (MODULE1_ID ) == 1 );
83
+ assertTrue (moduleTestData .getWillRefreshContextCallCount (MODULE2_ID ) == 1 );
84
+ assertTrue (moduleTestData .getContextRefreshedCallCount (MODULE1_ID ) == 1 );
85
+ assertTrue (moduleTestData .getContextRefreshedCallCount (MODULE2_ID ) == 1 );
86
+ }
49
87
}