Skip to content

Commit

Permalink
Merge pull request serverlessworkflow#188 from tsurdilo/fixcallbackva…
Browse files Browse the repository at this point in the history
…lidation

fix validation for callback state
  • Loading branch information
tsurdilo authored Apr 4, 2022
2 parents a37b464 + c92873b commit cefa865
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ public List<ValidationError> validate() {
ValidationError.WORKFLOW_VALIDATION);
}

if (haveFunctionDefinition(
if (!haveFunctionDefinition(
callbackState.getAction().getFunctionRef().getRefName(), functions)) {
addValidationError(
"CallbackState action function ref does not reference a defined workflow function definition",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,48 @@ public void testValidateWorkflowForOptionalIterationParam() {
1,
validationErrors.size()); // validation error raised for functionref not for iterationParam
}

@Test
public void testMissingFunctionRefForCallbackState() {
WorkflowValidator workflowValidator = new WorkflowValidatorImpl();
List<ValidationError> validationErrors =
workflowValidator
.setSource(
"{\n"
+ " \"id\": \"callbackstatemissingfuncref\",\n"
+ " \"version\": \"1.0\",\n"
+ " \"specVersion\": \"0.8\",\n"
+ " \"name\": \"Callback State Test\",\n"
+ " \"start\": \"CheckCredit\",\n"
+ " \"states\": [\n"
+ " {\n"
+ " \"name\": \"CheckCredit\",\n"
+ " \"type\": \"callback\",\n"
+ " \"action\": {\n"
+ " \"functionRef\": {\n"
+ " \"refName\": \"callCreditCheckMicroservice\",\n"
+ " \"arguments\": {\n"
+ " \"customer\": \"${ .customer }\"\n"
+ " }\n"
+ " }\n"
+ " },\n"
+ " \"eventRef\": \"CreditCheckCompletedEvent\",\n"
+ " \"timeouts\": {\n"
+ " \"stateExecTimeout\": \"PT15M\"\n"
+ " },\n"
+ " \"end\": true\n"
+ " }\n"
+ " ]\n"
+ "}")
.validate();

Assertions.assertNotNull(validationErrors);
Assertions.assertEquals(2, validationErrors.size());
Assertions.assertEquals(
"CallbackState event ref does not reference a defined workflow event definition",
validationErrors.get(0).getMessage());
Assertions.assertEquals(
"CallbackState action function ref does not reference a defined workflow function definition",
validationErrors.get(1).getMessage());
}
}

0 comments on commit cefa865

Please sign in to comment.