I would like to do an integration test of a Spring MVC Rest service. The purpose of this test is mainly to test the REST part, not the whole application. This means I would like to use HSQLDB instead of our PostgreSQL's main database. At the same time, i would like the Rest service to be deployed on Tomcat to be closer of our real target.
I've found this blog and its example application at the end which is really close to what I need : http://johndobie.blogspot.fr/2012/04/unit-and-integration-tests-with-maven.html It uses the cargo maven plugin to start tomcat and start the integration tests.
My only problem is: how can I use a special ApplicationContext for the test like I would for a simple unit test?
If I understand correctly, the integration test use the same war file than the real application. This means the war use the production web.xml which calls the production ApplicationContext.xml which use the real database (we use property placeholders for some parameters, but not for Hibernate's dialect).
So my question is: is there a way to use a test web.xml or at least a test ApplicationContext.xml for the integration test?
Thank you.
If you really want to use the same WAR for testing and production: Depending on your Spring Version:
For Spring > 3.1: You may use profiles see the example here: http://spring.io/blog/2011/02/11/spring-framework-3-1-m1-released/
Or for older Spring versions the Spring Configurator from the Apache Cocoon project: http://cocoon.apache.org/subprojects/configuration/spring-configurator/index.html