6 Replies Latest reply on Mar 2, 2011 8:17 AM by ssilvert

    Does JSFUnit 2.x support EARs?

    denis_k

      Hello everyone,

      I've been playing with JSFUnit2 for past couple of days, and I found it great. However, one questions captures my mind right now: does it support EAR files? For what I'm seeing now, it doesn't - I have the following deployment method:

          @Deployment
          public static EnterpriseArchive createArchive() {
              EnterpriseArchive enterpriseArchive = ...//get somehow
              return enterpriseArchive;
          }
      
      

       

      My test looks like this (pretty useful):

          @Test
          @InitialPage("/login.jsf")
          public void test() {
              int doNothing = 0;
          }
      

       

      And my test  fails with the following error:

      ...
      Caused by: java.lang.ClassCastException: org.jboss.shrinkwrap.impl.base.spec.EnterpriseArchiveImpl cannot be cast to org.jboss.shrinkwrap.api.spec.WebArchive
          at org.jboss.jsfunit.arquillian.JSFUnitApplicationArchiveProcessor.process(JSFUnitApplicationArchiveProcessor.java:41)
          at org.jboss.arquillian.impl.ClientDeploymentGenerator.applyApplicationProcessors(ClientDeploymentGenerator.java:85)
          at org.jboss.arquillian.impl.ClientDeploymentGenerator.generate(ClientDeploymentGenerator.java:60)
      

       

      Indeed, in JSFUnitApplicationArchiveProcessor there is the following piece of code:

         public void process(Archive<?> archive, TestClass tc)
         {
            WebArchive webArchive = (WebArchive)archive;              //this is where the error is thrown
            webArchive.addPackage(Package.getPackage("org.jboss.jsfunit.cdi"));
         }
      

       

      So, it tries to cast my EnterpriseArchive to WebArchive. But EnterpriseArchive is not a descendant of WebArchive, they are distinct class hierarchies.

       

      My question is - does JSFUnit 2.x support EARs at all or am I just doing something wrong?

       

      Thanks,

      Denis

        • 1. Re: Does JSFUnit 2.x support EARs?
          ssilvert

          Hi Denis,

           

          I think it was I who did something wrong.  I'll have to fix the JSFUnitApplicationArchiveProcessor so that it works with EARs as well.

           

          In the mean time, you can hack the jsfunit-arquillian.jar and remove the META-INF/services/org.jboss.arquillian.spi.ApplicationiArchiveProcessor file.  Then add the org.jboss.jsfunit.cdi classes to your WEB-INF/classes manually.

           

          Thanks for reporting this.

           

          Stan

           

          https://issues.jboss.org/browse/JSFUNIT-270

          • 2. Re: Does JSFUnit 2.x support EARs?
            ssilvert

            BTW, I tried to fix this but it's a little harder than I first suspected.  The workaround I suggested probably won't work becaue the JSFUnitArchiveAppender is going to add jars to the root of the EAR instead of WEB-INF/lib in the WAR.  It might be quite awhile before I have the time to provide a fix.

             

            Stan

            • 3. Re: Does JSFUnit 2.x support EARs?
              denis_k

              Thank you for your investigation, Stan.

              Is it possible to construct WAR that would be as functional, as EAR in ShrinkWrap? Will it be possible to use EJBs and PersistentContext and stuff like that? Theoretically, nothing prevents one from doing this.

              • 4. Re: Does JSFUnit 2.x support EARs?
                ssilvert

                Yes, you can do that in JEE6.  You can put EJBs in your WAR.  So if you are running on a JEE6 container you are good to go.  I'm not sure if it works in JBoss AS6 but I think it does.  I know it's not working yet in AS7.

                 

                Stan

                • 5. Does JSFUnit 2.x support EARs?
                  denis_k

                  Ok, I will try this and post my results in a separate discussion here. I think it will be useful for people to know if there are any pitfalls in turning EAR into WAR.

                  BTW, I have tried to hack jsfunit-arquillian jar, and I succeeded. The problem is, as you have mentioned, that it's impossible to add required org.jboss.jsfunit.cdi to the WAR file that settles inside EAR. What I did was copying files from org.jboss.jsfunit.cdi directly to the project, and it did the trick. Of course, this is not an option even for development environment. I have to study ShrinkWrap's sources more closely to detect the way of dealing with WAR file inside EAR file.

                  Thank you for your elaboration.

                   

                  Denis

                  • 6. Does JSFUnit 2.x support EARs?
                    ssilvert

                    Great.  Let me know if you come up with a patch.

                     

                    Stan