Flowable 7.1.0 测试运行时找不到 flowable.cfg.xml

问题描述 投票:0回答:1

我已经构建了一个可流动的 7.1.0 groovy springboot gradle 项目,当我手动运行时它可以工作。 但是我将测试过程复制到 test/resources/processes 中并构建了一个简单的测试,用 @FlowableTest 注释了我的 junit 5 测试

@FlowableTest

//@SpringBootTest 类过程测试{

private ProcessEngine processEngine
private RuntimeService runtimeService
private TaskService taskService

@BeforeEach
void setUp(ProcessEngine processEngine) {
    this.processEngine = processEngine
    this.runtimeService = processEngine.getRuntimeService()
    this.taskService = processEngine.getTaskService()
}

@Test
@Deployment (resources = [ "processes/one-task-process-test.bpmn20.xml" ])
void testOneTaskProcess() {
    runtimeService.startProcessInstanceByKey("oneTaskProcessTest")

    Task task = taskService.createTaskQuery().singleResult()

    assertEquals("my task", task.getName())

    taskService.complete(task.getId())
    assertEquals(0, runtimeService.createProcessInstanceQuery().count())
}

}

我的 build.gradle 依赖项是

dependencies {
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '3.4.0'
implementation group: 'org.flowable', name: 'flowable-spring-boot-starter-process', version: '7.1.0'
implementation group: 'org.flowable', name: 'flowable-spring-boot-starter-rest-api', version: '7.0.0.M1'
//implementation group: 'org.flowable', name: 'flowable-idm-spring', version: '7.1.0'
//include groovy script engine for groovy script tasks
implementation group: 'org.apache.groovy', name: 'groovy-jsr223', version: '4.0.24'


implementation group: 'com.h2database', name: 'h2', version: '2.3.232'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-actuator', version: '3.4.0'
//for actuator bean
//implementation group: 'org.springframework.security', name: 'spring-security-web', version: '6.4.1'
//implementation group: 'org.springframework.security', name: 'spring-security-config', version: '6.4.1'

implementation 'org.apache.groovy:groovy:4.0.14'
testImplementation platform('org.junit:junit-bom:5.10.0')
testImplementation 'org.junit.jupiter:junit-jupiter'
testImplementation 'org.junit.jupiter:junit-jupiter-engine'
testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: '3.4.0'


testImplementation group: 'com.h2database', name: 'h2', version: '2.3.232'

}

但是当你运行测试时我收到此错误

... 类路径资源 [flowable.cfg.xml] 无法打开,因为它不存在 java.io.FileNotFoundException:类路径资源 [flowable.cfg.xml] 无法打开,因为它不存在 在 org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:215) 在 org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:342) 在 org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:319) 在org.flowable.common.engine.impl.cfg.BeansConfigurationHelper.parseEngineConfiguration(BeansConfigurationHelper.java:38) 在 org.flowable.common.engine.impl.cfg.BeansConfigurationHelper.parseEngineConfigurationFromResource(BeansConfigurationHelper.java:62) 在org.flowable.engine.ProcessEngineConfiguration.createProcessEngineConfigurationFromResource(ProcessEngineConfiguration.java:176) 在org.flowable.engine.ProcessEngineConfiguration.createProcessEngineConfigurationFromResource(ProcessEngineConfiguration.java:172) 在 org.flowable.engine.impl.test.TestHelper.getProcessEngine(TestHelper.java:254) 在 org.flowable.engine.test.FlowableExtension.createProcessEngine(FlowableExtension.java:198) 在 org.flowable.engine.test.FlowableExtension.lambda$getTestHelper$4(FlowableExtension.java:194) ...

我看不出我哪里出了问题,我希望有人知道为什么测试无法执行。 为什么我需要 flowable.cfg.xml ,它会放在哪里?

unit-testing groovy junit5 flowable
1个回答
0
投票

有点奇怪 - 我期望可流动的测试框架通过其注释来设置所有这些。

但是进行了一些挖掘并发现了此页面条目https://www.flowable.com/open-source/docs/bpmn/ch03-Configuration

所以在我的 test/ressorces 文件夹中,我创建了一个 flowable.cfg.xml 文件和(用于内存测试中的 h2)一个包含该文件的文件

<?xml version="1.0" encoding="UTF-8"?>

<bean id="processEngineConfiguration" class="org.flowable.engine.impl.cfg.StandaloneProcessEngineConfiguration">

    <property name="jdbcUrl" value="jdbc:h2:mem:flowable;DB_CLOSE_DELAY=1000" />
    <property name="jdbcDriver" value="org.h2.Driver" />
    <property name="jdbcUsername" value="sa" />
    <property name="jdbcPassword" value="" />

    <property name="databaseSchemaUpdate" value="true" />

    <property name="asyncExecutorActivate" value="false" />

</bean>

当您尝试重新运行测试时,它似乎运行时没有错误。 需要向 flowable 项目发布一条消息,说明默认情况下,即使使用 @FlowableTest 注释,您的测试也无法工作

© www.soinside.com 2019 - 2024. All rights reserved.