cancel
Showing results for 
Search instead for 
Did you mean: 

Using delegateExpression in service task

hazel8
Champ in-the-making
Champ in-the-making
Hi

I have following question concerning delegateExpression in service task.
<serviceTask id="servicetask1" name="Srv Task check MF" activiti:delegateExpression="${delegateMedFolioProxy}"></serviceTask>

- Can I use a normal Java-class in delegateExpression or just Spring-Beans?
- How can I set the variable pointing to the class (bean) in a Script-task, in a Unit-test.

Many thanks for the help
4 REPLIES 4

frederikherema1
Star Contributor
Star Contributor
When using delegateExpressions, you can use all beans that ere defined in your engine. Concrete:

- All beans listed in the property "beans" of the processEngineConfiguration, when using non-spring processEngineConfigurtion
- All spring-beans in your application-context, when using SpringProcessEngineCOnfiguration when beans-property is not configured
- All referenced spring-beans in the "beans" property, when using Spring ProcessEngineConfiguration.

About testing. When using spring, you can define (or include) a test-context that mocks your classes or replaces them with dummies you can use and assert later.

This is a bit trickier when not in spring-context. But just setting serializable java beans as process-variable will be able to reslove this. All serializable's touched (so eg. when your dummy delegate changes a member field), the bean will be saved to the DB agian. This mean that you can also assert stuff in your test afterwards, by inspecting the process-variables.

hazel8
Champ in-the-making
Champ in-the-making
Many thanks for your answer.

I still can't define the delegateExpression-Variable in Unit-Test.

Can you check my example?

BPMN:
<serviceTask id="servicetask1" name="Srv Task check MF" activiti:delegateExpression="${delegateMedFolioProxy}"></serviceTask>

Unit-Test:
activiti.cfg.xml:
<bean id="MedFolioDelegateBean" class="ch.triemli.proc.hflow.tasksrvc.MedFolioProxy"/>
Java-Code –> leads to error:
variableMap.put("delegateMedFolioProxy", new MedFolioProxy());

Class:
public class MedFolioProxy implements JavaDelegate {
@Override
public void execute(DelegateExecution execution) throws Exception {
  String var = (String) execution.getVariable("fallNummer");
     var = var + "-zl";
     execution.setVariable("fallNummer", var);
}
}

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
I'm not sure (not used this spring way of configuring things) but I think you need to use the bean id in the expression, not put it in a variable

frederikherema1
Star Contributor
Star Contributor
By looking at you're code, I don't really see what you already tried. Can you elaborate a bit? (perhaps use code-tags for code etc)