package com.activiti.study.parallelGateWay;
import java.io.InputStream;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.junit.Test;
public class parallelGateWay {
/**
*加载默认的流程引擎: 加载 activiti.cfg.xml 文件
*/
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
/**
* 部署流程定义
*/
@Test
public void testDeployProcessDefination_inputStream(){
/**
* 从当前包下进行加载
*/
InputStream inputStreamBpmn = this.getClass().getResourceAsStream("parallelGateWay1.bpmn");
InputStream inputStreamPng = this.getClass().getResourceAsStream("parallelGateWay1.png");
Deployment deployment = processEngine.getRepositoryService()
.createDeployment()
.name("New_ParallelGateWay") //设定流程名称
.addInputStream("parallelGateWay.bpmn", inputStreamBpmn)
.addInputStream("parallelGateWay.png", inputStreamPng)
.deploy();
System.out.println("Id: " + deployment.getId());
System.out.println("Name: " + deployment.getName());
System.out.println("Category: " + deployment.getCategory());
}
/**
* 启动流程
*/
@Test
public void testStartProcessDefination(){
String processDefinationKey = "ParallelGateWay001";
ProcessInstance pi = processEngine.getRuntimeService().startProcessInstanceByKey(processDefinationKey);
System.out.println("Id: " + pi.getId());
System.out.println("Key: " + pi.getBusinessKey());
System.out.println("ActivityId: " + pi.getActivityId());
System.out.println("DefinitionId: " + pi.getProcessDefinitionId());
System.out.println("ProcessInstanceId: " + pi.getProcessInstanceId());
}
/**
* 完成任务
*/
@Test
public void testCompleteTask(){
String taskId = "302";
processEngine.getTaskService().complete(taskId);
System.out.println(taskId + " has Done.");
}
}
<?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">
<process id="ParallelGateWay001" name="Parallel GateWay" isExecutable="true">
<startEvent id="startevent1" name="Start"></startEvent>
<parallelGateway id="parallelgateway1" name="Branch GateWay"></parallelGateway>
<userTask id="usertask2" name="Ship" activiti:assignee="sellers01"></userTask>
<userTask id="usertask1" name="Pay For Somethings" activiti:assignee="buyers01"></userTask>
<userTask id="usertask3" name="Receipt Money" activiti:assignee="sellers02"></userTask>
<userTask id="usertask4" name="Receipt Somethings" activiti:assignee="buyers02"></userTask>
<parallelGateway id="parallelgateway2" name="汇聚网关"></parallelGateway>
<endEvent id="endevent1" name="End"></endEvent>
<sequenceFlow id="flow1" sourceRef="parallelgateway2" targetRef="endevent1"></sequenceFlow>
<sequenceFlow id="flow2" sourceRef="startevent1" targetRef="parallelgateway1"></sequenceFlow>
<sequenceFlow id="flow3" sourceRef="parallelgateway1" targetRef="usertask1"></sequenceFlow>
<sequenceFlow id="flow4" sourceRef="usertask1" targetRef="usertask3"></sequenceFlow>
<sequenceFlow id="flow7" sourceRef="usertask4" targetRef="parallelgateway2"></sequenceFlow>
<sequenceFlow id="flow8" sourceRef="usertask3" targetRef="parallelgateway2"></sequenceFlow>
<sequenceFlow id="flow9" sourceRef="parallelgateway1" targetRef="usertask2"></sequenceFlow>
<sequenceFlow id="flow10" sourceRef="usertask2" targetRef="usertask4"></sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_ParallelGateWay001">
<bpmndi:BPMNPlane bpmnElement="ParallelGateWay001" id="BPMNPlane_ParallelGateWay001">
<bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
<omgdc:Bounds height="35.0" width="35.0" x="383.0" y="10.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="parallelgateway1" id="BPMNShape_parallelgateway1">
<omgdc:Bounds height="40.0" width="40.0" x="380.0" y="108.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask2" id="BPMNShape_usertask2">
<omgdc:Bounds height="55.0" width="105.0" x="500.0" y="183.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
<omgdc:Bounds height="55.0" width="105.0" x="210.0" y="183.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask3" id="BPMNShape_usertask3">
<omgdc:Bounds height="51.0" width="105.0" x="210.0" y="290.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask4" id="BPMNShape_usertask4">
<omgdc:Bounds height="51.0" width="101.0" x="502.0" y="290.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="parallelgateway2" id="BPMNShape_parallelgateway2">
<omgdc:Bounds height="40.0" width="40.0" x="380.0" y="370.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
<omgdc:Bounds height="35.0" width="35.0" x="383.0" y="470.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
<omgdi:waypoint x="400.0" y="410.0"></omgdi:waypoint>
<omgdi:waypoint x="400.0" y="470.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
<omgdi:waypoint x="400.0" y="45.0"></omgdi:waypoint>
<omgdi:waypoint x="400.0" y="108.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
<omgdi:waypoint x="400.0" y="148.0"></omgdi:waypoint>
<omgdi:waypoint x="262.0" y="183.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">
<omgdi:waypoint x="262.0" y="238.0"></omgdi:waypoint>
<omgdi:waypoint x="262.0" y="290.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow7" id="BPMNEdge_flow7">
<omgdi:waypoint x="552.0" y="341.0"></omgdi:waypoint>
<omgdi:waypoint x="400.0" y="370.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow8" id="BPMNEdge_flow8">
<omgdi:waypoint x="262.0" y="341.0"></omgdi:waypoint>
<omgdi:waypoint x="400.0" y="370.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow9" id="BPMNEdge_flow9">
<omgdi:waypoint x="400.0" y="148.0"></omgdi:waypoint>
<omgdi:waypoint x="552.0" y="183.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow10" id="BPMNEdge_flow10">
<omgdi:waypoint x="552.0" y="238.0"></omgdi:waypoint>
<omgdi:waypoint x="552.0" y="290.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
![](https://img-blog.csdn.net/20170518233608151)
![](https://img-blog.csdn.net/20170518233618974)
![](https://img-blog.csdn.net/20170518233640573)
![](https://img-blog.csdn.net/20170518233647521)
![](https://img-blog.csdn.net/20170518233655350)
![](https://img-blog.csdn.net/20170518233709584)