4 Replies Latest reply on Sep 25, 2008 5:32 AM by alangote

    How to get Request URL in JSFUnit using FacesContext

      Hi All,

      I am using JSFUnit to testing in my product. I want to get the requested URL for eg (http://localhost:8000/Facelets/ServletTestRunner?suite=com.test.MyJSFUnitTest&xsl=cactus-report.xsl)

      I want this URL to do decide whether it is an JSFUnit request or other request.

      I tried same through FacesContext object like

      String reqPath = FacesContext.getCurrentInstance().getExternalContext().getRequestServletPath();

      I am getting different string is there any way to get the following string

      ServletTestRunner?suite=com.test.MyJSFUnitTest&xsl=cactus-report.xsl

      Any thoughts?

      Thanks
      Anil

        • 1. Re: How to get Request URL in JSFUnit using FacesContext
          ssilvert

          Hi Anil,

          "alangote" wrote:
          Hi All,

          I am using JSFUnit to testing in my product. I want to get the requested URL for eg (http://localhost:8000/Facelets/ServletTestRunner?suite=com.test.MyJSFUnitTest&xsl=cactus-report.xsl)

          I want this URL to do decide whether it is an JSFUnit request or other request.

          The URL above is not a request to the FacesServlet. It is a request to the ServletTestRunner. I'm wondering why you are interested in that request. Since it is not a Faces request, you can't get to it through the FacesContext.

          The request to the ServletTestRunner is the request thread that kicks off your JUnit test inside the container. When you call new JSFSession("/mypage.jsf"), it does call the FacesServlet. Then it returns control to your test thread and gives you access to the leftover FacesContext. See http://wiki.jboss.org/wiki/JSFUnitSessionAndThreads

          So I guess I don't understand what you are trying to do. Can you give me a little more information about your use case? Maybe if you show a little of your code as well?

          Stan


          • 2. Re: How to get Request URL in JSFUnit using FacesContext

            Hi Stan

            The ultimate thing is I want the URL may be using some JSFUnit API? If it is not possible using the FacesContext.

            My use case is I want to identify the request whether it is an JSFunit or JSF so that I can get the correct implementation from factory(There are two implementation one is for JSFunit and other is for JSF).

            Through these implementation actually I am picking the correct facelet for testing and showing. As the facelets for the testing and other are kept in different folders.


            Thanks
            Anil

            • 3. Re: How to get Request URL in JSFUnit using FacesContext
              ssilvert

              OK. This can be done, but the whole point of JSFUnit is that you are running in-container using real classes. So you shouldn't need to have a different implementation for testing. I'm very interested in this though. If there is a good reason to use some sort of Mock implementation I'd like to understand the use case.

              The way to tell if this is a JSFUnit request is to look at the cookies. Every faces request that originates in a JSFUnit test will have a cookie with name and value both "org.jboss.jsfunit.framework.WebConversationFactor.testing_flag". If you look at WebConversationFactory.makeWebClient() you can see where this is set.

              Stan

              • 4. Re: How to get Request URL in JSFUnit using FacesContext

                Many Thanks Stan it works for me.

                Thanks
                Anil