1
+ /*
2
+ * Copyright 2025 Conductor Authors.
3
+ * <p>
4
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5
+ * the License. You may obtain a copy of the License at
6
+ * <p>
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ * <p>
9
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11
+ * specific language governing permissions and limitations under the License.
12
+ */
13
+ package com .netflix .conductor .common .metadata .events ;
14
+
15
+ import java .util .HashMap ;
16
+ import java .util .Map ;
17
+
18
+ import org .junit .jupiter .api .Test ;
19
+
20
+ import com .netflix .conductor .common .metadata .events .EventHandler .Action ;
21
+
22
+ import static org .junit .jupiter .api .Assertions .*;
23
+
24
+ class TestEventExecutionPojoMethods {
25
+
26
+ @ Test
27
+ void testNoArgsConstructor () {
28
+ EventExecution execution = new EventExecution ();
29
+ assertNotNull (execution );
30
+ assertNull (execution .getId ());
31
+ assertNull (execution .getMessageId ());
32
+ assertNull (execution .getName ());
33
+ assertNull (execution .getEvent ());
34
+ assertEquals (0 , execution .getCreated ());
35
+ assertNull (execution .getStatus ());
36
+ assertNull (execution .getAction ());
37
+ assertNotNull (execution .getOutput ());
38
+ assertTrue (execution .getOutput ().isEmpty ());
39
+ }
40
+
41
+ @ Test
42
+ void testParameterizedConstructor () {
43
+ String id = "test-id" ;
44
+ String messageId = "test-message-id" ;
45
+
46
+ EventExecution execution = new EventExecution (id , messageId );
47
+
48
+ assertEquals (id , execution .getId ());
49
+ assertEquals (messageId , execution .getMessageId ());
50
+ assertNull (execution .getName ());
51
+ assertNull (execution .getEvent ());
52
+ assertEquals (0 , execution .getCreated ());
53
+ assertNull (execution .getStatus ());
54
+ assertNull (execution .getAction ());
55
+ assertNotNull (execution .getOutput ());
56
+ assertTrue (execution .getOutput ().isEmpty ());
57
+ }
58
+
59
+ @ Test
60
+ void testSetAndGetId () {
61
+ EventExecution execution = new EventExecution ();
62
+ String id = "test-id" ;
63
+
64
+ execution .setId (id );
65
+ assertEquals (id , execution .getId ());
66
+ }
67
+
68
+ @ Test
69
+ void testSetAndGetMessageId () {
70
+ EventExecution execution = new EventExecution ();
71
+ String messageId = "test-message-id" ;
72
+
73
+ execution .setMessageId (messageId );
74
+ assertEquals (messageId , execution .getMessageId ());
75
+ }
76
+
77
+ @ Test
78
+ void testSetAndGetName () {
79
+ EventExecution execution = new EventExecution ();
80
+ String name = "test-name" ;
81
+
82
+ execution .setName (name );
83
+ assertEquals (name , execution .getName ());
84
+ }
85
+
86
+ @ Test
87
+ void testSetAndGetEvent () {
88
+ EventExecution execution = new EventExecution ();
89
+ String event = "test-event" ;
90
+
91
+ execution .setEvent (event );
92
+ assertEquals (event , execution .getEvent ());
93
+ }
94
+
95
+ @ Test
96
+ void testSetAndGetCreated () {
97
+ EventExecution execution = new EventExecution ();
98
+ long created = System .currentTimeMillis ();
99
+
100
+ execution .setCreated (created );
101
+ assertEquals (created , execution .getCreated ());
102
+ }
103
+
104
+ @ Test
105
+ void testSetAndGetStatus () {
106
+ EventExecution execution = new EventExecution ();
107
+ EventExecution .Status status = EventExecution .Status .COMPLETED ;
108
+
109
+ execution .setStatus (status );
110
+ assertEquals (status , execution .getStatus ());
111
+ }
112
+
113
+ @ Test
114
+ void testSetAndGetAction () {
115
+ EventExecution execution = new EventExecution ();
116
+ Action .Type action = Action .Type .start_workflow ;
117
+
118
+ execution .setAction (action );
119
+ assertEquals (action , execution .getAction ());
120
+ }
121
+
122
+ @ Test
123
+ void testSetAndGetOutput () {
124
+ EventExecution execution = new EventExecution ();
125
+ Map <String , Object > output = new HashMap <>();
126
+ output .put ("key1" , "value1" );
127
+ output .put ("key2" , 100 );
128
+
129
+ execution .setOutput (output );
130
+ assertEquals (output , execution .getOutput ());
131
+ assertEquals (2 , execution .getOutput ().size ());
132
+ assertEquals ("value1" , execution .getOutput ().get ("key1" ));
133
+ assertEquals (100 , execution .getOutput ().get ("key2" ));
134
+ }
135
+
136
+ @ Test
137
+ void testEqualsAndHashCodeWithSameInstance () {
138
+ EventExecution execution = new EventExecution ();
139
+ assertTrue (execution .equals (execution ));
140
+ assertEquals (execution .hashCode (), execution .hashCode ());
141
+ }
142
+
143
+ @ Test
144
+ void testEqualsWithNull () {
145
+ EventExecution execution = new EventExecution ();
146
+ assertFalse (execution .equals (null ));
147
+ }
148
+
149
+ @ Test
150
+ void testEqualsWithDifferentClass () {
151
+ EventExecution execution = new EventExecution ();
152
+ assertFalse (execution .equals (new Object ()));
153
+ }
154
+
155
+ @ Test
156
+ void testEqualsAndHashCodeWithEqualObjects () {
157
+ EventExecution execution1 = createFullEventExecution ();
158
+ EventExecution execution2 = createFullEventExecution ();
159
+
160
+ assertTrue (execution1 .equals (execution2 ));
161
+ assertTrue (execution2 .equals (execution1 ));
162
+ assertEquals (execution1 .hashCode (), execution2 .hashCode ());
163
+ }
164
+
165
+ @ Test
166
+ void testEqualsAndHashCodeWithDifferentId () {
167
+ EventExecution execution1 = createFullEventExecution ();
168
+ EventExecution execution2 = createFullEventExecution ();
169
+ execution2 .setId ("different-id" );
170
+
171
+ assertFalse (execution1 .equals (execution2 ));
172
+ assertFalse (execution2 .equals (execution1 ));
173
+ assertNotEquals (execution1 .hashCode (), execution2 .hashCode ());
174
+ }
175
+
176
+ @ Test
177
+ void testEqualsAndHashCodeWithDifferentMessageId () {
178
+ EventExecution execution1 = createFullEventExecution ();
179
+ EventExecution execution2 = createFullEventExecution ();
180
+ execution2 .setMessageId ("different-message-id" );
181
+
182
+ assertFalse (execution1 .equals (execution2 ));
183
+ assertFalse (execution2 .equals (execution1 ));
184
+ assertNotEquals (execution1 .hashCode (), execution2 .hashCode ());
185
+ }
186
+
187
+ @ Test
188
+ void testEqualsAndHashCodeWithDifferentName () {
189
+ EventExecution execution1 = createFullEventExecution ();
190
+ EventExecution execution2 = createFullEventExecution ();
191
+ execution2 .setName ("different-name" );
192
+
193
+ assertFalse (execution1 .equals (execution2 ));
194
+ assertFalse (execution2 .equals (execution1 ));
195
+ assertNotEquals (execution1 .hashCode (), execution2 .hashCode ());
196
+ }
197
+
198
+ @ Test
199
+ void testEqualsAndHashCodeWithDifferentEvent () {
200
+ EventExecution execution1 = createFullEventExecution ();
201
+ EventExecution execution2 = createFullEventExecution ();
202
+ execution2 .setEvent ("different-event" );
203
+
204
+ assertFalse (execution1 .equals (execution2 ));
205
+ assertFalse (execution2 .equals (execution1 ));
206
+ assertNotEquals (execution1 .hashCode (), execution2 .hashCode ());
207
+ }
208
+
209
+ @ Test
210
+ void testEqualsAndHashCodeWithDifferentCreated () {
211
+ EventExecution execution1 = createFullEventExecution ();
212
+ EventExecution execution2 = createFullEventExecution ();
213
+ execution2 .setCreated (execution1 .getCreated () + 1000 );
214
+
215
+ assertFalse (execution1 .equals (execution2 ));
216
+ assertFalse (execution2 .equals (execution1 ));
217
+ assertNotEquals (execution1 .hashCode (), execution2 .hashCode ());
218
+ }
219
+
220
+ @ Test
221
+ void testEqualsAndHashCodeWithDifferentStatus () {
222
+ EventExecution execution1 = createFullEventExecution ();
223
+ EventExecution execution2 = createFullEventExecution ();
224
+ execution2 .setStatus (EventExecution .Status .FAILED );
225
+
226
+ assertFalse (execution1 .equals (execution2 ));
227
+ assertFalse (execution2 .equals (execution1 ));
228
+ assertNotEquals (execution1 .hashCode (), execution2 .hashCode ());
229
+ }
230
+
231
+ @ Test
232
+ void testEqualsAndHashCodeWithDifferentAction () {
233
+ EventExecution execution1 = createFullEventExecution ();
234
+ EventExecution execution2 = createFullEventExecution ();
235
+ execution2 .setAction (Action .Type .complete_task );
236
+
237
+ assertFalse (execution1 .equals (execution2 ));
238
+ assertFalse (execution2 .equals (execution1 ));
239
+ assertNotEquals (execution1 .hashCode (), execution2 .hashCode ());
240
+ }
241
+
242
+ @ Test
243
+ void testEqualsAndHashCodeWithDifferentOutput () {
244
+ EventExecution execution1 = createFullEventExecution ();
245
+ EventExecution execution2 = createFullEventExecution ();
246
+
247
+ Map <String , Object > differentOutput = new HashMap <>();
248
+ differentOutput .put ("different-key" , "different-value" );
249
+ execution2 .setOutput (differentOutput );
250
+
251
+ assertFalse (execution1 .equals (execution2 ));
252
+ assertFalse (execution2 .equals (execution1 ));
253
+ assertNotEquals (execution1 .hashCode (), execution2 .hashCode ());
254
+ }
255
+
256
+ private EventExecution createFullEventExecution () {
257
+ EventExecution execution = new EventExecution ("test-id" , "test-message-id" );
258
+ execution .setName ("test-name" );
259
+ execution .setEvent ("test-event" );
260
+ execution .setCreated (1234567890 );
261
+ execution .setStatus (EventExecution .Status .COMPLETED );
262
+ execution .setAction (Action .Type .start_workflow );
263
+
264
+ Map <String , Object > output = new HashMap <>();
265
+ output .put ("key1" , "value1" );
266
+ output .put ("key2" , 100 );
267
+ execution .setOutput (output );
268
+
269
+ return execution ;
270
+ }
271
+ }
0 commit comments