Skip to content

Commit cb618c1

Browse files
committed
fix validation for callback state
Signed-off-by: Tihomir Surdilovic <[email protected]>
1 parent ba56965 commit cb618c1

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

validation/src/main/java/io/serverlessworkflow/validation/WorkflowValidatorImpl.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ public List<ValidationError> validate() {
330330
ValidationError.WORKFLOW_VALIDATION);
331331
}
332332

333-
if (haveFunctionDefinition(
333+
if (!haveFunctionDefinition(
334334
callbackState.getAction().getFunctionRef().getRefName(), functions)) {
335335
addValidationError(
336336
"CallbackState action function ref does not reference a defined workflow function definition",

validation/src/test/java/io/serverlessworkflow/validation/test/WorkflowValidationTest.java

+44
Original file line numberDiff line numberDiff line change
@@ -213,4 +213,48 @@ public void testValidateWorkflowForOptionalIterationParam() {
213213
1,
214214
validationErrors.size()); // validation error raised for functionref not for iterationParam
215215
}
216+
217+
@Test
218+
public void testMissingFunctionRefForCallbackState() {
219+
WorkflowValidator workflowValidator = new WorkflowValidatorImpl();
220+
List<ValidationError> validationErrors =
221+
workflowValidator
222+
.setSource(
223+
"{\n"
224+
+ " \"id\": \"callbackstatemissingfuncref\",\n"
225+
+ " \"version\": \"1.0\",\n"
226+
+ " \"specVersion\": \"0.8\",\n"
227+
+ " \"name\": \"Callback State Test\",\n"
228+
+ " \"start\": \"CheckCredit\",\n"
229+
+ " \"states\": [\n"
230+
+ " {\n"
231+
+ " \"name\": \"CheckCredit\",\n"
232+
+ " \"type\": \"callback\",\n"
233+
+ " \"action\": {\n"
234+
+ " \"functionRef\": {\n"
235+
+ " \"refName\": \"callCreditCheckMicroservice\",\n"
236+
+ " \"arguments\": {\n"
237+
+ " \"customer\": \"${ .customer }\"\n"
238+
+ " }\n"
239+
+ " }\n"
240+
+ " },\n"
241+
+ " \"eventRef\": \"CreditCheckCompletedEvent\",\n"
242+
+ " \"timeouts\": {\n"
243+
+ " \"stateExecTimeout\": \"PT15M\"\n"
244+
+ " },\n"
245+
+ " \"end\": true\n"
246+
+ " }\n"
247+
+ " ]\n"
248+
+ "}")
249+
.validate();
250+
251+
Assertions.assertNotNull(validationErrors);
252+
Assertions.assertEquals(2, validationErrors.size());
253+
Assertions.assertEquals(
254+
"CallbackState event ref does not reference a defined workflow event definition",
255+
validationErrors.get(0).getMessage());
256+
Assertions.assertEquals(
257+
"CallbackState action function ref does not reference a defined workflow function definition",
258+
validationErrors.get(1).getMessage());
259+
}
216260
}

0 commit comments

Comments
 (0)