1 Reply Latest reply on Feb 8, 2011 9:32 AM by windigo

    embedded Junit testing of an EAR in Eclipse

    windigo Newbie

      Hallo I'm using Eclipse, JBoss 6 and JBoss Tools to develop my Application. I splitted the application in several projects - something like that:



      - commonEJB    

      - commonJPA 

      - applicationEJB

      - applicationJPA


      In the common*-Projects are some utility- and generic-classes. The applicationEJB-Project got a Eclipse-reference to the common*-Projects so I'm able to use CDI to inject EJBs from the commonEJB-project into the applicationEJB-Project.


      for example:

      public class ApplicationBean {
      CommonUtilityBean commonBean;


      Building the application every project is compiled and zipped in a JAR-file which is bundled into one EAR-file. The deployment of the application is fine because all Bean-classes in the ear-file are loaded into the same classloader. I've no referencing problems.


      My problem is that I dont know how to junit-test the applicationBeans which have dependencies to the commonEJB-project. Im using the embedded EJBContainer in jboss 6


      Properties ctxProps = new Properties();
      ejbContainer = EJBContainer.createEJBContainer(ctxProps);
      context = ejbContainer.getContext();


      Doing the Junit test in Eclipse I set up the classpath in the launch-configuration of JUnit that first of all the commonEJBs are published to the embedded ejbcontainer and afterwards the applicationEJB.jar. In the launch-configuration I can only add the both EJB- and JPA-projects to the classpath. Its not possible to add the Enterprise-Application-Project which holds the information of bundling the ear-file.

      It seems that it's not possible to "deploy" two jars containing EJBs (applicationEJB.jar and commonEJB.jar) to the embedded EJBcontainer so that they are in the same classloader.


      Is it possible to junit-test my application deploing the whole ear-file to the embedded-container or do i have to bundle my beans of both applicationEJB.jar and commonEJB.jar into one jar-file?