4
4
import org .junit .jupiter .api .Test ;
5
5
6
6
import io .javaoperatorsdk .operator .AggregatedOperatorException ;
7
+ import io .javaoperatorsdk .operator .api .reconciler .Context ;
7
8
import io .javaoperatorsdk .operator .processing .dependent .workflow .builder .WorkflowBuilder ;
8
9
import io .javaoperatorsdk .operator .sample .simple .TestCustomResource ;
9
10
10
11
import static io .javaoperatorsdk .operator .processing .dependent .workflow .ExecutionAssert .assertThat ;
11
12
import static org .junit .jupiter .api .Assertions .assertThrows ;
13
+ import static org .mockito .Mockito .mock ;
12
14
13
15
@ SuppressWarnings ("rawtypes" )
14
16
class WorkflowReconcileExecutorTest extends AbstractWorkflowExecutorTest {
@@ -21,14 +23,16 @@ class WorkflowReconcileExecutorTest extends AbstractWorkflowExecutorTest {
21
23
private final Condition <String , TestCustomResource > notMetReadyCondition =
22
24
(primary , secondary , context ) -> false ;
23
25
26
+ Context <TestCustomResource > mockContext = mock (Context .class );
27
+
24
28
@ Test
25
29
void reconcileTopLevelResources () {
26
30
var workflow = new WorkflowBuilder <TestCustomResource >()
27
31
.addDependentResource (dr1 )
28
32
.addDependentResource (dr2 )
29
33
.build ();
30
34
31
- var res = workflow .reconcile (new TestCustomResource (), null );
35
+ var res = workflow .reconcile (new TestCustomResource (), mockContext );
32
36
33
37
assertThat (executionHistory ).reconciled (dr1 , dr2 );
34
38
Assertions .assertThat (res .getErroredDependents ()).isEmpty ();
@@ -42,7 +46,7 @@ void reconciliationWithSimpleDependsOn() {
42
46
.addDependentResource (dr2 ).dependsOn (dr1 )
43
47
.build ();
44
48
45
- var res = workflow .reconcile (new TestCustomResource (), null );
49
+ var res = workflow .reconcile (new TestCustomResource (), mockContext );
46
50
47
51
Assertions .assertThat (res .getErroredDependents ()).isEmpty ();
48
52
assertThat (executionHistory ).reconciledInOrder (dr1 , dr2 );
@@ -61,7 +65,7 @@ void reconciliationWithTwoTheDependsOns() {
61
65
.addDependentResource (dr3 ).dependsOn (dr1 )
62
66
.build ();
63
67
64
- var res = workflow .reconcile (new TestCustomResource (), null );
68
+ var res = workflow .reconcile (new TestCustomResource (), mockContext );
65
69
66
70
Assertions .assertThat (res .getErroredDependents ()).isEmpty ();
67
71
assertThat (executionHistory )
@@ -83,7 +87,7 @@ void diamondShareWorkflowReconcile() {
83
87
.addDependentResource (dr4 ).dependsOn (dr3 ).dependsOn (dr2 )
84
88
.build ();
85
89
86
- var res = workflow .reconcile (new TestCustomResource (), null );
90
+ var res = workflow .reconcile (new TestCustomResource (), mockContext );
87
91
88
92
Assertions .assertThat (res .getErroredDependents ()).isEmpty ();
89
93
assertThat (executionHistory )
@@ -103,7 +107,7 @@ void exceptionHandlingSimpleCases() {
103
107
.withThrowExceptionFurther (false )
104
108
.build ();
105
109
106
- var res = workflow .reconcile (new TestCustomResource (), null );
110
+ var res = workflow .reconcile (new TestCustomResource (), mockContext );
107
111
108
112
assertThrows (AggregatedOperatorException .class ,
109
113
res ::throwAggregateExceptionIfErrorsPresent );
@@ -123,7 +127,7 @@ void dependentsOnErroredResourceNotReconciled() {
123
127
.withThrowExceptionFurther (false )
124
128
.build ();
125
129
126
- var res = workflow .reconcile (new TestCustomResource (), null );
130
+ var res = workflow .reconcile (new TestCustomResource (), mockContext );
127
131
assertThrows (AggregatedOperatorException .class ,
128
132
res ::throwAggregateExceptionIfErrorsPresent );
129
133
@@ -145,7 +149,7 @@ void oneBranchErrorsOtherCompletes() {
145
149
.withThrowExceptionFurther (false )
146
150
.build ();
147
151
148
- var res = workflow .reconcile (new TestCustomResource (), null );
152
+ var res = workflow .reconcile (new TestCustomResource (), mockContext );
149
153
assertThrows (AggregatedOperatorException .class ,
150
154
res ::throwAggregateExceptionIfErrorsPresent );
151
155
@@ -164,7 +168,7 @@ void onlyOneDependsOnErroredResourceNotReconciled() {
164
168
.withThrowExceptionFurther (false )
165
169
.build ();
166
170
167
- var res = workflow .reconcile (new TestCustomResource (), null );
171
+ var res = workflow .reconcile (new TestCustomResource (), mockContext );
168
172
assertThrows (AggregatedOperatorException .class ,
169
173
res ::throwAggregateExceptionIfErrorsPresent );
170
174
@@ -182,7 +186,7 @@ void simpleReconcileCondition() {
182
186
.addDependentResource (drDeleter ).withReconcilePrecondition (not_met_reconcile_condition )
183
187
.build ();
184
188
185
- var res = workflow .reconcile (new TestCustomResource (), null );
189
+ var res = workflow .reconcile (new TestCustomResource (), mockContext );
186
190
187
191
assertThat (executionHistory ).notReconciled (dr1 ).reconciled (dr2 ).deleted (drDeleter );
188
192
Assertions .assertThat (res .getErroredDependents ()).isEmpty ();
@@ -200,7 +204,7 @@ void triangleOnceConditionNotMet() {
200
204
.dependsOn (dr1 )
201
205
.build ();
202
206
203
- var res = workflow .reconcile (new TestCustomResource (), null );
207
+ var res = workflow .reconcile (new TestCustomResource (), mockContext );
204
208
205
209
assertThat (executionHistory ).reconciledInOrder (dr1 , dr2 ).deleted (drDeleter );
206
210
Assertions .assertThat (res .getErroredDependents ()).isEmpty ();
@@ -222,7 +226,7 @@ void reconcileConditionTransitiveDelete() {
222
226
.withReconcilePrecondition (met_reconcile_condition )
223
227
.build ();
224
228
225
- var res = workflow .reconcile (new TestCustomResource (), null );
229
+ var res = workflow .reconcile (new TestCustomResource (), mockContext );
226
230
227
231
Assertions .assertThat (res .getErroredDependents ()).isEmpty ();
228
232
assertThat (executionHistory ).notReconciled (dr2 );
@@ -246,7 +250,7 @@ void reconcileConditionAlsoErrorDependsOn() {
246
250
.withThrowExceptionFurther (false )
247
251
.build ();
248
252
249
- var res = workflow .reconcile (new TestCustomResource (), null );
253
+ var res = workflow .reconcile (new TestCustomResource (), mockContext );
250
254
assertThrows (AggregatedOperatorException .class ,
251
255
res ::throwAggregateExceptionIfErrorsPresent );
252
256
@@ -267,7 +271,7 @@ void oneDependsOnConditionNotMet() {
267
271
.addDependentResource (drDeleter ).dependsOn (dr1 , dr2 )
268
272
.build ();
269
273
270
- var res = workflow .reconcile (new TestCustomResource (), null );
274
+ var res = workflow .reconcile (new TestCustomResource (), mockContext );
271
275
272
276
Assertions .assertThat (res .getErroredDependents ()).isEmpty ();
273
277
@@ -287,7 +291,7 @@ void deletedIfReconcileConditionNotMet() {
287
291
.addDependentResource (drDeleter2 ).dependsOn (dr1 , drDeleter )
288
292
.build ();
289
293
290
- var res = workflow .reconcile (new TestCustomResource (), null );
294
+ var res = workflow .reconcile (new TestCustomResource (), mockContext );
291
295
292
296
assertThat (executionHistory )
293
297
.reconciledInOrder (dr1 , drDeleter2 , drDeleter )
@@ -313,7 +317,7 @@ void deleteDoneInReverseOrder() {
313
317
.addDependentResource (drDeleter4 ).dependsOn (drDeleter3 )
314
318
.build ();
315
319
316
- var res = workflow .reconcile (new TestCustomResource (), null );
320
+ var res = workflow .reconcile (new TestCustomResource (), mockContext );
317
321
318
322
assertThat (executionHistory )
319
323
.reconciledInOrder (dr1 , drDeleter4 , drDeleter3 , drDeleter )
@@ -339,7 +343,7 @@ void diamondDeleteWithPostConditionInMiddle() {
339
343
.addDependentResource (drDeleter4 ).dependsOn (drDeleter3 , drDeleter2 )
340
344
.build ();
341
345
342
- var res = workflow .reconcile (new TestCustomResource (), null );
346
+ var res = workflow .reconcile (new TestCustomResource (), mockContext );
343
347
344
348
assertThat (executionHistory ).notReconciled (drDeleter )
345
349
.reconciledInOrder (drDeleter4 , drDeleter2 )
@@ -363,7 +367,7 @@ void diamondDeleteErrorInMiddle() {
363
367
.withThrowExceptionFurther (false )
364
368
.build ();
365
369
366
- var res = workflow .reconcile (new TestCustomResource (), null );
370
+ var res = workflow .reconcile (new TestCustomResource (), mockContext );
367
371
368
372
assertThat (executionHistory )
369
373
.notReconciled (drDeleter , drError )
@@ -381,7 +385,7 @@ void readyConditionTrivialCase() {
381
385
.addDependentResource (dr2 ).dependsOn (dr1 )
382
386
.build ();
383
387
384
- var res = workflow .reconcile (new TestCustomResource (), null );
388
+ var res = workflow .reconcile (new TestCustomResource (), mockContext );
385
389
386
390
assertThat (executionHistory ).reconciledInOrder (dr1 , dr2 );
387
391
@@ -397,7 +401,7 @@ void readyConditionNotMetTrivialCase() {
397
401
.addDependentResource (dr2 ).dependsOn (dr1 )
398
402
.build ();
399
403
400
- var res = workflow .reconcile (new TestCustomResource (), null );
404
+ var res = workflow .reconcile (new TestCustomResource (), mockContext );
401
405
402
406
403
407
assertThat (executionHistory ).reconciled (dr1 ).notReconciled (dr2 );
@@ -417,7 +421,7 @@ void readyConditionNotMetInOneParent() {
417
421
.addDependentResource (dr3 ).dependsOn (dr1 , dr2 )
418
422
.build ();
419
423
420
- var res = workflow .reconcile (new TestCustomResource (), null );
424
+ var res = workflow .reconcile (new TestCustomResource (), mockContext );
421
425
422
426
assertThat (executionHistory ).reconciled (dr1 , dr2 ).notReconciled (dr3 );
423
427
Assertions .assertThat (res .getErroredDependents ()).isEmpty ();
@@ -437,7 +441,7 @@ void diamondShareWithReadyCondition() {
437
441
.addDependentResource (dr4 ).dependsOn (dr2 , dr3 )
438
442
.build ();
439
443
440
- var res = workflow .reconcile (new TestCustomResource (), null );
444
+ var res = workflow .reconcile (new TestCustomResource (), mockContext );
441
445
442
446
Assertions .assertThat (res .getErroredDependents ()).isEmpty ();
443
447
assertThat (executionHistory ).reconciledInOrder (dr1 , dr2 )
0 commit comments