7 Replies Latest reply on Aug 19, 2009 7:52 AM by Sebastian Schneider

    Confusing regarding unit test

    Sebastian Schneider Master

      Good morning!

      I am a bit confused regarding a process and a unit test of mine. This is my process:

      <?xml version="1.0" encoding="UTF-8"?>
      
      <process key="task_types" name="task_types" xmlns="http://jbpm.org/4.0/jpdl">
       <start g="95,26,48,48" name="start1">
       <transition g="-26,-29" name="to state1" to="state1"/>
       </start>
       <state g="209,39,92,52" name="state1">
       <transition g="-51,-21" name="to java1" to="java1"/>
       </state>
       <java class="JavaClass" g="212,124,92,52" method="printMessage" name="java1">
       <transition g="-50,-21" name="to task1" to="task1"/>
       </java>
       <task g="215,210,92,52" name="task1">
       <transition g="-68,-12" name="to custom1" to="custom1"/>
       </task>
       <custom class="CustomClass" g="214,290,92,52" name="custom1">
       <transition g="-48,-21" name="to end1" to="end1"/>
       </custom>
       <end g="395,303,48,48" name="end1"/>
      </process>
      


      This is the part of my unit test:

       public void testWaiteStateAndJavaTask() {
       ProcessInstance processInstance = executionService.startProcessInstanceByKey("task_types");
       Execution execution = processInstance.findActiveExecutionIn("state1");
       assertNotNull(execution);
       String executionId = execution.getId();
       executionService.signalExecutionById(executionId);
       Set<String> activities = processInstance.findActiveActivityNames();
       System.out.println(activities.toString());
      
       }
      


      Execution log:
      08:38:57,350 FIN | [ProcessDefinitionImpl] creating new execution for process 'task_types'
      08:38:57,413 FIN | [DefaultIdGenerator] generated execution id task_types.1
      08:38:57,413 FIN | [ExecuteActivity] executing activity(start1)
      08:38:57,413 FIN | [ExecuteActivity] executing activity(state1)
      08:38:57,491 FIN | [Signal] signalling activity(state1), signalName=null
      08:38:57,507 FIN | [ExecuteActivity] executing activity(java1)
      Methodenaufruf in JavaClass erfolgt.
      08:38:57,507 FIN | [ExecuteActivity] executing activity(task1)
      
      [state1]
      


      Calling activities.toString() returns [state1]. I expected [task1] rather than state1 when calling findActiveActivityNames(). Can somebody shed some light on this?

        • 1. Re: Confusing regarding unit test
          Sebastian Schneider Master

          It's annoying that one cannot edit and correct posts in the forums. The title should be "Confusion regarding unit test". :)

          • 2. Re: Confusing regarding unit test
            Nicolas Pirard Newbie

            I tried the your code, got the same result and got confused a bit

            but then I tried :

            ProcessInstance processInstance = executionService.startProcessInstanceByKey("task_types"/*, variables*/);
             Execution execution = processInstance.findActiveExecutionIn("state1");
             assertNotNull(execution);
             String executionId = execution.getId();
             executionService.signalExecutionById(executionId);
             Set<String> activities = processInstance.findActiveActivityNames();
             System.out.println(activities.toString());
            
             //reload
             processInstance = executionService.findProcessInstanceById(executionId);
             activities = processInstance.findActiveActivityNames();
             System.out.println(activities.toString());
            


            and here the log :
            12:03:26,545 FIN | [ProcessDefinitionImpl] creating new execution for process 'task_types'
            12:03:26,561 FIN | [DefaultIdGenerator] generated execution id task_types.226
            12:03:26,561 FIN | [ExecuteActivity] executing activity(start1)
            12:03:26,561 FIN | [ExecuteActivity] executing activity(state1)
            12:03:26,576 FIN | [Signal] signalling activity(state1), signalName=null
            12:03:26,592 FIN | [ExecuteActivity] executing activity(java1)
            JavaClass.printMessage() - Hallo !!
            12:03:26,592 FIN | [ExecuteActivity] executing activity(task1)
            [state1]
            [task1]
            


            it looks like the ProcessInstance object has to be reloaded by our means

            • 3. Re: Confusing regarding unit test
              Nicolas Pirard Newbie

              PS : not sure this is the intended behaviour, though ?

              • 4. Re: Confusing regarding unit test
                Sebastian Schneider Master

                I expected the process to have reached the task custom1. So this task should be in the list of active activities. state1 should not be active anymore since I sent the signal which makes task1 take the default transition.

                • 5. Re: Confusing regarding unit test
                  Nicolas Pirard Newbie

                  IMHO, state 1 is not active anymore, but the instance of ProcessInstance you use is obsolete at the end, there is a need to obtain a newer instance

                  what I question is wether the fact that instances of ProcessInstance get obsololete is intended or not

                  • 6. Re: Confusing regarding unit test
                    Ronald van Kuijk Master

                    What you get back is not a reference to something but the thing that is active at the time you requested it (disconnected). The behaviour of jBPM is as expected. Same is true for tasklists etc.

                    • 7. Re: Confusing regarding unit test
                      Sebastian Schneider Master

                      Okay I changed my unit test to this:

                       public void testWaiteStateAndJavaTask() {
                       ProcessInstance processInstance = executionService.startProcessInstanceByKey("task_types");
                       Execution execution = processInstance.findActiveExecutionIn("state1");
                       assertNotNull(execution);
                       String executionId = execution.getId();
                       executionService.signalExecutionById(executionId);
                       processInstance = executionService.findProcessInstanceById(processInstance.getId());
                       Set<String> activities = processInstance.findActiveActivityNames();
                       System.out.println(activities.toString());
                       }
                      


                      Now it works as expected. Thanks for your explanation, Ronald. Need to keep this in mind.

                      What you get back is not a reference to something but the thing that is active at the time you requested it (disconnected). The behaviour of jBPM is as expected. Same is true for tasklists etc.