-
1. Re: doubts navigation using JSFUnit
ssilvert Mar 12, 2009 10:16 AM (in response to dene.froes)Yes, that should work. It's one of the most basic tests you can do and the unit test that does this in the JSFUnit test suite always passes.
Can you post welcome.jsp?
You can see the HTML that was return after the submit by calling client.getPageAsText().
Because you are using RichFaces it is possible that your client.click() did an AJAX request that did not change the view ID. In other words, are you sure that you really went to success.jsp?
Stan -
2. Re: doubts navigation using JSFUnit
dene.froes Mar 12, 2009 10:34 AM (in response to dene.froes)Hi Stan,
thank you for your attention.
I'm not using RichFaces in this example. But briefly I'll to use.
Here's my welcome.jsp:<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%> <%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Login</title> </head> <body> <f:view> <h:form> <h:outputText value="Nome new:" /> <h:inputText value="#{firstMB.name}" id="name" /> <br> <h:outputText value="Senha:" /> <h:inputText value="#{firstMB.password}" id="password" /> <br> <h:commandButton value ="Login" action="#{firstMB.doLogin}" id="submit_button" /> </h:form> </f:view> </body> </html>
My faces-config.xml:<?xml version="1.0" encoding="UTF-8"?> <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>firstMB</managed-bean-name> <managed-bean-class>pr.ptinovacao.tdd.mb.FirstMB</managed-bean-class> <managed-bean-scope>session</managed-bean-scope> </managed-bean> <navigation-rule> <from-view-id>/welcome.jsp</from-view-id> <navigation-case> <from-outcome>success</from-outcome> <to-view-id>/pages/success.jsp</to-view-id> </navigation-case> <navigation-case> <from-outcome>fail</from-outcome> <to-view-id>/pages/fail.jsp</to-view-id> </navigation-case> </navigation-rule> </faces-config>
My managed-bean (FirstMB):package pr.ptinovacao.tdd.mb; import java.io.Serializable; public class FirstMB implements Serializable{ private static final long serialVersionUID = 6940936087084858374L; private String name; private String password; public FirstMB(){ this.name= "name"; this.password = "password"; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String doLogin(){ String result = "fail"; if(name.equals("Jonh")){ result = "success"; } return result; } }
I can't to use client.getPageAsText(), because when I'm for a real application, the contents of page will load dynamically. Therefore I don't know your contents.
Thanks. -
3. Re: doubts navigation using JSFUnit
ssilvert Mar 12, 2009 10:37 AM (in response to dene.froes)You misspelled "John" in the managed bean.
Stan -
4. Re: doubts navigation using JSFUnit
dene.froes Mar 12, 2009 11:01 AM (in response to dene.froes)Realy, but it seems that it was not, because I modified my welcome.jsp and the error (the fail) persist.
See the new welcome.jsp:<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%> <%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Login</title> </head> <body> <f:view> <h:form> <h:outputText value="Nome new:" /> <h:inputText value="#{firstMB.name}" id="name" /> <br> <h:outputText value="Senha:" /> <h:inputText value="#{firstMB.password}" id="password" /> <br> <h:commandButton value ="Login" action="success" id="submit_button" /> </h:form> </f:view> </body> </html>
See that the navigation is static now.
This is the message shown in the browser:expected:<...success...> but was:<...welcome...> junit.framework.ComparisonFailure: expected:<...success...> but was:<...welcome...> at pt.ptinovacao.tdd.test.FirstTest.testBasic(FirstTest.java:57) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at org.apache.cactus.internal.AbstractCactusTestCase.runBareServer(AbstractCactusTestCase.java:153) at org.apache.cactus.internal.server.AbstractWebTestCaller.doTest(AbstractWebTestCaller.java:119) at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest_aroundBody0(AbstractWebTestController.java:93) at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest_aroundBody1$advice(AbstractWebTestController.java:224) at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest(AbstractWebTestController.java) at org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody2(ServletTestRedirector.java:101) at org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody3$advice(ServletTestRedirector.java:224) at org.apache.cactus.server.ServletTestRedirector.doPost(ServletTestRedirector.java) at org.jboss.jsfunit.framework.JSFUnitServletRedirector.doPost(JSFUnitServletRedirector.java:46) at org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody0(ServletTestRedirector.java:72) at org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody1$advice(ServletTestRedirector.java:224) at org.apache.cactus.server.ServletTestRedirector.doGet(ServletTestRedirector.java) at org.jboss.jsfunit.framework.JSFUnitServletRedirector.doGet(JSFUnitServletRedirector.java:52) at javax.servlet.http.HttpServlet.service(HttpServlet.java:617) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.jboss.jsfunit.framework.JSFUnitFilter.doFilter(JSFUnitFilter.java:116) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) at java.lang.Thread.run(Unknown Source)
thanks. -
5. Re: doubts navigation using JSFUnit
ssilvert Mar 13, 2009 9:14 AM (in response to dene.froes)I think it must be your application. Does it now navigate to the right view when you manually click the submit button?
Stan -
6. Re: doubts navigation using JSFUnit
dene.froes Mar 16, 2009 1:07 PM (in response to dene.froes)"stan.silvert@jboss.com" wrote:
I think it must be your application. Does it now navigate to the right view when you manually click the submit button?
Stan
No, no. If you want, I send my application for your e-mail. -
7. Re: doubts navigation using JSFUnit
ssilvert Mar 16, 2009 1:56 PM (in response to dene.froes)"dene.froes" wrote:
"stan.silvert@jboss.com" wrote:
I think it must be your application. Does it now navigate to the right view when you manually click the submit button?
Stan
No, no. If you want, I send my application for your e-mail.
By manually, I mean when you run the application normally. If your application isn't navigating properly when a user tries it in a browser then this isn't a JSFUnit problem. You will need to find general JSF help on another forum such as the java.net JSF community forum.
Stan -
8. Re: doubts navigation using JSFUnit
dene.froes Mar 17, 2009 10:22 AM (in response to dene.froes)Relax, friend.
Running in browser, the navigation the direction is correct.
If you're aware that the JSFUnit really should not fail this test, ok. As we would say in Brazil: "isn't longer here who spoke";
But believe, this simple example failed me here.
Thank you. -
9. Re: doubts navigation using JSFUnit
ssilvert Mar 18, 2009 8:25 AM (in response to dene.froes)OK. If you have a simple example, please send it to me.
Regards,
Stan -
10. Re: doubts navigation using JSFUnit
ssilvert Mar 20, 2009 4:37 PM (in response to dene.froes)Sorry. I just now got around to looking at your app. I've never tried JSFUnit with Sun's Mojarra implementation of JSF 1.1. The versions I have tested against are:
MyFaces 1.1
Mojarra 1.2
Mojarra 2.0
Can you try Mojarra 1.2 perhaps?
Also, don't use jsfunit microdeployer. That's only for JBoss AS 5. It's possible that removing the microdeployer will fix it.
BTW, what server are you running this on?
Stan -
11. Re: doubts navigation using JSFUnit
dene.froes Mar 23, 2009 9:36 AM (in response to dene.froes)I'm using Tomcat 6 to run my application.
I'll to test with Mojarra 1.2 and post the feedback.
Thanks. -
12. Re: doubts navigation using JSFUnit
dene.froes Apr 3, 2009 10:54 AM (in response to dene.froes)Stan,
Resolved.
Thank you. -
13. Re: doubts navigation using JSFUnit
ssilvert Apr 3, 2009 11:22 AM (in response to dene.froes)"dene.froes" wrote:
Stan,
Resolved.
Thank you.
What turned out to be the problem? Was it due to Mojarra 1.1?
Stan -
14. Re: doubts navigation using JSFUnit
dene.froes Apr 3, 2009 11:56 AM (in response to dene.froes)exactly!