Search in sources :

Example 1 with MostUsefulConfiguration

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

the class CoreEmbedder method configuration.

@Override
public Configuration configuration() {
    Class<? extends CoreEmbedder> embedderClass = this.getClass();
    TableTransformers tableTransformers = new TableTransformers();
    LoadFromClasspath resourceLoader = new LoadFromClasspath(embedderClass.getClassLoader());
    return new MostUsefulConfiguration().useStoryLoader(resourceLoader).useStoryReporterBuilder(new StoryReporterBuilder().withCodeLocation(CodeLocations.codeLocationFromClass(embedderClass)).withDefaultFormats().withFormats(CONSOLE, TXT, HTML, XML).withCrossReference(new CrossReference())).useTableTransformers(tableTransformers).useParameterConverters(new ParameterConverters(resourceLoader, tableTransformers).addConverters(// use custom date pattern
    new DateConverter(new SimpleDateFormat("yyyy-MM-dd")))).useStepPatternParser(new RegexPrefixCapturingPatternParser(// use '%' instead of '$' to identify parameters
    "%")).useStepMonitor(new SilentStepMonitor());
}
Also used : StoryReporterBuilder(org.jbehave.core.reporters.StoryReporterBuilder) RegexPrefixCapturingPatternParser(org.jbehave.core.parsers.RegexPrefixCapturingPatternParser) DateConverter(org.jbehave.core.steps.ParameterConverters.DateConverter) LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) SilentStepMonitor(org.jbehave.core.steps.SilentStepMonitor) ParameterConverters(org.jbehave.core.steps.ParameterConverters) CrossReference(org.jbehave.core.reporters.CrossReference) SimpleDateFormat(java.text.SimpleDateFormat) TableTransformers(org.jbehave.core.model.TableTransformers)

Example 2 with MostUsefulConfiguration

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

the class CoreStories method configuration.

@Override
public Configuration configuration() {
    // alternative use #useConfiguration() in the constructor
    if (super.hasConfiguration()) {
        return super.configuration();
    }
    Class<? extends Embeddable> embeddableClass = this.getClass();
    Properties viewResources = new Properties();
    viewResources.put("decorateNonHtml", "true");
    viewResources.put("reports", "ftl/jbehave-reports.ftl");
    LoadFromClasspath resourceLoader = new LoadFromClasspath(embeddableClass);
    TableTransformers tableTransformers = new TableTransformers();
    ParameterControls parameterControls = new ParameterControls();
    // Start from default ParameterConverters instance
    ParameterConverters parameterConverters = new ParameterConverters(resourceLoader, tableTransformers);
    // factory to allow parameter conversion and loading from external
    // resources (used by StoryParser too)
    ExamplesTableFactory examplesTableFactory = new ExamplesTableFactory(new LocalizedKeywords(), resourceLoader, parameterConverters, parameterControls, tableTransformers);
    // add custom converters
    parameterConverters.addConverters(new DateConverter(new SimpleDateFormat("yyyy-MM-dd")), new ExamplesTableConverter(examplesTableFactory));
    return new MostUsefulConfiguration().useStoryLoader(resourceLoader).useStoryParser(new RegexStoryParser(examplesTableFactory)).useStoryReporterBuilder(new StoryReporterBuilder().withCodeLocation(CodeLocations.codeLocationFromClass(embeddableClass)).withDefaultFormats().withViewResources(viewResources).withFormats(contextFormat, CONSOLE, TXT, HTML_TEMPLATE, XML_TEMPLATE).withFailureTrace(true).withFailureTraceCompression(true).withCrossReference(xref).withSurefireReporter(new SurefireReporter(embeddableClass))).useParameterConverters(parameterConverters).useParameterControls(parameterControls).useTableTransformers(tableTransformers);
}
Also used : ParameterControls(org.jbehave.core.steps.ParameterControls) DateConverter(org.jbehave.core.steps.ParameterConverters.DateConverter) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) ExamplesTableConverter(org.jbehave.core.steps.ParameterConverters.ExamplesTableConverter) Properties(java.util.Properties) TableTransformers(org.jbehave.core.model.TableTransformers) RegexStoryParser(org.jbehave.core.parsers.RegexStoryParser) LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath) ParameterConverters(org.jbehave.core.steps.ParameterConverters) ExamplesTableFactory(org.jbehave.core.model.ExamplesTableFactory) SimpleDateFormat(java.text.SimpleDateFormat)

Example 3 with MostUsefulConfiguration

use of org.jbehave.core.configuration.MostUsefulConfiguration 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 MostUsefulConfiguration

use of org.jbehave.core.configuration.MostUsefulConfiguration 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 MostUsefulConfiguration

use of org.jbehave.core.configuration.MostUsefulConfiguration 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()));
    }
}
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) CandidateSteps(org.jbehave.core.steps.CandidateSteps) Test(org.junit.Test)

Aggregations

MostUsefulConfiguration (org.jbehave.core.configuration.MostUsefulConfiguration)66 Test (org.junit.Test)52 Configuration (org.jbehave.core.configuration.Configuration)14 CandidateSteps (org.jbehave.core.steps.CandidateSteps)14 StoryReporterBuilder (org.jbehave.core.reporters.StoryReporterBuilder)11 LoadFromClasspath (org.jbehave.core.io.LoadFromClasspath)8 TableTransformers (org.jbehave.core.model.TableTransformers)8 Method (java.lang.reflect.Method)7 LocalizedKeywords (org.jbehave.core.i18n.LocalizedKeywords)7 ParameterConverters (org.jbehave.core.steps.ParameterConverters)7 SimpleDateFormat (java.text.SimpleDateFormat)5 HashMap (java.util.HashMap)5 InjectableEmbedder (org.jbehave.core.InjectableEmbedder)5 UsingEmbedder (org.jbehave.core.annotations.UsingEmbedder)5 BeforeOrAfterFailed (org.jbehave.core.failures.BeforeOrAfterFailed)5 Failed (org.jbehave.core.steps.AbstractStepResult.Failed)5 ApplicationContext (org.springframework.context.ApplicationContext)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 OutputStream (java.io.OutputStream)4 PrintStream (java.io.PrintStream)4