/
BpmnAssert.java
139 lines (127 loc) · 5.2 KB
/
BpmnAssert.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
* Copyright © 2021 camunda services GmbH (info@camunda.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* 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 io.camunda.zeebe.process.test.assertions;
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.client.api.response.ProcessInstanceResult;
import io.camunda.zeebe.client.api.response.PublishMessageResponse;
import io.camunda.zeebe.process.test.filters.RecordStream;
import io.camunda.zeebe.process.test.inspections.model.InspectedProcessInstance;
/**
* This class manages all the entry points for the specific assertions.
*
* <p>For example when starting a process instance:
*
* <pre>{@code
* ProcessInstanceEvent event = client.newCreateInstanceCommand()
* .bpmnProcessId("processId")
* .latestVersion()
* .send()
* .join();
* ProcessInstanceAssert assertions = BpmnAssert.assertThat(event);
* }</pre>
*/
public abstract class BpmnAssert {
static ThreadLocal<RecordStream> recordStream = new ThreadLocal<>();
/**
* Initializes a {@link RecordStream}. The {@link RecordStream} will be stored in a {@link
* ThreadLocal} and thus will only be accessible in the current thread. This will be managed for
* you if you're using the @ZeebeProcessTest annotation.
*
* @param recordStream the {@link RecordStream}
*/
public static void initRecordStream(final RecordStream recordStream) {
BpmnAssert.recordStream.set(recordStream);
}
/** Removes the {@link RecordStream} from the {@link ThreadLocal}. */
public static void resetRecordStream() {
recordStream.remove();
}
/**
* Gets the {@link RecordStream} that is stored in the {@link ThreadLocal} for the current thread.
* This will be managed for you if you're using the @ZeebeProcessTest annotation.
*
* @return the {@link RecordStream} stored for this thread
* @throws AssertionError if no {@link RecordStream} has been initialized for the current thread
*/
public static RecordStream getRecordStream() {
if (recordStream.get() == null) {
throw new AssertionError(
"No RecordStream is set. Please make sure you are using the "
+ "@ZeebeProcessTest annotation. Alternatively, set one manually using "
+ "BpmnAssert.initRecordStream.");
}
return recordStream.get();
}
/**
* Creates a new instance of {@link ProcessInstanceAssert}.
*
* @param instanceEvent the event received when starting a process instance
* @return the created assertion object
*/
public static ProcessInstanceAssert assertThat(final ProcessInstanceEvent instanceEvent) {
return new ProcessInstanceAssert(instanceEvent.getProcessInstanceKey(), getRecordStream());
}
/**
* Creates a new instance of {@link ProcessInstanceAssert}.
*
* @param instanceResult the event received when starting a process instance
* @return the created assertion object
*/
public static ProcessInstanceAssert assertThat(final ProcessInstanceResult instanceResult) {
return new ProcessInstanceAssert(instanceResult.getProcessInstanceKey(), getRecordStream());
}
/**
* Creates a new instance of {@link ProcessInstanceAssert}.
*
* @param inspectedProcessInstance the {@link InspectedProcessInstance} received from the {@link
* io.camunda.zeebe.process.test.inspections.ProcessInstanceInspections}
* @return the created assertion object
*/
public static ProcessInstanceAssert assertThat(
final InspectedProcessInstance inspectedProcessInstance) {
return new ProcessInstanceAssert(
inspectedProcessInstance.getProcessInstanceKey(), getRecordStream());
}
/**
* Creates a new instance of {@link JobAssert}.
*
* @param activatedJob the response received when activating a job
* @return the created assertion object
*/
public static JobAssert assertThat(final ActivatedJob activatedJob) {
return new JobAssert(activatedJob, getRecordStream());
}
/**
* Creates a new instance of {@link DeploymentAssert}.
*
* @param deploymentEvent the event received when deploying a process
* @return the created assertion object
*/
public static DeploymentAssert assertThat(final DeploymentEvent deploymentEvent) {
return new DeploymentAssert(deploymentEvent, getRecordStream());
}
/**
* Creates a new instance of {@link PublishMessageResponse}.
*
* @param publishMessageResponse the response received when publishing a message
* @return the created assertion object
*/
public static MessageAssert assertThat(final PublishMessageResponse publishMessageResponse) {
return new MessageAssert(publishMessageResponse, getRecordStream());
}
}