5 Replies Latest reply on Jul 5, 2011 11:08 AM by ndrw_cheung

    Problems getting example to work (for JSFUnit1.3 and JBoss EPP5.1)

    ndrw_cheung

      Hi, all. I'm trying to build a sample application that uses JSFUnit. However, I cannot get it to work  (I got a 404 error). Code snippets and configuration files are below.

       

      Infrastructure :

      JBoss EPP5.1

       

      Also copied the JSFUnit AS5 Microcontainer deployer to /server/myNode/deployers folder and restarted the application server. The name of the war file is SampleJSFUnit-jsfunit.war.

       

      I've tried different variations of URL to execute the JSFUnit test, but always got a 404 error.

       

      Variations tried :

       

      http://localhost:8080/JsfUnitTest/ServletTestRunner?suite=com.sample.JSFUnitTest&xsl=cactus-report.xsl

      http://localhost:8080/JSFUnitTest/ServletTestRunner?suite=com.sample.JSFUnitTest&xsl=cactus-report.xsl

      http://localhost:8080/SampleJsfUnitTest/ServletTestRunner?suite=com.sample.JSFUnitTest&xsl=cactus-report.xsl

      http://localhost:8080/SampleJsfUnitTest-jsfunit/ServletTestRunner?suite=com.sample.JSFUnitTest&xsl=cactus-report.xsl

       

      --------------

       

      Jar files in WEB-INF/lib:

      -ant-1.5.4.jar

      -aspectjrt-1.2.1.jar

      -cactus-13-1.7.1.jar

      -cactus-ant-13-1.7.1.jar

      -cargo-0.5.jar

      -commons-codec-1.3.jar

      -commons-httpclient-3.1.jar

      -commons-io-1.4.jar

      -commons-lang-2.4.jar

      -cssparser-0.9.5.jar

      -htmlunit-2.4.jar

      -htmlunit-core-js-2.4.jar

      -jboss-jsfunit-core-1.3.0.Final.jar

      -junit-3.8.1.jar

      -nekohtml-1.9.9.jar

      -sac-1.3.jar

       

      (I have also tried adding in commons-logging-1.1.1.jar and common-collections-3.2.jar but they don't make a difference).http://repo1.maven.org/maven2/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar
       

      ------------------------

       

      web.xml :

       

       

      <web-app id="WebApp_ID" version="2.5" 
          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_2_5.xsd"> 
          <context-param> 
              <param-name>com.sun.faces.enableRestoreView11Compatibility</param-name> 
              <param-value>true</param-value> 
          </context-param> 
       
          <display-name>JsfUnitTest</display-name> 
          <filter> 
              <filter-name>JSFUnitFilter</filter-name> 
              <filter-class>org.jboss.jsfunit.framework.JSFUnitFilter</filter-class> 
          </filter> 
       
          <filter-mapping> 
              <filter-name>JSFUnitFilter</filter-name> 
              <servlet-name>ServletTestRunner</servlet-name> 
          </filter-mapping> 
       
          <filter-mapping> 
              <filter-name>JSFUnitFilter</filter-name> 
              <servlet-name>ServletRedirector</servlet-name> 
          </filter-mapping> 
       
          <servlet> 
              <servlet-name>Faces Config</servlet-name> 
              <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> 
          </servlet> 
          <servlet-mapping> 
              <servlet-name>Faces Config</servlet-name> 
              <url-pattern>*.jsf</url-pattern> 
          </servlet-mapping> 
       
          <servlet> 
              <servlet-name>ServletRedirector</servlet-name> 
              <servlet-class>org.jboss.jsfunit.framework.JSFUnitServletRedirector</servlet-class> 
          </servlet> 
       
          <servlet> 
              <servlet-name>ServletTestRunner</servlet-name> 
              <servlet-class>org.apache.cactus.server.runner.ServletTestRunner</servlet-class> 
          </servlet> 
       
          <servlet-mapping> 
              <servlet-name>ServletRedirector</servlet-name> 
              <url-pattern>/ServletRedirector</url-pattern> 
          </servlet-mapping> 
       
          <servlet-mapping> 
              <servlet-name>ServletTestRunner</servlet-name> 
              <url-pattern>/ServletTestRunner</url-pattern> 
          </servlet-mapping> 
       
          <welcome-file-list> 
              <welcome-file>index.html</welcome-file> 
              <welcome-file>index.htm</welcome-file> 
              <welcome-file>index.jsp</welcome-file> 
              <welcome-file>default.html</welcome-file> 
              <welcome-file>default.htm</welcome-file> 
              <welcome-file>default.jsp</welcome-file> 
          </welcome-file-list> 
          <login-config> 
              <auth-method>BASIC</auth-method> 
          </login-config> 
      </web-app> 

       

      ----------------------------

       

      jsp pages : (index.jsp)

       

      <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>

      <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>       

          <html> 

          <body> 

           <f:view>   

             <h:form id="form1">              

               <h:outputText value="Enter your name:"   id="prompt"/>              

               <h:inputText value="#{bean.username}" id="username"/> 

               <h:inputText value="#{bean.password}" id="password"/>         

               <br/>      

             <h:commandButton value="Submit" action="#{bean.login}" id="login"/>      

             </h:form> 

          </f:view> 

          </body> 

          </html>

       

       

      -----------------------

      jsp pages : (welcome.jsp)

       

       

      <?xml version="1.0" encoding="ISO-8859-1" ?>

      <%@ page language="java" contentType="text/html; charset=ISO-8859-1"

          pageEncoding="ISO-8859-1"%>

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

      <html xmlns="http://www.w3.org/1999/xhtml">

      <head>

      <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />

      <title>Insert title here</title>

      </head>

      <body>

      welcome!

      </body>

      </html>

       

      ----------------------

       

       

      Backing bean : (MyBean.java)

       

      package sample;

       

      public class MyBean {

          String username="guest"; 

          String password="guest"; 

          public String getUsername() { 

              return username; 

          } 

          public void setUsername(String username) { 

              this.username = username; 

          } 

          public String getPassword() { 

              return password; 

          } 

          public void setPassword(String password) { 

              this.password = password; 

          } 

           

          public String login() { 

              if (username != null && username.equals("john") && 

                  password != null && password.equals("ripple")) { 

                      return "success"; 

                  } 

              return "failure"; 

          } 

      }

       

       

      ----------------------

       

      faces-config.xml :

       

      <faces-config 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-facesconfig_1_2.xsd"

                    version="1.2">

         <managed-bean>

            <managed-bean-name>bean</managed-bean-name>

            <managed-bean-class>

               sample.MyBean

            </managed-bean-class>

            <managed-bean-scope>request</managed-bean-scope>

         </managed-bean>

       

         <navigation-rule>

            <navigation-case>

               <from-outcome>success</from-outcome>

               <to-view-id>/jsp/welcome.jsp</to-view-id>

            </navigation-case>

         </navigation-rule>

       

         <navigation-rule>

            <navigation-case>

               <from-outcome>failure</from-outcome>

               <to-view-id>/jsp/index.jsp</to-view-id>

            </navigation-case>

         </navigation-rule>

        

      </faces-config>

       

      --------------------

       

      JSFTests

       

      cactus.properties file (under WEB-INF folder) :

       

      cactus.contextURL=http://localhost:8080/JsfUnitTest

      cactus.servletRedirectorName=ServletRedirector

      cactus.jspRedirectorName=JspRedirector

      cactus.filterRedirectorName=cactus.filterRedirectorName

       

       

      ----------------------

       

      cactus-report.xsl file (in the root folder inside the war file)

       

      ---------------

       

      Test case (JSFUnitTest.java) :

       

      package com.sample;

      import java.io.IOException; 

       

      import org.jboss.jsfunit.jsfsession.JSFClientSession; 

      import org.jboss.jsfunit.jsfsession.JSFServerSession; 

      import org.jboss.jsfunit.jsfsession.JSFSession; 

       

      import junit.framework.Test; 

      import junit.framework.TestSuite; 

       

      public class JSFUnitTest extends org.apache.cactus.ServletTestCase   {

           public static Test suite() 

             { 

                return new TestSuite( JSFUnitTest.class ); 

             } 

          

           public void testInitialPage() throws IOException 

             { 

                // Send an HTTP request for the initial page 

                JSFSession jsfSession = new JSFSession("/index.jsf"); 

                 

                // A JSFClientSession emulates the browser and lets you test HTML 

                JSFClientSession client = jsfSession.getJSFClientSession(); 

                 

                // A JSFServerSession gives you access to JSF state       

                JSFServerSession server = jsfSession.getJSFServerSession(); 

           

                // Test navigation to initial viewID 

                assertEquals("/index.jsp", server.getCurrentViewID()); 

           

                // Assert that the current value of username is guest 

                assertEquals("guest", server.getManagedBeanValue("#{bean.name}"));   

                 

                // set values and hit login 

                 

                client.setValue("form1:username", "john"); 

                client.setValue("form1:password", "ripple"); 

                client.click("login"); 

                // Test navigation  

                assertEquals("/welcome.jsp", server.getCurrentViewID()); 

                 

             } 

      }

       

       

      ----------------

       

      Any help is appreciated.

       

        -Andrew

       

      P.S. I have also tried to use the example in the "GettingStarted" guide (http://community.jboss.org/docs/DOC-9819?uniqueTitle=false), but couldn't  make it work either.

        • 1. Re: Problems getting example to work (for JSFUnit1.3 and JBoss EPP5.1)
          ssilvert

          If you are using the AS5 Microcontainer Deployer then you don't need to add anything to your WAR to make JSFUnit work.  So you don't need the JSFUnit declarations in web.xml and you don't need any JSFUnit-related jars.  You also don't need to bundle cactus.properties or cactus-report.xsl.  That's the beauty of the deployer - it adds everything you need at deploy time.

           

          However (by default) you need to name your WAR in such a way that the deployer will recognize it as a JSFUnit WAR.  Since you are naming your WAR with the -jsfunit extension, your web context will (again, by default) be changed.  So the way to kick off tests from your browser is to use the correct context name.  In your case, something like this should work:

           

          http://localhost:8080/SampleJsfUnit-jsfunit/ServletTestRunner?suite=com.sample.JSFUnitTest&xsl=cactus-report.xsl

           

          I noticed above that you said your WAR was named "SampleJSFUnit-jsfunit.war".  But the URL you posted had "SampleJSFUnitTest-jsfunit.war".  So maybe that's your whole problem.

           

          Stan

          • 2. Re: Problems getting example to work (for JSFUnit1.3 and JBoss EPP5.1)
            ndrw_cheung

            Hi, Stan. Thanks for the pointers. So I followed your suggestion and removed all the jar files listed in my original post from WEB-INF/lib; added a reference to the AS5 Microcontainer Deployer jar file since I have a JSFUnit test class in my code (otherwise it won't compile); removed the cactus.properties and the cactus-report.xsl files; modified the web.xml file to become the following:

             

            <web-app id="WebApp_ID" version="2.5" 

                    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_2_5.xsd"> 

                    <context-param> 

                        <param-name>com.sun.faces.enableRestoreView11Compatibility</param-name> 

                        <param-value>true</param-value> 

                    </context-param> 

                  <!--

                    <display-name>JsfUnitTest</display-name> 

                    <filter> 

                        <filter-name>JSFUnitFilter</filter-name> 

                        <filter-class>org.jboss.jsfunit.framework.JSFUnitFilter</filter-class> 

                    </filter> 

                 

                    <filter-mapping> 

                        <filter-name>JSFUnitFilter</filter-name> 

                        <servlet-name>ServletTestRunner</servlet-name> 

                    </filter-mapping> 

                 

                    <filter-mapping> 

                        <filter-name>JSFUnitFilter</filter-name> 

                        <servlet-name>ServletRedirector</servlet-name> 

                    </filter-mapping> 

                  -->

                    <servlet> 

                        <servlet-name>Faces Config</servlet-name> 

                        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> 

                    </servlet> 

                    <servlet-mapping> 

                        <servlet-name>Faces Config</servlet-name> 

                        <url-pattern>*.jsf</url-pattern> 

                    </servlet-mapping> 

                  <!-- 

                    <servlet> 

                        <servlet-name>ServletRedirector</servlet-name> 

                        <servlet-class>org.jboss.jsfunit.framework.JSFUnitServletRedirector</servlet-class> 

                    </servlet> 

                 

                    <servlet> 

                        <servlet-name>ServletTestRunner</servlet-name> 

                        <servlet-class>org.apache.cactus.server.runner.ServletTestRunner</servlet-class> 

                    </servlet> 

                   

                     -->

                     <!--

                    <servlet-mapping> 

                        <servlet-name>ServletRedirector</servlet-name> 

                        <url-pattern>/ServletRedirector</url-pattern> 

                    </servlet-mapping> 

                 

                    <servlet-mapping> 

                        <servlet-name>ServletTestRunner</servlet-name> 

                        <url-pattern>/ServletTestRunner</url-pattern> 

                    </servlet-mapping> 

                -->

                    <welcome-file-list> 

                        <welcome-file>index.html</welcome-file> 

                        <welcome-file>index.htm</welcome-file> 

                        <welcome-file>index.jsp</welcome-file> 

                        <welcome-file>default.html</welcome-file> 

                        <welcome-file>default.htm</welcome-file> 

                        <welcome-file>default.jsp</welcome-file> 

                    </welcome-file-list> 

                    <login-config> 

                        <auth-method>BASIC</auth-method> 

                    </login-config> 

                </web-app> 

             

            ----------------

             

            I use the url you suggested :

             

            http://localhost:8080/SampleJsfUnit-jsfunit/ServletTestRunner?suite=com.sample.JSFUnitTest&xsl=cactus-report.xsl

             

            However, it still doesn't work.

             

            The server.log file contains the following after I deploy the war file:

             

            011-06-30 15:34:58,571 WARN  [org.jboss.jsfunit.microdeployer.JSFUnitDeployer] (HDScanner) Unable to add URL to classpath: file:/C:/jbdevstudio40/jboss-eap/jboss-as/server/Node01//jsfunitTests

            2011-06-30 15:34:58,572 INFO  [org.jboss.jsfunit.microdeployer.JSFUnitDeployer] (HDScanner) Added JSFUnit to vfszip:/C:/jbdevstudio40/jboss-eap/jboss-as/server/Node01/deploy/SampleJSFUnit-jsfunit.war/

            2011-06-30 15:34:59,454 INFO  [org.jboss.web.tomcat.service.deployers.TomcatDeployment] (HDScanner) deploy, ctxPath=/SampleJSFUnit-jsfunit

            2011-06-30 15:34:59,612 INFO  [javax.enterprise.resource.webcontainer.jsf.config] (HDScanner) Initializing Mojarra (1.2_13-b01-FCS) for context '/SampleJSFUnit-jsfunit'

            2011-06-30 15:39:27,400 INFO  [org.jboss.web.tomcat.service.deployers.TomcatDeployment] (HDScanner) undeploy, ctxPath=/SampleJSFUnit-jsfunit

            2011-06-30 15:39:27,404 WARN  [org.exoplatform.portal.resource.MainResourceResolver] (HDScanner) Cannot find servlet context module

            2011-06-30 15:39:27,408 WARN  [org.exoplatform.portal.resource.MainResourceResolver] (HDScanner) Cannot find servlet context module

            2011-06-30 15:39:27,410 WARN  [org.exoplatform.portal.resource.MainResourceResolver] (HDScanner) Cannot find servlet context module

            2011-06-30 15:39:28,477 WARN  [org.jboss.jsfunit.microdeployer.JSFUnitDeployer] (HDScanner) Unable to add URL to classpath: file:/C:/jbdevstudio40/jboss-eap/jboss-as/server/Node01//jsfunitTests

            2011-06-30 15:39:28,478 INFO  [org.jboss.jsfunit.microdeployer.JSFUnitDeployer] (HDScanner) Added JSFUnit to vfszip:/C:/jbdevstudio40/jboss-eap/jboss-as/server/Node01/deploy/SampleJSFUnit-jsfunit.war/

            2011-06-30 15:39:28,553 INFO  [org.jboss.web.tomcat.service.deployers.TomcatDeployment] (HDScanner) deploy, ctxPath=/SampleJSFUnit-jsfunit

            2011-06-30 15:39:28,654 INFO  [javax.enterprise.resource.webcontainer.jsf.config] (HDScanner) Initializing Mojarra (1.2_13-b01-FCS) for context '/SampleJSFUnit-jsfunit'

             

            --------------------

             

            I opened the war file to examine the contents but didn't notice any JSFUnit stuff added there (should I be expecting the Microcontainer deployer to add things in here as you said?)

             

            Thanks in advance for answering.

             

              -Andrew

            1 of 1 people found this helpful
            • 3. Re: Problems getting example to work (for JSFUnit1.3 and JBoss EPP5.1)
              ssilvert

              The deployer won't physically add anything to your WAR.  It just adds things to the classpath so JSFUnit can find what it needs.

               

              Did you get a different error message this time?  I don't think you will get a 404 any more as I see you are using the correct context path in your URL:

              2011-06-30 15:39:28,553 INFO  [org.jboss.web.tomcat.service.deployers.TomcatDeployment] (HDScanner) deploy, ctxPath=/SampleJSFUnit-jsfunit

               

              Stan

              • 4. Re: Problems getting example to work (for JSFUnit1.3 and JBoss EPP5.1)
                ndrw_cheung

                Hi, Stan. I got the same 404 error message.

                 

                If the deployer just adds things to the classpath, the error log trace that I quoted above seems to show that there is a problem adding stuff to the classpath:

                 

                >Unable to add URL to classpath: file:/C:/jbdevstudio40/jboss-eap/jboss-as/server/Node01//jsfunitTests

                 

                  -Andrew

                • 5. Re: Problems getting example to work (for JSFUnit1.3 and JBoss EPP5.1)
                  ndrw_cheung

                  OK I found what I did wrong : Incorrect case in "SampleJsfUnit-jsfunit"  (it should be SampleJSFUnit-jsfunit in the url).

                   

                  Correct URL:

                  http://localhost:8080/SampleJSFUnit-jsfunit/ServletTestRunner?suite=com.sample.JSFUnitTest&xsl=cactus-report.xsl

                   

                     -Andrew