Skip to content

Commit aaba7f6

Browse files
manick02tsurdilo
authored andcommitted
IterationParam made optional as per version V.8.0 of specification
Signed-off-by: manick02 <[email protected]>
1 parent 6dea9e4 commit aaba7f6

File tree

2 files changed

+48
-8
lines changed

2 files changed

+48
-8
lines changed

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -319,13 +319,6 @@ public List<ValidationError> validate() {
319319
"ForEach state should have a valid inputCollection",
320320
ValidationError.WORKFLOW_VALIDATION);
321321
}
322-
323-
if (forEachState.getIterationParam() == null
324-
|| forEachState.getIterationParam().isEmpty()) {
325-
addValidationError(
326-
"ForEach state should have a valid iteration parameter",
327-
ValidationError.WORKFLOW_VALIDATION);
328-
}
329322
}
330323

331324
if (s instanceof CallbackState) {

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

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public void testOperationStateNoFunctionRef() {
146146
}
147147

148148
@Test
149-
public void testValidatateWorkflowWithNoStartStateandNameSpecified() {
149+
public void testValidatateWorkflowForOptionalStartStateAndWorkflowName() {
150150
Workflow workflow =
151151
new Workflow()
152152
.withId("test-workflow")
@@ -164,4 +164,51 @@ public void testValidatateWorkflowWithNoStartStateandNameSpecified() {
164164
Assertions.assertNotNull(validationErrors);
165165
Assertions.assertEquals(0, validationErrors.size());
166166
}
167+
168+
@Test
169+
public void testValidateWorkflowForOptionalIterationParam() {
170+
WorkflowValidator workflowValidator = new WorkflowValidatorImpl();
171+
List<ValidationError> validationErrors =
172+
workflowValidator
173+
.setSource(
174+
"{\n"
175+
+ "\"id\": \"checkInbox\",\n"
176+
+ " \"name\": \"Check Inbox Workflow\",\n"
177+
+ "\"description\": \"Periodically Check Inbox\",\n"
178+
+ "\"version\": \"1.0\",\n"
179+
+ "\"start\": \"CheckInbox\",\n"
180+
+ "\"functions\": [\n"
181+
+ "\n"
182+
+ "],\n"
183+
+ "\"states\": [\n"
184+
+ " {\n"
185+
+ " \"name\": \"CheckInbox\",\n"
186+
+ " \"type\": \"operation\",\n"
187+
+ " \"actionMode\": \"sequential\",\n"
188+
+ " \"actions\": [\n"
189+
+ " {\n"
190+
+ " \"functionRef\": {\n"
191+
+ " \"refName\": \"checkInboxFunction\"\n"
192+
+ " }\n"
193+
+ " }\n"
194+
+ " ],\n"
195+
+ " \"transition\": {\n"
196+
+ " \"nextState\": \"SendTextForHighPrioriry\"\n"
197+
+ " }\n"
198+
+ " },\n"
199+
+ " {\n"
200+
+ " \"name\": \"SendTextForHighPrioriry\",\n"
201+
+ " \"type\": \"foreach\",\n"
202+
+ " \"inputCollection\": \"${ .message }\",\n"
203+
+ " \"end\": {\n"
204+
+ " \"kind\": \"default\"\n"
205+
+ " }\n"
206+
+ " }\n"
207+
+ "]\n"
208+
+ "}")
209+
.validate();
210+
211+
Assertions.assertNotNull(validationErrors);
212+
Assertions.assertEquals(1, validationErrors.size()); // validation error raised for functionref not for iterationParam
213+
}
167214
}

0 commit comments

Comments
 (0)