3
3
import com .apiflows .model .*;
4
4
import org .junit .jupiter .api .Test ;
5
5
6
- import java .util .ArrayList ;
7
- import java .util .List ;
6
+ import java .util .*;
8
7
9
8
import static org .junit .jupiter .api .Assertions .*;
10
9
@@ -235,7 +234,9 @@ void validateParameterWithoutValue() {
235
234
236
235
@ Test
237
236
void validateSuccessAction () {
237
+ String workflowId = "w1" ;
238
238
String stepId = "step-one" ;
239
+
239
240
SuccessAction successAction = new SuccessAction ()
240
241
.type ("end" )
241
242
.stepId ("step-one" );
@@ -244,12 +245,14 @@ void validateSuccessAction() {
244
245
new Criterion ()
245
246
.context ("$statusCode == 200" ));
246
247
247
- assertEquals (0 , validator .validateSuccessAction (successAction , stepId ).size ());
248
+ assertEquals (0 , validator .validateSuccessAction (workflowId , stepId , successAction ).size ());
248
249
}
249
250
250
251
@ Test
251
252
void validateSuccessActionInvalidType () {
253
+ String workflowId = "w1" ;
252
254
String stepId = "step-one" ;
255
+
253
256
SuccessAction successAction = new SuccessAction ()
254
257
.type ("invalid-type" )
255
258
.stepId ("step-one" );
@@ -258,12 +261,14 @@ void validateSuccessActionInvalidType() {
258
261
new Criterion ()
259
262
.context ("$statusCode == 200" ));
260
263
261
- assertEquals (1 , validator .validateSuccessAction (successAction , stepId ).size ());
264
+ assertEquals (1 , validator .validateSuccessAction (workflowId , stepId , successAction ).size ());
262
265
}
263
266
264
267
@ Test
265
268
void validateSuccessActionMissingEntity () {
269
+ String workflowId = "w1" ;
266
270
String stepId = "step-one" ;
271
+
267
272
SuccessAction successAction = new SuccessAction ()
268
273
.type ("end" )
269
274
.stepId (null )
@@ -273,12 +278,14 @@ void validateSuccessActionMissingEntity() {
273
278
new Criterion ()
274
279
.context ("$statusCode == 200" ));
275
280
276
- assertEquals (1 , validator .validateSuccessAction (successAction , stepId ).size ());
281
+ assertEquals (1 , validator .validateSuccessAction (workflowId , stepId , successAction ).size ());
277
282
}
278
283
279
284
@ Test
280
285
void validateSuccessActionInvalidEntity () {
286
+ String workflowId = "w1" ;
281
287
String stepId = "step-one" ;
288
+
282
289
SuccessAction successAction = new SuccessAction ()
283
290
.type ("end" )
284
291
.stepId ("step-one" )
@@ -288,9 +295,33 @@ void validateSuccessActionInvalidEntity() {
288
295
new Criterion ()
289
296
.condition ("$statusCode == 200" ));
290
297
291
- assertEquals (1 , validator .validateSuccessAction (successAction , stepId ).size ());
298
+ assertEquals (1 , validator .validateSuccessAction (workflowId , stepId , successAction ).size ());
299
+ }
300
+
301
+ @ Test
302
+ void validateSuccessActionInvalidStepId () {
303
+ String workflowId = "w1" ;
304
+
305
+ OpenAPIWorkflowValidator validator = new OpenAPIWorkflowValidator ();
306
+
307
+ Map <String , Set <String >> stepIds = new HashMap <>();
308
+ stepIds .put ("w1" , Set .of ("step-one" , "step-two" , "step-three" ));
309
+
310
+ validator .stepIds = stepIds ;
311
+
312
+ String stepId = "step-one" ;
313
+ SuccessAction successAction = new SuccessAction ()
314
+ .type ("goto" )
315
+ .stepId ("step-dummy" );
316
+
317
+ successAction .addCriteria (
318
+ new Criterion ()
319
+ .context ("$statusCode == 200" ));
320
+
321
+ assertEquals (1 , validator .validateSuccessAction (workflowId , stepId , successAction ).size ());
292
322
}
293
323
324
+
294
325
@ Test
295
326
void validateCriterion () {
296
327
String stepId = "step-one" ;
@@ -338,9 +369,11 @@ void validateCriterionMissingContext() {
338
369
339
370
@ Test
340
371
void validateFailureAction () {
372
+ String workflowId = "w1" ;
341
373
String stepId = "step-one" ;
374
+
342
375
FailureAction failureAction = new FailureAction ()
343
- .type ("retry " )
376
+ .type ("end " )
344
377
.stepId ("step-one" )
345
378
.retryAfter (1000L )
346
379
.retryLimit (3 );
@@ -349,12 +382,14 @@ void validateFailureAction() {
349
382
new Criterion ()
350
383
.context ("$statusCode == 200" ));
351
384
352
- assertEquals (0 , validator .validateFailureAction (failureAction , stepId ).size ());
385
+ assertEquals (0 , validator .validateFailureAction (workflowId , stepId , failureAction ).size ());
353
386
}
354
387
355
388
@ Test
356
389
void validateFailureActionInvalidType () {
390
+ String workflowId = "w1" ;
357
391
String stepId = "step-one" ;
392
+
358
393
FailureAction failureAction = new FailureAction ()
359
394
.type ("dummy" )
360
395
.stepId ("step-one" )
@@ -365,14 +400,16 @@ void validateFailureActionInvalidType() {
365
400
new Criterion ()
366
401
.context ("$statusCode == 200" ));
367
402
368
- assertEquals (1 , validator .validateFailureAction (failureAction , stepId ).size ());
403
+ assertEquals (1 , validator .validateFailureAction (workflowId , stepId , failureAction ).size ());
369
404
}
370
405
371
406
@ Test
372
407
void validateFailureActionInvalidRetrySettings () {
408
+ String workflowId = "w1" ;
373
409
String stepId = "step-one" ;
410
+
374
411
FailureAction failureAction = new FailureAction ()
375
- .type ("retry " )
412
+ .type ("end " )
376
413
.stepId ("step-one" )
377
414
.retryAfter (-1000L )
378
415
.retryLimit (-3 );
@@ -381,12 +418,14 @@ void validateFailureActionInvalidRetrySettings() {
381
418
new Criterion ()
382
419
.context ("$statusCode == 200" ));
383
420
384
- assertEquals (2 , validator .validateFailureAction (failureAction , stepId ).size ());
421
+ assertEquals (2 , validator .validateFailureAction (workflowId , stepId , failureAction ).size ());
385
422
}
386
423
387
424
@ Test
388
425
void validateFailureActionMissingEntity () {
426
+ String workflowId = "w1" ;
389
427
String stepId = "step-one" ;
428
+
390
429
FailureAction failureAction = new FailureAction ()
391
430
.type ("retry" )
392
431
.stepId (null )
@@ -398,14 +437,16 @@ void validateFailureActionMissingEntity() {
398
437
new Criterion ()
399
438
.context ("$statusCode == 200" ));
400
439
401
- assertEquals (1 , validator .validateFailureAction (failureAction , stepId ).size ());
440
+ assertEquals (1 , validator .validateFailureAction (workflowId , stepId , failureAction ).size ());
402
441
}
403
442
404
443
@ Test
405
444
void validateFailureActionInvalidEntity () {
445
+ String workflowId = "w1" ;
406
446
String stepId = "step-one" ;
447
+
407
448
FailureAction failureAction = new FailureAction ()
408
- .type ("retry " )
449
+ .type ("end " )
409
450
.stepId ("step-one" )
410
451
.workflowId ("workflow-test" )
411
452
.retryAfter (1000L )
@@ -415,9 +456,35 @@ void validateFailureActionInvalidEntity() {
415
456
new Criterion ()
416
457
.context ("$statusCode == 200" ));
417
458
418
- assertEquals (1 , validator .validateFailureAction (failureAction , stepId ).size ());
459
+ assertEquals (1 , validator .validateFailureAction (workflowId , stepId , failureAction ).size ());
460
+ }
461
+
462
+ @ Test
463
+ void validateFailureActionInvalidStepId () {
464
+ String workflowId = "w1" ;
465
+ String stepId = "step-one" ;
466
+
467
+ OpenAPIWorkflowValidator validator = new OpenAPIWorkflowValidator ();
468
+
469
+ Map <String , Set <String >> stepIds = new HashMap <>();
470
+ stepIds .put ("w1" , Set .of ("step-one" , "step-two" , "step-three" ));
471
+
472
+ validator .stepIds = stepIds ;
473
+
474
+ FailureAction failureAction = new FailureAction ()
475
+ .type ("retry" )
476
+ .stepId ("step-dummy" )
477
+ .retryAfter (1000L )
478
+ .retryLimit (3 );
479
+
480
+ failureAction .addCriteria (
481
+ new Criterion ()
482
+ .context ("$statusCode == 200" ));
483
+
484
+ assertEquals (1 , validator .validateFailureAction (workflowId , stepId , failureAction ).size ());
419
485
}
420
486
487
+
421
488
@ Test
422
489
void loadWorkflowIWithDuplicateIds () {
423
490
List <Workflow > list = List .of (
@@ -493,4 +560,20 @@ void invalidComponentKey() {
493
560
assertFalse (new OpenAPIWorkflowValidator ().isValidComponentKey ("pagination order" ));
494
561
}
495
562
563
+
564
+ @ Test
565
+ void isValidJsonPointer () {
566
+ assertTrue (new OpenAPIWorkflowValidator ().isValidJsonPointer ("/user/id" ));
567
+ }
568
+
569
+ @ Test
570
+ void invalidJsonPointer () {
571
+ assertFalse (new OpenAPIWorkflowValidator ().isValidJsonPointer ("user/id" ));
572
+ }
573
+
574
+ // @Test
575
+ // void isValidJsonPointer2() {
576
+ // assertTrue(new OpenAPIWorkflowValidator().isValidJsonPointer("#/petId"));
577
+ // }
578
+
496
579
}
0 commit comments