This project provides some classes that will make it possible to test Spring MVC Portlet controllers
In order to use this test framework
- add the springmvc-portlet-test-XX.jar in your project classpath
- create a simple JUnit Test
- inherit from fr.ippon.springmvc.test.unit.web.junit.AbstractRunnerFreeControllerTest or fr.ippon.springmvc.test.unit.web.junit.AbstractSpringRunnerControllerTest
- add the following annotations above your test class (see § Default configuration) :
@MockWebApplication(name="<your_portlet_name>")
@ContextConfiguration(loader = MockWebApplicationContextLoader.class)
- run your tests
The @ContextConfiguration
annotation normally takes an array of locations, the places where your spring configuration files are. By default, the Test framework assumes you use a Maven-type project, with configuration files located in the src/main/webapp/WEB-INF folder, as shown below :
|-src
|-main
|-src
|-webapp
|-WEB-INF
|-applicationContext.xml
|-<portlet_name_without_dashes>-portlet.xml
|-web.xml
The <portlet_name_without_dashes> name comes from the value of the @MockWebApplication
annotation, minus the dashes (my-portlet --> myportlet)
If you have a different configuration, then use the annotations like the following :
@MockWebApplication(name="portlet-with-tests")
@ContextConfiguration(locations = {
"file:path_to_a_config_file",
"classpath:path_to_another_config_file",
etc.
},
loader = MockWebApplicationContextLoader.class
)
You can look at the sources of the following project in order to see the test API in use : https://github.com/afillatre/Liferay-SpringMVC-Powermock