3 Replies Latest reply on Feb 4, 2008 11:47 PM by kumar kumar

    Re:Secure pages

    kumar kumar Newbie

      hi

      i am trying to write a testcase for sample login page using JSFUnit testing secure pages.....

      mytestcase

      public void testSecureLoginForm()throws IOException,SAXException
       {
       JSFClientSession client = new JSFClientSession("/login.faces");
      
       JSFServerSession server = new JSFServerSession(client);
      
       assertEquals("/login.jsp",server.getCurrentViewID());
       System.out.println("#################Current View of the page#############"+server.getCurrentViewID());
      
       WebForm loginform = client.getWebResponse().getFormWithID("form0");
      
       System.out.println("@@@@@@@@@@loginForm@@@@@@@@@"+loginform);
      
       loginform.setParameter("user_value","pavan");
      
       loginform.setParameter("pswd_value","pavan");
      
       loginform.getSubmitButton("login_button").click();
      
       assertEquals("/index.jsp",server.getCurrentViewID());
      
       assertEquals("pavan",server.getManagedBeanValue("#{foo.uname}"));
      
       assertEquals("pavan",server.getManagedBeanValue("#{foo.pswd}"));
       }



      user_value is my componentID

      when i try to run this i am trigerring with the following error

      testSecureLoginForm Error No parameter named 'user_value' is defined in the form
      
      com.meterware.httpunit.WebForm$NoSuchParameterException: No parameter named 'user_value' is defined in the form
      at com.meterware.httpunit.WebForm.setParameter(WebForm.java:611)
      at com.meterware.httpunit.WebForm.setParameter(WebForm.java:601)
      at com.foo.JSFUnitTest.testSecureLoginForm(JSFUnitTest.java:42)
      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.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 javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
      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:123)
      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:175)
      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:263)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
      at java.lang.Thread.run(Unknown Source)



        • 1. Re:Secure pages
          Stan Silvert Master

          This is probably happening because you are using the HttpUnit API instead of the JSFUnit API. If you wanted to use the HttpUnit API you would need to include any naming containers (such as forms) in your parameter name. If you look at the HTML for your login page you will see what I am talking about. You should find that there is indeed no parameter named "user_value". It's probably something like "form0:user_value".

          See http://wiki.jboss.org/wiki/UsingComponentIDs.

          The JSFUnit API takes care of this and other issues to make HttpUnit more useable with JSF applications. You should write your code like this instead:

          public void testSecureLoginForm()throws IOException,SAXException
           {
           JSFClientSession client = new JSFClientSession("/login.faces");
          
           JSFServerSession server = new JSFServerSession(client);
          
           assertEquals("/login.jsp",server.getCurrentViewID());
          
           client.setParameter("user_value","pavan");
          
           client.setParameter("pswd_value","pavan");
          
           client.submit("login_button");
          
           assertEquals("/index.jsp",server.getCurrentViewID());
          
           assertEquals("pavan",server.getManagedBeanValue("#{foo.uname}"));
          
           assertEquals("pavan",server.getManagedBeanValue("#{foo.pswd}"));
           }


          Also see http://wiki.jboss.org/wiki/JSFClientSessionAPI

          Regards,

          Stan

          • 2. Re: Re:Secure pages
            saurav kumar Newbie

            hi,
            i am also facing the same problem. i am using oracle adf jsf components,

            My code snippet is look like this.

            JSFClientSession client = new JSFClientSession("/login.faces");

            JSFServerSession server = new JSFServerSession(client);

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

            client.setParameter("user_value","pavan");

            client.setParameter("pswd_value","pavan");

            i am getting some exception while trying to set client parameters.
            Please suggest me how to pass the components identifier.

            • 3. Re:Secure pages
              kumar kumar Newbie

              Hi

              WebForm loginform = client.getWebResponse().getFormWithID("form0");
              
              
              loginform.setParameter("form0:user_value","pavan");
              
              loginform.setParameter("form0:pswd_value","pavan");
              
              loginform.getSubmitButton("form0:login_button").click();


              you need to set like this...


              Thanks