1 Reply Latest reply on Apr 23, 2012 3:46 AM by swiderski.maciej

    Unit Testing/Checking Variables

      Hello All


      Sorry to ask this, but I've looked around and haven't seen how to do this.


      I have a simple unit test using JbpmJUnitTestCase.  I want to validate my custom work handlers, so I have created a BPMN2 workflow with a work handler in it.  The work handler takes in some parameters and has results that are mapped to a variable.  I know that it is generally working correctly as I can put a script task after the custom task to output the variables to the console.  My unit test creates a parameter map and launches the flow:


      ProcessInstance processInstance = knowledgeSession.createProcessInstance("testprocess", parameterMap);



      I know I can do this in one step using the startProcess method.  This method above works, as does the startProcess method.


      I am also able to successfully assert, e.g.:




      However by this time the processInstance is completed (per the assertation).  So the variable context has been destroyed and I cannot use standard JUnit asserts to validate the output, retreived using getVariableValue.


      So does anyone have an idea how I am meant to get variables from the context after the flow is complete?  Or am I meant to watch the variables while the flow is happening, maybe through an event listener?


      Thanks for any help.

        • 1. Re: Unit Testing/Checking Variables

          If you don't have any wait states in your process which means it will process all nodes after calling start process then the only way is to use event listeners. While using event listeners you have two options:

          • use event listeners that are shipped with jbpm as part of BAM module
          • create your custom event listener


          If you use persistence for your processes I would recommend to use BAM module for this as it will record most of the data you would like to have and then you could query history log to get data, it includes variable information as well. For more information about history log, please have a look in the documentation.