java - How to have integration tests setUp() manipulate HSQL data in an in-memory DB running in embedded Jetty container? -



java - How to have integration tests setUp() manipulate HSQL data in an in-memory DB running in embedded Jetty container? -

i trying run integration tests against rest web service process started in embedded jetty container within maven integration test phase. much working.

i want configure server utilize in-memory hsql db such each junit test can setup database (create tables, insert records), , tear downwards (delete records).

the application context of web services process defines next datasource:

<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 executing unit tests (that did not rely on embedded jetty container running), setup worked fine. each unit test created database , inserted records so:

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"); // create tables // insert records } }

with integration tests, not working -apparently because datasource created when server started in jetty not accessible unit test class insert/delete data.

my question:

how can configure hsql in embedded jetty container unit test setup() method can manipulate data?

posting own solution here in case it's useful downwards road else.

allright, didn't end solving way had hoped.

i not find way have integration tests insert info in-memory hsql database running on server.

so instead of solving problem way, had server load info on startup. under src/test, added db initialization servlet start in-memory hsql db, execute insert statements load test data. copied web.xml src/main/webapp src/test/webapp (didn't having this), , added test servlet load on startup.

so, tests don't insert info in between tests, phone call doget() method on new test servlet tell refresh in-memory database.

java spring integration-testing hsqldb embedded-jetty

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -