Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions api/src/main/resources/schema/actions/action.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
"description": "References a sub-workflow to invoke",
"$ref": "../functions/subflowref.json"
},
"sleep": {
"$ref": "../sleep/sleep.json"
},
"actionDataFilter": {
"$ref": "../filters/actiondatafilter.json"
}
Expand Down
18 changes: 18 additions & 0 deletions api/src/main/resources/schema/sleep/sleep.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"type": "object",
"javaType": "io.serverlessworkflow.api.sleep.Sleep",
"properties": {
"before": {
"type": "string",
"description": "Amount of time (ISO 8601 duration format) to sleep before function/subflow invocation. Does not apply if 'eventRef' is defined."
},
"after": {
"type": "string",
"description": "Amount of time (ISO 8601 duration format) to sleep after function/subflow invocation. Does not apply if 'eventRef' is defined."
}
},
"required": [
"before",
"after"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -657,4 +657,47 @@ public void testAuthOAuth(String workflowLocation) {
assertEquals("${ $SECRETS.clientid }", auth.getOauth().getClientId());
assertEquals("${ $SECRETS.clientsecret }", auth.getOauth().getClientSecret());
}

@ParameterizedTest
@ValueSource(strings = {"/features/actionssleep.json", "/features/actionssleep.yml"})
public void testActionsSleep(String workflowLocation) {
Workflow workflow = Workflow.fromSource(WorkflowTestUtils.readWorkflowFile(workflowLocation));

assertNotNull(workflow);
assertNotNull(workflow.getId());
assertNotNull(workflow.getName());
assertNotNull(workflow.getStates());

assertNotNull(workflow.getStates());
assertEquals(1, workflow.getStates().size());

State state = workflow.getStates().get(0);
assertTrue(state instanceof OperationState);

OperationState operationState = (OperationState) workflow.getStates().get(0);
assertNotNull(operationState.getActions());
assertEquals(2, operationState.getActions().size());

Action action1 = operationState.getActions().get(0);
assertNotNull(action1);
assertNotNull(action1.getFunctionRef());
assertNotNull(action1.getSleep());
assertEquals("PT5S", action1.getSleep().getBefore());
assertEquals("PT10S", action1.getSleep().getAfter());
FunctionRef functionRef1 = action1.getFunctionRef();
assertEquals("creditCheckFunction", functionRef1.getRefName());
assertNull(functionRef1.getArguments());

Action action2 = operationState.getActions().get(1);
assertNotNull(action2);
assertNotNull(action2.getFunctionRef());
assertNotNull(action2.getSleep());
assertEquals("PT5S", action2.getSleep().getBefore());
assertEquals("PT10S", action2.getSleep().getAfter());
FunctionRef functionRef2 = action2.getFunctionRef();
assertEquals("sendRejectionEmailFunction", functionRef2.getRefName());
assertEquals(1, functionRef2.getArguments().size());
assertEquals("${ .customer }", functionRef2.getArguments().get("applicant").asText());

}
}
47 changes: 47 additions & 0 deletions api/src/test/resources/features/actionssleep.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"id": "functionrefs",
"version": "1.0",
"specVersion": "0.7",
"name": "Customer Credit Check Workflow",
"description": "Perform Customer Credit Check",
"start": "TestFunctionRef",
"functions": [
{
"name": "creditCheckFunction",
"operation": "http://myapis.org/creditcheckapi.json#doCreditCheck"
},
{
"name": "sendRejectionEmailFunction",
"operation": "http://myapis.org/creditcheckapi.json#rejectionEmail"
}
],
"states": [
{
"name": "TestFunctionRefs",
"type": "operation",
"actionMode": "sequential",
"actions": [
{
"functionRef": "creditCheckFunction",
"sleep": {
"before": "PT5S",
"after": "PT10S"
}
},
{
"functionRef": {
"refName": "sendRejectionEmailFunction",
"arguments": {
"applicant": "${ .customer }"
}
},
"sleep": {
"before": "PT5S",
"after": "PT10S"
}
}
],
"end": true
}
]
}
28 changes: 28 additions & 0 deletions api/src/test/resources/features/actionssleep.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
id: functionrefs
version: '1.0'
specVersion: '0.7'
name: Customer Credit Check Workflow
description: Perform Customer Credit Check
start: TestFunctionRef
functions:
- name: creditCheckFunction
operation: http://myapis.org/creditcheckapi.json#doCreditCheck
- name: sendRejectionEmailFunction
operation: http://myapis.org/creditcheckapi.json#rejectionEmail
states:
- name: TestFunctionRefs
type: operation
actionMode: sequential
actions:
- functionRef: creditCheckFunction
sleep:
before: PT5S
after: PT10S
- functionRef:
refName: sendRejectionEmailFunction
arguments:
applicant: "${ .customer }"
sleep:
before: PT5S
after: PT10S
end: true