-
1. Re: Test database with Seam2, Maven and TestNG?
thejavafreak Dec 19, 2007 1:35 AM (in response to andrew.rw.robinson)Try to add it in:
src/test/resources/META-INF
I haven't done this though. -
2. Re: Test database with Seam2, Maven and TestNG?
andrew.rw.robinson Dec 19, 2007 10:48 PM (in response to andrew.rw.robinson)I got it working, but it was a configuration pain. For those that read this post here is a very quick howto:
- create src/main/conf - this will be files that are added to the war but not added to target/classes on build (and therefore will not interfere with testing)
- move src/main/resources/META-INF/persistence.xml to src/main/conf/META-INF/persistence.xml
- create src/test/resources/META-INF/persistence.xml (see below for example)
- set the base directory for surefire to ensure that the relative paths work
- configure pom to include src/main/conf
src/test/resources/META-INF/persistence.xml:<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0"> <persistence-unit name="testDatabase" transaction-type="RESOURCE_LOCAL"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <mapping-file>file:classes/META-INF/orm.xml</mapping-file> <jar-file>file:classes</jar-file> <properties> ... </properties> </persistence-unit> </persistence>
The mapping-file and jar-file allow the entities be picked up as if the file was in the src/main/resources/META-INF was used.
pom.xml excerpts:... <plugin> <artifactId>maven-surefire-plugin</artifactId> <version>2.4-SNAPSHOT</version> <configuration> <workingDirectory>${project.build.directory}</workingDirectory> <includes> <include>**/*Test.java</include> </includes> </configuration> </plugin> <plugin> <artifactId>maven-war-plugin</artifactId> <version>2.1-alpha-2-SNAPSHOT</version> <configuration> <webResources> <resource> <directory>src/main/conf</directory> <targetPath>WEB-INF/classes</targetPath> </resource> </webResources> </configuration> </plugin> ...
-
3. Re: Test database with Seam2, Maven and TestNG?
pmuir Jan 10, 2008 8:27 AM (in response to andrew.rw.robinson)Thanks Andrew, I added this to the Seam knowledgebase
http://alpha.seamframework.org:9999/Documentation/SeamWithMaven -
4. Re: Test database with Seam2, Maven and TestNG?
svadu Jan 12, 2008 11:47 AM (in response to andrew.rw.robinson)There is a problem with eclipse (if use WTP configuration) is that it doesn't like more than one persistence unit defined.
As a workaround I defined the test persistence unit programmatically in my unit tests. -
5. Re: Test database with Seam2, Maven and TestNG?
svadu Jan 14, 2008 6:29 PM (in response to andrew.rw.robinson)Btw, maven starting from 2.0.8 puts test classpath before the source classpath (which wasn't the case before). This should make configuration quite simple. You'd need to enforce maven version then of course :)
-
6. Re: Test database with Seam2, Maven and TestNG?
pmuir Jan 14, 2008 6:43 PM (in response to andrew.rw.robinson)That is good news :)
-
7. Re: Test database with Seam2, Maven and TestNG?
ruettimac Jan 16, 2008 3:03 AM (in response to andrew.rw.robinson)Cool,
Surefire Plugin version 2.4 is finally out. Supporting TestNG as a first citizen. I will try it out over the weekend if the combination maven, seam combo is working now as expected.
Regards,
Cyrill -
8. Re: Test database with Seam2, Maven and TestNG?
svadu Jan 16, 2008 9:26 AM (in response to andrew.rw.robinson)Tbh, considering how much maven projects' (especially multimodule projects) layout is different from Seam project layout and considering how the Seam test framework 'tuned' for certain configurations and defaults I think it requires major work to make Seam tests work in maven projects.
In the meanwhile I am using shale test component for tests:<dependency> <groupId>org.apache.shale</groupId> <artifactId>shale-test</artifactId> <version>1.0.4</version> <scope>test</scope> </dependency>
It is enough to extend AbstractJsfTestCase (which can be combined with TestNG as well) and you get all mockups for JSF environment.
It requires somewhat more to code for this than you would with Seam tests but hey, at least it works :) -
9. Re: Test database with Seam2, Maven and TestNG?
andrew.rw.robinson Jan 16, 2008 12:51 PM (in response to andrew.rw.robinson)In regards to ordering in 2.0.8:
The ordering is not a concern. The problem is that both persistence.xml files are loaded and parsed. So my solution is important to ensure that the "main" persistence.xml is not used for unit tests. -
10. Re: Test database with Seam2, Maven and TestNG?
svadu Jan 16, 2008 2:45 PM (in response to andrew.rw.robinson)I am not sure I understand what exactly is the problem. Considering your test persistence unit has a different name than the one for production doesn't Peristence.createEntityManagerFactory(persistenceUnitName) just work for you?
-
11. Re: Test database with Seam2, Maven and TestNG?
annechou Jan 16, 2008 4:54 PM (in response to andrew.rw.robinson)Would anyone be able to post a complete example of a successful Seam 2.0 SeamTest (as an EJB jar deployed to the embedded container) using Maven and TestNG? We have spent several weeks working on a solution without success.
-
12. Re: Test database with Seam2, Maven and TestNG?
svadu Jan 17, 2008 3:18 AM (in response to andrew.rw.robinson)I don't think there is one, at least not with the multi module project layout.
Vote for the issue if interested: http://jira.jboss.org/jira/browse/JBSEAM-2371 -
13. Re: Test database with Seam2, Maven and TestNG?
cory_prowse Feb 6, 2008 11:19 PM (in response to andrew.rw.robinson)I solved this problem with a bit of trickery using Ant within Maven.
The behaviour is correct to the EJB3 spec of scoping rules for persistence.xml.
I've submitted an issue with Surefire here which goes into more detail, including the ant hack:
http://jira.codehaus.org/browse/SUREFIRE-443