3 Replies Latest reply on Dec 19, 2007 9:06 AM by Stan Silvert

    TestCase failure error.....

    kumar kumar Newbie

      hi every one,

      my testInitialPage is taking null value

      but i am setting the value....it not taking that value .. can any one correct me..this is my code for testInitialPage
      public void testInitialPage() throws IOException,SAXException
      {

      JSFClientSession client = new JSFClientSession("/index.faces");
      client.setParameter("input_foo_text","pavan");
      client.submit("submit_button");

      JSFServerSession server = new JSFServerSession(client);

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

      UIComponent prompt = server.findComponent("prompt");
      assertTrue(prompt.isRendered());

      assertEquals("pavan", server.getManagedBeanValue("#{foo.text}"));
      assertTrue(client.getWebResponse().getText().contains("Hello pavan"));


      }




      testInitialPage Failure null

      junit.framework.AssertionFailedError at
      com.foo.JSFUnitTest.testInitialPage(JSFUnitTest.java:38) 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: TestCase failure error.....
          Stan Silvert Master

          Your test is failing on an assert at line 38. Which one is line 38?

          I suspect that it's this one:

          assertEquals("pavan", server.getManagedBeanValue("#{foo.text}"));


          My guess is that you have not declared a managed bean named "foo". If you look at the new wiki page I created, I have a fully-functioning WAR based on the getting started guide:
          http://wiki.jboss.org/wiki/GettingStartedGuide

          It contains a managed bean declaration in faces-config.xml like this:
          <faces-config>
           <managed-bean>
           <description>Use a swing JButton as a simple javabean</description>
           <managed-bean-name>foo</managed-bean-name>
           <managed-bean-class>javax.swing.JButton</managed-bean-class>
           <managed-bean-scope>request</managed-bean-scope>
           <managed-property>
           <property-name>text</property-name>
           <value>Stan</value>
           </managed-property>
           </managed-bean>
          </faces-config>


          It uses a hidden swing button as the managed bean impl. I just did this to avoid writing extra code.

          If that's not your problem, please let me know which line is failing. Maybe I can help.

          Regards,

          Stan

          • 2. Re: TestCase failure error.....
            kumar kumar Newbie

            Thats not the problem...i have declared the managed bean foo.......and more over the error its showing is at this line

            assertTrue(prompt.isRendered());


            here it's getting null i think...can u help me out

            • 3. Re: TestCase failure error.....
              Stan Silvert Master

              Can you show me your JSF markup? Is there a component on the page with id="prompt"?

              If server.findComponent("prompt") is returning null then that means there is no component in the JSF component tree with that id. For more on how JSFUnit handles component ID's see this wiki page:
              http://wiki.jboss.org/wiki/UsingComponentIDs

              Also see "Testing the Component Tree" on this page:
              http://wiki.jboss.org/wiki/JSFServerSessionAPI

              Stan