Skip to content

Commit

Permalink
More work on module life cycle unit testing - TRUNK-4134
Browse files Browse the repository at this point in the history
  • Loading branch information
dkayiwa committed Nov 7, 2013
1 parent b83b4ec commit 336630f
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions api/src/test/java/org/openmrs/module/ModuleActivatorTest.java
Expand Up @@ -25,6 +25,12 @@ public class ModuleActivatorTest extends BaseContextSensitiveTest {
@Before
public void beforeEachTest() {
moduleTestData = ModuleTestData.getInstance();

init();

ModuleFactory.startModule(ModuleFactory.getModuleById(MODULE1_ID));

This comment has been minimized.

Copy link
@wluyima

wluyima Nov 8, 2013

Member

Since you have @StartModule on the class, all these modules get started when the test instance is created, what you want is to check if any module was stopped most likely from a previous test so that you start it again.

This comment has been minimized.

Copy link
@dkayiwa

dkayiwa Nov 8, 2013

Author Member

Makes perfect sense!

ModuleFactory.startModule(ModuleFactory.getModuleById(MODULE2_ID));
ModuleFactory.startModule(ModuleFactory.getModuleById(MODULE3_ID));
}

@Test
Expand Down Expand Up @@ -73,6 +79,23 @@ public void shouldCallWillStopAndStoppedOnlyForStoppedModule() throws Exception
assertTrue(moduleTestData.getStoppedCallCount(MODULE2_ID) == 0);
}

@Test
public void shouldStopDependantModulesOnStopModule() throws Exception {
//since module test2 depends on test1 and test3 depends on test2
//stopping test1 should also stop both modules test2 and test3
ModuleFactory.stopModule(ModuleFactory.getModuleById(MODULE1_ID));

//should have called willStop() for only modules test1, test2 and test3
assertTrue(moduleTestData.getWillStopCallCount(MODULE1_ID) == 1);
assertTrue(moduleTestData.getWillStopCallCount(MODULE2_ID) == 1);
assertTrue(moduleTestData.getWillStopCallCount(MODULE3_ID) == 1);

//should have called stopped() for only modules test1, test2 and test3
assertTrue(moduleTestData.getStoppedCallCount(MODULE1_ID) == 1);
assertTrue(moduleTestData.getStoppedCallCount(MODULE2_ID) == 1);
assertTrue(moduleTestData.getStoppedCallCount(MODULE3_ID) == 1);
}

@Test
public void shouldCallWillStopAndStoppedOnShutdown() throws Exception {
ModuleUtil.shutdown();
Expand Down

5 comments on commit 336630f

@wluyima
Copy link
Member

@wluyima wluyima commented on 336630f Nov 7, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would have been good to have this code in one PR but it is probably late for that

@dkayiwa
Copy link
Member Author

@dkayiwa dkayiwa commented on 336630f Nov 7, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is PR in full? :)

@wluyima
Copy link
Member

@wluyima wluyima commented on 336630f Nov 7, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request :)

@dkayiwa
Copy link
Member Author

@dkayiwa dkayiwa commented on 336630f Nov 7, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes i full agree. Do you know how i can combine them into one commit? :)

@wluyima
Copy link
Member

@wluyima wluyima commented on 336630f Nov 7, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think so since you are committing to trunk directly

Please sign in to comment.