-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
CreateInvoiceProcessTest.java
112 lines (98 loc) · 4.19 KB
/
CreateInvoiceProcessTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
* under one or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information regarding copyright
* ownership. Camunda licenses this file to you under the Apache License,
* Version 2.0; you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.camunda.bpm.quickstart;
import java.util.HashMap;
import java.util.Map;
import org.camunda.bpm.engine.task.TaskQuery;
import org.camunda.bpm.engine.test.ProcessEngineRule;
import org.camunda.bpm.example.invoice.service.ArchiveInvoiceService;
import org.camunda.bpm.model.bpmn.Bpmn;
import org.camunda.bpm.model.bpmn.BpmnModelInstance;
import org.camunda.bpm.model.bpmn.GatewayDirection;
import org.junit.Rule;
import org.junit.Test;
/**
* @author Sebastian Menski
*/
public class CreateInvoiceProcessTest {
@Rule
public ProcessEngineRule processEngine = new ProcessEngineRule();
@Test
public void testCreateInvoiceProcess() throws Exception {
BpmnModelInstance modelInstance = Bpmn.createExecutableProcess("invoice")
.camundaHistoryTimeToLive(180)
.name("BPMN API Invoice Process")
.startEvent()
.name("Invoice received")
.userTask()
.name("Assign Approver")
.camundaAssignee("demo")
.userTask()
.id("approveInvoice")
.name("Approve Invoice")
.exclusiveGateway()
.name("Invoice approved?")
.gatewayDirection(GatewayDirection.Diverging)
.condition("yes", "${approved}")
.userTask()
.name("Prepare Bank Transfer")
.camundaFormKey("embedded:app:forms/prepare-bank-transfer.html")
.camundaCandidateGroups("accounting")
.serviceTask()
.name("Archive Invoice")
.camundaClass("org.camunda.bpm.example.invoice.service.ArchiveInvoiceService")
.endEvent()
.name("Invoice processed")
.moveToLastGateway()
.condition("no", "${!approved}")
.userTask()
.name("Review Invoice")
.camundaAssignee("demo")
.exclusiveGateway()
.name("Review successful?")
.gatewayDirection(GatewayDirection.Diverging)
.condition("no", "${!clarified}")
.endEvent()
.name("Invoice not processed")
.moveToLastGateway()
.condition("yes", "${clarified}")
.connectTo("approveInvoice")
.done();
// deploy process model
processEngine.getRepositoryService().createDeployment().addModelInstance("invoice.bpmn", modelInstance).deploy();
// start process model
processEngine.getRuntimeService().startProcessInstanceByKey("invoice");
TaskQuery taskQuery = processEngine.getTaskService().createTaskQuery();
// check and complete task "Assign Approver"
org.junit.Assert.assertEquals(1, taskQuery.count());
processEngine.getTaskService().complete(taskQuery.singleResult().getId());
// check and complete task "Approve Invoice"
Map<String, Object> variables = new HashMap<>();
variables.put("approved", true);
org.junit.Assert.assertEquals(1, taskQuery.count());
processEngine.getTaskService().complete(taskQuery.singleResult().getId(), variables);
// check and complete task "Prepare Bank Transfer"
org.junit.Assert.assertEquals(1, taskQuery.count());
processEngine.getTaskService().complete(taskQuery.singleResult().getId());
// check if Delegate was executed
org.junit.Assert.assertEquals(true, ArchiveInvoiceService.wasExecuted);
// check if process instance is ended
org.junit.Assert.assertEquals(0, processEngine.getRuntimeService().createProcessInstanceQuery().count());
// show the BPMN 2.0 process model XML on the console log
// Bpmn.writeModelToStream(System.out, modelInstance);
}
}