EJB3 packaging as jar archive in JBoss 4.2.3
abhishekhp Mar 23, 2012 10:40 AMI am trying to setup an intergration tests for an ejb project with the persistence context being different for the intergration tests. I would like to have the intergration test be executed as part of the maven execution that generates the actual build. The difference would be that the actual build will generate a ejb jar that has the persistence.xml that points to oracle db but the packaging for integration tests using arquillian will general a jar that has the persistence.xml (available as test resource test-persistence.xml) that points to the in memory hsqldb.
Here is how I have my arquillian test setup to programatically replace the persistence.xml using the shrinkwrap API.
{noformat}
// this archive bundles the class files in target classes generated by the actual build including the persistence.xml in source resource that points to oracle db and additional test classes
JavaArchive oracleEJBArchive = ShrinkWrap.create( JavaArchive.class,"async-ejb-test.jar").addClasses(edu.ksu.ome.asyc.test.AsyncITest.class, edu.ksu.ome.async.test.TestCommand.class, edu.ksu.ome.async.test.JNDITree.class);
oracleEJBArchive.as(ExplodedImporter.class).importDirectory(new java.io.File("target/classes"));
// this archive replaces the persitence.xml in the above generated archive with a test-persistence.xml that points to in-memory hsqldb
JavaArchive hsqlEJBArchive = ShrinkWrap.create( JavaArchive.class,"async-ejb-hsql-test.jar").addAsManifestResource("test-persistence.xml", ArchivePaths.create("persistence.xml"));
// note how i am trying to exclude the original persistence.xml while merging from the oracleEJBArchive source
hsqlEJBArchive.merge(oracleEJBArchive, Filters.exclude(".*META-INF.*"));
{noformat}
The problem I am running into is for some reason the replaced persistence.xml is not being recongnized and the async-ejb-hsql-test.jar does not deploy as an EJB. The async-ejb-test.jar deploys just fine and i am sure the test persistence context for hsqldb is correct as if i have the persistence.xml point to the hsqld the jar deploys fine. So i am assuming it has to with the way i am progrmatically packaging the async-ejb-hsql-test.jar that the replaced persistence.xml as a manifest resource is unrecongonized.
Here are the exploded structure of the two jars. I guess on the replaced jar the manifest seems to added last. Could that be the issue. Is there a good way of programattically replacing the persistence.
* Exploded package with the async-ejb-test.jar that works (note i can get this to work if use test-persistence.xml as the actual persistence.xml in src/resources/ without programatically constructing the ejb jar as above
{noformat}
ome@devvm:/as/data/jboss/ome/tmp/jsr88$ jar -xvf test.ear
inflated: lib/arquillian-testenricher-ejb.jar
inflated: lib/arquillian-core.jar
inflated: lib/arquillian-testenricher-resource.jar
inflated: lib/arquillian-junit.jar
inflated: lib/arquillian-testenricher-initialcontext.jar
inflated: async-ejb-test.jar
inflated: arquillian-protocol.war
inflated: META-INF/application.xml
ome@devvm:/as/data/jboss/ome/tmp/jsr88$ jar -xvf async-ejb-test.jar
inflated: rebel.xml
created: META-INF/
inflated: META-INF/persistence.xml
created: edu/
created: edu/ksu/
created: edu/ksu/ome/
created: edu/ksu/ome/async/
created: edu/ksu/ome/async/entity/
inflated: edu/ksu/ome/async/entity/CommandStatus.class
inflated: edu/ksu/ome/async/AsyncCommand.class
created: edu/ksu/ome/async/lib/
inflated: edu/ksu/ome/async/lib/StatusLib.class
inflated: edu/ksu/ome/async/lib/StatusLibLocal.class
inflated: edu/ksu/ome/async/lib/SchedulerLib.class
created: edu/ksu/ome/async/ejb/
inflated: edu/ksu/ome/async/ejb/SchedulerLibEJB.class
inflated: edu/ksu/ome/async/ejb/DefaultListenerEJB.class
inflated: edu/ksu/ome/async/ejb/ViewsEJB.class
inflated: edu/ksu/ome/async/ejb/StatusLibEJB.class
created: edu/ksu/ome/async/test/
inflated: edu/ksu/ome/async/test/AsyncITest.class
inflated: edu/ksu/ome/async/test/JNDITree.class
inflated: edu/ksu/ome/async/test/TestCommand.class
inflated: edu/ksu/ome/async/CommandState.class
created: edu/ksu/ome/async/util/
inflated: edu/ksu/ome/async/util/Services.class
inflated: edu/ksu/ome/async/Util.class
{noformat}
* Exploded package with the async-ejb-hsql-test.jar that fails
{noformat}
ome@devvm:/as/data/jboss/ome/tmp/jsr88$ jar -xvf test.ear
inflated: lib/arquillian-testenricher-ejb.jar
inflated: lib/arquillian-core.jar
inflated: lib/arquillian-testenricher-resource.jar
inflated: lib/arquillian-junit.jar
inflated: lib/arquillian-testenricher-initialcontext.jar
inflated: arquillian-protocol.war
inflated: async-ejb-hsql-test.jar
inflated: META-INF/application.xml
ome@devvm:/as/data/jboss/ome/tmp/jsr88$ jar -xvf async-ejb-hsql-test.jar
inflated: rebel.xml
created: edu/
created: edu/ksu/
created: edu/ksu/ome/
created: edu/ksu/ome/async/
created: edu/ksu/ome/async/entity/
inflated: edu/ksu/ome/async/entity/CommandStatus.class
inflated: edu/ksu/ome/async/AsyncCommand.class
created: edu/ksu/ome/async/lib/
inflated: edu/ksu/ome/async/lib/StatusLib.class
inflated: edu/ksu/ome/async/lib/StatusLibLocal.class
inflated: edu/ksu/ome/async/lib/SchedulerLib.class
created: edu/ksu/ome/async/ejb/
inflated: edu/ksu/ome/async/ejb/SchedulerLibEJB.class
inflated: edu/ksu/ome/async/ejb/DefaultListenerEJB.class
inflated: edu/ksu/ome/async/ejb/ViewsEJB.class
inflated: edu/ksu/ome/async/ejb/StatusLibEJB.class
created: edu/ksu/ome/async/test/
inflated: edu/ksu/ome/async/test/AsyncITest.class
inflated: edu/ksu/ome/async/test/JNDITree.class
inflated: edu/ksu/ome/async/test/TestCommand.class
inflated: edu/ksu/ome/async/CommandState.class
created: edu/ksu/ome/async/util/
inflated: edu/ksu/ome/async/util/Services.class
inflated: edu/ksu/ome/async/Util.class
created: META-INF/
inflated: META-INF/persistence.xml
{noformat}