1 Reply Latest reply on Jun 10, 2013 11:21 PM by sm4

    JSFUnit + TestNG + Arquillian on JBoss 7, Could not inject method parameters

    sm4

      I am using Arquillian for some time now. Successfuly migrated EJB, MBeans and some Seam integration tests. I am having problems with JSF tests though. I am looking for the FacesRequest (from SeamTest) replacement. I have tried JSFUnit, but without success. The only thing I really need is to get JSFSession, which I am not getting due to HttpSession being null. That results in:

       

      Caused by: java.lang.NullPointerException
          at org.jboss.jsfunit.arquillian.container.JSFUnitSessionFactory.findJSFSession(JSFUnitSessionFactory.java:85)
          at org.jboss.jsfunit.arquillian.container.JSFUnitSessionFactory.getJSFServerSession(JSFUnitSessionFactory.java:70)
          at org.jboss.jsfunit.arquillian.container.JSFUnitTestEnricher.resolve(JSFUnitTestEnricher.java:84)
          ... 85 more
      

       

      And that of course ends with test result like this:

       

      Could not inject method parameters
      

       

      Here are the relevant parts of my code:

       

      arquillian.xml

       

          <defaultProtocol type="Servlet 3.0"></defaultProtocol>    <container qualifier="jboss7" default="true">
              <configuration>
      ...        </configuration>
      
      

       

      MyTest class


      public class MyTest extends Arquillian {
           
          @Deployment
          public static EnterpriseArchive createDeployment() {
      
              EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, "myear.ear");
              ear.addAsManifestResource("jboss-deployment-structure.xml");
      
              final WebArchive war = ShrinkWrap.create(WebArchive.class, "test.war")
                      .addAsWebInfResource("WEB-INF/faces-config.xml")
                      .addAsWebInfResource("WEB-INF/web.xml")
                      .addClass(MyTest.class)
                      .addAsWebResource("index.xhtml");
      
              
              ear.addAsModule(Testable.archiveToTest(war));
              
              return ear;
          }    
      
      
          @Test(dataProvider = Arquillian.ARQUILLIAN_DATA_PROVIDER)
          @InitialPage("/test/index.faces")
          public void testOne(JSFServerSession server, JSFClientSession client)
                  throws IOException {
              System.out.println("inside JSFUNIT unit one");
      
          }
      }
      

       

      I have tried to set @InitialPage value to

       

      /test/index.faces, /test/index.xhtml, /index.faces, /index.xhtml, / and ""
      

       

      None of these work.

       

      web.xml, faces-config.xml, jboss-deployment-structure.xml

      web.xml is pretty standard sample-jsf web.xml (mapping the servlet to *.faces), faces-config.xml has empty <faces-config> tag just with version and jboss descriptor simply adds jsf dependencies

       

       

      Attached is my complete project stripped down to a bare minimum. I had to play a bit with the dependencies, because I am using Arquillian 1.0.3.Final, which doesn't play very well with JSFUnit 2.0.0.Beta2. Don't mind the project name, there is no seam (anymore).

       

      Any help with my setup will be appreaciated. Also  any other way how to simply replace FacesRequest testing is welcome. Thanks.

        • 1. Re: JSFUnit + TestNG + Arquillian on JBoss 7, Could not inject method parameters
          sm4

          I have finally found a solution to this problem. JSFUnit expects certain filters to be running. Using `Servet 3.0` protocol, these should be added automatically. But they are not. That's why I am not getting injected anything.

           

          I have downloaded JSFUnit Arquillian integration sources and found what needs to be added:

           

          jsfunit-arquillian-2.0.0.Beta2-sources.jar/org/jboss/arquillian/jsfunit/internals/web-fragment.xml
          

           

          Added it manually to your `web.xml` and everything worked as expected. Here is the relevant part:

           

              <filter>
                <filter-name>JSFUnitCleanupTestTreadFilter</filter-name>
                <filter-class>org.jboss.jsfunit.arquillian.container.JSFUnitCleanupTestTreadFilter</filter-class>
              </filter>
          
              <filter>
                <filter-name>JSFUnitFilter</filter-name>
                <filter-class>org.jboss.jsfunit.framework.JSFUnitFilter</filter-class>
              </filter>
          
              <filter-mapping>
                <filter-name>JSFUnitCleanupTestTreadFilter</filter-name>
                <url-pattern>/ArquillianServletRunner</url-pattern>
              </filter-mapping>    
          
              <filter-mapping>
                <filter-name>JSFUnitFilter</filter-name>
                <url-pattern>/ArquillianServletRunner</url-pattern>
              </filter-mapping>