cancel
Showing results for 
Search instead for 
Did you mean: 

Mock a Java service task

rangoo
Champ in-the-making
Champ in-the-making
I have a process where I have a timer job which calls a Java Service Task(which calls a webservice). In my unit test I am triggering Jobs like this


      // Manually execute the job
      
ManagementService managementService = activitiRule
            .getManagementService();
      Job timer = managementService.createJobQuery().singleResult();

      managementService.executeJob(timer.getId());



But I am not sure how I mock my Java Service Tasks' execute method, so that the actual webservice is not made.
6 REPLIES 6

rangoo
Champ in-the-making
Champ in-the-making
I mean to avoid the actual webservice call*

gromar
Champ in-the-making
Champ in-the-making
One possibility is to skip task execution.
see https://github.com/gro-mar/activiti-crystalball/blob/master/examples/src/main/process/org/activiti/c...

there is code which is skipping e-mail sending task (Noop = No Operation):

<serviceTask id="rejection_email" name="Send rejection e-mail" activiti:type="mail" sim:behavior="org.activiti.crystalball.simulator.delegate.Noop">


to run whole test download project from
http://gro-mar.github.io/activiti-crystalball/

(you can consider to use simulation for testing too)

frederikherema1
Star Contributor
Star Contributor
Another way is to extend the org.activiti.engine.impl.bpmn.parser.factory.AbstractBehaviorFactory and override the relevant methods so they return "dummy" ActivitiyBehaviours instead of actual WS-calls or service-calls.

You can, for example, use the same process-engine configuration as in production, but in your test-cases, replace the activityBehaviourFactory on the ProcessEngineConfigurationImpl, prior to building the engine. Or off course, configure it in the activiti.cfg.xml-file…

rangoo
Champ in-the-making
Champ in-the-making
Thanks for your reply.  I am using the 2nd option, But Crystal ball simulation looks interesting. Thanks for sharing it.

Only issue to use it for testing - I need to maintain separate BPMN files for testing to add simulation something like this:

<code> sim:behavior="org.activiti.crystalball.simulator.delegate.Noop" </code>

Am I correct?

gromar
Champ in-the-making
Champ in-the-making
Yes you are correct. I am going to implement simulation experiment description which won't be part of process definition.

jbarrez
Star Contributor
Star Contributor
You could add a new BpmnParseHandler that swaps out the service task in test. That way you don't need to have multiple bpmn files.