use of org.jbehave.core.model.Story in project jbehave-core by jbehave.
the class PerformableTree method performableGivenStories.
private List<PerformableStory> performableGivenStories(RunContext context, GivenStories givenStories, Map<String, String> parameters) {
List<PerformableStory> stories = new ArrayList<>();
if (givenStories.getPaths().size() > 0) {
for (GivenStory givenStory : givenStories.getStories()) {
RunContext childContext = context.childContextFor(givenStory);
// run given story, using any parameters provided
Story story = storyOfPath(context.configuration(), childContext.path());
if (givenStory.hasAnchorParameters()) {
story = storyWithMatchingScenarios(story, givenStory.getAnchorParameters());
}
parameters.putAll(givenStory.getParameters());
stories.add(performableStory(childContext, story, parameters));
}
}
return stories;
}
use of org.jbehave.core.model.Story in project jbehave-core by jbehave.
the class PrintStreamEmbedderMonitor method storiesNotAllowed.
public void storiesNotAllowed(List<Story> stories, MetaFilter filter, boolean verbose) {
StringBuffer sb = new StringBuffer();
sb.append(stories.size() + " stories excluded by filter: " + filter.asString() + "\n");
if (verbose) {
for (Story story : stories) {
sb.append(story.getPath()).append("\n");
}
}
print(sb.toString());
}
use of org.jbehave.core.model.Story in project jbehave-core by jbehave.
the class StoryRunner method runBeforeOrAfterStories.
/**
* Run steps before or after a collection of stories. Steps are execute only
* <b>once</b> per collection of stories.
*
* @param configuration the Configuration used to find the steps to run
* @param candidateSteps the List of CandidateSteps containing the candidate
* steps methods
* @param stage the Stage
* @return The State after running the steps
*/
public State runBeforeOrAfterStories(Configuration configuration, List<CandidateSteps> candidateSteps, Stage stage) {
String storyPath = capitalizeFirstLetter(stage.name().toLowerCase()) + "Stories";
reporter.set(configuration.storyReporter(storyPath));
reporter.get().beforeStory(new Story(storyPath), false);
RunContext context = new RunContext(configuration, candidateSteps, storyPath, MetaFilter.EMPTY);
if (stage == Stage.BEFORE) {
resetStoryFailure(context);
}
if (stage == Stage.AFTER && storiesState.get() != null) {
context.stateIs(storiesState.get());
}
try {
runStepsWhileKeepingState(context, configuration.stepCollector().collectBeforeOrAfterStoriesSteps(context.candidateSteps(), stage));
} catch (InterruptedException e) {
throw new UUIDExceptionWrapper(e);
}
reporter.get().afterStory(false);
storiesState.set(context.state());
// methods, otherwise we will forget to close files on BeforeStories
if (stage == Stage.BEFORE) {
if (reporter.get() instanceof ConcurrentStoryReporter) {
((ConcurrentStoryReporter) reporter.get()).invokeDelayed();
}
}
// handle any after stories failure according to strategy
if (stage == Stage.AFTER) {
try {
handleStoryFailureByStrategy();
} catch (Throwable e) {
return new SomethingHappened(storyFailure.get());
} finally {
if (reporter.get() instanceof ConcurrentStoryReporter) {
((ConcurrentStoryReporter) reporter.get()).invokeDelayed();
}
}
}
return context.state();
}
use of org.jbehave.core.model.Story in project serenity-jbehave by serenity-bdd.
the class SerenityReporter method processExcludedByFilter.
public List<String> processExcludedByFilter(final Story story, final Set<String> exclude) {
final Meta storyMeta = story.getMeta();
final List<Scenario> processing = new LinkedList<>();
final List<String> processed = new LinkedList<>();
if (isSkipped(storyMeta) || isIgnored(storyMeta)) {
// this story should be excluded by filter
processing.addAll(story.getScenarios());
} else {
for (Scenario scenario : story.getScenarios()) {
final Meta scenarioMeta = scenario.getMeta();
if (isSkipped(scenarioMeta) || isIgnored(scenarioMeta)) {
// this scenario should be excluded by filter
processing.add(scenario);
}
}
}
if (processing.size() > 0) {
final Story beforeStory = new Story();
beforeStory.namedAs(BEFORE_STORIES);
final Story afterStory = new Story();
afterStory.namedAs(AFTER_STORIES);
final Narrative narrative = story.getNarrative();
beforeStory(beforeStory, false);
afterStory(false);
beforeStory(story, false);
narrative(narrative);
for (final Scenario filtered : processing) {
final String scenarioKey = scenarioKey(story, filtered);
if (!exclude.contains(scenarioKey)) {
beforeScenario(filtered.getTitle());
scenarioMeta(filtered.getMeta());
final List<String> steps = filtered.getSteps();
if (ExamplesTable.EMPTY == filtered.getExamplesTable() || filtered.getExamplesTable().getRows().size() == 0) {
for (final String step : steps) {
beforeStep(step);
successful(step);
}
} else {
final ExamplesTable examples = filtered.getExamplesTable();
beforeExamples(steps, examples);
for (final Map<String, String> row : examples.getRows()) {
example(row);
for (final String step : steps) {
beforeStep(step);
successful(step);
}
}
afterExamples();
}
afterScenario();
processed.add(scenarioKey(story, filtered));
}
}
afterStory(false);
beforeStory(afterStory, false);
afterStory(false);
}
return processed;
}
use of org.jbehave.core.model.Story in project jbehave-core by jbehave.
the class EmbedderBehaviour method shouldRunStoriesAsPathsInBatchIfBatchFlagIsSet.
@SuppressWarnings("unchecked")
@Test
public void shouldRunStoriesAsPathsInBatchIfBatchFlagIsSet() throws Throwable {
// Given
PerformableTree performableTree = mock(PerformableTree.class);
EmbedderControls embedderControls = new EmbedderControls().doBatch(true);
OutputStream out = new ByteArrayOutputStream();
EmbedderMonitor monitor = new PrintStreamEmbedderMonitor(new PrintStream(out));
List<? extends Class<? extends Embeddable>> embeddables = asList(MyStory.class, MyOtherEmbeddable.class);
Embedder embedder = embedderWith(performableTree, embedderControls, monitor);
Configuration configuration = embedder.configuration();
InjectableStepsFactory stepsFactory = embedder.stepsFactory();
MetaFilter filter = embedder.metaFilter();
StoryPathResolver resolver = configuration.storyPathResolver();
List<String> storyPaths = new ArrayList<>();
Map<String, Story> stories = new HashMap<>();
for (Class<? extends Embeddable> embeddable : embeddables) {
String storyPath = resolver.resolve(embeddable);
storyPaths.add(storyPath);
Story story = mockStory(Meta.EMPTY);
stories.put(storyPath, story);
when(performableTree.storyOfPath(configuration, storyPath)).thenReturn(story);
when(story.getPath()).thenReturn(storyPath);
}
RunContext runContext = new RunContext(configuration, stepsFactory, monitor, filter, new BatchFailures());
when(performableTree.newRunContext(isA(Configuration.class), isA(InjectableStepsFactory.class), isA(EmbedderMonitor.class), isA(MetaFilter.class), isA(BatchFailures.class))).thenReturn(runContext);
for (String storyPath : storyPaths) {
doNothing().when(performableTree).perform(runContext, stories.get(storyPath));
}
// When
embedder.runStoriesAsPaths(storyPaths);
// Then
for (String storyPath : storyPaths) {
assertThat(out.toString(), containsString("Running story " + storyPath));
}
}
Aggregations