14 Replies Latest reply on Jun 5, 2008 6:23 PM by Stan Silvert

    JSFunit test for h:commandLink fails

    Harinath C Newbie

      Issue: I am trying to test the navigation using h:commandLink and it throws following error
      java.lang.StringIndexOutOfBoundsException: String index out of range: -1
      at java.lang.String.substring(String.java:1762)
      at java.lang.String.substring(String.java:1735)
      at org.jboss.jsfunit.facade.JSFClientSession.setMojarraCmdLinkParams(JSFClientSession.java:546)
      at org.jboss.jsfunit.facade.JSFClientSession.setCmdLinkParams(JSFClientSession.java:520)
      at org.jboss.jsfunit.facade.JSFClientSession.clickCommandLink(JSFClientSession.java:473)
      at com.myapp.jsfunit.ListTest.testClick(ListTest.java:99)

      When I did debug following is what I found
      - Since I am using myfaces 1.2.2 setCmdLinkParams() is going to setMojarraCmdLinkParams().
      This method has the following code that throws above error
      script = script.substring(script.indexOf("{jsfcljs("));

      I am new to JSF and JSFUnit, I appreciate if you can help me in this regard.

      - Hari

        • 1. Re: JSFunit test for h:commandLink fails
          Stan Silvert Master

          MyFaces 1.2 hasn't been tested with JSFUnit yet. In fact, you are the first person I've heard of who is using it. The JSFUnit code for h:commandLink is specific to the JSF implementation, so I'm not surprised that this doesn't work.

          This week I'll be working on changing JSFUnit so that it relies on HTMLUnit instead of HttpUnit. If that works out then HTMLUnit will be able to handle the javascript submits and we'll no longer have to write specific code for JSF implementations or component libraries. Stay tuned.

          Stan

          • 2. Re: JSFunit test for h:commandLink fails
            Harinath C Newbie

            Stan, thank you for your quick response.

            So, are you planning to test JSFUnit with MyFaces 1.2.x ?
            Can you give an idea of what needs to be implemented/changed inorder to support MyFaces 1.2.x command link?

            - Hari


            • 3. Re: JSFunit test for h:commandLink fails
              Stan Silvert Master

              MyFaces 1.2 should work fine except for h:commandLink. I'm sure we'll be adding it to our test suite as long as there is some demand for it.

              To get this to work today, you just need to look at the javascript that MyFaces 1.2 executes. I assume that it is very similar to MyFaces 1.1. You would need to use HttpUnit to do the submit with the same parameters that javascript would do in a real browser. You can see how this is accomplished for MyFaces 1.1 and Mojarra (RI) 1.2.

              If my research with HTMLUnit pans out, we won't need to mimick the javascript any more. HTMLUnit looks like it has pretty good javascript support so we will just use that.

              Stan

              • 4. Re: JSFunit test for h:commandLink fails
                Harinath C Newbie

                Hi Stan,

                Did you get a chance to work on this issue? Support for MyFaces 1.2.x or HTMLUnit. I appreciate if you can update me on this.

                Thanks,
                H

                • 5. Re: JSFunit test for h:commandLink fails
                  Stan Silvert Master

                  The fix will be to use the HtmlUnit version of JSFUnit. Tentatively, I'm planning to do one more beta with both HttpUnit and HtmlUnit. Then the GA version will get rid of HttpUnit. However, there is a critical issue that needs to be addressed in HtmlUnit before I can put out the beta.

                  In the mean time you can still try out the HtmlUnit stuff if you build from SVN. That should fix the MyFaces 1.2 problem. I'd love to get your feedback on it.

                  See details for running the new stuff here:
                  http://www.jboss.com/index.html?module=bb&op=viewtopic&t=136280

                  Regards,

                  Stan

                  • 6. Re: JSFunit test for h:commandLink fails
                    J InOK Newbie

                    Following up on this, I'm trying to build from svn trunk. I can't get the build to finish; the jboss-jsfunit-richfaces module is complaining about missing servlet classes (easy enough to fix), as well as:

                    /jsfunit/trunk/jboss-jsfunit-richfaces/src/main/java/org/jboss/jsfunit/richfaces/RichFacesClient.java:[82,30] cannot access org.ajax4jsf.component.AjaxContainer
                    file org/ajax4jsf/component/AjaxContainer.class not found
                    UIComponent container = (UIComponent)AjaxRendererUtils.findAjaxContainer(ctx, uiComp);

                    /jsfunit/trunk/jboss-jsfunit-richfaces/src/main/java/org/jboss/jsfunit/richfaces/RichFacesClient.java:[330,13] cannot access org.ajax4jsf.component.AjaxComponent
                    file org/ajax4jsf/component/AjaxComponent.class not found
                    if (tab.isDisabled()) return;

                    I'm starting with a clean repository, using maven 2.0.8. Is this on my end, or does the pom need to be updated?

                    Thanks!
                    Jason

                    • 7. Re: JSFunit test for h:commandLink fails
                      Stan Silvert Master

                      Did the clean repository fix your problem?

                      I know that the Hudson nightly build is working.

                      Stan

                      • 8. Re: JSFunit test for h:commandLink fails
                        J InOK Newbie

                        I know better than to complain about a maven build breaking without first trying a clean repository :)

                        It looks to me like the jboss-jsfunit-richfaces project is missing a dep reference to the servlet api as well as richfaces-api artifact. The jboss-jsfunit-seam project seems to be missing the servlet api dep reference. Once I added these references to the pom files, everything built.

                        As for your Hudson build, I don't know. It looks like you're using an earlier version of maven (2.0.6), but I didn't see anything in the maven changelog that jumped out as being the difference.

                        • 9. Re: JSFunit test for h:commandLink fails
                          Stan Silvert Master

                           

                          "l.jinok.l" wrote:
                          I know better than to complain about a maven build breaking without first trying a clean repository :)

                          Sorry, I misunderstood you. I thought you were going to try a clean repo and get back to me.

                          Anyway, I've tried to recreate the problem, but I can't. I'm looking at the seam subproject since it is the simplest. The transitive dependency to servlet api is there. It goes like this:

                          jboss-jsfunit-seam --> jboss-jsfunit-core --> cactus --> httpunit --> servlet-api

                          Even so, I agree that the dependency should be stated explicitly rather than relying on a fourth-level transitive dependency. I'll fix it.

                          I love Maven, but sometimes I think transitive dependencies are just a little TOO fun.

                          Stan



                          • 10. Re: JSFunit test for h:commandLink fails
                            J InOK Newbie

                            I was able to get trunk to build by bypassing my company's local mirror; it looks like we have some different poms than what gets pulled in from the jboss or central repos. Thanks again, sorry for the bother.

                            • 11. Re: JSFunit test for h:commandLink fails
                              Jane Zhen Newbie

                              Hi Stan,

                              Did you mean this should work for Myfaces 1.1? I'm using tomahawk-1.1.6.jar, but still no luck?

                              • 12. Re: JSFunit test for h:commandLink fails
                                Stan Silvert Master

                                JSFUnit Beta 2 will work with MyFaces 1.1. The new HtmlUnit stuff is also known to work with MyFaces 1.1.

                                However, I haven't tried Tomahawk yet. Tomahawk doesn't work with the JSFUnit Beta 2, but it might work with the new HtmlUnit-based JSFClientSession.

                                Stan

                                • 13. Re: JSFunit test for h:commandLink fails
                                  Jane Zhen Newbie

                                  A little newbie question. how do I build JSFUNit with htmlUnit? I saw in pom.xml, tehre are both dependencies to httpunit and htmlunit. should I disable httpunit?

                                  thanks
                                  Jane

                                  • 14. Re: JSFunit test for h:commandLink fails
                                    Stan Silvert Master

                                    Don't worry. That's not a newbie question at all. This stuff is not released or documented yet.

                                    Just build. It will build both packages. So if you want to use HtmlUnit instead of HttpUnit you will use the jsfsession package instead of the facade package.

                                    See the Announcement at the top of this forum for more details.

                                    Stan