1 2 Previous Next 18 Replies Latest reply on Dec 4, 2008 6:31 PM by kragoth

    facelets.DEVELOPMENT when used with jsfunit

    kragoth

      Hi all,

      Just wondering what I can do with this situation.

      If I have facelets.DEVELOPMENT set to true in my web.xml it makes it difficult to use jsfunit.

      What happens is this:

      If I go to a page and there is an EL expression that is invalid I would normally get a 500 response and thus my jsfunit test fails.

      But, when I have facelets.DEVELOPMENT enabled, the 500 response is never returned but wrapped up and returned in 200 response. This wouldn't be tooo bad except that the url does not change either. So..... does anyone know how I can determine if this is a real 200 response or a wrapped up version of the facelets debugger.

      As it stands even in a wrapped 500 response the component model is still there as well so....I can't even check that a component exists to determine the result.

      Thanks for any help.

        • 1. Re: facelets.DEVELOPMENT when used with jsfunit
          ssilvert

          I'm not sure I completely understand your question. You should be able to look at the raw response and tell that it is a Facelets error page. Or I suspect that you can call into the Facelets API and find the status.

          Maybe we need a new feature in JSFUnit that makes this easier?

          Also, don't you want the JSFUnit test to fail in this case?

          Stan

          • 2. Re: facelets.DEVELOPMENT when used with jsfunit
            kragoth

            Ok... I'll try make my situation clearer.

            I'm assuming you know what I mean when I refer to the facelets debug page which is displayed when an error occurs on the page.

            The default way of checking if a page loaded is

            assertEquals("/home.xhtml", server.getCurrentViewID());
            


            But with facelets debugging on this doesn't work. This is because the faclets debug page is actually the page I received but you can't tell that easily.

            Currently the really BAD way I'm doing this is by checking to see if the DOM has the "An Error Occurred:" string in the first h1 tag.
            Like this:
            NodeList h1Nodes = client.getUpdatedDOM().getElementsByTagName("h1");
             if (h1Nodes.getLength() > 0 &&
             "An Error Occurred:".equals(h1Nodes.item(0).getFirstChild).getNodeValue()))
            {
             log.error("testPages() - found an error on:" + url);
             errors.add(url);
            }
            


            I don't know how else to explain the situation. To have this happen yourself just put an invalid EL expression on a facelets page and try prove this using JSFUnit.

            • 3. Re: facelets.DEVELOPMENT when used with jsfunit
              ssilvert

               

              "Kragoth" wrote:

              But with facelets debugging on this doesn't work. This is because the faclets debug page is actually the page I received but you can't tell that easily.


              OK. So what you are saying is that we need a "fail-fast" feature for this case. You shouldn't have to check for this with each request. JSFUnit should do it for you.

              What if we just throw an exception from the JSFClientSession? So if you said

              client.submit("my_submit_button");


              If development mode is on and the request generated a facelets debug page, the above line of code would throw a JSFUnit exception containing essentially the same information a developer would see in his browser.

              Do you think that would be the way to go?

              Stan

              • 4. Re: facelets.DEVELOPMENT when used with jsfunit
                kragoth

                I like the idea of throwing the exception.

                But will this exception be thrown on loading of the page as well?
                As it stands what I am doing is writing a really basic jsf unit test that just tries to access all my .xhtml pages (except for an exclude list) and ensures that they load without an error.

                So if the Facelets debug page is what I get, this is when I would like the JSFUnit test to throw the exception. Not just when I try to do an action. But, that does not mean that this shouldn't happen when I do an action of course.

                But ultimately I like the idea of having the exception thrown up so I can actually see what error there was on the page in my unit test.


                Thanks

                • 5. Re: facelets.DEVELOPMENT when used with jsfunit
                  ssilvert

                  Yes, it would throw the exception whenever any page is accessed that returns a Facelets error page.

                  Stan

                  • 6. Re: facelets.DEVELOPMENT when used with jsfunit
                    kragoth

                    Sounds great!

                    I can't wait.... just like having seam support....will make my life so much easier :P

                    • 7. Re: facelets.DEVELOPMENT when used with jsfunit
                      ssilvert

                      FYI. This is fixed now if you want to build from SVN and give it a try.

                      Stan

                      • 8. Re: facelets.DEVELOPMENT when used with jsfunit
                        kragoth

                        Thanks Stan!

                        I'll try build up and give it a go. I must admit I havn't actually tried to build JSFUnit from SVN yet so....might take me a while.

                        Out of curiosity, how was this implemented? (Or point me to the file I can look at what you did :) )

                        Thanks

                        • 9. Re: facelets.DEVELOPMENT when used with jsfunit
                          ssilvert

                          You'll want to look at these then:
                          http://labs.jboss.com/jsfunit/source-repository.html
                          http://labs.jboss.com/jsfunit/building-jsfunit.html

                          All calls to the server must go through JSFClientSession.doWebRequest(). So I just check to see if the page returned is the Facelets error page. If so, I throw a new exception that extracts the stack trace from the HTML. The code is in org.jboss.jsfunit.facade.FaceletsErrorPageException. The unit tests for it are in the ajax4jsf example.

                          It's nothing fancy. I didn't see a good way to tap into the Facelets API for this. Thanks in advance for your feedback.

                          Stan

                          • 10. Re: facelets.DEVELOPMENT when used with jsfunit
                            kragoth

                            Ok, I've built from SVN...wasn't too hard :)

                            The fix is working for me :D
                            So, I'm all happy now. The only thing I'm waiting on is the ability to look up seam beans :)


                            But, thanks heaps. I found where you were detecting the error page - an interesting approach. I like the fact I get the facelets stacktrace.

                            • 11. Re: facelets.DEVELOPMENT when used with jsfunit
                              ssilvert

                              The Seam stuff should be working now too. You will get a stack trace on the server, but it doesn't affect the tests or the application.

                              There is more work to do on Seam support, but the major problem - looking up beans in conversation scope - should work.

                              Stan

                              • 12. Re: facelets.DEVELOPMENT when used with jsfunit
                                kragoth

                                How do I look up seam beans?

                                • 13. Re: facelets.DEVELOPMENT when used with jsfunit
                                  ssilvert

                                  First, make sure you use the org.jboss.jsfunit.seam.SeamClient instead of JSFClientSession. SeamClient extends JSFClientSession.

                                  Then just use the EL to reference managed beans in conversation scope:

                                  jsfServerSession.getManagedBeanValue("#{hotel.name}");


                                  You can see two examples of JSFUnit/Seam that now reside with the project. Look in jsfunit/jboss-jsfunit-examples/jboss-jsfunit-examples-seam/

                                  Stan

                                  • 14. Re: facelets.DEVELOPMENT when used with jsfunit
                                    kragoth

                                    This issue seems to have raised its head again. For some reason the exception is not getting thrown when I end up on the debug page anymore :(

                                    Is it just me or has it somehow come out again with all the work that's been going on?

                                    1 2 Previous Next