1 Reply Latest reply on Jul 14, 2011 1:09 PM by Stan Silvert

    jsfunit help

    tamizharasi periyasamy Newbie

      Hi,

       

      I am creating a simple program to test JSF application.

       

      private JSFClientSession client;

          private JSFServerSession server;

              private JSFSession jsfSession;

          @Override

          public void setUp() throws IOException{

            

             

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

            

             

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

                 JSFClientSession client = jsfSession.getJSFClientSession();

       

      JSFServerSession server = jsfSession.getJSFServerSession();

             

                 assertEquals("/jsp/login.xhtml", server.getCurrentViewID());

          

                 UIComponent prompt = server.findComponent("j_idt7:t1");

              

                 assertTrue(prompt.isRendered());

       

      this is working fine. But If I want to test a URL which is like http://uat.server.com/simple/jsp/index.jsp.

       

      then How can I do that.

       

      The test results I am able to see as the xml output. Is it possible to see some graphical output?

        • 1. Re: jsfunit help
          Stan Silvert Master

          A few comments about your code:

           

           

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

          The argument to the JSFSession constructor must map to a JSF request and hit the JSFServlet.  If you have the JSFServlet mapped to /jsp using path mapping then this is fine.  But typically with path mapping you map a path like /jsf instead of /jsp.  In my experience, most actually use extension mapping instead of path mapping so that your start page would just use /index.jsf.  If you have further questions about this, post your web.xml and I can tell for sure if you are doing it right.

           

           

           

                     assertEquals("/jsp/login.xhtml", server.getCurrentViewID());         

          Are you using both JSP and Facelets in the same application?  You can do this but it is unusual and I wouldn't recommend it.

           

           

                     UIComponent prompt = server.findComponent("j_idt7:t1");                 

          You need to use an id in your markup (XHTML or JSP) for this component.  You can't be sure that the component ID will always be j_idt7:t1.  This is an ID that was generated by JSF because you didn't assign one in your markup.

           

           

          But If I want to test a URL which is like http://uat.server.com/simple/jsp/index.jsp.

           

          then How can I do that.

          I don't understand your question.  It looks like that is indeed the URL you are testing, assuming that your application is running on http://uat.server.com and your web context is mapped to "simple".

           

           

           

          The test results I am able to see as the xml output. Is it possible to see some graphical output?

          JSFUnit can be run with any JUnit test runner.  I assume you are using the JSFUnit 1.3 release and not the JSFUnit 2.0 beta.  So you are using Cactus to run your tests.  See the Cactus web site for details on using different test runners.

           

          Stan