github.com/unirita/cuto@v0.9.8-0.20160830082821-aa6652f877b7/flowgen/converter/bpmn_test.go (about) 1 package converter 2 3 import "testing" 4 5 func TestNewDefinitions(t *testing.T) { 6 d := NewDefinitions() 7 if d.Process == nil { 8 t.Error("Created Definitions has nil Process.") 9 } 10 } 11 12 func TestAppendServiceTask(t *testing.T) { 13 d := NewDefinitions() 14 d.AppendServiceTask(NewServiceTask(NewJob("test1"))) 15 d.AppendServiceTask(NewServiceTask(NewJob("test2"))) 16 if len(d.Process.Tasks) != 2 { 17 t.Fatalf("Number of tasks[%d] is not equal to expected[%d].", 18 len(d.Process.Tasks), 2) 19 } 20 } 21 22 func TestAppendParallelGateway(t *testing.T) { 23 d := NewDefinitions() 24 ogw, cgw := NewParallelGatewayPair(NewGateway()) 25 d.AppendParallelGateway(ogw) 26 d.AppendParallelGateway(cgw) 27 if len(d.Process.Gateways) != 2 { 28 t.Fatalf("Number of gateway[%d] is not equal to expected[%d].", 29 len(d.Process.Gateways), 2) 30 } 31 } 32 33 func TestAppendSequenceFlow(t *testing.T) { 34 d := NewDefinitions() 35 d.AppendSequenceFlow(NewSequenceFlow("from1", "to1")) 36 d.AppendSequenceFlow(NewSequenceFlow("from2", "to2")) 37 if len(d.Process.Flows) != 2 { 38 t.Fatalf("Number of flow[%d] is not equal to expected[%d].", 39 len(d.Process.Flows), 2) 40 } 41 } 42 43 func TestAppendJob(t *testing.T) { 44 d := NewDefinitions() 45 j := NewJob("test") 46 d.AppendJob(j, "pre") 47 if len(d.Process.Tasks) != 1 { 48 t.Fatalf("ServiceTask was not appended.") 49 } 50 if len(d.Process.Flows) != 1 { 51 t.Fatalf("SequenceFlow was not appended.") 52 } 53 } 54 55 func TestAppendGateway(t *testing.T) { 56 d := NewDefinitions() 57 g := NewGateway() 58 g.AddPathHead(NewJob("test1")) 59 g.AddPathHead(NewJob("test2")) 60 g.AddPathHead(NewJob("test3")) 61 g.PathHeads[2].SetNext(NewJob("test4")) 62 d.AppendGateway(g, "pre") 63 if len(d.Process.Tasks) != 4 { 64 t.Logf("Number of ServiceTask is %d", len(d.Process.Tasks)) 65 t.Fatalf("ServiceTask was not appended enough.") 66 } 67 if len(d.Process.Gateways) != 2 { 68 t.Logf("Number of ParallelGateways is %d", len(d.Process.Gateways)) 69 t.Fatalf("ParallelGateways was not appended enough.") 70 } 71 if len(d.Process.Flows) != 8 { 72 t.Logf("Number of SequenceFlow is %d", len(d.Process.Flows)) 73 t.Fatalf("SequenceFlow was not appended enough.") 74 } 75 } 76 77 func TestNewProcess(t *testing.T) { 78 p := NewProcess() 79 if p.Start == nil { 80 t.Error("Created Process has nil StartEvent.") 81 } 82 if p.End == nil { 83 t.Error("Created Process has nil EndEvent.") 84 } 85 if len(p.Tasks) != 0 { 86 t.Error("Created Process has unexpected ServiceTasks.") 87 } 88 if len(p.Gateways) != 0 { 89 t.Error("Created Process has unexpected ParallelGateways.") 90 } 91 if len(p.Flows) != 0 { 92 t.Error("Created Process has unexpected SequenceFlows.") 93 } 94 } 95 96 func TestNewStartEvent(t *testing.T) { 97 s := NewStartEvent() 98 if validateJobName(s.ID) == nil { 99 t.Error("StartEvent ID[%s] has possibility of using for job ID or Name.", s.ID) 100 } 101 } 102 103 func TestNewEndEvent(t *testing.T) { 104 e := NewEndEvent() 105 if validateJobName(e.ID) == nil { 106 t.Error("EndEvent ID[%s] has possibility of using for job ID or Name.", e.ID) 107 } 108 } 109 110 func TestNewServiceTask(t *testing.T) { 111 initIndexes() 112 j := NewJob("test") 113 s := NewServiceTask(j) 114 if s.ID != "job1" { 115 t.Errorf("Created ServiceTasks has unexpected ID[%s].", s.ID) 116 } 117 if s.Name != "test" { 118 t.Errorf("Created ServiceTasks has unexpected ID[%s].", s.Name) 119 } 120 } 121 122 func TestNewParallelGatewayPair(t *testing.T) { 123 initIndexes() 124 g := NewGateway() 125 openGW, closeGW := NewParallelGatewayPair(g) 126 if openGW.ID != "gw1_open" { 127 t.Errorf("Created ParallelGateway for open has unexpected ID[%s].", openGW.ID) 128 } 129 if closeGW.ID != "gw1_close" { 130 t.Errorf("Created ParallelGateway for close has unexpected ID[%s].", closeGW.ID) 131 } 132 } 133 134 func TestNewSequenceFlow(t *testing.T) { 135 s := NewSequenceFlow("fromid", "toid") 136 if s.From != "fromid" { 137 t.Errorf("Created SequenceFlow has unexpected From[%s].", s.From) 138 } 139 if s.To != "toid" { 140 t.Errorf("Created SequenceFlow has unexpected To[%s].", s.To) 141 } 142 }