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

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
durgaprasadb
Member II

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

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
cjose
Senior Member II

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

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
Member II

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

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
Senior Member II

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

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

cjose
Senior Member II

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

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
Established Member

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

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.