-
Notifications
You must be signed in to change notification settings - Fork 2
/
umlgraph_test.go
104 lines (83 loc) · 3 KB
/
umlgraph_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package pipeline_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/saantiaguilera/go-pipeline"
)
func TestUMLGraph_GivenAGraph_WhenAddingEmptyConcurrentCases_ThenPlantUMLForksAreAdded(t *testing.T) {
diagram := pipeline.NewUMLGraph()
diagram.AddConcurrency(
func(graph pipeline.Graph) {
},
func(graph pipeline.Graph) {
},
func(graph pipeline.Graph) {
},
)
content := diagram.String()
expectedContent := "\nfork\nfork again\nfork again\nend fork\n"
assert.Contains(t, content, expectedContent)
}
func TestUMLGraph_GivenAGraph_WhenAddingConcurrentCases_ThenPlantUMLForksAreAdded(t *testing.T) {
diagram := pipeline.NewUMLGraph()
diagram.AddConcurrency(
func(graph pipeline.Graph) {
graph.AddActivity("1")
},
func(graph pipeline.Graph) {
graph.AddActivity("2")
},
func(graph pipeline.Graph) {
graph.AddActivity("3")
},
)
content := diagram.String()
expectedContent := "\nfork\n:1;\nfork again\n:2;\nfork again\n:3;\nend fork\n"
assert.Contains(t, content, expectedContent)
}
func TestUMLGraph_GivenAGraph_WhenAddingZeroConcurrentCases_ThenNothingHappens(t *testing.T) {
diagram := pipeline.NewUMLGraph()
diagram.AddConcurrency()
content := diagram.String()
notExpectedContent := "fork"
assert.NotContains(t, content, notExpectedContent)
}
func TestUMLGraph_GivenAGraph_WhenAddingActivities_ThenPlantUMLActivitiesAreAdded(t *testing.T) {
diagram := pipeline.NewUMLGraph()
diagram.AddActivity("1")
diagram.AddActivity("1 2")
diagram.AddActivity("1 2 3")
diagram.AddActivity("1 2 3 4")
diagram.AddActivity("1 2 3 4 5")
content := diagram.String()
expectedContent := "\n:1;\n:1 2;\n:1 2 3;\n:1 2 3 4;\n:1 2 3 4 5;\n"
assert.Contains(t, content, expectedContent)
}
func TestUMLGraph_GivenAGraph_WhenAddingADecision_ThenPlantUMLChoiceIsAdded(t *testing.T) {
diagram := pipeline.NewUMLGraph()
diagram.AddDecision("is this a test?", func(graph pipeline.Graph) {
graph.AddActivity("yes, this is a test")
}, func(graph pipeline.Graph) {
graph.AddActivity("seems this isn't a test")
})
content := diagram.String()
expectedContent := "\nif (is this a test?) then (yes)\n:yes, this is a test;\nelse (no)\n:seems this isn't a test;\n"
assert.Contains(t, content, expectedContent)
}
func TestUMLGraph_GivenAGraph_WhenStringRepresentationIsAsked_ThenCompletePlantUMLIsRepresented(t *testing.T) {
diagram := pipeline.NewUMLGraph()
diagram.AddActivity("beginning")
diagram.AddConcurrency(func(graph pipeline.Graph) {
graph.AddActivity("branch 1")
}, func(graph pipeline.Graph) {
diagram.AddDecision("is this a test?", func(graph pipeline.Graph) {
graph.AddActivity("yes, this is a test")
}, func(graph pipeline.Graph) {
graph.AddActivity("seems this isn't a test")
})
})
content := diagram.String()
expectedContent := "@startuml\nstart\n:beginning;\nfork\n:branch 1;\nfork again\nif (is this a test?) then (yes)" +
"\n:yes, this is a test;\nelse (no)\n:seems this isn't a test;\nendif\nend fork\nstop\n@enduml\n"
assert.Equal(t, expectedContent, content)
}