-
1. Re: Integration test environmnet not loading import.sql successfully, maven build
kapitanpetko Mar 16, 2009 3:20 AM (in response to troy.sellers)It would probably be easier to use Maven filters to set up persistence.xml for test and production
instead of juggling the classpath. Something like:persitence.xml:
<persistence-unit name="pu"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <jta-data-source>java:/MyPuDS</jta-data-source> <properties> <property name="hibernate.dialect" value="${hibernate.dialect}" /> ... </properties> ... </persistence.unit>
src/main/filters/dev.properties:
hibernate.dialect=org.hibernate.dialect.HSQLDialect
src/main/filters/prod.properties:
hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
Of course you will also need to set up your pom.xml to use filters for this to work.
-
2. Re: Integration test environmnet not loading import.sql successfully, maven build
troy.sellers Mar 16, 2009 4:25 AM (in response to troy.sellers)Hi Nikolay,
Thanks for the response on that, sounds like a good solution to the problem.
I found this http://jira.codehaus.org/browse/SUREFIRE-443 that talks about why this doesn't work very well for JBoss and Maven. The Maven hack that is described in here works for me, but you have proposed a far more elegant solution i think.Cheers,
Troy -
3. Re: Integration test environmnet not loading import.sql successfully, maven build
troy.sellers Mar 16, 2009 5:25 AM (in response to troy.sellers)Hi,
After some investigation this doesn't seem as promising as I had hoped. I wanted to apply the filters during the test deployment, then again for the build of the artifact.
Can't see a way to do this..Cheers,
Troy -
4. Re: Integration test environmnet not loading import.sql successfully, maven build
kapitanpetko Mar 16, 2009 5:51 AM (in response to troy.sellers)
Troy Sellers wrote on Mar 16, 2009 05:25:
I wanted to apply the filters during the test deployment, then again for the build of the artifact.
e a way to do this..Why do you need to filter twice? You can setup a filter per resource, so you can have one for your
presistence.xml (see below) and for any other resources you may need.You can also have profiles, so that dev.properties is used by default, and prod.properties when you
build a production version (say: mvn -Pprod package).<resource> <filtering>true</filtering> <directory>src/main/resources/META-INF</directory> <includes> <include>**/*.xml</include> </includes> <targetPath>META-INF</targetPath> </resource>
-
5. Re: Integration test environmnet not loading import.sql successfully, maven build
troy.sellers Mar 16, 2009 11:30 PM (in response to troy.sellers)Hi,
I think i might have confused the issue, problem is not changing this to target a specific environment, rather that it needs to run for a test phase in the build (using Hypersonic) and then be ready for deployment to an Oracle environment (dev / test / prod.. doesn't matter).
The persistence.xml needs to be pointing to an HSQL database while the integration tests are running, then, once build is finished, it needs to be pointing to the Oracle datasource that is used for dev / prod.
The problem seems to lie with the way Maven packages its compiled test resources, using two directories, classes and test-classes. Adding a persistence.xml in with the test resources doesn't overwrite the persistence.xml in the main resources.
As both of these are copied to the classpath, and given that jboss embedded seems to load both of these directories using separate class loaders (just a guess from witnessing behavior!), when the entities of my application are trying to load they are failing because the main persistence.xml specifies an Oracle9iDialect.This is probably something that the maven surefire plugin should handle (maybe a 'combine-resources' flag?) although they have listed this as a minor priority.
Cheers,
Troy -
6. Re: Integration test environmnet not loading import.sql successfully, maven build
kapitanpetko Mar 17, 2009 2:46 AM (in response to troy.sellers)
Troy Sellers wrote on Mar 16, 2009 23:30:
I think i might have confused the issue, problem is not changing this to target a specific environment, rather that it needs to run for a test phase in the build (using Hypersonic) and then be ready for deployment to an Oracle environment (dev / test / prod.. doesn't matter).OK, I see what you are trying to do. While this maybe doable, it is probably not worth the trouble. Since you are running your
integration tests in HSQL (not Oracle) your test application is actually different from your production one (different configuration).
So instead of trying to replace presistence.xml and friends before deployment, simply build with a different profile. Yes, it requires
an additional step (or two), but it is actually cleaner and ensures that none of your test code/configurations end up in production.To test:
mvn -Pdev test
To deploy production:
mvn -Pprod deploy
HTH