Skip to content

afillatre/SpringMVC-Portlet-Test-Framework

Repository files navigation

Spring MVC Portlet Test Framework

Project's goal

This project provides some classes that will make it possible to test Spring MVC Portlet controllers

Very quick start

In order to use this test framework

  1. add the springmvc-portlet-test-XX.jar in your project classpath
  2. create a simple JUnit Test
  3. inherit from fr.ippon.springmvc.test.unit.web.junit.AbstractRunnerFreeControllerTest or fr.ippon.springmvc.test.unit.web.junit.AbstractSpringRunnerControllerTest
  4. add the following annotations above your test class (see § Default configuration) :
@MockWebApplication(name="<your_portlet_name>")
@ContextConfiguration(loader = MockWebApplicationContextLoader.class)
  1. run your tests

Default configuration

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
)

Project example

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages