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"?><br><span><beans xmlns="</span><a class="jive-link-external-small" href="http://www.springframework.org/schema/beans" rel="nofollow noopener noreferrer" target="_blank">http://www.springframework.org/schema/beans</a><span>"</span><br><span>xmlns:xsi="</span><a class="jive-link-external-small" href="http://www.w3.org/2001/XMLSchema-instance" rel="nofollow noopener noreferrer" target="_blank">http://www.w3.org/2001/XMLSchema-instance</a><span>"</span><br><span>xsi:schemaLocation="</span><a class="jive-link-external-small" href="http://www.springframework.org/schema/beans" rel="nofollow noopener noreferrer" target="_blank">http://www.springframework.org/schema/beans</a><span> </span><a class="jive-link-external-small" href="http://www.springframework.org/schema/beans/spring-beans.xsd" rel="nofollow noopener noreferrer" target="_blank">http://www.springframework.org/schema/beans/spring-beans.xsd</a><span>"></span>
<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<br>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<br>
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.