AnsweredAssumed Answered

MockSupport for Delegate Execution Beans

Question asked by texens on Sep 25, 2014
Latest reply on Aug 14, 2015 by jsalmon
Currently Activiti support Mock Support for Service Tasks if they are defined as classes.

In the BPMN file, define the service task as :

    <serviceTask id="serviceTask" activiti:class="com.yourcompany.delegate"/>


and then in the test file,

   @Test
   @Deployment
   @MockServiceTask(originalClassName="com.yourcompany.delegate",
                    mockedClassName="org.activiti.standalone.testing.helpers.ServiceTaskTestMock")
   public void testMockedServiceTaskAnnotation() {
      Assert.assertEquals(0, ServiceTaskTestMock.CALL_COUNT.get());
      activitiRule.getRuntimeService().startProcessInstanceByKey("mockSupportTest");
      Assert.assertEquals(1, ServiceTaskTestMock.CALL_COUNT.get());   
   }


Source : MockSupportWithActivitiRuleTest.java


Question : I have defined my classes in the bpmn file as delegate expression :


    <serviceTask id="serviceTask" activiti:delegateExpression="${serviceTaskBean}"/>


and in the activiti.cfg.xml file, I define these beans.

Is there a way I can mock these delegate expressions, in a way similar to the facility for service tasks defined as class (aforementioned manner).
Example :

   @MockServiceTask(originalClassName="com.yourcompany.delegate",
                    mockedClassName="org.activiti.standalone.testing.helpers.SuccessfulServiceTaskTestMock")
   public void testMockedServiceTaskSuccess() {



   @MockServiceTask(originalClassName="com.yourcompany.delegate",
                    mockedClassName="org.activiti.standalone.testing.helpers.FailedServiceTaskTestMock")
   public void testMockedServiceTaskFailure() {


The first code takes in the SuccessfulServiceTaskTestMock class in delegate, while the second code tests that the FailedServiceTaskTestMock class in delegate.

One brute force solution is to have separate activiti.cfg.xml file for each test and set the beans appropriately on a per unit test basis. But this is not scalable, as I have to update all the xml files for the test cases when I change the workflow.

Anybody has come across this scenario, and found a solution for this ?

TIA

Outcomes