From 1b211c984db4ca6f8787940715024e4ccf66cf3c Mon Sep 17 00:00:00 2001 From: Beppe Catanese Date: Sun, 29 Mar 2026 13:15:24 +0200 Subject: [PATCH 1/2] Fix Arazzo spec inconsistencies in validator and model - Remove 'body' from valid parameter 'in' values (spec: path/query/header/cookie only) - Fix SuccessAction/FailureAction validation: workflowId or stepId is only required when type is 'goto', not for 'end' or 'retry' - Fix validateSuccessAction workflowId existence check used the parent workflowId instead of successAction.getWorkflowId() - Fix workflowIdRegularExpression broken regex (escaped backslash and possessive quantifier) - Change FailureAction.retryAfter from Long to Double (spec defines it as a non-negative decimal number) - Rename PayoadReplacement to PayloadReplacement and change RequestBody.replacements to List - Update and expand tests to cover all fixed behaviours Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com> --- .../com/apiflows/model/FailureAction.java | 10 +- .../apiflows/model/PayloadReplacement.java | 23 +++ .../java/com/apiflows/model/RequestBody.java | 12 +- .../parser/OpenAPIWorkflowParserResult.java | 3 +- .../parser/OpenAPIWorkflowValidator.java | 50 +++--- .../parser/OpenAPIWorkflowValidatorTest.java | 144 +++++++++++++----- 6 files changed, 169 insertions(+), 73 deletions(-) create mode 100644 src/main/java/com/apiflows/model/PayloadReplacement.java diff --git a/src/main/java/com/apiflows/model/FailureAction.java b/src/main/java/com/apiflows/model/FailureAction.java index b045586..838135e 100644 --- a/src/main/java/com/apiflows/model/FailureAction.java +++ b/src/main/java/com/apiflows/model/FailureAction.java @@ -1,7 +1,5 @@ package com.apiflows.model; -import io.swagger.v3.oas.models.media.IntegerSchema; - import java.util.ArrayList; import java.util.List; @@ -10,7 +8,7 @@ public class FailureAction { private String type; private String workflowId; private String stepId; - private Long retryAfter; + private Double retryAfter; private Integer retryLimit; private List criteria; @@ -38,11 +36,11 @@ public void setStepId(String stepId) { this.stepId = stepId; } - public Long getRetryAfter() { + public Double getRetryAfter() { return retryAfter; } - public void setRetryAfter(Long retryAfter) { + public void setRetryAfter(Double retryAfter) { this.retryAfter = retryAfter; } @@ -77,7 +75,7 @@ public FailureAction workflowId(String workflowId) { return this; } - public FailureAction retryAfter(Long retryAfter) { + public FailureAction retryAfter(Double retryAfter) { this.retryAfter = retryAfter; return this; } diff --git a/src/main/java/com/apiflows/model/PayloadReplacement.java b/src/main/java/com/apiflows/model/PayloadReplacement.java new file mode 100644 index 0000000..1c03657 --- /dev/null +++ b/src/main/java/com/apiflows/model/PayloadReplacement.java @@ -0,0 +1,23 @@ +package com.apiflows.model; + +public class PayloadReplacement { + + private String target; + private String value; + + public String getTarget() { + return target; + } + + public void setTarget(String target) { + this.target = target; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } +} diff --git a/src/main/java/com/apiflows/model/RequestBody.java b/src/main/java/com/apiflows/model/RequestBody.java index 89e419d..5fa7223 100644 --- a/src/main/java/com/apiflows/model/RequestBody.java +++ b/src/main/java/com/apiflows/model/RequestBody.java @@ -1,10 +1,12 @@ package com.apiflows.model; +import java.util.List; + public class RequestBody { private String contentType; private Object payload; - private PayoadReplacement payoadReplacement; + private List replacements; public String getContentType() { return contentType; @@ -22,11 +24,11 @@ public void setPayload(Object payload) { this.payload = payload; } - public PayoadReplacement getPayoadReplacement() { - return payoadReplacement; + public List getReplacements() { + return replacements; } - public void setPayoadReplacement(PayoadReplacement payoadReplacement) { - this.payoadReplacement = payoadReplacement; + public void setReplacements(List replacements) { + this.replacements = replacements; } } diff --git a/src/main/java/com/apiflows/parser/OpenAPIWorkflowParserResult.java b/src/main/java/com/apiflows/parser/OpenAPIWorkflowParserResult.java index b747903..c558b86 100644 --- a/src/main/java/com/apiflows/parser/OpenAPIWorkflowParserResult.java +++ b/src/main/java/com/apiflows/parser/OpenAPIWorkflowParserResult.java @@ -2,6 +2,7 @@ import com.apiflows.model.OpenAPIWorkflow; +import java.util.ArrayList; import java.util.List; public class OpenAPIWorkflowParserResult { @@ -10,7 +11,7 @@ public enum Format { JSON, YAML } private boolean valid = true; - private List errors = null; + private List errors = new ArrayList<>(); private OpenAPIWorkflow openAPIWorkflow; private String location; diff --git a/src/main/java/com/apiflows/parser/OpenAPIWorkflowValidator.java b/src/main/java/com/apiflows/parser/OpenAPIWorkflowValidator.java index 7ab4343..1669eaa 100644 --- a/src/main/java/com/apiflows/parser/OpenAPIWorkflowValidator.java +++ b/src/main/java/com/apiflows/parser/OpenAPIWorkflowValidator.java @@ -217,7 +217,7 @@ List validateStep(Step step, String workflowId ) { } List validateParameter(Parameter parameter, String workflowId, String componentName) { - List SUPPORTED_VALUES = Arrays.asList("path", "query", "header", "cookie", "body"); + List SUPPORTED_VALUES = Arrays.asList("path", "query", "header", "cookie"); String source; @@ -299,25 +299,22 @@ List validateSuccessAction(String workflowId, String stepId, SuccessActi } } - if(successAction.getWorkflowId() == null && successAction.getStepId() == null) { - errors.add("Step " + stepId + " SuccessAction must define either workflowId or stepId"); - } - - if(successAction.getWorkflowId() != null && successAction.getStepId() != null) { - errors.add("Step " + stepId + " SuccessAction cannot define both workflowId and stepId"); - } - - if(successAction.getStepId() != null && successAction.getType() != null && successAction.getType().equals("goto")) { - // when type `goto` stepId must exist (if provided) - if (!stepExists(workflowId, successAction.getStepId())) { - errors.add("Step " + stepId + " SuccessAction stepId is invalid (no such a step exists)"); + if("goto".equals(successAction.getType())) { + if(successAction.getWorkflowId() == null && successAction.getStepId() == null) { + errors.add("Step " + stepId + " SuccessAction must define either workflowId or stepId"); } - } - - if(successAction.getWorkflowId() != null && successAction.getType() != null && successAction.getType().equals("goto")) { - // when type `goto` workflowId must exist (if provided) - if(!workflowExists(workflowId)) { - errors.add("Step " + stepId + " SuccessAction workflowId is invalid (no such a workflow exists)"); + if(successAction.getWorkflowId() != null && successAction.getStepId() != null) { + errors.add("Step " + stepId + " SuccessAction cannot define both workflowId and stepId"); + } + if(successAction.getStepId() != null) { + if (!stepExists(workflowId, successAction.getStepId())) { + errors.add("Step " + stepId + " SuccessAction stepId is invalid (no such a step exists)"); + } + } + if(successAction.getWorkflowId() != null) { + if(!workflowExists(successAction.getWorkflowId())) { + errors.add("Step " + stepId + " SuccessAction workflowId is invalid (no such a workflow exists)"); + } } } @@ -339,12 +336,13 @@ List validateFailureAction(String workflowId, String stepId, FailureActi } } - if(failureAction.getWorkflowId() == null && failureAction.getStepId() == null) { - errors.add("Step " + stepId + " FailureAction must define either workflowId or stepId"); - } - - if(failureAction.getWorkflowId() != null && failureAction.getStepId() != null) { - errors.add("Step " + stepId + " FailureAction cannot define both workflowId and stepId"); + if("goto".equals(failureAction.getType())) { + if(failureAction.getWorkflowId() == null && failureAction.getStepId() == null) { + errors.add("Step " + stepId + " FailureAction must define either workflowId or stepId"); + } + if(failureAction.getWorkflowId() != null && failureAction.getStepId() != null) { + errors.add("Step " + stepId + " FailureAction cannot define both workflowId and stepId"); + } } if(failureAction.getRetryAfter() != null && failureAction.getRetryAfter() < 0) { @@ -434,7 +432,7 @@ String getStepIdRegularExpression() { } String getWorkflowIdRegularExpression() { - return "[A-Za-z0-9_\\\\-]++"; + return "[A-Za-z0-9_\\-]+"; } String getComponentKeyRegularExpression() { return "^[a-zA-Z0-9\\.\\-_]+$"; diff --git a/src/test/java/com/apiflows/parser/OpenAPIWorkflowValidatorTest.java b/src/test/java/com/apiflows/parser/OpenAPIWorkflowValidatorTest.java index 4c55163..bbe3394 100644 --- a/src/test/java/com/apiflows/parser/OpenAPIWorkflowValidatorTest.java +++ b/src/test/java/com/apiflows/parser/OpenAPIWorkflowValidatorTest.java @@ -254,6 +254,17 @@ void validateParameterInvalidIn() { assertEquals(1, validator.validateParameter(parameter, worklowId, null).size()); } + @Test + void validateParameterBodyInIsInvalid() { + Parameter parameter = new Parameter() + .name("param") + .value("1") + .in("body"); + String worklowId = "q1"; + + assertEquals(1, validator.validateParameter(parameter, worklowId, null).size()); + } + @Test void validateParameterWithoutValue() { Parameter parameter = new Parameter() @@ -271,8 +282,7 @@ void validateSuccessAction() { String stepId = "step-one"; SuccessAction successAction = new SuccessAction() - .type("end") - .stepId("step-one"); + .type("end"); successAction.addCriteria( new Criterion() @@ -281,6 +291,19 @@ void validateSuccessAction() { assertEquals(0, validator.validateSuccessAction(workflowId, stepId, successAction).size()); } + @Test + void validateSuccessActionEndTypeDoesNotRequireTarget() { + String workflowId = "w1"; + String stepId = "step-one"; + + SuccessAction successAction = new SuccessAction() + .type("end") + .stepId(null) + .workflowId(null); + + assertEquals(0, validator.validateSuccessAction(workflowId, stepId, successAction).size()); + } + @Test void validateSuccessActionInvalidType() { String workflowId = "w1"; @@ -298,35 +321,63 @@ void validateSuccessActionInvalidType() { } @Test - void validateSuccessActionMissingEntity() { + void validateSuccessActionGotoMissingTarget() { String workflowId = "w1"; String stepId = "step-one"; SuccessAction successAction = new SuccessAction() - .type("end") + .type("goto") .stepId(null) .workflowId(null); - successAction.addCriteria( - new Criterion() - .context("$statusCode == 200")); - assertEquals(1, validator.validateSuccessAction(workflowId, stepId, successAction).size()); } @Test - void validateSuccessActionInvalidEntity() { + void validateSuccessActionGotoInvalidEntity() { + OpenAPIWorkflowValidator validator = new OpenAPIWorkflowValidator(); + validator.workflowIds.add("target-workflow"); + Map> stepIds = new HashMap<>(); + stepIds.put("w1", Set.of("step-one", "step-two")); + validator.stepIds = stepIds; + String workflowId = "w1"; String stepId = "step-one"; SuccessAction successAction = new SuccessAction() - .type("end") + .type("goto") .stepId("step-one") - .workflowId("workflow-id"); + .workflowId("target-workflow"); - successAction.addCriteria( - new Criterion() - .condition("$statusCode == 200")); + assertEquals(1, validator.validateSuccessAction(workflowId, stepId, successAction).size()); + } + + @Test + void validateSuccessActionGotoValidWorkflowId() { + OpenAPIWorkflowValidator validator = new OpenAPIWorkflowValidator(); + validator.workflowIds.add("target-workflow"); + + String workflowId = "w1"; + String stepId = "step-one"; + + SuccessAction successAction = new SuccessAction() + .type("goto") + .workflowId("target-workflow"); + + assertEquals(0, validator.validateSuccessAction(workflowId, stepId, successAction).size()); + } + + @Test + void validateSuccessActionGotoInvalidWorkflowId() { + OpenAPIWorkflowValidator validator = new OpenAPIWorkflowValidator(); + validator.workflowIds.add("w1"); + + String workflowId = "w1"; + String stepId = "step-one"; + + SuccessAction successAction = new SuccessAction() + .type("goto") + .workflowId("non-existent-workflow"); assertEquals(1, validator.validateSuccessAction(workflowId, stepId, successAction).size()); } @@ -407,8 +458,7 @@ void validateFailureAction() { FailureAction failureAction = new FailureAction() .type("end") - .stepId("step-one") - .retryAfter(1000L) + .retryAfter(1.5) .retryLimit(3); failureAction.addCriteria( @@ -425,8 +475,7 @@ void validateFailureActionInvalidType() { FailureAction failureAction = new FailureAction() .type("dummy") - .stepId("step-one") - .retryAfter(1000L) + .retryAfter(1.5) .retryLimit(3); failureAction.addCriteria( @@ -443,8 +492,7 @@ void validateFailureActionInvalidRetrySettings() { FailureAction failureAction = new FailureAction() .type("end") - .stepId("step-one") - .retryAfter(-1000L) + .retryAfter(-1.5) .retryLimit(-3); failureAction.addCriteria( @@ -455,7 +503,7 @@ void validateFailureActionInvalidRetrySettings() { } @Test - void validateFailureActionMissingEntity() { + void validateFailureActionRetryTypeDoesNotRequireTarget() { String workflowId = "w1"; String stepId = "step-one"; @@ -463,35 +511,56 @@ void validateFailureActionMissingEntity() { .type("retry") .stepId(null) .workflowId(null) - .retryAfter(1000L) + .retryAfter(1.5) .retryLimit(3); - failureAction.addCriteria( - new Criterion() - .context("$statusCode == 200")); + assertEquals(0, validator.validateFailureAction(workflowId, stepId, failureAction).size()); + } + + @Test + void validateFailureActionGotoMissingTarget() { + String workflowId = "w1"; + String stepId = "step-one"; + + FailureAction failureAction = new FailureAction() + .type("goto") + .stepId(null) + .workflowId(null); assertEquals(1, validator.validateFailureAction(workflowId, stepId, failureAction).size()); } @Test - void validateFailureActionInvalidEntity() { + void validateFailureActionGotoInvalidEntity() { + OpenAPIWorkflowValidator validator = new OpenAPIWorkflowValidator(); + Map> stepIds = new HashMap<>(); + stepIds.put("w1", Set.of("step-one", "step-two")); + validator.stepIds = stepIds; + String workflowId = "w1"; String stepId = "step-one"; FailureAction failureAction = new FailureAction() - .type("end") + .type("goto") .stepId("step-one") - .workflowId("workflow-test") - .retryAfter(1000L) - .retryLimit(3); - - failureAction.addCriteria( - new Criterion() - .context("$statusCode == 200")); + .workflowId("workflow-test"); assertEquals(1, validator.validateFailureAction(workflowId, stepId, failureAction).size()); } + @Test + void validateFailureActionRetryAfterDecimalValue() { + String workflowId = "w1"; + String stepId = "step-one"; + + FailureAction failureAction = new FailureAction() + .type("retry") + .retryAfter(0.5) + .retryLimit(3); + + assertEquals(0, validator.validateFailureAction(workflowId, stepId, failureAction).size()); + } + @Test void validateFailureActionInvalidStepId() { String workflowId = "w1"; @@ -507,7 +576,7 @@ void validateFailureActionInvalidStepId() { FailureAction failureAction = new FailureAction() .type("retry") .stepId("step-dummy") - .retryAfter(1000L) + .retryAfter(1.5) .retryLimit(3); failureAction.addCriteria( @@ -700,6 +769,11 @@ void validWorkflowId() { assertTrue(new OpenAPIWorkflowValidator().isValidWorkflowId("idOfTheWorkflow_1")); } + @Test + void validWorkflowIdWithHyphen() { + assertTrue(new OpenAPIWorkflowValidator().isValidWorkflowId("workflow-id-1")); + } + @Test void invalidWorkflowId() { assertFalse(new OpenAPIWorkflowValidator().isValidWorkflowId("workflow id")); From a3e5e1ef8539d3903807b04ee56ea5755a23ac3c Mon Sep 17 00:00:00 2001 From: Beppe Catanese Date: Sun, 29 Mar 2026 13:22:47 +0200 Subject: [PATCH 2/2] Reduce code duplication in validator and tests - Extract validateGotoTarget() private helper in OpenAPIWorkflowValidator to eliminate the duplicated 'must define either' and 'cannot define both' goto checks shared between validateSuccessAction and validateFailureAction - Add validatorWithStepIds() and validatorWithWorkflowIds() private helpers in the test class to replace repeated Map/Set setup boilerplate across eight tests Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com> --- .../parser/OpenAPIWorkflowValidator.java | 25 ++-- .../parser/OpenAPIWorkflowValidatorTest.java | 111 +++++------------- 2 files changed, 44 insertions(+), 92 deletions(-) diff --git a/src/main/java/com/apiflows/parser/OpenAPIWorkflowValidator.java b/src/main/java/com/apiflows/parser/OpenAPIWorkflowValidator.java index 1669eaa..52a7b5b 100644 --- a/src/main/java/com/apiflows/parser/OpenAPIWorkflowValidator.java +++ b/src/main/java/com/apiflows/parser/OpenAPIWorkflowValidator.java @@ -300,12 +300,7 @@ List validateSuccessAction(String workflowId, String stepId, SuccessActi } if("goto".equals(successAction.getType())) { - if(successAction.getWorkflowId() == null && successAction.getStepId() == null) { - errors.add("Step " + stepId + " SuccessAction must define either workflowId or stepId"); - } - if(successAction.getWorkflowId() != null && successAction.getStepId() != null) { - errors.add("Step " + stepId + " SuccessAction cannot define both workflowId and stepId"); - } + errors.addAll(validateGotoTarget(stepId, "SuccessAction", successAction.getStepId(), successAction.getWorkflowId())); if(successAction.getStepId() != null) { if (!stepExists(workflowId, successAction.getStepId())) { errors.add("Step " + stepId + " SuccessAction stepId is invalid (no such a step exists)"); @@ -337,12 +332,7 @@ List validateFailureAction(String workflowId, String stepId, FailureActi } if("goto".equals(failureAction.getType())) { - if(failureAction.getWorkflowId() == null && failureAction.getStepId() == null) { - errors.add("Step " + stepId + " FailureAction must define either workflowId or stepId"); - } - if(failureAction.getWorkflowId() != null && failureAction.getStepId() != null) { - errors.add("Step " + stepId + " FailureAction cannot define both workflowId and stepId"); - } + errors.addAll(validateGotoTarget(stepId, "FailureAction", failureAction.getStepId(), failureAction.getWorkflowId())); } if(failureAction.getRetryAfter() != null && failureAction.getRetryAfter() < 0) { @@ -593,4 +583,15 @@ boolean isRuntimeExpression(String name) { return name != null && name.startsWith("$"); } + private List validateGotoTarget(String stepId, String actionLabel, String targetStepId, String targetWorkflowId) { + List errors = new ArrayList<>(); + if (targetWorkflowId == null && targetStepId == null) { + errors.add("Step " + stepId + " " + actionLabel + " must define either workflowId or stepId"); + } + if (targetWorkflowId != null && targetStepId != null) { + errors.add("Step " + stepId + " " + actionLabel + " cannot define both workflowId and stepId"); + } + return errors; + } + } diff --git a/src/test/java/com/apiflows/parser/OpenAPIWorkflowValidatorTest.java b/src/test/java/com/apiflows/parser/OpenAPIWorkflowValidatorTest.java index bbe3394..ba3078c 100644 --- a/src/test/java/com/apiflows/parser/OpenAPIWorkflowValidatorTest.java +++ b/src/test/java/com/apiflows/parser/OpenAPIWorkflowValidatorTest.java @@ -1,7 +1,6 @@ package com.apiflows.parser; import com.apiflows.model.*; -import org.checkerframework.checker.units.qual.C; import org.junit.jupiter.api.Test; import java.util.*; @@ -12,6 +11,20 @@ class OpenAPIWorkflowValidatorTest { OpenAPIWorkflowValidator validator = new OpenAPIWorkflowValidator(); + private OpenAPIWorkflowValidator validatorWithStepIds(String workflowId, String... steps) { + OpenAPIWorkflowValidator v = new OpenAPIWorkflowValidator(); + Map> ids = new HashMap<>(); + ids.put(workflowId, new HashSet<>(Arrays.asList(steps))); + v.stepIds = ids; + return v; + } + + private OpenAPIWorkflowValidator validatorWithWorkflowIds(String... workflowIds) { + OpenAPIWorkflowValidator v = new OpenAPIWorkflowValidator(); + v.workflowIds.addAll(Arrays.asList(workflowIds)); + return v; + } + @Test void validate() { OpenAPIWorkflow openAPIWorkflow = new OpenAPIWorkflow(); @@ -335,74 +348,48 @@ void validateSuccessActionGotoMissingTarget() { @Test void validateSuccessActionGotoInvalidEntity() { - OpenAPIWorkflowValidator validator = new OpenAPIWorkflowValidator(); - validator.workflowIds.add("target-workflow"); - Map> stepIds = new HashMap<>(); - stepIds.put("w1", Set.of("step-one", "step-two")); - validator.stepIds = stepIds; - - String workflowId = "w1"; - String stepId = "step-one"; + OpenAPIWorkflowValidator v = validatorWithStepIds("w1", "step-one", "step-two"); + v.workflowIds.add("target-workflow"); SuccessAction successAction = new SuccessAction() .type("goto") .stepId("step-one") .workflowId("target-workflow"); - assertEquals(1, validator.validateSuccessAction(workflowId, stepId, successAction).size()); + assertEquals(1, v.validateSuccessAction("w1", "step-one", successAction).size()); } @Test void validateSuccessActionGotoValidWorkflowId() { - OpenAPIWorkflowValidator validator = new OpenAPIWorkflowValidator(); - validator.workflowIds.add("target-workflow"); - - String workflowId = "w1"; - String stepId = "step-one"; + OpenAPIWorkflowValidator v = validatorWithWorkflowIds("target-workflow"); SuccessAction successAction = new SuccessAction() .type("goto") .workflowId("target-workflow"); - assertEquals(0, validator.validateSuccessAction(workflowId, stepId, successAction).size()); + assertEquals(0, v.validateSuccessAction("w1", "step-one", successAction).size()); } @Test void validateSuccessActionGotoInvalidWorkflowId() { - OpenAPIWorkflowValidator validator = new OpenAPIWorkflowValidator(); - validator.workflowIds.add("w1"); - - String workflowId = "w1"; - String stepId = "step-one"; + OpenAPIWorkflowValidator v = validatorWithWorkflowIds("w1"); SuccessAction successAction = new SuccessAction() .type("goto") .workflowId("non-existent-workflow"); - assertEquals(1, validator.validateSuccessAction(workflowId, stepId, successAction).size()); + assertEquals(1, v.validateSuccessAction("w1", "step-one", successAction).size()); } @Test void validateSuccessActionInvalidStepId() { - String workflowId = "w1"; - - OpenAPIWorkflowValidator validator = new OpenAPIWorkflowValidator(); + OpenAPIWorkflowValidator v = validatorWithStepIds("w1", "step-one", "step-two", "step-three"); - Map> stepIds = new HashMap<>(); - stepIds.put("w1", Set.of("step-one", "step-two", "step-three")); - - validator.stepIds = stepIds; - - String stepId = "step-one"; SuccessAction successAction = new SuccessAction() .type("goto") .stepId("step-dummy"); - successAction.addCriteria( - new Criterion() - .context("$statusCode == 200")); - - assertEquals(1, validator.validateSuccessAction(workflowId, stepId, successAction).size()); + assertEquals(1, v.validateSuccessAction("w1", "step-one", successAction).size()); } @@ -532,20 +519,14 @@ void validateFailureActionGotoMissingTarget() { @Test void validateFailureActionGotoInvalidEntity() { - OpenAPIWorkflowValidator validator = new OpenAPIWorkflowValidator(); - Map> stepIds = new HashMap<>(); - stepIds.put("w1", Set.of("step-one", "step-two")); - validator.stepIds = stepIds; - - String workflowId = "w1"; - String stepId = "step-one"; + OpenAPIWorkflowValidator v = validatorWithStepIds("w1", "step-one", "step-two"); FailureAction failureAction = new FailureAction() .type("goto") .stepId("step-one") .workflowId("workflow-test"); - assertEquals(1, validator.validateFailureAction(workflowId, stepId, failureAction).size()); + assertEquals(1, v.validateFailureAction("w1", "step-one", failureAction).size()); } @Test @@ -563,15 +544,7 @@ void validateFailureActionRetryAfterDecimalValue() { @Test void validateFailureActionInvalidStepId() { - String workflowId = "w1"; - String stepId = "step-one"; - - OpenAPIWorkflowValidator validator = new OpenAPIWorkflowValidator(); - - Map> stepIds = new HashMap<>(); - stepIds.put("w1", Set.of("step-one", "step-two", "step-three")); - - validator.stepIds = stepIds; + OpenAPIWorkflowValidator v = validatorWithStepIds("w1", "step-one", "step-two", "step-three"); FailureAction failureAction = new FailureAction() .type("retry") @@ -579,11 +552,7 @@ void validateFailureActionInvalidStepId() { .retryAfter(1.5) .retryLimit(3); - failureAction.addCriteria( - new Criterion() - .context("$statusCode == 200")); - - assertEquals(1, validator.validateFailureAction(workflowId, stepId, failureAction).size()); + assertEquals(1, v.validateFailureAction("w1", "step-one", failureAction).size()); } @@ -728,40 +697,22 @@ public void validateStepsWorkflowIdsWithoutRuntimeExpression() { @Test void stepExists() { - OpenAPIWorkflowValidator validator = new OpenAPIWorkflowValidator(); - Map> stepIds = new HashMap<>(); - stepIds.put("w1", Set.of("step-one", "step-two", "step-three")); - - validator.stepIds = stepIds; - - assertTrue(validator.stepExists("w1", "step-one")); + assertTrue(validatorWithStepIds("w1", "step-one", "step-two", "step-three").stepExists("w1", "step-one")); } @Test void stepNotFound() { - OpenAPIWorkflowValidator validator = new OpenAPIWorkflowValidator(); - Map> stepIds = new HashMap<>(); - stepIds.put("w1", Set.of("step-one", "step-two", "step-three")); - - validator.stepIds = stepIds; - - assertFalse(validator.stepExists("w1", "step-dummy")); + assertFalse(validatorWithStepIds("w1", "step-one", "step-two", "step-three").stepExists("w1", "step-dummy")); } @Test void workflowExists() { - OpenAPIWorkflowValidator validator = new OpenAPIWorkflowValidator(); - validator.workflowIds.add("w1"); - - assertTrue(validator.workflowExists("w1")); + assertTrue(validatorWithWorkflowIds("w1").workflowExists("w1")); } @Test void workflowNotFound() { - OpenAPIWorkflowValidator validator = new OpenAPIWorkflowValidator(); - validator.workflowIds.add("w1"); - - assertFalse(validator.workflowExists("dummy")); + assertFalse(validatorWithWorkflowIds("w1").workflowExists("dummy")); } @Test