-
Notifications
You must be signed in to change notification settings - Fork 1
/
DemoApplicationTests.java
106 lines (91 loc) · 2.85 KB
/
DemoApplicationTests.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
package camunda.cloud.testing.demo;
import io.camunda.zeebe.client.ZeebeClient;
import io.camunda.zeebe.client.api.response.ActivateJobsResponse;
import io.camunda.zeebe.client.api.response.ActivatedJob;
import io.camunda.zeebe.client.api.response.DeploymentEvent;
import io.camunda.zeebe.client.api.response.ProcessInstanceEvent;
import io.camunda.zeebe.process.test.assertions.BpmnAssert;
import io.camunda.zeebe.process.test.assertions.DeploymentAssert;
import io.camunda.zeebe.process.test.assertions.JobAssert;
import io.camunda.zeebe.process.test.assertions.ProcessInstanceAssert;
import io.camunda.zeebe.process.test.extensions.ZeebeProcessTest;
import io.camunda.zeebe.process.test.testengine.InMemoryEngine;
import io.camunda.zeebe.process.test.testengine.RecordStreamSource;
import org.junit.jupiter.api.Test;
@ZeebeProcessTest
public class DemoApplicationTests {
private InMemoryEngine engine;
private ZeebeClient client;
private RecordStreamSource recordStreamSource;
private void initDeployment(){
client.newDeployCommand()
.addResourceFromClasspath("test-process.bpmn")
.send()
.join();
}
private ProcessInstanceAssert initProcessInstanceStart(){
ProcessInstanceEvent event = client.newCreateInstanceCommand()
.bpmnProcessId("TestProcess")
.latestVersion()
.send()
.join();
return BpmnAssert.assertThat(event);
}
@Test
public void testDeployment() {
//When
DeploymentEvent event = client.newDeployCommand()
.addResourceFromClasspath("test-process.bpmn")
.send()
.join();
//Then
BpmnAssert.assertThat(event);
}
@Test
public void testProcessInstanceStart(){
//Given
initDeployment();
//When
ProcessInstanceEvent event = client.newCreateInstanceCommand()
.bpmnProcessId("TestProcess")
.latestVersion()
.send()
.join();
//Then
ProcessInstanceAssert assertions = BpmnAssert.assertThat(event);
assertions.hasPassedElement("StartEvent_1");
}
@Test
public void testJobAssertion() {
//Given
initDeployment();
initProcessInstanceStart();
//When
ActivateJobsResponse response = client.newActivateJobsCommand()
.jobType("serviceTask")
.maxJobsToActivate(1)
.send()
.join();
//Then
ActivatedJob activatedJob = response.getJobs().get(0);
BpmnAssert.assertThat(activatedJob);
client.newCompleteCommand(activatedJob.getKey()).send().join();
}
@Test
public void testCompletionOfInstance() throws InterruptedException {
//Given
initDeployment();
ProcessInstanceAssert instanceAssert = initProcessInstanceStart();
//When
ActivateJobsResponse response = client.newActivateJobsCommand()
.jobType("serviceTask")
.maxJobsToActivate(1)
.send()
.join();
ActivatedJob activatedJob = response.getJobs().get(0);
client.newCompleteCommand(activatedJob.getKey()).send().join();
engine.waitForIdleState();
//then
instanceAssert.isCompleted();
}
}