2 Replies Latest reply on Feb 1, 2011 5:37 PM by hmashruf

    JsfUnit testing with Richfaces

    hmashruf

      Hi All, I am using Sun Jsf 2.0, Richfaces 4.0, Spring 2.5.x; have setup JsfUnit as a seperate maven project with war overlays. When I deploy this war to the Tomcat server, it runs good. But when run with JsfUnit, I am getting this error while calling new JSFSession(wcSpec);. Here is the code. I see this error reported on many forurms, gave them a try but not of help. Do I miss any steps?

       

      Thanks in advance.

       

      ----

      public class JSFUnitTest extends ServletTestCase {

       

          private JSFClientSession client;

          private JSFServerSession server;

       

          public JSFUnitTest() {

              System.out.println("**** JSFUnitTest ****");

          }

       

          public static TestSuite suite() {

             return new TestSuite( JSFUnitTest.class );

          }

       

         /**

          * Start a JSFUnit session by getting the /index.faces page.

          */

          @Override

         public void setUp() throws IOException {

           try{

                // Initial JSF request

                String mainPageURI = "/faces/web/main/main.xhtml?ID=MyId";   

                WebClientSpec wcSpec = new WebClientSpec(mainPageURI, BrowserVersion.INTERNET_EXPLORER_8);

                WebClient wc = wcSpec.getWebClient();

                wc.setJavaScriptEnabled(true);

                wc.setCssEnabled(false);

                wc.setAjaxController(new NicelyResynchronizingAjaxController());

                wc.setThrowExceptionOnScriptError(false);

                wc.setCssErrorHandler(new SilentCssErrorHandler());

                wc.setUseInsecureSSL(false);

                JSFSession jsfSession = new JSFSession(wcSpec); //***

                client = jsfSession.getJSFClientSession();

                server = jsfSession.getJSFServerSession();

           } catch (Exception e) {

              e.printStackTrace();

          }

         }

       

      ----

      ...

      2011-01-24 10:12:12,311 DEBUG [java.sql.Connection] - {conn-100105} Preparing Statement:      SELECT COUNT(*) FROM HDR hdr      WHERE                 hdr.type_entry_cd = ?                                                                            AND     hdr.edoc_stat_cd = ?             

      2011-01-24 10:12:12,311 DEBUG [java.sql.PreparedStatement] - {pstm-100106} Executing Statement:      SELECT COUNT(*) FROM HDR hdr      WHERE                 hdr.type_entry_cd = ?                                                                            AND     hdr.edoc_stat_cd = ?             

      2011-01-24 10:12:12,311 DEBUG [java.sql.PreparedStatement] - {pstm-100106} Parameters: [54, AP]

      2011-01-24 10:12:12,311 DEBUG [java.sql.PreparedStatement] - {pstm-100106} Types: [java.lang.String, java.lang.String]

      2011-01-24 10:12:12,311 DEBUG [java.sql.ResultSet] - {rset-100107} ResultSet

      2011-01-24 10:12:12,311 DEBUG [java.sql.ResultSet] - {rset-100107} Header: [1]

      2011-01-24 10:12:12,311 DEBUG [java.sql.ResultSet] - {rset-100107} Result: [19]

      2011-01-24 10:12:12,404 DEBUG [java.sql.Connection] - {conn-100108} Connection

      2011-01-24 10:12:12,498 DEBUG [java.sql.Connection] - {conn-100109} Connection

      2011-01-24 10:07:06,110 ERROR [com.gargoylesoftware.htmlunit.javascript.StrictErrorReporter] - runtimeError: message=[The data necessary to complete this operation is not yet available.] sourceName=[http://localhost:9090/myapp/faces/javax.faces.resource/jquery.js] line=[767] lineSource=[null] lineOffset=[0]

      2011-01-24 10:07:06,360 DEBUG [java.sql.Connection] - {conn-100053} Connection

      2011-01-24 10:07:06,641 DEBUG [java.sql.Connection] - {conn-100054} Connection

      2011-01-24 10:07:07,610 DEBUG [java.sql.Connection] - {conn-100055} Connection

      java.lang.IllegalStateException

          at org.mortbay.jetty.servlet.AbstractSessionManager$Session.getAttribute(AbstractSessionManager.java:781)

          at org.jboss.jsfunit.framework.FacesContextBridge.getCurrentInstance(FacesContextBridge.java:56)

          at org.jboss.jsfunit.jsfsession.JSFServerSession.pageCreated(JSFServerSession.java:214)

          at org.jboss.jsfunit.jsfsession.JSFServerSession.<init>(JSFServerSession.java:57)

          at org.jboss.jsfunit.jsfsession.JSFSession.<init>(JSFSession.java:83)

          at edu.ucla.ais.nonpear.test.JSFUnitTest.setUp(JSFUnitTest.java:60)

          at junit.framework.TestCase.runBare(TestCase.java:132)

          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)...

        • 1. JsfUnit testing with Richfaces
          ssilvert

          Does your mainPageURI map to the FacesServlet?  You can use path mapping if you like, but most choose extension mapping like /main.jsf or /main.faces.  If "/faces/web/main/main.xhtml?ID=MyId" doesn't map to the FacesServlet then that is your main problem.  Also, it's unusual to pass in a query param like "?ID=MyId".  Try without it if you can.

           

          Most of your settings on WebClient are not needed because JSFUnit sets them internally.  I'd try without WebClientSpec and then add IE8 if that's what you really want.

           

          Lastly, your output is a little strange.  I don't understand why the ERROR at 10:07:06,110.  Also, I don't understand why the IllegalStateException appears with no time stamp at all.

           

          Regards,

           

          Stan

          • 2. JsfUnit testing with Richfaces
            hmashruf

            Hi Stan,

             

            This setting in the spring context file worked: there may exist other solutions, please post them.

             

            <http auto-config="true" session-fixation-protection="none"

            . . .

             

            Thank you