Version 1

    Hello, guys!

     

    I am new to JSF Unit and  Arquillian. Now trying to launch JSFUnit tests on Tomcat server. I tried to start managed, remote and even embeded tomcat configuration but nothing works. I always got some errors. I believe it somehow connected with version conflicts between Arquillian, Tomcat and JSFUnit.

     

    So here is my pom.xml

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>org.jboss.jsfunit</groupId>
        <artifactId>gettingstarted</artifactId>
        <version>2.0.0.Beta2</version>
        <packaging>war</packaging>
        <name>Minimal example for the Getting Started Guide</name>
    
        <repositories>
            <repository>
                <id>jboss-public-repository-group</id>
                <name>JBoss Public Maven Repository Group</name>
                <url>https://repository.jboss.org/nexus/content/groups/public</url>
                <layout>default</layout>
                <releases>
                    <enabled>true</enabled>
                    <updatePolicy>never</updatePolicy>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                    <updatePolicy>never</updatePolicy>
                </snapshots>
            </repository>
        </repositories>
        <pluginRepositories>
            <pluginRepository>
                <id>jboss-public-repository-group</id>
                <name>JBoss Public Repository Group</name>
                <url>http://repository.jboss.org/nexus/content/groups/public/</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </pluginRepository>
        </pluginRepositories>
    
        <properties>
            <version.jsfunit>2.0.0.Beta2</version.jsfunit>
            <version.arquillian>1.0.0.CR4</version.arquillian>
            <version.arquillian.jboss>1.0.0.CR2</version.arquillian.jboss>
            <version.shrinkwrap>1.0.0-beta-5</version.shrinkwrap>
            <version.shrinkwrap.descriptors>1.1.0-alpha-2</version.shrinkwrap.descriptors>
            <version.jboss_60>6.0.0.Final</version.jboss_60>
        </properties>
    
        <dependencies>
    
    
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.8.2</version>
                <scope>test</scope>
            </dependency>
    
            <dependency>
                <groupId>org.jboss.arquillian.junit</groupId>
                <artifactId>arquillian-junit-container</artifactId>
                <version>${version.arquillian}</version>
                <scope>test</scope>
            </dependency>
    
            <dependency>
                <groupId>org.jboss.arquillian.protocol</groupId>
                <artifactId>arquillian-protocol-servlet</artifactId>
                <version>${version.arquillian}</version>
                <scope>test</scope>
            </dependency>
    
            <dependency>
                <groupId>org.jboss.arquillian.container</groupId>
                <artifactId>arquillian-container-spi</artifactId>
                <version>${version.arquillian}</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.jboss.spec.javax.faces</groupId>
                <artifactId>jboss-jsf-api_2.0_spec</artifactId>
                <version>1.0.0.Final</version>
                <scope>provided</scope>
            </dependency>
    
            <dependency>
                <groupId>org.jboss.spec.javax.servlet</groupId>
                <artifactId>jboss-servlet-api_3.0_spec</artifactId>
                <version>1.0.0.Final</version>
                <scope>provided</scope>
            </dependency>
    
            <dependency>
                <groupId>org.jboss.jsfunit</groupId>
                <artifactId>jsfunit-arquillian</artifactId>
                <version>${version.jsfunit}</version>
                <scope>test</scope>
            </dependency>
    
            <dependency>
                <groupId>org.jboss.jsfunit</groupId>
                <artifactId>jboss-jsfunit-core</artifactId>
                <version>${version.jsfunit}</version>
                <scope>test</scope>
            </dependency>
    
            <dependency>
                <groupId>org.jboss.shrinkwrap.descriptors</groupId>
                <artifactId>shrinkwrap-descriptors-impl</artifactId>
                <version>${version.shrinkwrap.descriptors}</version>
                <scope>test</scope>
            </dependency>
    
            <dependency>
                <groupId>org.jboss.shrinkwrap.resolver</groupId>
                <artifactId>shrinkwrap-resolver-api-maven</artifactId>
                <version>${version.shrinkwrap}</version>
                <scope>test</scope>
            </dependency>
    
            <dependency>
                <groupId>org.jboss.shrinkwrap.resolver</groupId>
                <artifactId>shrinkwrap-resolver-impl-maven</artifactId>
                <version>${version.shrinkwrap}</version>
                <scope>test</scope>
            </dependency>
    
            <dependency>
                <groupId>javax.faces</groupId>
                <artifactId>jsf-api</artifactId>
                <version>2.1</version>
    
            </dependency>
            <dependency>
                <groupId>javax.faces</groupId>
                <artifactId>jsf-impl</artifactId>
                <version>2.0.2-FCS</version>
    
            </dependency>
    
            <dependency>
                <groupId>org.jboss.jsfunit</groupId>
                <artifactId>jboss-jsfunit-richfaces</artifactId>
                <version>2.0.0.Beta1</version>
            </dependency>
    
        </dependencies>
    
        <profiles>
    
            <profile>
                <id>tomcat-embedded</id>
                <dependencies>
                    <dependency>
                        <groupId>org.jboss.arquillian.container</groupId>
                        <artifactId>arquillian-tomcat-embedded-6</artifactId>
                        <version>1.0.0.Final-SNAPSHOT</version>
                        <scope>test</scope>
                    </dependency>
                    <dependency>
                        <groupId>org.apache.tomcat</groupId>
                        <artifactId>catalina</artifactId>
                        <version>6.0.29</version>
                        <scope>test</scope>
                    </dependency>
                    <dependency>
                        <groupId>org.apache.tomcat</groupId>
                        <artifactId>coyote</artifactId>
                        <version>6.0.29</version>
                        <scope>provided</scope>
                    </dependency>
                    <dependency>
                        <groupId>org.apache.tomcat</groupId>
                        <artifactId>jasper</artifactId>
                        <version>6.0.29</version>
                        <scope>provided</scope>
                    </dependency>
                    <!-- Weld servlet, EL and JSP required for testing CDI injections -->
                    <dependency>
                        <groupId>org.jboss.weld.servlet</groupId>
                        <artifactId>weld-servlet</artifactId>
                        <version>1.0.1-Final</version>
                        <scope>test</scope>
                    </dependency>
                    <dependency>
                        <groupId>org.glassfish.web</groupId>
                        <artifactId>el-impl</artifactId>
                        <version>2.2</version>
                        <scope>test</scope>
                    </dependency>
                    <dependency>
                        <groupId>javax.servlet.jsp</groupId>
                        <artifactId>jsp-api</artifactId>
                        <version>2.2</version>
                        <scope>test</scope>
                    </dependency>
                </dependencies>
            </profile>
    
    
        </profiles>
    </project>
    
    

     

    arquillian.xml :

    <?xml version="1.0" encoding="UTF-8"?>
    <arquillian xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:schemaLocation="http://jboss.org/schema/arquillian
                 http://jboss.org/schema/arquillian/arquillian-1.0.xsd">
    
        <engine>
            <property name="deploymentExportPath">target/</property>
        </engine>
    
        <container qualifier="tomcat" default="true">
            <configuration>
                <property name="unpackArchive">true</property>
                <property name="user">tomcat</property>
                <property name="pass">tomcat</property>
            </configuration>
        </container>
    
        <defaultProtocol type="Servlet 2.5" />
    
    </arquillian>
    

     

    web.xml

    <?xml version="1.0"?>
    <web-app xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
        version="3.0">
    
        <listener>
            <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
        </listener>
    
      <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
      </servlet>
    
      <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.faces</url-pattern>
      </servlet-mapping>
    
      <welcome-file-list>
        <welcome-file>index.html</welcome-file>
      </welcome-file-list>
    
        <servlet>
        <servlet-name>ServletTestRunner</servlet-name>
        <servlet-class>org.jboss.arquillian.protocol.servlet_3.ServletTestRunner</servlet-class>
        </servlet>
        <servlet-mapping>
        <servlet-name>ServletTestRunner</servlet-name>
        <url-pattern>/ArquillianServletRunner</url-pattern>
        </servlet-mapping>
    
    
    </web-app>
    

     

    HelloJsfTest class from JSFUnit gettingstarted tutorial:

    @RunWith(Arquillian.class)
    public class HelloJSFTest
    {
        // property surefire sys prop setting
        public static final boolean IS_JETTY = (System.getProperty("jetty-embedded") != null);
    
        @Deployment
        public static WebArchive createDeployment() {
            WebArchive war =
                    ShrinkWrap.create(WebArchive.class, "test.war")
                            .setWebXML(new File("src/main/webapp/WEB-INF/web.xml"))
                            .addPackage(Package.getPackage("org.jboss.jsfunit.example.hellojsf")) // my test package
                            .addAsWebResource(new File("src/main/webapp", "index.xhtml"))
                            .addAsWebInfResource(new File("src/main/webapp/WEB-INF/faces-config.xml"), "faces-config.xml");
            System.out.println(war.toString(true)); // for debugging
            return war;
        }
    
        @Test
        @InitialPage("/index.faces")
        public void testInitialPage(JSFServerSession server, JSFClientSession client) throws IOException
        {
            // Test navigation to initial viewID
            Assert.assertEquals("/index.xhtml", server.getCurrentViewID());
    
            // Set the param and submit
            client.setValue("name", "Stan");
            client.click("submit_button");
    
            // Assert that the greeting component is in the component tree and rendered
            UIComponent greeting = server.findComponent("greeting");
            Assert.assertTrue(greeting.isRendered());
    
            System.out.println("\nHALLO WORD from testInitialPage method!");
    
            // Test a managed bean using EL. We cheat and use the request object.
            Assert.assertEquals("Stan", server.getManagedBeanValue("#{request.getParameter('form1:name')}"));
        }
    
    
    }
    
    

     

    Result of running this configuration is following:

    Method createDeployment  successfully launched, I  see the war.toString in the output.

    But  testInitialPage is not launched. There is an error in surefire-reports log. here is it:

    Could not inject method parameters

    at org.jboss.jsfunit.arquillian.container.JSFUnitTestEnricher.resolve(JSFUnitTestEnricher.java:89)

    at org.jboss.arquillian.container.test.impl.execution.LocalTestExecuter.enrichArguments(LocalTestExecuter.java:94)

    at org.jboss.arquillian.container.test.impl.execution.LocalTestExecuter.execute(LocalTestExecuter.java:60)

    ...

     

    Caused by: java.lang.NullPointerException

    at org.jboss.jsfunit.arquillian.container.JSFUnitSessionFactory.findJSFSession(JSFUnitSessionFactory.java:85)

     

     

     

     

    First remark: if I change

    <defaultProtocol type="Servlet 2.5" />
    

    to

    <defaultProtocol type="Servlet 3.0" />
    

    then I got

     

     

    java.lang.IllegalArgumentException: ArquillianServletRunner not found. Could not determine ContextRoot from ProtocolMetadata, please contact DeployableContainer developer.

    at org.jboss.arquillian.protocol.servlet.ServletUtil.determineBaseURI(ServletUtil.java:68)

     

    but servlet org.jboss.arquillian.protocol.servlet_3.ServletTestRunner is specified in web.xml

     

    Second remark: when I try to launch the same project on JBoss(remote or managed) everything works fine.

     

    Any suggestions?

     

    Thanks!!