use of org.jbehave.core.io.StoryPathResolver in project jbehave-core by jbehave.
the class EmbedderBehaviour method shouldRunStoriesApplyingFilter.
@SuppressWarnings("unchecked")
@Test
public void shouldRunStoriesApplyingFilter() throws Throwable {
// Given
PerformableTree performableTree = mock(PerformableTree.class);
EmbedderControls embedderControls = new EmbedderControls();
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);
final StoryReporter storyReporter = mock(StoryReporter.class);
Configuration configuration = new MostUsefulConfiguration() {
@Override
public StoryReporter storyReporter(String storyPath) {
return storyReporter;
}
};
embedder.useConfiguration(configuration);
InjectableStepsFactory stepsFactory = embedder.stepsFactory();
StoryPathResolver resolver = configuration.storyPathResolver();
List<String> storyPaths = new ArrayList<>();
Map<String, Story> stories = new HashMap<>();
Meta meta = mock(Meta.class);
for (Class<? extends Embeddable> embeddable : embeddables) {
String storyPath = resolver.resolve(embeddable);
storyPaths.add(storyPath);
Story story = mockStory(Meta.EMPTY);
when(story.getMeta()).thenReturn(meta);
stories.put(storyPath, story);
when(performableTree.storyOfPath(configuration, storyPath)).thenReturn(story);
when(story.getPath()).thenReturn(storyPath);
assertThat(configuration.storyReporter(storyPath), sameInstance(storyReporter));
}
// When
MetaFilter filter = mock(MetaFilter.class);
when(filter.allow(meta)).thenReturn(false);
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);
embedder.runStoriesAsPaths(storyPaths);
// Then
for (String storyPath : storyPaths) {
verify(performableTree, never()).perform(runContext, stories.get(storyPath));
}
assertThatReportsViewGenerated(out);
assertThat(embedder.hasExecutorService(), is(false));
}
use of org.jbehave.core.io.StoryPathResolver in project jbehave-core by jbehave.
the class EmbedderBehaviour method shouldNotGenerateViewWhenRunningStoriesAsPathsIfGenerateViewAfterStoriesFlagIsNotSet.
@SuppressWarnings("unchecked")
@Test
public void shouldNotGenerateViewWhenRunningStoriesAsPathsIfGenerateViewAfterStoriesFlagIsNotSet() throws Throwable {
// Given
PerformableTree performableTree = mock(PerformableTree.class);
EmbedderControls embedderControls = new EmbedderControls().doGenerateViewAfterStories(false);
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);
// When
embedder.runStoriesAsPaths(storyPaths);
// Then
for (String storyPath : storyPaths) {
verify(performableTree).perform(runContext, stories.get(storyPath));
assertThat(out.toString(), containsString("Running story " + storyPath));
}
assertThat(out.toString(), not(containsString("Generating stories view")));
assertThat(out.toString(), not(containsString("Stories view generated")));
}
use of org.jbehave.core.io.StoryPathResolver 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.io.StoryPathResolver in project jbehave-core by jbehave.
the class ConfigurableEmbedderBehaviour method shouldAllowAdditionOfSteps.
@Test
public void shouldAllowAdditionOfSteps() throws Throwable {
// Given
Embedder embedder = mock(Embedder.class);
Configuration configuration = mock(Configuration.class);
StoryPathResolver pathResolver = mock(StoryPathResolver.class);
when(embedder.configuration()).thenReturn(configuration);
when(configuration.storyPathResolver()).thenReturn(pathResolver);
Class<MyStory> storyClass = MyStory.class;
String storyPath = "/path/to/story";
when(pathResolver.resolve(storyClass)).thenReturn(storyPath);
CandidateSteps steps = mock(CandidateSteps.class);
// When
MyStory story = new MyStory(configuration, steps);
story.useEmbedder(embedder);
story.run();
// Then
verify(embedder).runStoriesAsPaths(asList(storyPath));
}
use of org.jbehave.core.io.StoryPathResolver in project jbehave-core by jbehave.
the class JUnitStory method run.
@Test
public void run() throws Throwable {
Embedder embedder = configuredEmbedder();
StoryPathResolver pathResolver = embedder.configuration().storyPathResolver();
String storyPath = pathResolver.resolve(this.getClass());
try {
embedder.runStoriesAsPaths(asList(storyPath));
} finally {
embedder.generateCrossReference();
embedder.generateSurefireReport();
}
}
Aggregations