You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by afryer <ap...@hotmail.com> on 2011/11/29 02:53:43 UTC

tomee-embedded test case best practice?

I'm currently trying to setup automated integration testing of my webapp
which uses ejbs and have been looking at some of the arquillian examples 
https://svn.apache.org/repos/asf/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-moviefun-example/src/test/java/org/superbiz/moviefun
here .

It looks like there's a couple of ways to startup an embedded tomee server
and i was wondering if any way was preferrable to another.

In MoviesHtmlUnitTest.java, the tomee server is started without arquillian
using this code...

@BeforeClass public static void start() throws IOException {
        webApp = createWebApp();
        Properties p = new Properties();
        p.setProperty(EJBContainer.APP_NAME, "moviefun");
        p.setProperty(EJBContainer.PROVIDER, "tomee-embedded"); // need web
feature
        p.setProperty(EJBContainer.MODULES, webApp.getAbsolutePath());
        p.setProperty(EmbeddedTomEEContainer.TOMEE_EJBCONTAINER_HTTP_PORT,
"9999");
        container = EJBContainer.createEJBContainer(p);
    }

In MoviesSeleniumTest.java, the tomee server is started like this...

@Deployment(testable = false)
    public static WebArchive createDeployment() {
        WebArchive archive = ShrinkWrap.create(WebArchive.class,
"moviefun.war")
        		.addClasses(ActionServlet.class, SetupServlet.class, Movie.class,
MovieController.class, Movies.class, MoviesImpl.class, MoviesRemote.class,
JsfUtil.class, PaginationHelper.class, ExampleDataProducer.class,
Examples.class, Setup.class)
        		.addAsResource(new ClassLoaderAsset("META-INF/ejb-jar.xml") ,
"META-INF/ejb-jar.xml")
        		.addAsResource(new ClassLoaderAsset("META-INF/persistence.xml") ,
"META-INF/persistence.xml")
        		.addAsLibraries(new
File("target/test-libs/commons-beanutils.jar"),
        				new File("target/test-libs/commons-codec.jar"),
        				new File("target/test-libs/commons-collections.jar"),
        				new File("target/test-libs/commons-digester.jar"),
        				new File("target/test-libs/commons-logging.jar"),
        				new File("target/test-libs/jstl.jar"),
        				new File("target/test-libs/log4j.jar"),
        				new File("target/test-libs/standard.jar"));
        
        addResources("src/main/webapp", "", archive);
        System.out.println(archive.toString(true));
		return archive;
    }

The first way looks simpler to me, but I'm wondering if I'm missing some
benefit provided by the arquillian way.

Also is there an easy way to just use the .war file created in the target
folder and have that deployed in tomee-embedded.  Programmatically creating
the archive seems like hard work to me if the war file has already been
created, but again being new to all this, i could have easily missed the
point.  I also don't get why you have to manually copy the dependent jars
when you have already specified the jars you need in your maven depedencies. 
This is probably more arquillian related questions than openejb questions
but appreciate any directions or tips i can get since i know openejb dev
guys are working on this sort of integration testing capability.

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

Re: tomee-embedded test case best practice?

Posted by afryer <ap...@hotmail.com>.
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.

Re: tomee-embedded test case best practice?

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi,

What is cool with arquillian is all its plugins. If you don't need them
maybe you don't need arquillian. However i think it manages more easily the
lifecycle of the container and it allows you through shrinkwrap to create
partial archive on the fly.

To use an already created war there is no magic today, you can do as in the
example and simply give the tomee-embedded its path or you can use the
maven t7 plugin to automatically deploy your built war.

Hope it helps...

- Romain

Le 29 nov. 2011 02:54, "afryer" <ap...@hotmail.com> a écrit :

> I'm currently trying to setup automated integration testing of my webapp
> which uses ejbs and have been looking at some of the arquillian examples
>
> https://svn.apache.org/repos/asf/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-moviefun-example/src/test/java/org/superbiz/moviefun
> here .
>
> It looks like there's a couple of ways to startup an embedded tomee server
> and i was wondering if any way was preferrable to another.
>
> In MoviesHtmlUnitTest.java, the tomee server is started without arquillian
> using this code...
>
> @BeforeClass public static void start() throws IOException {
>        webApp = createWebApp();
>        Properties p = new Properties();
>        p.setProperty(EJBContainer.APP_NAME, "moviefun");
>        p.setProperty(EJBContainer.PROVIDER, "tomee-embedded"); // need web
> feature
>        p.setProperty(EJBContainer.MODULES, webApp.getAbsolutePath());
>        p.setProperty(EmbeddedTomEEContainer.TOMEE_EJBCONTAINER_HTTP_PORT,
> "9999");
>        container = EJBContainer.createEJBContainer(p);
>    }
>
> In MoviesSeleniumTest.java, the tomee server is started like this...
>
> @Deployment(testable = false)
>    public static WebArchive createDeployment() {
>        WebArchive archive = ShrinkWrap.create(WebArchive.class,
> "moviefun.war")
>                        .addClasses(ActionServlet.class,
> SetupServlet.class, Movie.class,
> MovieController.class, Movies.class, MoviesImpl.class, MoviesRemote.class,
> JsfUtil.class, PaginationHelper.class, ExampleDataProducer.class,
> Examples.class, Setup.class)
>                        .addAsResource(new
> ClassLoaderAsset("META-INF/ejb-jar.xml") ,
> "META-INF/ejb-jar.xml")
>                        .addAsResource(new
> ClassLoaderAsset("META-INF/persistence.xml") ,
> "META-INF/persistence.xml")
>                        .addAsLibraries(new
> File("target/test-libs/commons-beanutils.jar"),
>                                        new
> File("target/test-libs/commons-codec.jar"),
>                                        new
> File("target/test-libs/commons-collections.jar"),
>                                        new
> File("target/test-libs/commons-digester.jar"),
>                                        new
> File("target/test-libs/commons-logging.jar"),
>                                        new
> File("target/test-libs/jstl.jar"),
>                                        new
> File("target/test-libs/log4j.jar"),
>                                        new
> File("target/test-libs/standard.jar"));
>
>        addResources("src/main/webapp", "", archive);
>        System.out.println(archive.toString(true));
>                return archive;
>    }
>
> The first way looks simpler to me, but I'm wondering if I'm missing some
> benefit provided by the arquillian way.
>
> Also is there an easy way to just use the .war file created in the target
> folder and have that deployed in tomee-embedded.  Programmatically creating
> the archive seems like hard work to me if the war file has already been
> created, but again being new to all this, i could have easily missed the
> point.  I also don't get why you have to manually copy the dependent jars
> when you have already specified the jars you need in your maven
> depedencies.
> This is probably more arquillian related questions than openejb questions
> but appreciate any directions or tips i can get since i know openejb dev
> guys are working on this sort of integration testing capability.
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/tomee-embedded-test-case-best-practice-tp4117711p4117711.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>