@@ -103,4 +103,91 @@ public void complexParallelBranchesHaveCorrectSteps() throws Exception {
103
103
assertThat (steps .get (0 ).getName (), is ("In stage Nested 2 - 1 within Branch C - Print Message" ));
104
104
assertThat (steps .get (1 ).getName (), is ("In stage Nested 2 - 2 within Branch C - Print Message" ));
105
105
}
106
+
107
+ @ Test
108
+ public void nestedStagesHaveCorrectSteps () throws Exception {
109
+ // It's a bit dirty, but do this in one to avoid reloading and rerunning the job (as it takes a
110
+ // long time)
111
+ WorkflowRun run =
112
+ TestUtils .createAndRunJob (j , "nestedStages" , "nestedStages.jenkinsfile" , Result .SUCCESS );
113
+
114
+ String childAId = TestUtils .getNodesByDisplayName (run , "Child A" ).get (0 ).getId ();
115
+ String childBId = TestUtils .getNodesByDisplayName (run , "Child B" ).get (0 ).getId ();
116
+ String grandchildBId = TestUtils .getNodesByDisplayName (run , "Grandchild B" ).get (0 ).getId ();
117
+ String childCId = TestUtils .getNodesByDisplayName (run , "Child C" ).get (0 ).getId ();
118
+ String grandchildCId = TestUtils .getNodesByDisplayName (run , "Grandchild C" ).get (0 ).getId ();
119
+ String greatGrandchildCId =
120
+ TestUtils .getNodesByDisplayName (run , "Great-grandchild C" ).get (0 ).getId ();
121
+
122
+ PipelineStepApi api = new PipelineStepApi (run );
123
+
124
+ // Check 'Child A'
125
+ List <PipelineStep > steps = api .getSteps (childAId ).getSteps ();
126
+ assertThat (steps , hasSize (1 ));
127
+ assertThat (steps .get (0 ).getName (), is ("In child A - Print Message" ));
128
+
129
+ // Check 'Child A'
130
+ steps = api .getSteps (childBId ).getSteps ();
131
+ assertThat (steps , hasSize (0 ));
132
+
133
+ // Check 'Grandchild B'
134
+ steps = api .getSteps (grandchildBId ).getSteps ();
135
+ assertThat (steps , hasSize (1 ));
136
+ assertThat (steps .get (0 ).getName (), is ("In grandchild B - Print Message" ));
137
+
138
+ // Check 'Child C'
139
+ steps = api .getSteps (childCId ).getSteps ();
140
+ assertThat (steps , hasSize (0 ));
141
+
142
+ // Check 'Grandchild C'
143
+ steps = api .getSteps (grandchildCId ).getSteps ();
144
+ assertThat (steps , hasSize (0 ));
145
+
146
+ // Check 'Great-Grandchild C'
147
+ steps = api .getSteps (greatGrandchildCId ).getSteps ();
148
+ assertThat (steps , hasSize (1 ));
149
+ assertThat (steps .get (0 ).getName (), is ("In great-grandchild C - Print Message" ));
150
+ }
151
+
152
+ @ Test
153
+ public void getAllStepsReturnsStepsForComplexParallelBranches () throws Exception {
154
+ // It's a bit dirty, but do this in one to avoid reloading and rerunning the job (as it takes a
155
+ // long time)
156
+ WorkflowRun run =
157
+ TestUtils .createAndRunJob (
158
+ j , "complexParallelSmokes" , "complexParallelSmokes.jenkinsfile" , Result .SUCCESS );
159
+
160
+ // Check 'Non-Parallel Stage'
161
+ PipelineStepApi api = new PipelineStepApi (run );
162
+
163
+ List <PipelineStep > steps = api .getAllSteps ().getSteps ();
164
+ assertThat (steps , hasSize (10 ));
165
+ assertThat (steps .get (0 ).getName (), is ("This stage will be executed first. - Print Message" ));
166
+ assertThat (steps .get (1 ).getName (), is ("Print Message" ));
167
+ assertThat (steps .get (2 ).getName (), is ("On Branch A - 1 - Print Message" ));
168
+ assertThat (steps .get (3 ).getName (), is ("On Branch A - 2 - Print Message" ));
169
+ assertThat (steps .get (4 ).getName (), is ("On Branch B - 1 - Print Message" ));
170
+ assertThat (steps .get (5 ).getName (), is ("On Branch B - 2 - Print Message" ));
171
+
172
+ assertThat (steps .get (6 ).getName (), is ("In stage Nested 1 - 1 within Branch C - Print Message" ));
173
+ assertThat (steps .get (7 ).getName (), is ("In stage Nested 1 - 2 within Branch C - Print Message" ));
174
+ assertThat (steps .get (8 ).getName (), is ("In stage Nested 2 - 1 within Branch C - Print Message" ));
175
+ assertThat (steps .get (9 ).getName (), is ("In stage Nested 2 - 2 within Branch C - Print Message" ));
176
+ }
177
+
178
+ @ Test
179
+ public void getAllStepsReturnsStepsForNestedStages () throws Exception {
180
+ // It's a bit dirty, but do this in one to avoid reloading and rerunning the job (as it takes a
181
+ // long time)
182
+ WorkflowRun run =
183
+ TestUtils .createAndRunJob (j , "nestedStages" , "nestedStages.jenkinsfile" , Result .SUCCESS );
184
+
185
+ PipelineStepApi api = new PipelineStepApi (run );
186
+
187
+ List <PipelineStep > steps = api .getAllSteps ().getSteps ();
188
+ assertThat (steps , hasSize (3 ));
189
+ assertThat (steps .get (0 ).getName (), is ("In child A - Print Message" ));
190
+ assertThat (steps .get (1 ).getName (), is ("In grandchild B - Print Message" ));
191
+ assertThat (steps .get (2 ).getName (), is ("In great-grandchild C - Print Message" ));
192
+ }
106
193
}
0 commit comments