@@ -16,6 +16,7 @@ package parser
1616
1717import (
1818 "encoding/json"
19+ "fmt"
1920 "os"
2021 "path/filepath"
2122 "strings"
@@ -556,6 +557,14 @@ func TestFromFile(t *testing.T) {
556557 assert .Equal (t , "PT100S" , w .States [9 ].SleepState .Timeouts .StateExecTimeout .Total )
557558 assert .Equal (t , "PT200S" , w .States [9 ].SleepState .Timeouts .StateExecTimeout .Single )
558559 assert .Equal (t , true , w .States [9 ].End .Terminate )
560+
561+ // switch state with DefaultCondition as string
562+ assert .NotEmpty (t , w .States [10 ].SwitchState )
563+ assert .Equal (t , "HelloStateWithDefaultConditionString" , w .States [10 ].Name )
564+ assert .Equal (t , "${ true }" , w .States [10 ].SwitchState .DataConditions [0 ].Condition )
565+ assert .Equal (t , "HandleApprovedVisa" , w .States [10 ].SwitchState .DataConditions [0 ].Transition .NextState )
566+ assert .Equal (t , "SendTextForHighPriority" , w .States [10 ].SwitchState .DefaultCondition .Transition .NextState )
567+ assert .Equal (t , true , w .States [10 ].End .Terminate )
559568 },
560569 },
561570 }
@@ -815,7 +824,17 @@ states:
815824 single: PT20S
816825 defaultCondition:
817826 transition:
818- nextState: CheckCreditCallback
827+ nextState: HelloStateWithDefaultConditionString
828+ - name: HelloStateWithDefaultConditionString
829+ type: switch
830+ dataConditions:
831+ - condition: ${ true }
832+ transition:
833+ nextState: HandleApprovedVisa
834+ - condition: ${ false }
835+ transition:
836+ nextState: HandleRejectedVisa
837+ defaultCondition: SendTextForHighPriority
819838- name: SendTextForHighPriority
820839 type: foreach
821840 inputCollection: "${ .messages }"
@@ -911,6 +930,7 @@ states:
911930 terminate: true
912931` ))
913932 assert .Nil (t , err )
933+ fmt .Println (err )
914934 assert .NotNil (t , workflow )
915935 b , err := json .Marshal (workflow )
916936
@@ -936,7 +956,10 @@ states:
936956 assert .True (t , strings .Contains (string (b ), "{\" name\" :\" ParallelExec\" ,\" type\" :\" parallel\" ,\" transition\" :{\" nextState\" :\" CheckVisaStatusSwitchEventBased\" },\" branches\" :[{\" name\" :\" ShortDelayBranch\" ,\" actions\" :[{\" subFlowRef\" :{\" workflowId\" :\" shortdelayworkflowid\" ,\" invoke\" :\" sync\" ,\" onParentComplete\" :\" terminate\" },\" actionDataFilter\" :{\" useResults\" :true}}],\" timeouts\" :{\" actionExecTimeout\" :\" PT5H\" ,\" branchExecTimeout\" :\" PT6M\" }},{\" name\" :\" LongDelayBranch\" ,\" actions\" :[{\" subFlowRef\" :{\" workflowId\" :\" longdelayworkflowid\" ,\" invoke\" :\" sync\" ,\" onParentComplete\" :\" terminate\" },\" actionDataFilter\" :{\" useResults\" :true}}]}],\" completionType\" :\" atLeast\" ,\" numCompleted\" :13,\" timeouts\" :{\" stateExecTimeout\" :{\" single\" :\" PT2S\" ,\" total\" :\" PT1S\" },\" branchExecTimeout\" :\" PT6M\" }}" ))
937957
938958 // Switch State
939- assert .True (t , strings .Contains (string (b ), "{\" name\" :\" CheckVisaStatusSwitchEventBased\" ,\" type\" :\" switch\" ,\" defaultCondition\" :{\" transition\" :{\" nextState\" :\" CheckCreditCallback\" }},\" eventConditions\" :[{\" name\" :\" visaApprovedEvent\" ,\" eventRef\" :\" visaApprovedEventRef\" ,\" metadata\" :{\" mastercard\" :\" disallowed\" ,\" visa\" :\" allowed\" },\" end\" :null,\" transition\" :{\" nextState\" :\" HandleApprovedVisa\" }},{\" eventRef\" :\" visaRejectedEvent\" ,\" metadata\" :{\" test\" :\" tested\" },\" end\" :null,\" transition\" :{\" nextState\" :\" HandleRejectedVisa\" }}],\" dataConditions\" :null,\" timeouts\" :{\" stateExecTimeout\" :{\" single\" :\" PT20S\" ,\" total\" :\" PT10S\" },\" eventTimeout\" :\" PT10H\" }}" ))
959+ assert .True (t , strings .Contains (string (b ), "{\" name\" :\" CheckVisaStatusSwitchEventBased\" ,\" type\" :\" switch\" ,\" defaultCondition\" :{\" transition\" :{\" nextState\" :\" HelloStateWithDefaultConditionString\" }},\" eventConditions\" :[{\" name\" :\" visaApprovedEvent\" ,\" eventRef\" :\" visaApprovedEventRef\" ,\" metadata\" :{\" mastercard\" :\" disallowed\" ,\" visa\" :\" allowed\" },\" end\" :null,\" transition\" :{\" nextState\" :\" HandleApprovedVisa\" }},{\" eventRef\" :\" visaRejectedEvent\" ,\" metadata\" :{\" test\" :\" tested\" },\" end\" :null,\" transition\" :{\" nextState\" :\" HandleRejectedVisa\" }}],\" dataConditions\" :null,\" timeouts\" :{\" stateExecTimeout\" :{\" single\" :\" PT20S\" ,\" total\" :\" PT10S\" },\" eventTimeout\" :\" PT10H\" }}" ))
960+
961+ // Switch State with string DefaultCondition
962+ assert .True (t , strings .Contains (string (b ), "{\" name\" :\" HelloStateWithDefaultConditionString\" ,\" type\" :\" switch\" ,\" defaultCondition\" :{\" transition\" :{\" nextState\" :\" SendTextForHighPriority\" }},\" eventConditions\" :null,\" dataConditions\" :[{\" condition\" :\" ${ true }\" ,\" end\" :null,\" transition\" :{\" nextState\" :\" HandleApprovedVisa\" }},{\" condition\" :\" ${ false }\" ,\" end\" :null,\" transition\" :{\" nextState\" :\" HandleRejectedVisa\" }}]}" ))
940963
941964 // Foreach State
942965 assert .True (t , strings .Contains (string (b ), "{\" name\" :\" SendTextForHighPriority\" ,\" type\" :\" foreach\" ,\" transition\" :{\" nextState\" :\" HelloInject\" },\" inputCollection\" :\" ${ .messages }\" ,\" outputCollection\" :\" ${ .outputMessages }\" ,\" iterationParam\" :\" ${ .this }\" ,\" batchSize\" :45,\" actions\" :[{\" name\" :\" test\" ,\" functionRef\" :{\" refName\" :\" sendTextFunction\" ,\" arguments\" :{\" message\" :\" ${ .singlemessage }\" },\" invoke\" :\" sync\" },\" eventRef\" :{\" triggerEventRef\" :\" example1\" ,\" resultEventRef\" :\" example2\" ,\" resultEventTimeout\" :\" PT12H\" ,\" invoke\" :\" sync\" },\" actionDataFilter\" :{\" useResults\" :true}}],\" mode\" :\" sequential\" ,\" timeouts\" :{\" stateExecTimeout\" :{\" single\" :\" PT22S\" ,\" total\" :\" PT11S\" },\" actionExecTimeout\" :\" PT11H\" }}" ))
@@ -973,7 +996,7 @@ states:
973996 nextState: HandleRejectedVisa
974997 defaultCondition:
975998 transition:
976- nextState: HandleNoVisaDecision
999+ nextState: HandleApprovedVisa
9771000- name: HandleApprovedVisa
9781001 type: operation
9791002 actions:
0 commit comments