@@ -16,6 +16,7 @@ package parser
16
16
17
17
import (
18
18
"encoding/json"
19
+ "fmt"
19
20
"os"
20
21
"path/filepath"
21
22
"strings"
@@ -556,6 +557,14 @@ func TestFromFile(t *testing.T) {
556
557
assert .Equal (t , "PT100S" , w .States [9 ].SleepState .Timeouts .StateExecTimeout .Total )
557
558
assert .Equal (t , "PT200S" , w .States [9 ].SleepState .Timeouts .StateExecTimeout .Single )
558
559
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 )
559
568
},
560
569
},
561
570
}
@@ -815,7 +824,17 @@ states:
815
824
single: PT20S
816
825
defaultCondition:
817
826
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
819
838
- name: SendTextForHighPriority
820
839
type: foreach
821
840
inputCollection: "${ .messages }"
@@ -911,6 +930,7 @@ states:
911
930
terminate: true
912
931
` ))
913
932
assert .Nil (t , err )
933
+ fmt .Println (err )
914
934
assert .NotNil (t , workflow )
915
935
b , err := json .Marshal (workflow )
916
936
@@ -936,7 +956,10 @@ states:
936
956
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\" }}" ))
937
957
938
958
// 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\" }}]}" ))
940
963
941
964
// Foreach State
942
965
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:
973
996
nextState: HandleRejectedVisa
974
997
defaultCondition:
975
998
transition:
976
- nextState: HandleNoVisaDecision
999
+ nextState: HandleApprovedVisa
977
1000
- name: HandleApprovedVisa
978
1001
type: operation
979
1002
actions:
0 commit comments