【发布时间】:2017-05-01 07:33:53
【问题描述】:
我正在使用带有共享流程引擎的 Spring MVC 和 Camunda 编写一个简单的流程应用程序。现在我想添加简单的测试用例,我遇到了流程引擎为每个工厂方法返回 null 的问题。运行应用程序时,流程引擎会按预期返回服务。
当使用共享流程引擎时,我应该如何为 JUnit 测试配置 camunda?
这是我的 camunda 流程引擎配置:
<?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">
<!-- bind the process engine service as Spring Bean -->
<bean name="processEngineService" class="org.camunda.bpm.BpmPlatform" factory-method="getProcessEngineService" />
<!-- bind the default process engine as Spring Bean -->
<bean name="processEngine" factory-bean="processEngineService" factory-method="getDefaultProcessEngine" />
<bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService"/>
<bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService"/>
<bean id="taskService" factory-bean="processEngine" factory-method="getTaskService"/>
<bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService"/>
<bean id="managementService" factory-bean="processEngine" factory-method="getManagementService"/>
<bean id="identityService" factory-bean="processEngine" factory-method="getIdentityService"/>
<bean id="authorizationService" factory-bean="processEngine" factory-method="getAuthorizationService"/>
<!-- bootstrap the process application -->
<bean id="processApplication" class="org.camunda.bpm.engine.spring.application.SpringServletProcessApplication" />
</beans>
这是我的简单测试类的相关部分:
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration({
"file:src/main/webapp/WEB-INF/process-conf.xml",
"file:src/main/webapp/WEB-INF/hibernate-conf.xml",
"file:src/main/webapp/WEB-INF/camunda-conf.xml",
"file:src/main/webapp/WEB-INF/dispatcher-servlet.xml",
})
public class OrderControllerTest {
@Autowired
private WebApplicationContext wac;
private MockMvc mockMvc;
@Before
public void setup() {
DefaultMockMvcBuilder builder = MockMvcBuilders.webAppContextSetup(this.wac);
this.mockMvc = builder.build();
}
@Test
public void testTest() throws Exception {
ResultMatcher ok = MockMvcResultMatchers.status().isOk();
MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.get("/");
this.mockMvc.perform(builder)
.andExpect(ok);
}
}
这是启动junit测试时抛出的异常:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'repositoryService' defined in URL [file:src/main/webapp/WEB-INF/camunda-conf.xml]: factory-bean 'processEngine' (or a BeanPostProcessor involved) returned null
【问题讨论】:
-
你试过在调试器中运行它,并在工厂方法中设置断点吗?
-
谢谢,我从没想过为 camunda 代码运行调试器
标签: spring-mvc junit camunda