How to Mock Camunda Expression

Hello,

I need to create a unit test to a JavaDelegate that uses an Expression from org.camunda.bpm.engine.delegate.Expression. However, I was not able to Mock the Expression. I am using Mockito and it is an integration test.

I am able to mock the DelegateExecution:

@MockBean
private DelegateExecution execution;

Nevertheless, to Expression this is not working.

My Class is as follow:

@Service(“engineRuleDelegates”)
public class EngineRuleDelegates implements JavaDelegate {

@Autowired
private EngineRulesConnector engineRulesConnector;

@Autowired
private ObjectMapper mapper;

@Autowired
private EngineProperties engineProperties;

private Expression step;

@Override
public void execute(DelegateExecution execution) throws Exception {

String stepValue = (String) step.getValue(execution);

Any ideas of how to mock the Expression would be helpful.

Hi @Heloisa_Carbone,

depending on your JUnit setup, you can use Mocks.register("beanName", object instance) to create the expression result manually.

To do this, you have to add the org.camunda.bpm.engine.test.mock.MockExpressionManager as expressionManager in your test engine.

Have a look at this test class https://github.com/ingorichtsmeier/twitter-process-application/blob/master/twitter/src/test/java/org/camunda/bpm/example/twitter/ProcessTestCase.java#L30
and at this configuration: https://github.com/ingorichtsmeier/twitter-process-application/blob/master/twitter/src/test/resources/camunda.cfg.xml.

Hope this helps, Ingo

2 Likes