AnsweredAssumed Answered

Activiti is not using object registered with Mocks.register() inside groovy scripts

Question asked by emilgenov on Oct 20, 2014
Latest reply on Oct 20, 2014 by emilgenov
Activiti is not using object registered with Mocks.register() inside groovy scripts

I have following problem. I try to unit test activiti flow using Mock framework provided by activiti. I have the following activiti.cfg.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

<bean id="processEngineConfiguration"
class="org.activiti.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration">
<property name="jobExecutorActivate" value="false" />
<property name="expressionManager">
<bean class="org.activiti.engine.test.mock.MockExpressionManager" />
</property>
</bean>
</beans>

Then in the test I use ActivitiRule to run the process:

@Rule
public ActivitiRule activitiRule = new ActivitiRule();

@Before
public void onInit() throws Exception {
Mocks.reset();
//Deploy flows ...
Mocks.register("timeService", new TimeServiceImpl(null));
}

private void execute() {
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("req", request);
activitiRule.getRuntimeService().startProcessInstanceByKey("ReturningFlow", variables);
}

Problem that I have is that all objects registered with Mock.register() are available for use inside ServiceTasks (inside the expression), but are not available inside groovy scripts. I get:

groovy.lang.MissingPropertyException: No such property: timeService for class: Script1

So the questions:
Am I doing something wrong? Is this an intended behavior of Activiti? What can I do in order to test scripts inside the flow using Mock objects?

Thanks in advance.

Outcomes