1 Reply Latest reply on Aug 14, 2007 10:20 AM by ssilvert

    JSFUnit : testing ajax4JSf and richFaces component

    mblondel

      Hello,

      I use ajax4jsf and richFaces components and I would like to know if it is possible to test those components with jsfUnit.
      For example, if a select a checkbox and another jsf component appears, can I test that ?

      Thanks

        • 1. Re: JSFUnit : testing ajax4JSf and richFaces component
          ssilvert

          Ajax4jsf support was just recently added. The jira task is here:
          http://jira.jboss.com/jira/browse/JSFUNIT-8

          The current plan is to support many AJAX libraries, but because of each library does things a bit differently, there is no single solution that works for all of them.

          The first priority it to have really solid A4J/RichFaces support. These two libraries are merging, BTW. I haven't yet tried out any RichFaces stuff.

          To answer your question, I think the answer is yes, but it may depend on exactly what you are trying to do. The AJAX support in JSFUnit is brand new and you may run into some things we didn't expect. We'd love to get your feedback on it. We don't have any docs written on it yet, but you should be able to get started from looking at the ajax4jsf sample app included with the code base.

          Here is the announcement I sent out to the dev email list about it:
          -----------------------------------------------------------------------------

          FYI, I just finished the ajax4jsf support and an example application. It's really three apps in one. I combined three of the ajax4jsf sample apps into one WAR and wrote tests for them. You can see this in:
          jsfunit/jboss-jsfunit-examples/jboss-jsfunit-examples-ajax4jsf

          There is no library I have found that adequately handles the javascript for the A4J components. So for AJAX, you are only testing the server side and not the dynamic things that would happen in the browser.

          The Ajax4jsfClient creates the same HTTP request that would be sent by the A4J.AJAX.Submit javascript function. After that request, it sends a second request to the server that does a page refresh, which keeps the client and server side in sync.

          For example, I have a page with this form:

          <h:form id="form1">
           <h:inputText id="input_text" size="50" value="#{textbean.text}">
           <a4j:support id="a4jsupport" event="onkeyup" reRender="rep"/>
           </h:inputText>
           <h:outputText value="#{textbean.text}" id="rep"/>
          </h:form>



          The code to test the AJAX submit looks something like this:

          ClientFacade client = new ClientFacade("/pages/echo.jsf");
          Ajax4jsfClient ajaxClient = new Ajax4jsfClient(client);
          ServerFacade server = new ServerFacade(client);
          client.setParameter("input_text", "foo");
          ajaxClient.fireAjaxEvent("a4jsupport");
          assertEquals("foo", server.getManagedBeanValue("#{textbean.text}"));

          -----------------------------------------------------------------------------

          Feedback on this feature is greatly appreciated.

          Stan