Search in sources :

Example 1 with Configuration

use of org.jbehave.core.configuration.Configuration in project jbehave-core by jbehave.

the class CustomCoreStories method configuration.

@Override
public Configuration configuration() {
    Configuration configuration = super.configuration();
    Properties viewResources = new Properties();
    viewResources.put("reports", "ftl/custom-reports.ftl");
    configuration.useViewGenerator(new FreemarkerViewGenerator(this.getClass()));
    Keywords keywords = new LocalizedKeywords(new Locale("en"), "i18n/custom", "i18n/keywords", this.getClass().getClassLoader());
    StoryReporterBuilder reporterBuilder = configuration.storyReporterBuilder().withKeywords(keywords).withViewResources(viewResources).withFormats(CustomHtmlOutput.FORMAT);
    return configuration.useKeywords(keywords).useStepCollector(new MarkUnmatchedStepsAsPending(keywords)).useStoryParser(new RegexStoryParser(keywords)).useStoryReporterBuilder(reporterBuilder);
}
Also used : Locale(java.util.Locale) StoryReporterBuilder(org.jbehave.core.reporters.StoryReporterBuilder) Keywords(org.jbehave.core.configuration.Keywords) LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) RegexStoryParser(org.jbehave.core.parsers.RegexStoryParser) Configuration(org.jbehave.core.configuration.Configuration) FreemarkerViewGenerator(org.jbehave.core.reporters.FreemarkerViewGenerator) LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) Properties(java.util.Properties) MarkUnmatchedStepsAsPending(org.jbehave.core.steps.MarkUnmatchedStepsAsPending)

Example 2 with Configuration

use of org.jbehave.core.configuration.Configuration in project jbehave-core by jbehave.

the class JFrameCoreStories method configuration.

@Override
public Configuration configuration() {
    Configuration configuration = super.configuration();
    configuration.useStepMonitor(contextStepMonitor);
    return configuration;
}
Also used : Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration)

Example 3 with Configuration

use of org.jbehave.core.configuration.Configuration 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));
}
Also used : StoryReporter(org.jbehave.core.reporters.StoryReporter) Meta(org.jbehave.core.model.Meta) StoryPathResolver(org.jbehave.core.io.StoryPathResolver) Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) HashMap(java.util.HashMap) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) InjectableEmbedder(org.jbehave.core.InjectableEmbedder) UsingEmbedder(org.jbehave.core.annotations.UsingEmbedder) Matchers.containsString(org.hamcrest.Matchers.containsString) JUnitStory(org.jbehave.core.junit.JUnitStory) Story(org.jbehave.core.model.Story) PrintStream(java.io.PrintStream) InjectableStepsFactory(org.jbehave.core.steps.InjectableStepsFactory) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BatchFailures(org.jbehave.core.failures.BatchFailures) RunContext(org.jbehave.core.embedder.PerformableTree.RunContext) Test(org.junit.Test)

Example 4 with Configuration

use of org.jbehave.core.configuration.Configuration in project jbehave-core by jbehave.

the class EmbedderBehaviour method shouldMapStoriesAsEmbeddables.

@Test
public void shouldMapStoriesAsEmbeddables() throws Throwable {
    // Given
    PerformableTree performableTree = mock(PerformableTree.class);
    OutputStream out = new ByteArrayOutputStream();
    EmbedderMonitor monitor = new PrintStreamEmbedderMonitor(new PrintStream(out));
    String myEmbeddableName = MyStoryMaps.class.getName();
    List<String> classNames = asList(myEmbeddableName);
    Embeddable myEmbeddable = new MyStoryMaps();
    List<Embeddable> embeddables = asList(myEmbeddable);
    EmbedderClassLoader classLoader = mock(EmbedderClassLoader.class);
    when(classLoader.newInstance(Embeddable.class, myEmbeddableName)).thenReturn(myEmbeddable);
    // When
    Configuration configuration = new MostUsefulConfiguration();
    Embedder embedder = embedderWith(performableTree, new EmbedderControls(), monitor);
    embedder.useClassLoader(classLoader);
    embedder.useConfiguration(configuration);
    embedder.runAsEmbeddables(classNames);
    // Then
    for (Embeddable embeddable : embeddables) {
        assertThat(out.toString(), containsString("Running embeddable " + embeddable.getClass().getName()));
    }
    assertThat(MyStoryMaps.run, is(true));
}
Also used : PrintStream(java.io.PrintStream) Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) InjectableEmbedder(org.jbehave.core.InjectableEmbedder) UsingEmbedder(org.jbehave.core.annotations.UsingEmbedder) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Matchers.containsString(org.hamcrest.Matchers.containsString) Embeddable(org.jbehave.core.Embeddable) Test(org.junit.Test)

Example 5 with Configuration

use of org.jbehave.core.configuration.Configuration 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")));
}
Also used : PrintStream(java.io.PrintStream) InjectableStepsFactory(org.jbehave.core.steps.InjectableStepsFactory) StoryPathResolver(org.jbehave.core.io.StoryPathResolver) Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) HashMap(java.util.HashMap) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) InjectableEmbedder(org.jbehave.core.InjectableEmbedder) UsingEmbedder(org.jbehave.core.annotations.UsingEmbedder) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Matchers.containsString(org.hamcrest.Matchers.containsString) BatchFailures(org.jbehave.core.failures.BatchFailures) RunContext(org.jbehave.core.embedder.PerformableTree.RunContext) JUnitStory(org.jbehave.core.junit.JUnitStory) Story(org.jbehave.core.model.Story) Test(org.junit.Test)

Aggregations

Configuration (org.jbehave.core.configuration.Configuration)64 MostUsefulConfiguration (org.jbehave.core.configuration.MostUsefulConfiguration)61 Test (org.junit.Test)55 AnnotationBuilder (org.jbehave.core.configuration.AnnotationBuilder)18 StoryReporter (org.jbehave.core.reporters.StoryReporter)15 ConcurrentStoryReporter (org.jbehave.core.reporters.ConcurrentStoryReporter)13 StoryPathResolver (org.jbehave.core.io.StoryPathResolver)11 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10 OutputStream (java.io.OutputStream)10 PrintStream (java.io.PrintStream)10 Matchers.containsString (org.hamcrest.Matchers.containsString)10 InjectableEmbedder (org.jbehave.core.InjectableEmbedder)10 UsingEmbedder (org.jbehave.core.annotations.UsingEmbedder)10 AbstractStep (org.jbehave.core.steps.StepCreator.AbstractStep)10 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)8 JUnitStory (org.jbehave.core.junit.JUnitStory)8 Story (org.jbehave.core.model.Story)8 SimpleDateFormat (java.text.SimpleDateFormat)7 RunContext (org.jbehave.core.embedder.PerformableTree.RunContext)7