Problems getting example to work (for JSFUnit1.3 and JBoss EPP5.1)
ndrw_cheung Jun 29, 2011 3:47 PMHi, 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 :
--------------
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.