use of org.jbehave.core.configuration.Configuration in project jbehave-core by jbehave.
the class EmbedderBehaviour method shouldRunStoriesAsEmbeddables.
@Test
public void shouldRunStoriesAsEmbeddables() throws Throwable {
// Given
PerformableTree performableTree = mock(PerformableTree.class);
EmbedderControls embedderControls = new EmbedderControls();
OutputStream out = new ByteArrayOutputStream();
EmbedderMonitor monitor = new PrintStreamEmbedderMonitor(new PrintStream(out));
String myEmbeddableName = MyEmbeddable.class.getName();
String myOtherEmbeddableName = MyOtherEmbeddable.class.getName();
List<String> classNames = asList(myEmbeddableName, myOtherEmbeddableName);
Embeddable myEmbeddable = new MyEmbeddable();
Embeddable myOtherEmbeddable = new MyOtherEmbeddable();
List<Embeddable> embeddables = asList(myEmbeddable, myOtherEmbeddable);
EmbedderClassLoader classLoader = mock(EmbedderClassLoader.class);
when(classLoader.newInstance(Embeddable.class, myEmbeddableName)).thenReturn(myEmbeddable);
when(classLoader.newInstance(Embeddable.class, myOtherEmbeddableName)).thenReturn(myOtherEmbeddable);
// When
Configuration configuration = new MostUsefulConfiguration();
CandidateSteps steps = mock(CandidateSteps.class);
Embedder embedder = embedderWith(performableTree, embedderControls, monitor);
embedder.useClassLoader(classLoader);
embedder.useConfiguration(configuration);
embedder.useCandidateSteps(asList(steps));
embedder.runAsEmbeddables(classNames);
// Then
for (Embeddable embeddable : embeddables) {
assertThat(out.toString(), containsString("Running embeddable " + embeddable.getClass().getName()));
}
}
use of org.jbehave.core.configuration.Configuration in project jbehave-core by jbehave.
the class EmbedderBehaviour method shouldNotThrowExceptionUponFailingStoriesAsPathsIfIgnoreFailureInStoriesFlagIsSet.
@SuppressWarnings("unchecked")
@Test
public void shouldNotThrowExceptionUponFailingStoriesAsPathsIfIgnoreFailureInStoriesFlagIsSet() throws Throwable {
// Given
PerformableTree performableTree = mock(PerformableTree.class);
EmbedderControls embedderControls = new EmbedderControls().doIgnoreFailureInStories(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) {
doThrow(new RuntimeException(storyPath + " failed")).when(performableTree).perform(runContext, stories.get(storyPath));
}
// When
embedder.runStoriesAsPaths(storyPaths);
TimeUnit.SECONDS.sleep(2);
// Then
for (String storyPath : storyPaths) {
assertThat(out.toString(), containsString("Running story " + storyPath));
assertThat(out.toString(), containsString("Failed to run story " + storyPath));
}
}
use of org.jbehave.core.configuration.Configuration in project jbehave-core by jbehave.
the class StoryRunnerBehaviour method shouldRunAfterAndBeforeScenarioSteps.
@Test
public void shouldRunAfterAndBeforeScenarioSteps() throws Throwable {
// Given
Scenario scenario1 = new Scenario("my title 1", Meta.EMPTY, GivenStories.EMPTY, ExamplesTable.EMPTY, asList("step"));
Story story = new Story(new Description("my blurb"), Narrative.EMPTY, asList(scenario1));
StoryReporter reporter = mock(ConcurrentStoryReporter.class);
StepCollector collector = mock(StepCollector.class);
FailureStrategy failureStrategy = mock(FailureStrategy.class);
Configuration configuration = configurationWith(reporter, collector, failureStrategy);
configuration.storyControls().doDryRun(true);
CandidateSteps mySteps = new Steps(configuration);
Step firstStep = mockSuccessfulStep("step");
when(collector.collectScenarioSteps(asList(mySteps), scenario1, new HashMap<String, String>())).thenReturn(asList(firstStep));
boolean givenStory = false;
givenStoryWithNoBeforeOrAfterSteps(story, givenStory, collector, mySteps);
givenBeforeAndAfterScenarioSteps(ScenarioType.NORMAL, collector, mySteps);
givenBeforeAndAfterScenarioSteps(ScenarioType.ANY, collector, mySteps);
givenLifecycleSteps(collector, mySteps);
// When
StoryRunner runner = new StoryRunner();
runner.run(configuration, asList(mySteps), story);
// Then
InOrder inOrder = inOrder(reporter, failureStrategy);
inOrder.verify(reporter).successful(stepNameFor(Stage.BEFORE, ScenarioType.NORMAL));
inOrder.verify(reporter).successful(stepNameFor(Stage.BEFORE, ScenarioType.ANY));
inOrder.verify(reporter).successful(lifecycleStepNameFor(Stage.BEFORE));
inOrder.verify(reporter).successful("step");
inOrder.verify(reporter).successful(lifecycleStepNameFor(Stage.AFTER));
inOrder.verify(reporter).successful(stepNameFor(Stage.AFTER, ScenarioType.ANY));
inOrder.verify(reporter).successful(stepNameFor(Stage.AFTER, ScenarioType.NORMAL));
}
use of org.jbehave.core.configuration.Configuration in project jbehave-core by jbehave.
the class StoryRunnerBehaviour method shouldNotRunStoriesNotAllowedByFilterOnStoryElement.
@Test
public void shouldNotRunStoriesNotAllowedByFilterOnStoryElement() throws Throwable {
// Given
StoryReporter reporter = mock(ConcurrentStoryReporter.class);
StepCollector collector = mock(StepCollector.class);
FailureStrategy strategy = mock(FailureStrategy.class);
CandidateSteps mySteps = new Steps();
when(collector.collectScenarioSteps(eq(asList(mySteps)), (Scenario) anyObject(), eq(parameters))).thenReturn(Arrays.<Step>asList());
Story story = new Story("excluded_path", Description.EMPTY, Meta.EMPTY, Narrative.EMPTY, asList(new Scenario()));
boolean givenStory = false;
givenStoryWithNoBeforeOrAfterSteps(story, givenStory, collector, mySteps);
String filterAsString = "-story_path excluded_path";
MetaFilter filter = new MetaFilter(filterAsString);
// When
StoryRunner runner = new StoryRunner();
Configuration configuration = configurationWith(reporter, collector, strategy);
configuration.storyControls().useStoryMetaPrefix("story_");
runner.run(configuration, asList(mySteps), story, filter);
// Then
verify(reporter).beforeStory(story, givenStory);
verify(reporter).storyNotAllowed(story, filterAsString);
verify(reporter).afterStory(givenStory);
}
use of org.jbehave.core.configuration.Configuration in project jbehave-core by jbehave.
the class StoryRunnerBehaviour method shouldAllowToSkipBeforeAndAfterScenarioStepsIfGivenStory.
@Test
public void shouldAllowToSkipBeforeAndAfterScenarioStepsIfGivenStory() throws Throwable {
// Given
Scenario scenario1 = new Scenario("scenario 1", asList("successfulStep"));
GivenStories givenStories = new GivenStories("/path/to/given/story1");
Scenario scenario2 = new Scenario("scenario 2", Meta.EMPTY, givenStories, ExamplesTable.EMPTY, asList("anotherSuccessfulStep"));
Story story1 = new Story(new Description("story 1"), Narrative.EMPTY, asList(scenario1));
Story story2 = new Story(new Description("story 2"), Narrative.EMPTY, asList(scenario2));
Step step = mock(Step.class);
StepResult result = mock(StepResult.class);
when(step.perform(null)).thenReturn(result);
StoryParser storyParser = mock(StoryParser.class);
StoryLoader storyLoader = mock(StoryLoader.class);
StoryReporter reporter = mock(ConcurrentStoryReporter.class);
StepCollector collector = mock(StepCollector.class);
CandidateSteps mySteps = new Steps();
Step successfulStep = mockSuccessfulStep("successfulStep");
Step anotherSuccessfulStep = mockSuccessfulStep("anotherSuccessfulStep");
givenStoryWithNoBeforeOrAfterSteps(story1, false, collector, mySteps);
when(collector.collectScenarioSteps(asList(mySteps), scenario1, parameters)).thenReturn(asList(successfulStep));
givenStoryWithNoBeforeOrAfterSteps(story2, true, collector, mySteps);
when(collector.collectScenarioSteps(asList(mySteps), scenario2, parameters)).thenReturn(asList(anotherSuccessfulStep));
when(storyLoader.loadStoryAsText("/path/to/given/story1")).thenReturn("storyContent");
when(storyParser.parseStory("storyContent", "/path/to/given/story1")).thenReturn(story1);
FailureStrategy failureStrategy = mock(FailureStrategy.class);
Step beforeStep = mockSuccessfulStep("SuccessfulBeforeScenarioStep");
Step afterStep = mockSuccessfulStep("SuccessfulAfterScenarioStep");
when(collector.collectBeforeOrAfterScenarioSteps(eq(asList(mySteps)), Matchers.<Meta>any(), eq(Stage.BEFORE), eq(ScenarioType.NORMAL))).thenReturn(asList(beforeStep));
when(collector.collectBeforeOrAfterScenarioSteps(eq(asList(mySteps)), Matchers.<Meta>any(), eq(Stage.AFTER), eq(ScenarioType.NORMAL))).thenReturn(asList(afterStep));
// When
StoryRunner runner = new StoryRunner();
Configuration configuration = configurationWith(storyParser, storyLoader, reporter, collector, failureStrategy);
configuration.storyControls().doSkipBeforeAndAfterScenarioStepsIfGivenStory(true);
runner.run(configuration, asList(mySteps), story2);
// Then
verify(collector).collectScenarioSteps(asList(mySteps), scenario1, parameters);
verify(collector).collectScenarioSteps(asList(mySteps), scenario2, parameters);
InOrder inOrder = inOrder(beforeStep, successfulStep, anotherSuccessfulStep, afterStep);
inOrder.verify(beforeStep).perform(null);
inOrder.verify(successfulStep).perform(null);
inOrder.verify(anotherSuccessfulStep).perform(null);
inOrder.verify(afterStep).perform(null);
}
Aggregations