use of org.jbehave.core.model.Story 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.model.Story 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.model.Story 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.model.Story in project jbehave-core by jbehave.
the class EmbedderMonitorBehaviour method shouldAllowDecorationOfDelegate.
@Test
public void shouldAllowDecorationOfDelegate() throws Throwable {
// Given
EmbedderMonitor delegate = mock(EmbedderMonitor.class);
EmbedderMonitor monitor = new EmbedderMonitorDecorator(delegate);
// When
Object annotatedInstance = new Object();
monitor.annotatedInstanceNotOfType(annotatedInstance, annotatedInstance.getClass());
BatchFailures failures = new BatchFailures();
monitor.batchFailed(failures);
monitor.beforeOrAfterStoriesFailed();
String name = "name";
Throwable cause = new Throwable();
monitor.embeddableFailed(name, cause);
monitor.embeddableNotConfigurable(name);
List<String> names = asList("name1");
monitor.embeddablesSkipped(names);
File outputDirectory = new File("target");
StoryMaps storyMaps = mock(StoryMaps.class);
Properties viewProperties = mock(Properties.class);
monitor.generatingMapsView(outputDirectory, storyMaps, viewProperties);
Properties viewResources = mock(Properties.class);
monitor.generatingNavigatorView(outputDirectory, viewResources);
List<String> formats = asList("TXT");
monitor.generatingReportsView(outputDirectory, formats, viewProperties);
String storyPath = "path";
List<String> metaFilters = asList("- skip");
monitor.mappingStory(storyPath, metaFilters);
monitor.mapsViewGenerationFailed(outputDirectory, storyMaps, viewProperties, cause);
Meta meta = mock(Meta.class);
MetaFilter filter = mock(MetaFilter.class);
monitor.metaNotAllowed(meta, filter);
monitor.navigatorViewGenerationFailed(outputDirectory, viewResources, cause);
monitor.navigatorViewNotGenerated();
Properties properties = mock(Properties.class);
monitor.processingSystemProperties(properties);
ReportsCount count = mock(ReportsCount.class);
monitor.reportsViewGenerated(count);
monitor.reportsViewGenerationFailed(outputDirectory, formats, viewProperties, cause);
monitor.reportsViewNotGenerated();
monitor.runningEmbeddable(name);
monitor.runningStory(storyPath);
monitor.runningWithAnnotatedEmbedderRunner(name);
List<String> storyPaths = asList("path1");
monitor.storiesSkipped(storyPaths);
monitor.storyFailed(storyPath, cause);
Story story = mock(Story.class);
long durationInSecs = 1L;
long timeoutInSecs = 2L;
StoryDuration storyDuration = new StoryDuration(timeoutInSecs);
monitor.storyTimeout(story, storyDuration);
String value = "value";
monitor.systemPropertySet(name, value);
int threads = 2;
monitor.usingThreads(threads);
// Then
verify(delegate).annotatedInstanceNotOfType(annotatedInstance, annotatedInstance.getClass());
verify(delegate).batchFailed(failures);
verify(delegate).beforeOrAfterStoriesFailed();
verify(delegate).embeddableFailed(name, cause);
verify(delegate).embeddableNotConfigurable(name);
verify(delegate).embeddablesSkipped(names);
verify(delegate).generatingMapsView(outputDirectory, storyMaps, viewProperties);
verify(delegate).generatingNavigatorView(outputDirectory, viewResources);
verify(delegate).generatingReportsView(outputDirectory, formats, viewProperties);
verify(delegate).mappingStory(storyPath, metaFilters);
verify(delegate).mapsViewGenerationFailed(outputDirectory, storyMaps, viewProperties, cause);
verify(delegate).metaNotAllowed(meta, filter);
verify(delegate).navigatorViewGenerationFailed(outputDirectory, viewResources, cause);
verify(delegate).navigatorViewNotGenerated();
verify(delegate).processingSystemProperties(properties);
verify(delegate).reportsViewGenerated(count);
verify(delegate).reportsViewGenerationFailed(outputDirectory, formats, viewProperties, cause);
verify(delegate).reportsViewNotGenerated();
verify(delegate).storiesSkipped(storyPaths);
verify(delegate).storyFailed(storyPath, cause);
verify(delegate).storyTimeout(story, storyDuration);
verify(delegate).systemPropertySet(name, value);
verify(delegate).usingThreads(threads);
}
use of org.jbehave.core.model.Story in project jbehave-core by jbehave.
the class RegexStoryParserBehaviour method shouldIgnoreCommentsInMetaProperties.
@Test
public void shouldIgnoreCommentsInMetaProperties() {
String wholeStory = "Meta: !-- this is the theme @theme parsing !-- skip me @skip" + NL + "Scenario: " + NL + "Meta: !-- these are the authors @authors Mauro Paul" + NL + "Given a scenario " + NL + "When I parse it" + NL + "Then I should get steps";
Story story = parser.parseStory(wholeStory, storyPath);
assertThat(story.getPath(), equalTo(storyPath));
Meta storyMeta = story.getMeta();
assertThat(storyMeta.getProperty("theme"), equalTo("parsing"));
assertThat(storyMeta.getProperty("skip"), equalTo(EMPTY));
assertThat(story.getScenarios().get(0).getMeta().getProperty("authors"), equalTo("Mauro Paul"));
}
Aggregations