cancel
Showing results for 
Search instead for 
Did you mean: 

Hi, I need to write a testcase to test an asynchronous process mocking some of the service tasks in it.

durgaprasadb
Champ in-the-making
Champ in-the-making

Hi,

I need to write a testcase to test an asynchronous process mocking some of the service tasks in it. I am able to mock by extending from ActivitiTestCase class but the process doesnt wait until all jobs are done. And I am able to test async process with the help of PluggableActivitiTestCase class but in this case, I am unable to mock a service task. Not sure how to test my scenario. Your inputs are highly appreciated. Thanks in advance.

Regards,
Durga Prasad.

5 REPLIES 5

cjose
Elite Collaborator
Elite Collaborator

If there are async jobs/tasks in the process, you may need to query for jobs via the management service and complete the jobs in your test case for it to move to the next step. There are plenty of examples in the activiti repo under unit test cases.  GitHub - Activiti/Activiti: Activiti is a light-weight workflow and Business Process Management (BPM...  

durgaprasadb
Champ in-the-making
Champ in-the-making
Thanks for your reply
My async process doesnot have any user tasks for me to fetch and complete. All the tasks are service tasks and I need to mock those service tasks with some dummy classes to ensure the actual service is not hit. 
I looked into the activiti-engine test cases and I could find the below ones. 
- I could see synchronous processes being tested with mock classes
- I could see async process being tested by waiting for the jobs to be complete by using waitForJobExecutorToProcessAllJobs() method. 
I am looking for an example with combination of both the above scenarios and I could not find one there. Can you please point one for me ? Thanks again. 
Regards,
Durga Prasad. 
Srihari Kiran • 34 mins

cjose
Elite Collaborator
Elite Collaborator

Are you using Activiti Community or Alfresco Process Services (enterprise version)?

cjose
Elite Collaborator
Elite Collaborator

If enterprise, I have an example in this blog where I am using org.mockito.Mockito to mock some classes. You could take a similar approach even with community version, but I don't have an example handy!

hari
Star Contributor
Star Contributor

Hi, 

You will need to follow the below steps to be able to mock the service tasks of an async process. 

1) Create a custom class to extend AbstractActivitiTestCase class and add mock support to it. You may refer to ActivitiTestCase class on how it was done.  

2) Extend PluggableActivitiTestCase and modify it to extend from the above created custom class. 

3) In your test case, extend from your CustomPluggableActivitiTestCase class.