I want to re-use an sql script from the test resources of the database
module in my in-memory test in the pizza
module, but I can't get the script from the classpath.
My directory structure looks like this:
(I left most of the files/directories out for brevity)
| pom.xml
|
|
+---database
| | pom.xml
| |
| \---src
| \---test
| \---resources
| \---db
| \---migration
| \---hsqldb
| V1__create_schema.sql
| V2__config_data.sql
| V3__user_data.sql
|
+---pizza
| | pom.xml
| |
| \---src
| +---main
| | +---java
| | | \---com
| | | \---example
| | | +---domain
| | | | DoStuff.java
| | |
| | \---resources
| | | applicationContext.xml
| |
| \---test
| +---java
| | \---com
| | \---example
| | DoStuffTest.java
| |
| \---resources
| insert-test-data.sql
| test-applicationContext.xml
| test-in-memory-database.xml
|
\---poms
| pom.xml
|
\---parent
pom.xml
Now, I would like test-applicationContext in the pizza
module to create an in-memory database from the V1__create_schema.sql
script in the database
module, so I can run tests against it. I put this into my test-applicationContext.xml
:
<jdbc:embedded-database id="dataSource" type="HSQL">
<jdbc:script location="classpath:V1__create_schema.sql"/>
<jdbc:script location="insert-test-data.sql"/>
</jdbc:embedded-database>
... but it can't find V1__create_schema.sql
on my classpath. I have tried many different ways of reaching it, including maven-remote-resources-plugin
, without luck.
How would I go about getting hold of that resource?
... or maybe I'm using the wrong approach?
EDIT: Thanks a lot for all the suggestions, the answer I was looking for was the one from Java1337. However, it seems like this question has already been answered here on SO. I can't believe I missed it! Sorry about the inconvenience!
If you want to get "test-resources", you will need to generate a "test-jar" in the database/pom.xml as follows:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
and then in the pizza/pom.xml, reference the test jar as follows:
<dependencies>
<dependency>
<groupId>groupId</groupId>
<artifactId>database</artifactId>
<type>test-jar</type>
<version>version</version>
<scope>test</scope>
</dependency>
</dependencies>
Cheers!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With