1 Reply Latest reply on Sep 12, 2013 8:08 PM by John Ament

    How to run an EJB Session Test using Arquillian and Maven?

    William Lovett Newbie

      Hello my astonishingly well informed Arquillianites.


      I've been working with Maven and Arquillian for about 2 weeks now and I'm finally to a point where I'm trying to combine all my disparate knowledge into one usable, deployable setup.  I'm using JBoss Developer Studio (6.0.1.GA), Maven (M2E - Maven Integration), and the latest Arquillian version as of 9/1/2013.  Additionally, my server setup is JBoss EAP 6.1.0 / AS 7.2. 


      First, I'm setting up an EAR using maven comprised of three projects: ear, model and shared.  The shared project holds jar dependencies for the model and (in the future) the view.  The model holds a single entity (project.class), a session bean, and a handful of other xml files.  The ear project declares the model as a dependency and packages everything up nice and neat.  All three maven poms are attached as poms.txt because for some reason this editor is not maintaining the xml formatting.   Deploying this by right-clicking on the ear and selecting Run As -> Run on Server works like a charm.  The model's jar dependencies are put in the Ear's lib folder, the persistence files works, etc.  No errors.


      From here I start to get confused. What am I supposed to do to get running tests?  The pom for my Arquillian project called test is attached as ProjectTestPom.txt  Here are the scenarios I've done and the errors I get.


      1) Declare the model tests as a module/project within the ear and declare the model as a dependency in my test project.  This results in a "ZipException: error in opening zip file" as detailed in log1.txt

      2) Declare the model tests as a separate project outside the ear.  Right-click the ear project Run As -> Run on Server.  Then, with the server running, right click the arquillian project test and select Run As -> Run AS J-Unit Test.  This turns into an java.io.IOException error stating that the server is already running.  I've attached the log as log2.txt and here is my arquillian.xml file.  Note the line  <property name="allowConnectingToRunningServer">true</property>. I thought that was supposed to fix the running server issue.  No luck.  /property>


      <arquillian xmlns="http://jboss.org/schema/arquillian"
      <defaultProtocol type="Servlet 3.0"></defaultProtocol>
      <container qualifier="arquillian-jbossas-managed" default="true">
              <property name="jbossHome">C:\Dev\eap</property>
              <property name="allowConnectingToRunningServer">true</property>


      3) For my third attempt, I try something slightly different from #2.  With the server STOPPED, Instead of selecting the project test, I select the actual SessionTest.java file, right-click Run As -> J Unit Test.  This time I get an error stating


      New missing/unsatisfied dependencies:
            service jboss.naming.context.java.myAppConnDS


      Here's my SessionTest.java file.


      public class SessionTest {
        myAppManagerBean em;
        public static JavaArchive createDeployment() {
        return ShrinkWrap
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
        public void should_create_greeting() {
        List<Project> projectList = em.queryProjectFindAll();


      Here's my persistence file:


      <?xml version="1.0" encoding="UTF-8"?>
      <persistence version="2.0"
        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_2_0.xsd">
        <persistence-unit name="Model" transaction-type="JTA">
        <property name="eclipselink.target-server" value="JBoss" />
        <property name="eclipselink.target-database" value="Oracle" />


      I've done quite a bit of research just to get to this point.  I can deploy a maven ear project with multiple dependencies.  I can get arquillian to run some simple tests by following their getting started guides.  However, I can't get it all to work together.  While there's lots of information out there on pieces here and there, assimilating it together is proving difficult.  Any help would be appreciated. 





      PS: Here are some (definitely not all) links I've used to get this far.







        • 1. Re: How to run an EJB Session Test using Arquillian and Maven?
          John Ament Master



          Honestly, your best bet is to ignore your IDE for a minute when looking at Arquillian.  Then, once you have it working just with Maven, figure out the best way to invoke it from the IDE. 


          I guess, the first question is what are you trying to accomplish?


          If you want to deploy an EAR file, you need to have a deployment that returns an enterprise archive.  That enterprise archive should be constructed very similarly to your real EAR, including application.xml and any dependencies.  You can use the ShrinkWrap maven resolver to look up the dependencies.