I am trying to run integration tests regarding a REST web service process that runs in an embedded berth container during the maven integration integration phase. It works.
I want to configure the server to use the HSQL database in memory, so that every JUnit test can configure the database (create tables, insert records) and tear it (delete records).
The web service process application context defines the following data source:
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="#{applicationProperties['jdbc.driver.class.name']}" /> <property name="url" value="#{applicationProperties['jdbc.url']}" /> <property name="username" value="#{applicationProperties['db.user']}" /> <property name="password" value="#{applicationProperties['db.pass']}" /> </bean>
Properties:
jdbc.driver.class.name=org.hsqldb.jdbcDriver jdbc.url=jdbc:hsqldb:mem:mytestdb db.user=sa db.pass=
When doing unit tests (which did not rely on Jetty's built-in container to run), this setting worked fine. Each unit test created a database and inserted records as follows:
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.core.io.ClassPathResource; import org.springframework.jdbc.datasource.DriverManagerDataSource; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @RunWith(SpringJUnit4ClassRunner.class) public class TestBase { @Autowired protected ApplicationContext context; ... @Before public void setUp() { DriverManagerDataSource ds = (DriverManagerDataSource) context.getBean("dataSource");
With my integration tests, this does not work, because the data source created when I started my server in Jetty is not available for my unit test class for inserting / deleting data.
My question is:
- How to configure HSQL in an embedded Jetty container so that my unit test setUp () method can manage data?
source share