Skip to content

Commit

Permalink
Rebase with latest changes
Browse files Browse the repository at this point in the history
Signed-off-by: Ricardo Zanini <[email protected]>
  • Loading branch information
ricardozanini committed May 28, 2024
1 parent 044ceb7 commit fea2703
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -359,13 +359,12 @@ private void checkActionsDefinition(
}

if (action.getRetryRef() != null
&& isMissingRetryDefinition(
action.getRetryRef(), workflow.getRetries().getRetryDefs())) {
&& isMissingRetryDefinition(action.getRetryRef(), workflow.getRetries().getRetryDefs())) {
addValidationError(
String.format(
"Operation State action '%s' retryRef does not reference an existing workflow retry definition",
action.getName()),
ValidationError.WORKFLOW_VALIDATION);
String.format(
"Operation State action '%s' retryRef does not reference an existing workflow retry definition",
action.getName()),
ValidationError.WORKFLOW_VALIDATION);
}
}
}
Expand All @@ -391,8 +390,8 @@ private boolean isMissingEventsDefinition(String eventName, List<EventDefinition
}

private boolean isMissingRetryDefinition(String retryName, List<RetryDefinition> retries) {
return retries == null || ! retries.stream()
.anyMatch(f -> f.getName() != null && f.getName().equals(retryName));
return retries == null
|| !retries.stream().anyMatch(f -> f.getName() != null && f.getName().equals(retryName));
}

private static final Set<String> skipMessages =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,66 +369,67 @@ void testActionDefForEach() {
}

/**
* @see <a href="https://github.com/serverlessworkflow/sdk-java/issues/213">Retry definition validation doesn't work</a>
* @see <a href="https://github.com/serverlessworkflow/sdk-java/issues/213">Retry definition
* validation doesn't work</a>
*/
@Test
public void testValidateRetry() {
WorkflowValidator workflowValidator = new WorkflowValidatorImpl();
List<ValidationError> validationErrors =
workflowValidator
.setSource(
"{\n"
+ " \"id\": \"workflow_1\",\n"
+ " \"name\": \"workflow_1\",\n"
+ " \"description\": \"workflow_1\",\n"
+ " \"version\": \"1.0\",\n"
+ " \"specVersion\": \"0.8\",\n"
+ " \"start\": \"Task1\",\n"
+ " \"functions\": [\n"
+ " {\n"
+ " \"name\": \"increment\",\n"
+ " \"type\": \"custom\",\n"
+ " \"operation\": \"worker\"\n"
+ " }\n"
+ " ],\n"
+ " \"retries\": [\n"
+ " {\n"
+ " \"maxAttempts\": 3\n"
+ " },\n"
+ " {\n"
+ " \"name\": \"testRetry\" \n"
+ " }\n"
+ " ],\n"
+ " \"states\": [\n"
+ " {\n"
+ " \"name\": \"Task1\",\n"
+ " \"type\": \"operation\",\n"
+ " \"actionMode\": \"sequential\",\n"
+ " \"actions\": [\n"
+ " {\n"
+ " \"functionRef\": {\n"
+ " \"refName\": \"increment\",\n"
+ " \"arguments\": {\n"
+ " \"input\": \"some text\"\n"
+ " }\n"
+ " },\n"
+ " \"retryRef\": \"const\",\n"
+ " \"actionDataFilter\": {\n"
+ " \"toStateData\": \"${ .result }\"\n"
+ " }\n"
+ " }\n"
+ " ],\n"
+ " \"end\": true\n"
+ " }\n"
+ " ]\n"
+ "}")
.validate();
workflowValidator
.setSource(
"{\n"
+ " \"id\": \"workflow_1\",\n"
+ " \"name\": \"workflow_1\",\n"
+ " \"description\": \"workflow_1\",\n"
+ " \"version\": \"1.0\",\n"
+ " \"specVersion\": \"0.8\",\n"
+ " \"start\": \"Task1\",\n"
+ " \"functions\": [\n"
+ " {\n"
+ " \"name\": \"increment\",\n"
+ " \"type\": \"custom\",\n"
+ " \"operation\": \"worker\"\n"
+ " }\n"
+ " ],\n"
+ " \"retries\": [\n"
+ " {\n"
+ " \"maxAttempts\": 3\n"
+ " },\n"
+ " {\n"
+ " \"name\": \"testRetry\" \n"
+ " }\n"
+ " ],\n"
+ " \"states\": [\n"
+ " {\n"
+ " \"name\": \"Task1\",\n"
+ " \"type\": \"operation\",\n"
+ " \"actionMode\": \"sequential\",\n"
+ " \"actions\": [\n"
+ " {\n"
+ " \"functionRef\": {\n"
+ " \"refName\": \"increment\",\n"
+ " \"arguments\": {\n"
+ " \"input\": \"some text\"\n"
+ " }\n"
+ " },\n"
+ " \"retryRef\": \"const\",\n"
+ " \"actionDataFilter\": {\n"
+ " \"toStateData\": \"${ .result }\"\n"
+ " }\n"
+ " }\n"
+ " ],\n"
+ " \"end\": true\n"
+ " }\n"
+ " ]\n"
+ "}")
.validate();

Assertions.assertNotNull(validationErrors);
Assertions.assertEquals(2, validationErrors.size());
Assertions.assertEquals("Retry name should not be empty", validationErrors.get(0).getMessage());
Assertions.assertEquals(
"Operation State action 'null' retryRef does not reference an existing workflow retry definition",
validationErrors.get(1).getMessage());
"Operation State action 'null' retryRef does not reference an existing workflow retry definition",
validationErrors.get(1).getMessage());
}
}

0 comments on commit fea2703

Please sign in to comment.