在我的BPMN中,我在执行监听器中设置了一个变量,如Internal Context Variables中所述:
下面的示例显示一个表达式,该表达式将变量test设置为执行侦听器的当前事件名称。
<camunda:executionListener event="start" expression="${execution.setVariable('test', execution.eventName)}" />
我尝试在Camunda Spring Boot应用程序的JUnit测试中测试此BPMN,但未应用执行侦听器。
BPMN:
<bpmn:process id="test_bpmn" isExecutable="true">
<bpmn:startEvent id="StartEvent_1">
<bpmn:extensionElements>
<camunda:executionListener expression="execution.setVariable("test", "success")" event="start" />
</bpmn:extensionElements>
<bpmn:outgoing>SequenceFlow_0hgrhd2</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id="SequenceFlow_0hgrhd2" sourceRef="StartEvent_1" targetRef="Task_11dxb5y" />
<bpmn:userTask id="Task_11dxb5y">
<bpmn:incoming>SequenceFlow_0hgrhd2</bpmn:incoming>
</bpmn:userTask>
</bpmn:process>
JUnit测试:
@Deployment(resources = {"test.bpmn"})
public class MyTest {
@Rule
public ProcessEngineRule rule = new StandaloneInMemoryTestConfiguration().rule();
@Test
public void test() {
ProcessInstance instance = rule.getRuntimeService().startProcessInstanceByKey("test_bpmn");
assertThat(instance).isActive().hasVariables("test");
}
错误:
java.lang.AssertionError: Expecting actual ProcessInstance {id='4', processDefinitionId='test_bpmn:1:3', businessKey='null'} to hold process variables [test], instead we found it to hold no variables at all.
at org.camunda.bpm.engine.test.assertions.ProcessInstanceAssert.hasVars(ProcessInstanceAssert.java:284)
at org.camunda.bpm.engine.test.assertions.ProcessInstanceAssert.hasVariables(ProcessInstanceAssert.java:257)
at com.mycompany.MyTest.test(MyTest.java:24)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55)
at org.camunda.bpm.engine.test.ProcessEngineRule$1.evaluate(ProcessEngineRule.java:165)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
我错了什么?