2 Replies Latest reply on Jul 21, 2008 12:52 PM by Wiktor Gworek

    simulating click on table row

    Wiktor Gworek Newbie


      I'm using rich:dataTable with

      <a4j:support id="showDetails" event="onRowClick" reRender="detailsOfUser" actionListener="#{userList.editAction}">
       <f:attribute name="user" value="#{user}"/>

      I would like to test it. Unfortunatelly it cannot be done by RichFacesClient. I tried this code:
      JSFClientServerSession session = goTo("/pages/users.jsf");
      WebTable usersTable = session.getClient().getWebResponse().getTableWithID("listForm:userListTable");
      TableRow firstUserRow = usersTable.getRows()[1];
      HashMap<String, String> params = extractParams(firstUserRow.getAttribute("onclick"));
      PostMethodWebRequest request = new WebRequestFactory(session.getClient()).buildRequest("listForm");
      for (Map.Entry<String, String> entry : params.entrySet()) {
       request.setParameter(entry.getKey(), entry.getValue());
      session.getAjaxClient().ajaxSubmit("listForm", params);

      It extracts parameters from javascript event onclick and tries to make a ajax request. The problem is that it server logs this request is being made (that's good) but test fails. Exception
      at org.apache.xml.serializer.TreeWalker.startNode(TreeWalker.java:368)
      at org.apache.xml.serializer.TreeWalker.traverse(TreeWalker.java:143)
      at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:389)
      at org.jboss.jsfunit.facade.DOMUtil.convertToDomLevel2(DOMUtil.java:143)
      at org.jboss.jsfunit.facade.JSFClientSession.updateInternalState(JSFClientSession.java:215)
      at org.jboss.jsfunit.facade.JSFClientSession.doWebRequest(JSFClientSession.java:201)
      at org.jboss.jsfunit.richfaces.Ajax4jsfClient.doAjaxRequest(Ajax4jsfClient.java:186)
      at org.jboss.jsfunit.richfaces.Ajax4jsfClient.ajaxSubmit(Ajax4jsfClient.java:179)
      at ui.test.UserListTest.testShowDetails(UserListTest.java:92)

      I search the web and it seems to be Xalan problem (I'm on JBoss 4.2). Does anyone knows a workaround? Or how to emulate click on table row differently?

      Cheers :)

        • 1. Re: simulating click on table row
          Stan Silvert Master

          You might want to try out the new JSFUnit from subversion. It replaces the client with one that is based on HtmlUnit instead of HttpUnit. Though this code is still a few weeks from beta, at least you won't see the NPE you are running into now.

          If you look at the online demo, you will see that RichDataFilterSlider has an example JSFUnit test and that example uses rich:dataTable. Click on the source link to see the old version of the test.

          The new version of the test is below:

           * JBoss, Home of Professional Open Source.
           * Copyright 2008, Red Hat Middleware LLC, and individual contributors
           * as indicated by the @author tags. See the copyright.txt file in the
           * distribution for a full listing of individual contributors.
           * This is free software; you can redistribute it and/or modify it
           * under the terms of the GNU Lesser General Public License as
           * published by the Free Software Foundation; either version 2.1 of
           * the License, or (at your option) any later version.
           * This software is distributed in the hope that it will be useful,
           * but WITHOUT ANY WARRANTY; without even the implied warranty of
           * Lesser General Public License for more details.
           * You should have received a copy of the GNU Lesser General Public
           * License along with this software; if not, write to the Free
           * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
           * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
          package org.jboss.jsfunit.test.richfaces;
          import java.io.IOException;
          import junit.framework.Test;
          import junit.framework.TestSuite;
          import org.apache.cactus.ServletTestCase;
          import org.jboss.jsfunit.jsfsession.JSFClientSession;
          import org.jboss.jsfunit.jsfsession.JSFSession;
          import org.jboss.jsfunit.richfaces.RichFacesClient;
          import org.w3c.dom.Element;
           * Peform JSFUnit tests on RichFaces demo application.
           * @author Stan Silvert
          public class RichDataFilterSliderTest extends ServletTestCase
           public void testDataFilterSlider() throws IOException
           JSFSession jsfSession = new JSFSession("/richfaces/dataFilterSlider.jsf");
           JSFClientSession client = jsfSession.getJSFClientSession();
           RichFacesClient richClient = new RichFacesClient(client);
           richClient.setDataFilterSlider("slider_1", "60000");
           // The data table is built with random data, so there's nothing to
           // reliably assert about it except the make of the car.
           Element element = client.getElement("form1:carList:0:make");
           assertEquals("Ford", element.getTextContent());
           // Click the link to change make to Chevy. I happen to know it is the
           // first in the list.
           element = client.getElement("form1:carList:0:make");
           assertEquals("Chevrolet", element.getTextContent());
           public static Test suite()
           return new TestSuite( RichDataFilterSliderTest.class );

          Hope that helps. I won't be around as much for the next few days, but I'll be back on this forum regularly again on Wednesday.


          • 2. Re: simulating click on table row
            Wiktor Gworek Newbie

            With JSFUnit from the trunk it works and no errors are generated. Thanks a lot.

            Just in case anybody had a problem. One should use this classes:

            import org.jboss.jsfunit.jsfsession.JSFClientSession;
            import org.jboss.jsfunit.jsfsession.JSFServerSession;

            and not from org.jboss.jsfunit.facade.