2
我有以下问题。我尝试使用activiti提供的模拟框架对单元测试进行单元测试。我有以下activiti.cfg.xml:Activiti未使用在Groovy脚本中使用Mocks.register()注册的对象
<?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>
然后在测试我使用ActivitiRule
运行过程:
@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);
}
的问题,我是用模拟注册的所有对象。 register()可用于ServiceTasks(在表达式中)内部使用,但在groovy脚本中不可用。我得到:
groovy.lang.MissingPropertyException: No such property: timeService for class: Script1
所以的问题: 我做错了什么?这是Activiti的预期行为吗?我可以做些什么来测试使用Mock对象的流程中的脚本?
在此先感谢。