AnsweredAssumed Answered

Unit Test cases for Custom Java Service Task

Question asked by babjikundateeri on Aug 29, 2016
Latest reply on Aug 30, 2016 by babjikundateeri
Hi,

I am new to activiti.

I am not able to figure out the way to write test cases for custom java delegate classes.
below is my test code snippet,
```
public class WorkFlowTest {

    @Rule
    public ActivitiRule activitiRule = new ActivitiRule();

    @Test
    @Deployment(resources = {"testemailflow.bpmn20.xml"})
    public void activitiTest() {
        Map<String, Object>  variables = new HashMap<>();
        RuntimeService runtimeService = activitiRule.getRuntimeService();
        runtimeService.startProcessInstanceByKey("testemailflow", variables);
        System.out.println(runtimeService);
    }
}
```
and my service task is as below
```
<serviceTask id="sid-3E402CB5-51C0-4BB9-9483-941C0BBB7128" name="contact picker" activiti:delegateExpression="${contactPickerTaskDelegation}">
            <extensionElements>
                <activiti:field name="contactPickerRuleId">
                    <activiti:string><![CDATA[7]]></activiti:string>
                </activiti:field>
            </extensionElements>
        </serviceTask>
```
my delegate code is as below
```
public class ContactPickerTaskDelegation implements JavaDelegate {
   private Expression contactPickerRuleId;

  @Override
    public void execute(DelegateExecution delegateExecution) throws Exception {
         LOGGER.debug("contactPickerRuleId " + contactPickerRuleId.getValue(delegateExecution).toString());
         List<Contact> contacts;  // doing something to get contacts
         delegateExecution.setVariable("contacts", contacts);
   }
}
``
while running the test case i' end-up with the exception like below
```
org.activiti.engine.ActivitiException: Unknown property used in expression: ${contactPickerTaskDelegation}

   at org.activiti.engine.impl.el.JuelExpression.getValue(JuelExpression.java:53)
   at org.activiti.engine.impl.bpmn.helper.DelegateExpressionUtil.resolveDelegateExpression(DelegateExpressionUtil.java:37)
   at org.activiti.engine.impl.bpmn.behavior.ServiceTaskDelegateExpressionActivityBehavior.execute(ServiceTaskDelegateExpressionActivityBehavior.java:85)
   at org.activiti.engine.impl.pvm.runtime.AtomicOperationActivityExecute.execute(AtomicOperationActivityExecute.java:60)
```


My Application is using `spring-boot`.

Thanks in advance.

Outcomes