diff --git a/.gitignore b/.gitignore index aef41c5..036f9f5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ bin .idea -*.out \ No newline at end of file +*.out +.vscode \ No newline at end of file diff --git a/model/workflow.go b/model/workflow.go index 489eebf..986e497 100644 --- a/model/workflow.go +++ b/model/workflow.go @@ -117,7 +117,7 @@ func (w *Workflow) UnmarshalJSON(data []byte) error { } w.States = make([]State, len(rawStates)) - var mapState map[string]interface{} + mapState := map[string]interface{}{} for i, rawState := range rawStates { if err := json.Unmarshal(rawState, &mapState); err != nil { return err @@ -130,6 +130,7 @@ func (w *Workflow) UnmarshalJSON(data []byte) error { return err } w.States[i] = state + mapState = map[string]interface{}{} } if _, ok := workflowMap["events"]; ok { if err := json.Unmarshal(workflowMap["events"], &w.Events); err != nil { diff --git a/parser/parser_test.go b/parser/parser_test.go index 0b91a25..2bdbfa6 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -64,6 +64,12 @@ func TestFromFile(t *testing.T) { assert.NotNil(t, w.States[0].(*model.OperationState).Actions[0].FunctionRef) assert.Equal(t, "greetingFunction", w.States[0].(*model.OperationState).Actions[0].FunctionRef.RefName) }, + "./testdata/workflows/eventbaseddataandswitch.sw.json": func(t *testing.T, w *model.Workflow) { + assert.Equal(t, "Start", w.States[0].GetName()) + assert.Equal(t, "CheckVisaStatus", w.States[1].GetName()) + assert.IsType(t, &model.DataBasedSwitchState{}, w.States[0]) + assert.IsType(t, &model.EventBasedSwitchState{}, w.States[1]) + }, "./testdata/workflows/eventbasedgreeting.sw.json": func(t *testing.T, w *model.Workflow) { assert.Equal(t, "GreetingEvent", w.Events[0].Name) assert.IsType(t, &model.EventState{}, w.States[0]) diff --git a/parser/testdata/workflows/eventbaseddataandswitch.sw.json b/parser/testdata/workflows/eventbaseddataandswitch.sw.json new file mode 100644 index 0000000..58482be --- /dev/null +++ b/parser/testdata/workflows/eventbaseddataandswitch.sw.json @@ -0,0 +1,100 @@ +{ + "id": "eventbaseddataandswitch", + "version": "1.0", + "name": "Event Based Switch Transitions", + "description": "Event Based Switch Transitions with Event Database Condition", + "specVersion": "0.7", + "start": { + "stateName": "Start" + }, + "events": [ + { + "name": "visaApprovedEvent", + "type": "VisaApproved", + "source": "visaCheckSource" + }, + { + "name": "visaRejectedEvent", + "type": "VisaRejected", + "source": "visaCheckSource" + } + ], + "states": [ + { + "name": "Start", + "type": "switch", + "dataConditions": [ + { + "condition": "${ true }", + "transition": "CheckVisaStatus" + } + ] + }, + { + "name": "CheckVisaStatus", + "type": "switch", + "eventConditions": [ + { + "eventRef": "visaApprovedEvent", + "transition": { + "nextState": "HandleApprovedVisa" + } + }, + { + "eventRef": "visaRejectedEvent", + "transition": { + "nextState": "HandleRejectedVisa" + } + } + ], + "eventTimeout": "PT1H", + "defaultCondition": { + "transition": { + "nextState": "HandleNoVisaDecision" + } + } + }, + { + "name": "HandleApprovedVisa", + "type": "operation", + "actions": [ + { + "subFlowRef": { + "workflowId": "handleApprovedVisaWorkflowID" + } + } + ], + "end": { + "terminate": true + } + }, + { + "name": "HandleRejectedVisa", + "type": "operation", + "actions": [ + { + "subFlowRef": { + "workflowId": "handleRejectedVisaWorkflowID" + } + } + ], + "end": { + "terminate": true + } + }, + { + "name": "HandleNoVisaDecision", + "type": "operation", + "actions": [ + { + "subFlowRef": { + "workflowId": "handleNoVisaDecisionWorkfowId" + } + } + ], + "end": { + "terminate": true + } + } + ] +} \ No newline at end of file