trigger的配置与测试文件内容如下
<process id="my-process">
<startEvent id="start"/>
<sequenceFlow sourceRef="start" targetRef="someTask" id="flow1"/>
<receiveTask id="someTask" />
<endEvent id="end"/>
<sequenceFlow id="flow3" sourceRef="someTask" targetRef="end"/>
</process>
@Test
@Deployment(resources = {"receiveTask.bpmn20.xml"})
public void testTrigger() {
RuntimeService runtimeService = activitiRule.getRuntimeService();
//启动流程
runtimeService.startProcessInstanceByKey("my-process");
Execution task = runtimeService.createExecutionQuery().activityId("someTask").singleResult();
LOGGER.info("task = {}", task);
//执行触发器之后就会完成
runtimeService.trigger(task.getId());
task = runtimeService.createExecutionQuery().activityId("someTask").singleResult();
LOGGER.info("task = {}", task);
}
signal的配置与测试
<signal id="signalStart" name="my-signal"/>
<process id="my-process">
<startEvent id="start"/>
<sequenceFlow sourceRef="start" targetRef="signal-received" id="flow1"/>
<intermediateCatchEvent id="signal-received">
<signalEventDefinition signalRef="signalStart"/>
</intermediateCatchEvent>
<endEvent id="end"/>
<sequenceFlow id="flow3" sourceRef="signal-received" targetRef="end"/>
</process>
@Test
@Deployment(resources = {"my-process-signal.bpmn20.xml"})
public void testSignalEventRecrived() {
RuntimeService runtimeService = activitiRule.getRuntimeService();
//启动流程
runtimeService.startProcessInstanceByKey("my-process");
//在数据库中是否存在信号执行流
Execution execution = runtimeService
.createExecutionQuery().signalEventSubscriptionName("my-signal").singleResult();
LOGGER.info("execution = {}", execution);
//触发信息向后执行
runtimeService.signalEventReceived("my-signal");
execution = runtimeService
.createExecutionQuery().signalEventSubscriptionName("my-signal").singleResult();
LOGGER.info("execution = {}", execution);
}
Message的配置与测试文件内容如下(message有两种配置,一种是类似于signal那样配置,一种是放在start里面,可以通过messageId进行启动流程)
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
<message id="messageStart" name="my-message"/>
<process id="my-process">
<startEvent id="start"/>
<sequenceFlow sourceRef="start" targetRef="message-received" id="flow1"/>
<intermediateCatchEvent id="message-received">
<messageEventDefinition messageRef="messageStart"/>
</intermediateCatchEvent>
<endEvent id="end"/>
<sequenceFlow id="flow3" sourceRef="message-received" targetRef="end"/>
</process>
</definitions>
@Test
@Deployment(resources = {"my-process-message.bpmn20.xml"})
public void testMessage() {
RuntimeService runtimeService = activitiRule.getRuntimeService();
runtimeService.startProcessInstanceByKey("my-process");
Execution execution = runtimeService.createExecutionQuery().messageEventSubscriptionName("my-message").singleResult();
LOGGER.info("execution = {}", execution);
runtimeService.messageEventReceived("my-message", execution.getId());
execution = runtimeService.createExecutionQuery().messageEventSubscriptionName("my-message").singleResult();
LOGGER.info("execution = {}", execution);
}
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn"
xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI"
typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath"
targetNamespace="http://www.activiti.org/test">
<message id="messageStart" name="my-message"/>
<process id="my-process">
<startEvent id="start">
<messageEventDefinition messageRef="messageStart"/>
</startEvent>
<sequenceFlow sourceRef="start" targetRef="someTask" id="flow1"/>
<userTask id="someTask"/>
<endEvent id="end"/>
<sequenceFlow id="flow3" sourceRef="someTask" targetRef="end"/>
</process>
</definitions>
@Test
@Deployment(resources = {"my-process-message-send.bpmn20.xml"})
public void testMessageStart() {
RuntimeService runtimeService = activitiRule.getRuntimeService();
ProcessInstance processInstance = runtimeService.startProcessInstanceByMessage("my-message");
LOGGER.info("processInstance = {}", processInstance);
}