Commit
require refreshing of the spring application context - TRUNK-4134
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* The contents of this file are subject to the OpenMRS Public License | ||
* Version 1.0 (the "License"); you may not use this file except in | ||
* compliance with the License. You may obtain a copy of the License at | ||
* http://license.openmrs.org | ||
* | ||
* Software distributed under the License is distributed on an "AS IS" | ||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing rights and limitations | ||
* under the License. | ||
* | ||
* Copyright (C) OpenMRS, LLC. All Rights Reserved. | ||
*/ | ||
package org.openmrs.module; | ||
|
||
import org.junit.Before; | ||
import org.openmrs.test.BaseContextSensitiveTest; | ||
|
||
/** | ||
* Has functionality commonly used by unit tests for module activator | ||
*/ | ||
public abstract class BaseModuleActivatorTest extends BaseContextSensitiveTest { | ||
|
||
protected static final String MODULE1_ID = "test1"; | ||
|
||
protected static final String MODULE2_ID = "test2"; | ||
|
||
protected static final String MODULE3_ID = "test3"; | ||
|
||
protected ModuleTestData moduleTestData; | ||
|
||
@Before | ||
public void beforeEachTest() throws Exception { | ||
moduleTestData = ModuleTestData.getInstance(); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
ModuleUtil.shutdown(); | ||
|
||
init(); | ||
|
||
String modulesToLoad = "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"; | ||
runtimeProperties.setProperty(ModuleConstants.RUNTIMEPROPERTY_MODULE_LIST_TO_LOAD, modulesToLoad); | ||
ModuleUtil.startup(runtimeProperties); | ||
} | ||
|
||
protected 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,39 @@ | ||
/** | ||
* The contents of this file are subject to the OpenMRS Public License | ||
* Version 1.0 (the "License"); you may not use this file except in | ||
* compliance with the License. You may obtain a copy of the License at | ||
* http://license.openmrs.org | ||
* | ||
* Software distributed under the License is distributed on an "AS IS" | ||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing rights and limitations | ||
* under the License. | ||
* | ||
* Copyright (C) OpenMRS, LLC. All Rights Reserved. | ||
*/ | ||
package org.openmrs.web.test; | ||
|
||
import org.springframework.context.ConfigurableApplicationContext; | ||
import org.springframework.context.support.ClassPathXmlApplicationContext; | ||
import org.springframework.test.context.support.AbstractContextLoader; | ||
|
||
/** | ||
* The only reason why i created this class is to be able to create an application context which can | ||
* be refreshed multiple times, unlike the default GenericApplicationContext which can be refreshed | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
dkayiwa
Author
Member
|
||
* only once. This class is used for @ContextConfiguration in WebModuleActivatorTest | ||
*/ | ||
public class TestContextLoader extends AbstractContextLoader { | ||
|
||
public TestContextLoader() { | ||
} | ||
|
||
@Override | ||
public final ConfigurableApplicationContext loadContext(String... locations) throws Exception { | ||
return new ClassPathXmlApplicationContext(locations); | ||
} | ||
|
||
@Override | ||
protected String getResourceSuffix() { | ||
return "-context.xml"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* The contents of this file are subject to the OpenMRS Public License | ||
* Version 1.0 (the "License"); you may not use this file except in | ||
* compliance with the License. You may obtain a copy of the License at | ||
* http://license.openmrs.org | ||
* | ||
* Software distributed under the License is distributed on an "AS IS" | ||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing rights and limitations | ||
* under the License. | ||
* | ||
* Copyright (C) OpenMRS, LLC. All Rights Reserved. | ||
*/ | ||
package org.openmrs.web.test; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
import org.junit.Test; | ||
import org.openmrs.module.BaseModuleActivatorTest; | ||
import org.openmrs.module.ModuleUtil; | ||
import org.springframework.context.support.AbstractRefreshableApplicationContext; | ||
import org.springframework.test.annotation.NotTransactional; | ||
import org.springframework.test.context.ContextConfiguration; | ||
|
||
/** | ||
* 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 | ||
*/ | ||
@ContextConfiguration(locations = { "classpath*:webModuleApplicationContext.xml" }, inheritLocations = true, loader = TestContextLoader.class) | ||
This comment has been minimized.
Sorry, something went wrong.
wluyima
Member
|
||
public class WebModuleActivatorTest extends BaseModuleActivatorTest { | ||
|
||
@Test | ||
@NotTransactional | ||
public void shouldCallWillRefreshContextAndContextRefreshedOnRefresh() throws Exception { | ||
|
||
ModuleUtil.refreshApplicationContext((AbstractRefreshableApplicationContext) applicationContext, false, null); | ||
This comment has been minimized.
Sorry, something went wrong.
wluyima
Member
|
||
|
||
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); | ||
} | ||
} |
I thought you said you would change this since it is not necessary to call it all the time, another option would be actually to assign it during declaration on line 30 above