6 Replies Latest reply on Sep 29, 2009 7:31 AM by lucio piccoli

    JBPM unit testing

    lucio piccoli Newbie

      hi all,



      i am having difficulty in testing JBPM component in the seam test environment.


      i have used the exact code from the 'todo' example, yet i get the following error when trying to login.


      i have attached the error, test code and the simple Login class.


      javax.el.ELException: org.jboss.seam.RequiredException: @In attribute requires non-null value: login.actor
           at javax.el.BeanELResolver.setValue(BeanELResolver.java:376)
           at javax.el.CompositeELResolver.setValue(CompositeELResolver.java:283)
           at org.jboss.el.parser.AstPropertySuffix.setValue(AstPropertySuffix.java:73)
           at org.jboss.el.parser.AstValue.setValue(AstValue.java:84)
           at org.jboss.el.ValueExpressionImpl.setValue(ValueExpressionImpl.java:249)
           at org.jboss.seam.core.Expressions$1.setValue(Expressions.java:117)
           at org.jboss.seam.mock.AbstractSeamTest$ComponentTest.setValue(AbstractSeamTest.java:152)
           at com.asteriski.itpflow.business.LotFormActionTest$1.testComponents(LotFormActionTest.java:37)
           at org.jboss.seam.mock.AbstractSeamTest$ComponentTest.run(AbstractSeamTest.java:162)
           at com.asteriski.itpflow.business.LotFormActionTest.getActor(LotFormActionTest.java:43)
      Caused by: org.jboss.seam.RequiredException: @In attribute requires non-null value: login.actor
           at org.jboss.seam.Component.getValueToInject(Component.java:2335)
           at org.jboss.seam.Component.injectAttributes(Component.java:1736)
           at org.jboss.seam.Component.inject(Component.java:1554)
           at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:61)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
           at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
           at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
           at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)
           at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)
           at com.asteriski.itpflow.test.Login_$$_javassist_seam_1.setUser(Login_$$_javassist_seam_1.java)
           at javax.el.BeanELResolver.setValue(BeanELResolver.java:371)






      @Test  
           public void createProcess() throws Exception{
                
                 new FacesRequest() {
      
                    @Override
                    protected void updateModelValues() throws Exception
                    {
                       setValue("#{login.user}", "qa");
                    }
      
                    @Override
                    protected void invokeApplication() throws Exception
                    {
                       assert invokeMethod("#{login.login}").equals("/todo.jsp");
                       assert Actor.instance().getId().equals("qa");
                    }
      
                    @Override
                    protected void renderResponse() throws Exception
                    {
                       assert ( (List) getInstance(TaskInstanceList.class) ).size()==0;
                    }
                    
                 }.run();





      @Name("login")
      public class Login 
      {
         
         @In private Actor actor;
         
         private String user;
      
         public String getUser() {
            return user;
         }
      
         public void setUser(String user) {
            this.user = user;
         }
         
         public String login()
         {
            actor.setId(user);
            return "/todo.jsp";
         }
      }




      Q1. what have i missed in my config?


      Q2. is there a simpler way to test jbpm?


      -lp


        • 1. Re: JBPM unit testing
          Ronald van Kuijk Apprentice

          Q1: No idea, the error just says:



          @In attribute requires non-null value: login.actor

          Which might be the case and you have to solve that like you would for any other identical error. Nothing (directly) jBPM related.



          Q2: Testing jBPM is done in the jBPM project ;- Testing your processdefinition in a seam context you probably mean? Well, then my question would be: Simpeler than what? I do not see you testing any process in what you provide.

          • 2. Re: JBPM unit testing
            lucio piccoli Newbie

            @In attribute requires non-null value: login.actor

            Which might be the case and you have to solve that like you would for any other identical error. Nothing (directly) jBPM related.

            true it is not directly related to Jbpm. But without having the Actor set the taskinstanceList will always return 0.



             assert ( (List) getInstance(TaskInstanceList.class) ).size()==0;




            so rephrasing question Q1.


            Q1.1. In order to test Jbpm functionality that requires the Actor to be set, what or how is needed to be done?



            Q2: Testing jBPM is done in the jBPM project ;- Testing your processdefinition in a seam context you probably mean? Well, then my question would be: Simpeler than what? I do not see you testing any process in what you provide.

            i am unable to get to the process def testing because i cant get an actor within seamtest.


            so rephrasing Q2.


            Q2.1 Simpler than using Seam integration testing?


            -lp



            • 3. Re: JBPM unit testing
              Ronald van Kuijk Apprentice

              Q1.1: The DVDStore example has Actor etc included in it. Have a look at that, it is a fairly complete example of using jBPM and Seam


              Q2.1 In tests afaik, you can do things like Actor.instance().setId(gavin); Then the tasklist will not return a list of size 0


              • 4. Re: JBPM unit testing
                lucio piccoli Newbie



                Q1.1: The DVDStore example has Actor etc included in it. Have a look at that, it is a fairly complete example of using jBPM and Seam

                i am using the Actor ok in the code just cant find an example of using it in testing. DVDStore doesnt use the Actor for testing, but the Todo example does. I cant get the Todo code to work.


                The DVDStore uses identity.login which seems to be used for the shopping cart user id. But no JBPM Actor stuff.




                Q2.1 In tests afaik, you can do things like Actor.instance().setId('gavin'); Then the tasklist will not return a list of size 0

                tried that but i get NPE when accessing the Actor.instance().


                my simple test case is below.


                 new FacesRequest() {
                
                              @Override
                              protected void updateModelValues() throws Exception
                              {
                                 
                                   Actor.instance().setId("qa");
                                  
                              }
                
                              @Override
                              protected void invokeApplication() throws Exception
                              {                 
                                   
                                 assert Actor.instance().getId().equals("qa");
                              }
                
                              @Override
                              protected void renderResponse() throws Exception
                              {
                                 assert ( (List) getInstance(TaskInstanceList.class) ).size()==0;
                              }
                              
                           }.run();




                Q.Has anyone got a working example of accessing the JBPM Actor in seam test?


                -lp

                • 5. Re: JBPM unit testing
                  lucio piccoli Newbie

                  still not having any fun getting the Jbpm actor intialised in a test.


                  i cant seem to find any doc that indicate explicit testing procedures for JBPM in seam other than the examples which are very lite on JBPM testing.


                  Q1. is my JBPM testing procedure correct for seam?


                  Q2. is there a standard pattern to use when testing JBPM in seam?


                  any help appreciated


                  -lp

                  • 6. Re: JBPM unit testing
                    lucio piccoli Newbie

                    ah solved it.


                    it seems that the Component: org.jboss.seam.bpm.jbpm was not being loaded by SeamTest.


                    this was due to not having a bpm definition defined in bootstrap/META-INF/components.xml


                    add a definition and all works.


                    components.xml
                    
                    ....
                     <bpm:jbpm>
                            <bpm:process-definitions>
                                 <!-- value>activity.jpdl.xml</value-->
                            </bpm:process-definitions>
                    </bpm:jbpm>



                    -lp