4 Replies Latest reply on Dec 22, 2010 4:36 PM by zaddo

    JSF Unit with webMethods CAF

    andrzej.dmoch

      I tried using JSF Unit with webMethods' CAF implementations (version 7.1 of CAF is JSF 1.1 and version 8.0 of CAF is JSF 1.2 compliant). Here are my experiences:

       

      1. JSF Unit out-of-the-box doesn't work with webMethods CAF. There are two major problems:

      • NoNewEntryMap's put method is too restrictive. It seems that some of JSF implementations execute the put method when getManagedBeanValue is executed (I've seen the same problem already posted on the forum) and this method throws an exception and in the end result returns null. I made a workaround and made the put method a bit less restrictive, like:

       

       

         public Object put(Object key, Object value)
         {
             return wrapped.put(key, value);
         }

       

           I know it may be dangerous, as the test may modify the application but the current implementation simply doesn't work with wM CAF. Maybe Stan will have a better proposition?

       

      • JSF Unit code seems to use the classes available only in JSF 2.0. The following classes needed corrections to work with wM CAF 7.1:
        • JSFUnitDelegatingExternalContext and JSFUnitExternalContext (contained import javax.faces.context.Flash),
        • JSFUnitFacesContext (contained imports of javax.faces.application.ProjectStage, javax.faces.context.ExceptionHandler, javax.faces.context.PartialViewContext),

                But possibly there's a better method to avoid the versioning conflict. Any hints?

       

      2. I didn't overcome the problem how to create a scenario consisting of actions executed by different users. In one testcase only one user was able to login successfully. But I made a workaround and implemented the test class allowing to execute the scenarios for each user remotely in the sequence and reporting errors from each user's action to the main scenario.

        • 1. Re: JSF Unit with webMethods CAF
          ssilvert

          Hi,

           

          Forgive me for only answering off the top of my head.  I'm on holiday and I don't have time to do proper research on these questions.

          andrzej.dmoch wrote:

           

          I tried using JSF Unit with webMethods' CAF implementations (version 7.1 of CAF is JSF 1.1 and version 8.0 of CAF is JSF 1.2 compliant). Here are my experiences:

           

          1. JSF Unit out-of-the-box doesn't work with webMethods CAF. There are two major problems:

          • NoNewEntryMap's put method is too restrictive. It seems that some of JSF implementations execute the put method when getManagedBeanValue is executed (I've seen the same problem already posted on the forum) and this method throws an exception and in the end result returns null. I made a workaround and made the put method a bit less restrictive, like:

           

           

             public Object put(Object key, Object value)
             {
                 return wrapped.put(key, value);
             }

           

               I know it may be dangerous, as the test may modify the application but the current implementation simply doesn't work with wM CAF. Maybe Stan will have a better proposition?

          I don't think the NoNewEntryMap should be active during the JSF lifecycle.  But I'm not familiar with webMethods CAF.  Perhaps webMethods CAF is doing this inside some EL code?  If that's the case then we might need to put in some sort of hook to allow the put() to continue without the exception.
          • JSF Unit code seems to use the classes available only in JSF 2.0. The following classes needed corrections to work with wM CAF 7.1:
            • JSFUnitDelegatingExternalContext and JSFUnitExternalContext (contained import javax.faces.context.Flash),
            • JSFUnitFacesContext (contained imports of javax.faces.application.ProjectStage, javax.faces.context.ExceptionHandler, javax.faces.context.PartialViewContext),

                    But possibly there's a better method to avoid the versioning conflict. Any hints?

          I think you should be OK for this.  I do lots of tests where I compile and run with JSFUnit under JSF 1.1 and JSF 1.2.  The only time this would be a problem is if you are using JSFUnitFacesContext or JSFUnitDelegatingExternalContext in your test code.  You should not cast to these classes.  You should cast to FacesContext or ExternalContext instead.  But maybe you are doing something different?  Why are you having this problem?

           

          2. I didn't overcome the problem how to create a scenario consisting of actions executed by different users. In one testcase only one user was able to login successfully. But I made a workaround and implemented the test class allowing to execute the scenarios for each user remotely in the sequence and reporting errors from each user's action to the main scenario.

          You can have more than one user but you can only have one JSFSession object at a time.  To simulate a second user you will need to use plain HtmlUnit.

           

          Stan

          • 2. Re: JSF Unit with webMethods CAF
            andrzej.dmoch

            Hi Stan,

             

            1) Yes, that's probably the case, that is happens during evaluation of some EL code. Some relaxation of the current code would be appreciated.

             

            2) Probably I miss something on the proper configuration. I see that for instance this class: http://java.sun.com/javaee/6/docs/api/javax/faces/application/ProjectStage.html

            is in JSF since 2.0 version. So with no JSF 2.0 jars in the classpath the code must throw some exceptions. On the other hand I need JSF 1.0 classes on the classpath, because this is required by webMethods CAF. There should be some detail description what jars in what sequence (and how to enforce this sequence) should be there in order to make it work with JSF versions other than current.

             

            3) I had problems with logging out the current user or clearing his session information. I tried different methods (clicking on the logout button, clearing all session scope object but none of the methods worked). I used only one user in a particular point in time.

             

            Regards,

             

            Andrzej

            • 3. Re: JSF Unit with webMethods CAF
              ssilvert

              andrzej.dmoch wrote:

               

              Hi Stan,

               

              1) Yes, that's probably the case, that is happens during evaluation of some EL code. Some relaxation of the current code would be appreciated.

              OK, I'll see what I can do about it.

               

              2) Probably I miss something on the proper configuration. I see that for instance this class: http://java.sun.com/javaee/6/docs/api/javax/faces/application/ProjectStage.html

              is in JSF since 2.0 version. So with no JSF 2.0 jars in the classpath the code must throw some exceptions. On the other hand I need JSF 1.0 classes on the classpath, because this is required by webMethods CAF. There should be some detail description what jars in what sequence (and how to enforce this sequence) should be there in order to make it work with JSF versions other than current.

              You will not get an error unless the JVM or compiler tries to load a class that is not there.  This should not happen if you stick to JSF interfaces in JSF 1.1 or 1.2.  If you will post your error I can probably guess what is wrong.  Lots of developers are using JSFUnit with JSF 1.1 and 1.2.  So I'm sure we can fix your problem.

               

              3) I had problems with logging out the current user or clearing his session information. I tried different methods (clicking on the logout button, clearing all session scope object but none of the methods worked). I used only one user in a particular point in time.

               

              Regards,

               

              Andrzej

              See JSFUnitTestingSecurePages for instructions on logging out.  Let me know if you have any questions.

               

              Stan

              • 4. Re: JSF Unit with webMethods CAF
                zaddo

                Hi Andrzej,

                 

                i am also interested in unit testing webMethods 8 CAF applications. Did you succeed in getting JSFUnit to work with CAF? I would appreciate any information and would also be grateful for a sample project.

                 

                Regards,

                Mathias