7 Replies Latest reply on Nov 24, 2010 3:46 PM by aslak

    Glassfish remote 3: failing test case

    ljnelson

      Still enough of a rookie with Arquillian that I want to see if this is a Glassfish problem or an Arquillian problem.

       

      The following test case fails.  The deployment ear is deliberately stupid: there is one testCase.jar in its lib directory, containing only the test case class itself (and a META-INF/beans.xml):

       

      @RunWith(Arquillian.class)

      public class TestCase {

       

        @Deployment

        public static EnterpriseArchive createEar() {

          final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, "test.ear");

          assertNotNull(ear);

       

          final JavaArchive testCaseJar = ShrinkWrap.create(JavaArchive.class, "testCase.jar");

          assertNotNull(testCaseJar);

          testCaseJar.addClass(new Object() {}.getClass().getEnclosingClass());

          testCaseJar.addManifestResource(EmptyAsset.INSTANCE, "beans.xml");

          System.out.println(testCaseJar.toString(true));

       

          ear.addLibrary(testCaseJar);

       

          System.out.println(ear.toString(true));

          return ear;

        }

       

        @Inject

        private Gorp bean;

       

        @Test

        public void hi() {

          assertNotNull(this.bean);

        }

       

        public static class SessionScopedBean implements Serializable {

       

          public String sayHi() {

            return "Hi!";

          }

       

        }

       

        @Stateless

        public static class Gorp {

       

          @Inject

          private SessionScopedBean bean;

       

          public String sayHi() {

            return this.bean.sayHi();

          }

       

        }

       

      }

       

      Glassfish 3.1 b30.  The error is a simple assertion failure; the injected Gorp reference is null.


      Best,

      Laird

        • 1. Re: Glassfish remote 3: failing test case
          ljnelson

          (The SessionScopedBean is named that because originally I was trying to get it injected with @SessionScoped on it.  But that didn't work, so I fell back on just @Dependent scope.)

          • 2. Re: Glassfish remote 3: failing test case
            aslak

            Could you try to just return the JavaArchive, not the EnterpriseArhcive ?

             

            and what is the output of System.out.println(testCaseJar.toString(true)); ?

            • 3. Re: Glassfish remote 3: failing test case
              ljnelson

              First, the output:

               

              -------------------------------------------------------
              T E S T S
              -------------------------------------------------------
              Running ljnelson.weld761.TestCase
              testCase.jar:
              /META-INF/
              /META-INF/beans.xml
              /ljnelson/
              /ljnelson/weld761/
              /ljnelson/weld761/TestCase$SessionScopedBean.class
              /ljnelson/weld761/TestCase$1.class
              /ljnelson/weld761/TestCase$Gorp.class
              /ljnelson/weld761/TestCase.class
              test.ear:
              /lib/
              /lib/testCase.jar

               

              Now, on to the other thing.  :-)

               

              L

              • 4. Re: Glassfish remote 3: failing test case
                ljnelson

                That works.  So it would appear, then, I've got a bug in Glassfish, right?

                • 5. Re: Glassfish remote 3: failing test case
                  aslak

                  No, it's probably due to the hirarchy of BeanManagers..

                   

                  pr CDI spec a BeanManager is only exposed/created if a EE module contains a beans.xml.

                   

                  Your jar should be threated as a EE Module since it contains a @Statless, but the Arquillian Test runner using a War, can not see the ejb jars bean manager. We're working on that part..

                   

                  But when deployed as a Jar alone(it becomes a war) or a war, they are all in the same context..

                  • 6. Re: Glassfish remote 3: failing test case
                    ljnelson

                    Any hackish way to affect the Arquillian war itself?

                    • 7. Re: Glassfish remote 3: failing test case
                      aslak

                      hmm.. you can implement the ClassContextAppender SPI to add a EventHandler registered for callbacks on BeforeDeploy. Then get the Archive<?> from Context and manipulate it. That is tho your final Deployment so you'll have to find the test.war inside the ear and add a beans.xml to it..