1 | |
package org.jbehave.core.embedder; |
2 | |
|
3 | |
import java.util.ArrayList; |
4 | |
import java.util.HashMap; |
5 | |
import java.util.List; |
6 | |
import java.util.Map; |
7 | |
|
8 | |
import org.jbehave.core.annotations.ScenarioType; |
9 | |
import org.jbehave.core.configuration.Configuration; |
10 | |
import org.jbehave.core.failures.FailureStrategy; |
11 | |
import org.jbehave.core.failures.PendingStepFound; |
12 | |
import org.jbehave.core.failures.PendingStepStrategy; |
13 | |
import org.jbehave.core.failures.RestartingScenarioFailure; |
14 | |
import org.jbehave.core.failures.UUIDExceptionWrapper; |
15 | |
import org.jbehave.core.model.ExamplesTable; |
16 | |
import org.jbehave.core.model.GivenStories; |
17 | |
import org.jbehave.core.model.GivenStory; |
18 | |
import org.jbehave.core.model.Meta; |
19 | |
import org.jbehave.core.model.Scenario; |
20 | |
import org.jbehave.core.model.Story; |
21 | |
import org.jbehave.core.model.StoryDuration; |
22 | |
import org.jbehave.core.reporters.ConcurrentStoryReporter; |
23 | |
import org.jbehave.core.reporters.StoryReporter; |
24 | |
import org.jbehave.core.steps.CandidateSteps; |
25 | |
import org.jbehave.core.steps.InjectableStepsFactory; |
26 | |
import org.jbehave.core.steps.PendingStepMethodGenerator; |
27 | |
import org.jbehave.core.steps.ProvidedStepsFactory; |
28 | |
import org.jbehave.core.steps.Step; |
29 | |
import org.jbehave.core.steps.StepCollector.Stage; |
30 | |
import org.jbehave.core.steps.StepCreator.PendingStep; |
31 | |
import org.jbehave.core.steps.StepResult; |
32 | |
|
33 | |
import static org.codehaus.plexus.util.StringUtils.capitalizeFirstLetter; |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | 253 | public class StoryRunner { |
44 | |
|
45 | 65 | private ThreadLocal<FailureStrategy> currentStrategy = new ThreadLocal<FailureStrategy>(); |
46 | 65 | private ThreadLocal<FailureStrategy> failureStrategy = new ThreadLocal<FailureStrategy>(); |
47 | 65 | private ThreadLocal<PendingStepStrategy> pendingStepStrategy = new ThreadLocal<PendingStepStrategy>(); |
48 | 65 | private ThreadLocal<UUIDExceptionWrapper> storyFailure = new ThreadLocal<UUIDExceptionWrapper>(); |
49 | 65 | private ThreadLocal<StoryReporter> reporter = new ThreadLocal<StoryReporter>(); |
50 | 65 | private ThreadLocal<String> reporterStoryPath = new ThreadLocal<String>(); |
51 | 65 | private ThreadLocal<State> storiesState = new ThreadLocal<State>(); |
52 | |
|
53 | 65 | private Map<Story, StoryDuration> cancelledStories = new HashMap<Story, StoryDuration>(); |
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
public State runBeforeOrAfterStories(Configuration configuration, List<CandidateSteps> candidateSteps, Stage stage) { |
66 | 7 | String storyPath = capitalizeFirstLetter(stage.name().toLowerCase()) + "Stories"; |
67 | 7 | reporter.set(configuration.storyReporter(storyPath)); |
68 | 7 | reporter.get().beforeStory(new Story(storyPath), false); |
69 | 7 | RunContext context = new RunContext(configuration, candidateSteps, storyPath, MetaFilter.EMPTY); |
70 | 7 | if (stage == Stage.BEFORE) { |
71 | 4 | resetStoryFailure(context); |
72 | |
} |
73 | 7 | if (stage == Stage.AFTER && storiesState.get() != null) { |
74 | 3 | context.stateIs(storiesState.get()); |
75 | |
} |
76 | |
try { |
77 | 7 | runStepsWhileKeepingState(context, |
78 | |
configuration.stepCollector().collectBeforeOrAfterStoriesSteps(context.candidateSteps(), stage)); |
79 | 0 | } catch (InterruptedException e) { |
80 | 0 | throw new UUIDExceptionWrapper(e); |
81 | 7 | } |
82 | 7 | reporter.get().afterStory(false); |
83 | 7 | storiesState.set(context.state()); |
84 | |
|
85 | 7 | if (stage == Stage.AFTER) { |
86 | |
try { |
87 | 3 | handleStoryFailureByStrategy(); |
88 | 1 | } catch (Throwable e) { |
89 | 1 | return new SomethingHappened(storyFailure.get()); |
90 | |
} finally { |
91 | 3 | if (reporter.get() instanceof ConcurrentStoryReporter) { |
92 | 1 | ((ConcurrentStoryReporter) reporter.get()).invokeDelayed(); |
93 | |
} |
94 | |
} |
95 | |
} |
96 | 6 | return context.state(); |
97 | |
} |
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
public void run(Configuration configuration, List<CandidateSteps> candidateSteps, Story story) throws Throwable { |
110 | 15 | run(configuration, candidateSteps, story, MetaFilter.EMPTY); |
111 | 14 | } |
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
public void run(Configuration configuration, List<CandidateSteps> candidateSteps, Story story, MetaFilter filter) |
126 | |
throws Throwable { |
127 | 19 | run(configuration, candidateSteps, story, filter, null); |
128 | 18 | } |
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
|
141 | |
|
142 | |
|
143 | |
|
144 | |
public void run(Configuration configuration, List<CandidateSteps> candidateSteps, Story story, MetaFilter filter, |
145 | |
State beforeStories) throws Throwable { |
146 | 19 | run(configuration, new ProvidedStepsFactory(candidateSteps), story, filter, beforeStories); |
147 | 18 | } |
148 | |
|
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | |
public void run(Configuration configuration, InjectableStepsFactory stepsFactory, Story story, MetaFilter filter, |
165 | |
State beforeStories) throws Throwable { |
166 | 21 | RunContext context = new RunContext(configuration, stepsFactory, story.getPath(), filter); |
167 | 21 | if (beforeStories != null) { |
168 | 2 | context.stateIs(beforeStories); |
169 | |
} |
170 | 21 | Map<String, String> storyParameters = new HashMap<String, String>(); |
171 | 21 | run(context, story, storyParameters); |
172 | 18 | } |
173 | |
|
174 | |
|
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | |
public Story storyOfPath(Configuration configuration, String storyPath) { |
182 | 3 | String storyAsText = configuration.storyLoader().loadStoryAsText(storyPath); |
183 | 3 | return configuration.storyParser().parseStory(storyAsText, storyPath); |
184 | |
} |
185 | |
|
186 | |
|
187 | |
|
188 | |
|
189 | |
|
190 | |
|
191 | |
|
192 | |
|
193 | |
|
194 | |
public Story storyOfText(Configuration configuration, String storyAsText, String storyId) { |
195 | 0 | return configuration.storyParser().parseStory(storyAsText, storyId); |
196 | |
} |
197 | |
|
198 | |
|
199 | |
|
200 | |
|
201 | |
|
202 | |
|
203 | |
|
204 | |
public void cancelStory(Story story, StoryDuration storyDuration) { |
205 | 2 | cancelledStories.put(story, storyDuration); |
206 | 2 | } |
207 | |
|
208 | |
private void run(RunContext context, Story story, Map<String, String> storyParameters) throws Throwable { |
209 | |
try { |
210 | 23 | runCancellable(context, story, storyParameters); |
211 | 3 | } catch (Throwable e) { |
212 | 3 | if (cancelledStories.containsKey(story)) { |
213 | 2 | reporter.get().storyCancelled(story, cancelledStories.get(story)); |
214 | 2 | reporter.get().afterStory(context.givenStory); |
215 | |
} |
216 | 3 | throw e; |
217 | |
} finally { |
218 | 23 | if (!context.givenStory() && reporter.get() instanceof ConcurrentStoryReporter) { |
219 | 21 | ((ConcurrentStoryReporter) reporter.get()).invokeDelayed(); |
220 | |
} |
221 | |
} |
222 | 20 | } |
223 | |
|
224 | |
private void runCancellable(RunContext context, Story story, Map<String, String> storyParameters) throws Throwable { |
225 | 23 | if (!context.givenStory) { |
226 | 21 | reporter.set(reporterFor(context, story)); |
227 | |
} |
228 | 23 | pendingStepStrategy.set(context.configuration().pendingStepStrategy()); |
229 | 23 | failureStrategy.set(context.configuration().failureStrategy()); |
230 | |
|
231 | 23 | resetStoryFailure(context); |
232 | |
|
233 | 23 | if (context.dryRun()) { |
234 | 2 | reporter.get().dryRun(); |
235 | |
} |
236 | |
|
237 | 23 | if (context.configuration().storyControls().resetStateBeforeStory()) { |
238 | 21 | context.resetState(); |
239 | |
} |
240 | |
|
241 | |
|
242 | 23 | reporter.get().beforeStory(story, context.givenStory()); |
243 | |
|
244 | 23 | boolean storyAllowed = true; |
245 | |
|
246 | 23 | FilteredStory filterContext = context.filter(story); |
247 | 22 | Meta storyMeta = story.getMeta(); |
248 | 22 | if (!filterContext.allowed()) { |
249 | 2 | reporter.get().storyNotAllowed(story, context.metaFilterAsString()); |
250 | 2 | storyAllowed = false; |
251 | |
} |
252 | |
|
253 | 22 | if (storyAllowed) { |
254 | |
|
255 | 20 | reporter.get().narrative(story.getNarrative()); |
256 | |
|
257 | 20 | runBeforeOrAfterStorySteps(context, story, Stage.BEFORE); |
258 | |
|
259 | |
|
260 | 20 | boolean runBeforeAndAfterScenarioSteps = shouldRunBeforeOrAfterScenarioSteps(context); |
261 | |
|
262 | 20 | for (Scenario scenario : story.getScenarios()) { |
263 | |
|
264 | 26 | boolean scenarioAllowed = true; |
265 | 26 | if (failureOccurred(context) && context.configuration().storyControls().skipScenariosAfterFailure()) { |
266 | 1 | continue; |
267 | |
} |
268 | 25 | reporter.get().beforeScenario(scenario.getTitle()); |
269 | 25 | reporter.get().scenarioMeta(scenario.getMeta()); |
270 | |
|
271 | 25 | if (!filterContext.allowed(scenario)) { |
272 | 2 | reporter.get().scenarioNotAllowed(scenario, context.metaFilterAsString()); |
273 | 2 | scenarioAllowed = false; |
274 | |
} |
275 | |
|
276 | 25 | if (scenarioAllowed) { |
277 | 23 | if (context.configuration().storyControls().resetStateBeforeScenario()) { |
278 | 20 | context.resetState(); |
279 | |
} |
280 | 23 | Meta storyAndScenarioMeta = scenario.getMeta().inheritFrom(storyMeta); |
281 | |
|
282 | 23 | if (runBeforeAndAfterScenarioSteps) { |
283 | 22 | runBeforeOrAfterScenarioSteps(context, scenario, storyAndScenarioMeta, Stage.BEFORE, |
284 | |
ScenarioType.NORMAL); |
285 | |
} |
286 | |
|
287 | |
|
288 | 23 | runGivenStories(scenario, context); |
289 | 23 | if (isParameterisedByExamples(scenario)) { |
290 | |
|
291 | 1 | runParametrisedScenariosByExamples(context, scenario, storyAndScenarioMeta); |
292 | |
} else { |
293 | 22 | addMetaParameters(storyParameters, storyAndScenarioMeta); |
294 | 22 | runScenarioSteps(context, scenario, storyParameters); |
295 | |
} |
296 | |
|
297 | |
|
298 | 22 | if (runBeforeAndAfterScenarioSteps) { |
299 | 21 | runBeforeOrAfterScenarioSteps(context, scenario, storyAndScenarioMeta, Stage.AFTER, |
300 | |
ScenarioType.NORMAL); |
301 | |
} |
302 | |
|
303 | |
} |
304 | |
|
305 | 24 | reporter.get().afterScenario(); |
306 | 24 | } |
307 | |
|
308 | |
|
309 | 19 | runBeforeOrAfterStorySteps(context, story, Stage.AFTER); |
310 | |
|
311 | |
} |
312 | |
|
313 | 21 | reporter.get().afterStory(context.givenStory()); |
314 | |
|
315 | |
|
316 | 21 | if (!context.givenStory()) { |
317 | 19 | handleStoryFailureByStrategy(); |
318 | |
} |
319 | 20 | } |
320 | |
|
321 | |
private void addMetaParameters(Map<String, String> storyParameters, Meta meta) { |
322 | 22 | for (String name : meta.getPropertyNames()) { |
323 | 0 | storyParameters.put(name, meta.getProperty(name)); |
324 | |
} |
325 | 22 | } |
326 | |
|
327 | |
private boolean shouldRunBeforeOrAfterScenarioSteps(RunContext context) { |
328 | 20 | Configuration configuration = context.configuration(); |
329 | 20 | if (!configuration.storyControls().skipBeforeAndAfterScenarioStepsIfGivenStory()) { |
330 | 18 | return true; |
331 | |
} |
332 | |
|
333 | 2 | return !context.givenStory(); |
334 | |
} |
335 | |
|
336 | |
private boolean failureOccurred(RunContext context) { |
337 | 26 | return context.failureOccurred(); |
338 | |
} |
339 | |
|
340 | |
private StoryReporter reporterFor(RunContext context, Story story) { |
341 | 21 | Configuration configuration = context.configuration(); |
342 | 21 | if (context.givenStory()) { |
343 | 0 | return configuration.storyReporter(reporterStoryPath.get()); |
344 | |
} else { |
345 | |
|
346 | 21 | reporterStoryPath.set(story.getPath()); |
347 | 21 | return configuration.storyReporter(reporterStoryPath.get()); |
348 | |
} |
349 | |
} |
350 | |
|
351 | |
private void handleStoryFailureByStrategy() throws Throwable { |
352 | 22 | Throwable throwable = storyFailure.get(); |
353 | 22 | if (throwable != null) { |
354 | 11 | currentStrategy.get().handleFailure(throwable); |
355 | |
} |
356 | 20 | } |
357 | |
|
358 | |
private void resetStoryFailure(RunContext context) { |
359 | 27 | if (context.givenStory()) { |
360 | |
|
361 | 2 | return; |
362 | |
} |
363 | 25 | currentStrategy.set(context.configuration().failureStrategy()); |
364 | 25 | storyFailure.set(null); |
365 | 25 | } |
366 | |
|
367 | |
private void runGivenStories(Scenario scenario, RunContext context) throws Throwable { |
368 | 23 | GivenStories givenStories = scenario.getGivenStories(); |
369 | 23 | if (givenStories.getPaths().size() > 0) { |
370 | 2 | reporter.get().givenStories(givenStories); |
371 | 2 | for (GivenStory givenStory : givenStories.getStories()) { |
372 | 2 | RunContext childContext = context.childContextFor(givenStory); |
373 | |
|
374 | 2 | Story story = storyOfPath(context.configuration(), childContext.path()); |
375 | 2 | run(childContext, story, givenStory.getParameters()); |
376 | 2 | } |
377 | |
} |
378 | 23 | } |
379 | |
|
380 | |
private boolean isParameterisedByExamples(Scenario scenario) { |
381 | 23 | return scenario.getExamplesTable().getRowCount() > 0 && !scenario.getGivenStories().requireParameters(); |
382 | |
} |
383 | |
|
384 | |
private void runParametrisedScenariosByExamples(RunContext context, Scenario scenario, Meta storyAndScenarioMeta) |
385 | |
throws InterruptedException { |
386 | 1 | ExamplesTable table = scenario.getExamplesTable(); |
387 | 1 | reporter.get().beforeExamples(scenario.getSteps(), table); |
388 | 1 | for (Map<String, String> scenarioParameters : table.getRows()) { |
389 | 1 | reporter.get().example(scenarioParameters); |
390 | 1 | if (context.configuration().storyControls().resetStateBeforeScenario()) { |
391 | 1 | context.resetState(); |
392 | |
} |
393 | 1 | runBeforeOrAfterScenarioSteps(context, scenario, storyAndScenarioMeta, Stage.BEFORE, ScenarioType.EXAMPLE); |
394 | 1 | runScenarioSteps(context, scenario, scenarioParameters); |
395 | 1 | runBeforeOrAfterScenarioSteps(context, scenario, storyAndScenarioMeta, Stage.AFTER, ScenarioType.EXAMPLE); |
396 | |
} |
397 | 1 | reporter.get().afterExamples(); |
398 | 1 | } |
399 | |
|
400 | |
private void runBeforeOrAfterStorySteps(RunContext context, Story story, Stage stage) throws InterruptedException { |
401 | 39 | runStepsWhileKeepingState(context, context.collectBeforeOrAfterStorySteps(story, stage)); |
402 | 39 | } |
403 | |
|
404 | |
private void runBeforeOrAfterScenarioSteps(RunContext context, Scenario scenario, Meta storyAndScenarioMeta, |
405 | |
Stage stage, ScenarioType type) throws InterruptedException { |
406 | 45 | runStepsWhileKeepingState(context, context.collectBeforeOrAfterScenarioSteps(storyAndScenarioMeta, stage, type)); |
407 | 45 | } |
408 | |
|
409 | |
private void runScenarioSteps(RunContext context, Scenario scenario, Map<String, String> scenarioParameters) |
410 | |
throws InterruptedException { |
411 | 23 | boolean restart = true; |
412 | 46 | while (restart) { |
413 | 24 | restart = false; |
414 | 24 | List<Step> steps = context.collectScenarioSteps(scenario, scenarioParameters); |
415 | |
try { |
416 | 24 | runStepsWhileKeepingState(context, steps); |
417 | 1 | } catch (RestartingScenarioFailure e) { |
418 | 1 | restart = true; |
419 | 1 | continue; |
420 | 22 | } |
421 | 22 | generatePendingStepMethods(context, steps); |
422 | 22 | } |
423 | 22 | } |
424 | |
|
425 | |
private void generatePendingStepMethods(RunContext context, List<Step> steps) { |
426 | 22 | List<PendingStep> pendingSteps = new ArrayList<PendingStep>(); |
427 | 22 | for (Step step : steps) { |
428 | 33 | if (step instanceof PendingStep) { |
429 | 0 | pendingSteps.add((PendingStep) step); |
430 | |
} |
431 | |
} |
432 | 22 | if (!pendingSteps.isEmpty()) { |
433 | 0 | PendingStepMethodGenerator generator = new PendingStepMethodGenerator(context.configuration().keywords()); |
434 | 0 | List<String> methods = new ArrayList<String>(); |
435 | 0 | for (PendingStep pendingStep : pendingSteps) { |
436 | 0 | if (!pendingStep.annotated()) { |
437 | 0 | methods.add(generator.generateMethod(pendingStep)); |
438 | |
} |
439 | |
} |
440 | 0 | reporter.get().pendingMethods(methods); |
441 | |
} |
442 | 22 | } |
443 | |
|
444 | |
private void runStepsWhileKeepingState(RunContext context, List<Step> steps) throws InterruptedException { |
445 | 115 | if (steps == null || steps.size() == 0) { |
446 | 82 | return; |
447 | |
} |
448 | 33 | State state = context.state(); |
449 | 33 | for (Step step : steps) { |
450 | |
try { |
451 | 46 | context.interruptIfCancelled(); |
452 | 45 | state = state.run(step); |
453 | 1 | } catch (RestartingScenarioFailure e) { |
454 | 1 | reporter.get().restarted(step.toString(), e); |
455 | 1 | throw e; |
456 | 44 | } |
457 | |
} |
458 | 31 | context.stateIs(state); |
459 | 31 | } |
460 | |
|
461 | |
public interface State { |
462 | |
State run(Step step); |
463 | |
} |
464 | |
|
465 | 144 | private final class FineSoFar implements State { |
466 | |
|
467 | |
public State run(Step step) { |
468 | 38 | UUIDExceptionWrapper storyFailureIfItHappened = storyFailure.get(); |
469 | 38 | StepResult result = step.perform(storyFailureIfItHappened); |
470 | 37 | result.describeTo(reporter.get()); |
471 | 37 | UUIDExceptionWrapper stepFailure = result.getFailure(); |
472 | 37 | if (stepFailure == null) { |
473 | 22 | return this; |
474 | |
} |
475 | |
|
476 | 15 | storyFailure.set(mostImportantOf(storyFailureIfItHappened, stepFailure)); |
477 | 15 | currentStrategy.set(strategyFor(storyFailure.get())); |
478 | 15 | return new SomethingHappened(stepFailure); |
479 | |
} |
480 | |
|
481 | |
private UUIDExceptionWrapper mostImportantOf(UUIDExceptionWrapper failure1, UUIDExceptionWrapper failure2) { |
482 | 15 | return failure1 == null ? failure2 |
483 | |
: failure1.getCause() instanceof PendingStepFound ? (failure2 == null ? failure1 : failure2) |
484 | |
: failure1; |
485 | |
} |
486 | |
|
487 | |
private FailureStrategy strategyFor(Throwable failure) { |
488 | 15 | if (failure instanceof PendingStepFound) { |
489 | 6 | return pendingStepStrategy.get(); |
490 | |
} else { |
491 | 9 | return failureStrategy.get(); |
492 | |
} |
493 | |
} |
494 | |
} |
495 | |
|
496 | |
private final class SomethingHappened implements State { |
497 | |
UUIDExceptionWrapper scenarioFailure; |
498 | |
|
499 | 16 | public SomethingHappened(UUIDExceptionWrapper scenarioFailure) { |
500 | 16 | this.scenarioFailure = scenarioFailure; |
501 | 16 | } |
502 | |
|
503 | |
public State run(Step step) { |
504 | 7 | StepResult result = step.doNotPerform(scenarioFailure); |
505 | 7 | result.describeTo(reporter.get()); |
506 | 7 | return this; |
507 | |
} |
508 | |
} |
509 | |
|
510 | |
@Override |
511 | |
public String toString() { |
512 | 1 | return this.getClass().getSimpleName(); |
513 | |
} |
514 | |
|
515 | |
|
516 | |
|
517 | |
|
518 | 65 | private class RunContext { |
519 | |
private final Configuration configuration; |
520 | |
private final List<CandidateSteps> candidateSteps; |
521 | |
private final String path; |
522 | |
private final MetaFilter filter; |
523 | |
private final boolean givenStory; |
524 | |
private State state; |
525 | |
|
526 | |
public RunContext(Configuration configuration, InjectableStepsFactory stepsFactory, String path, |
527 | |
MetaFilter filter) { |
528 | 21 | this(configuration, stepsFactory.createCandidateSteps(), path, filter); |
529 | 21 | } |
530 | |
|
531 | |
public RunContext(Configuration configuration, List<CandidateSteps> steps, String path, MetaFilter filter) { |
532 | 28 | this(configuration, steps, path, filter, false); |
533 | 28 | } |
534 | |
|
535 | |
private RunContext(Configuration configuration, List<CandidateSteps> steps, String path, MetaFilter filter, |
536 | 30 | boolean givenStory) { |
537 | 30 | this.configuration = configuration; |
538 | 30 | this.candidateSteps = steps; |
539 | 30 | this.path = path; |
540 | 30 | this.filter = filter; |
541 | 30 | this.givenStory = givenStory; |
542 | 30 | resetState(); |
543 | 30 | } |
544 | |
|
545 | |
public void interruptIfCancelled() throws InterruptedException { |
546 | 46 | for (Story story : cancelledStories.keySet()) { |
547 | 1 | if (path.equals(story.getPath())) { |
548 | 1 | throw new InterruptedException(path); |
549 | |
} |
550 | |
} |
551 | 45 | } |
552 | |
|
553 | |
public boolean dryRun() { |
554 | 23 | return configuration.storyControls().dryRun(); |
555 | |
} |
556 | |
|
557 | |
public Configuration configuration() { |
558 | 166 | return configuration; |
559 | |
} |
560 | |
|
561 | |
public List<CandidateSteps> candidateSteps() { |
562 | 7 | return candidateSteps; |
563 | |
} |
564 | |
|
565 | |
public boolean givenStory() { |
566 | 138 | return givenStory; |
567 | |
} |
568 | |
|
569 | |
public String path() { |
570 | 2 | return path; |
571 | |
} |
572 | |
|
573 | |
public FilteredStory filter(Story story) { |
574 | 23 | return new FilteredStory(filter, story, configuration.storyControls()); |
575 | |
} |
576 | |
|
577 | |
public String metaFilterAsString() { |
578 | 4 | return filter.asString(); |
579 | |
} |
580 | |
|
581 | |
public List<Step> collectBeforeOrAfterStorySteps(Story story, Stage stage) { |
582 | 39 | return configuration.stepCollector().collectBeforeOrAfterStorySteps(candidateSteps, story, stage, |
583 | |
givenStory); |
584 | |
} |
585 | |
|
586 | |
public List<Step> collectBeforeOrAfterScenarioSteps(Meta storyAndScenarioMeta, Stage stage, ScenarioType type) { |
587 | 45 | return configuration.stepCollector().collectBeforeOrAfterScenarioSteps(candidateSteps, |
588 | |
storyAndScenarioMeta, stage, type); |
589 | |
} |
590 | |
|
591 | |
public List<Step> collectScenarioSteps(Scenario scenario, Map<String, String> parameters) { |
592 | 24 | return configuration.stepCollector().collectScenarioSteps(candidateSteps, scenario, parameters); |
593 | |
} |
594 | |
|
595 | |
public RunContext childContextFor(GivenStory givenStory) { |
596 | 2 | String actualPath = configuration.pathCalculator().calculate(path, givenStory.getPath()); |
597 | 2 | return new RunContext(configuration, candidateSteps, actualPath, filter, true); |
598 | |
} |
599 | |
|
600 | |
public State state() { |
601 | 46 | return state; |
602 | |
} |
603 | |
|
604 | |
public void stateIs(State state) { |
605 | 36 | this.state = state; |
606 | 36 | } |
607 | |
|
608 | |
public boolean failureOccurred() { |
609 | 26 | return failed(state); |
610 | |
} |
611 | |
|
612 | |
public void resetState() { |
613 | 72 | this.state = new FineSoFar(); |
614 | 72 | } |
615 | |
|
616 | |
} |
617 | |
|
618 | |
public boolean failed(State state) { |
619 | 28 | return !state.getClass().equals(FineSoFar.class); |
620 | |
} |
621 | |
|
622 | |
public Throwable failure(State state) { |
623 | 0 | if (failed(state)) { |
624 | 0 | return ((SomethingHappened) state).scenarioFailure.getCause(); |
625 | |
} |
626 | 0 | return null; |
627 | |
} |
628 | |
} |