After much head banging I managed to work out how to create an almost
identical war file to deploy using arquillian.  I'm posting the code here
because I found it pretty difficult to work out how to do this...

        @Deployment
        public static WebArchive createTestArchive() {
                WebArchive war = ShrinkWrap.create(WebArchive.class, 
"test.war");
                
                // adds every dependency from the pom.xml with a scope of 
compile
                war.addAsLibraries(
                                DependencyResolvers
                                        .use(MavenDependencyResolver.class)
                                        .includeDependenciesFromPom("pom.xml")
                                        .resolveAs(JavaArchive.class, new 
ScopeFilter("compile"))
                                );
                
                // add any other jars in the src folder.  Could make this 
generic.
                war.addAsLibrary(new
File("src/main/webapp/WEB-INF/lib/jquery-ui-1.8.9.jar"));
                
                // adds everything in target/classes to the war file 
WEB-INF/classes
folder
                war.addAsResource(new File("target/classes"), "");
                
                // add everything in /src/main/webapp but filter out .svn 
directory
                JavaArchive webappFolder = ShrinkWrap.create(JavaArchive.class,
"webappFolder.jar");
        
webappFolder.as(ExplodedImporter.class).importDirectory("src/main/webapp");
                war.merge(webappFolder, "", new Filter<ArchivePath>() {
                        @Override
                        public boolean include(ArchivePath ap) {
                                String path = ap.get();
                                return (!path.contains(".svn") && 
!path.contains("context.xml"));
                        }
                        
                });

                // uncomment this if you want to examine the war file
                //war.as(ZipExporter.class).exportTo(new File("test.war"));
                        
                return war;
        }

--
View this message in context: 
http://openejb.979440.n4.nabble.com/tomee-embedded-test-case-best-practice-tp4117711p4122164.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Reply via email to