Search in sources :

Example 1 with RegexPrefixCapturingPatternParser

use of org.jbehave.core.parsers.RegexPrefixCapturingPatternParser 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 RegexPrefixCapturingPatternParser

use of org.jbehave.core.parsers.RegexPrefixCapturingPatternParser in project jbehave-core by jbehave.

the class StepCandidateBehaviour method shouldNotMatchOrIgnoreStepWhenStartingWordNotFound.

@Test
public void shouldNotMatchOrIgnoreStepWhenStartingWordNotFound() throws Exception {
    Method method = SomeSteps.class.getMethod("aMethod");
    Keywords keywords = new LocalizedKeywords() {

        @Override
        public String startingWordFor(StepType stepType) {
            throw new StartingWordNotFound(stepType, new HashMap<StepType, String>());
        }
    };
    ParameterConverters parameterConverters = new ParameterConverters(new LoadFromClasspath(), new TableTransformers());
    StepCandidate candidate = new StepCandidate("windows on the $nth floor", 0, WHEN, method, null, null, new StepsContext(), keywords, new RegexPrefixCapturingPatternParser(), parameterConverters, new ParameterControls());
    assertThat(candidate.matches("When windows on the 1st floor"), is(false));
    assertThat(candidate.ignore("!-- windows on the 1st floor"), is(false));
}
Also used : Keywords(org.jbehave.core.configuration.Keywords) LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) StartingWordNotFound(org.jbehave.core.configuration.Keywords.StartingWordNotFound) StepType(org.jbehave.core.steps.StepType) LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) Method(java.lang.reflect.Method) TableTransformers(org.jbehave.core.model.TableTransformers) StepsContext(org.jbehave.core.steps.context.StepsContext) RegexPrefixCapturingPatternParser(org.jbehave.core.parsers.RegexPrefixCapturingPatternParser) LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath) Test(org.junit.Test)

Example 3 with RegexPrefixCapturingPatternParser

use of org.jbehave.core.parsers.RegexPrefixCapturingPatternParser in project jbehave-core by jbehave.

the class GuiceAnnotationBuilderBehaviour method shouldBuildConfigurationFromAnnotations.

@Test
public void shouldBuildConfigurationFromAnnotations() {
    AnnotationBuilder builder = new GuiceAnnotationBuilder(AnnotatedUsingGuice.class);
    Configuration configuration = builder.buildConfiguration();
    assertThat(configuration.storyControls().dryRun(), is(true));
    assertThat(configuration.storyControls().skipScenariosAfterFailure(), is(true));
    assertThat(configuration.failureStrategy(), instanceOf(SilentlyAbsorbingFailure.class));
    assertThat(configuration.storyLoader(), instanceOf(LoadFromURL.class));
    assertThat(configuration.stepPatternParser(), instanceOf(RegexPrefixCapturingPatternParser.class));
    assertThat(((RegexPrefixCapturingPatternParser) configuration.stepPatternParser()).getPrefix(), equalTo("MyPrefix"));
    assertThatCustomObjectIsConverted(configuration.parameterConverters());
    assertThatDateIsConvertedWithFormat(configuration.parameterConverters(), new SimpleDateFormat("yyyy-MM-dd"));
    assertThat(configuration.storyReporterBuilder().formats(), hasItems(CONSOLE, HTML, TXT, XML, STATS));
    Keywords keywords = configuration.storyReporterBuilder().keywords();
    assertThat(keywords, instanceOf(LocalizedKeywords.class));
    assertThat(((LocalizedKeywords) keywords).getLocale(), equalTo(Locale.ITALIAN));
    assertThat(configuration.storyReporterBuilder().outputDirectory().getName(), equalTo("my-output-directory"));
    assertThat(configuration.storyReporterBuilder().viewResources().getProperty("index"), equalTo("my-reports-index.ftl"));
    assertThat(configuration.storyReporterBuilder().viewResources().getProperty("decorateNonHtml"), equalTo("true"));
    assertThat(configuration.storyReporterBuilder().reportFailureTrace(), is(true));
}
Also used : SilentlyAbsorbingFailure(org.jbehave.core.failures.SilentlyAbsorbingFailure) RegexPrefixCapturingPatternParser(org.jbehave.core.parsers.RegexPrefixCapturingPatternParser) LoadFromURL(org.jbehave.core.io.LoadFromURL) Keywords(org.jbehave.core.configuration.Keywords) LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) AnnotationBuilder(org.jbehave.core.configuration.AnnotationBuilder) LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 4 with RegexPrefixCapturingPatternParser

use of org.jbehave.core.parsers.RegexPrefixCapturingPatternParser in project jbehave-core by jbehave.

the class PicoAnnotationBuilderBehaviour method shouldBuildConfigurationFromAnnotations.

@Test
public void shouldBuildConfigurationFromAnnotations() {
    PicoAnnotationBuilder builder = new PicoAnnotationBuilder(AnnotatedUsingPico.class);
    Configuration configuration = builder.buildConfiguration();
    assertThat(configuration.storyControls().dryRun(), is(true));
    assertThat(configuration.storyControls().skipScenariosAfterFailure(), is(true));
    assertThat(configuration.failureStrategy(), instanceOf(SilentlyAbsorbingFailure.class));
    assertThat(configuration.storyLoader(), instanceOf(LoadFromURL.class));
    assertThat(configuration.stepPatternParser(), instanceOf(RegexPrefixCapturingPatternParser.class));
    assertThat(((RegexPrefixCapturingPatternParser) configuration.stepPatternParser()).getPrefix(), equalTo("MyPrefix"));
    assertThatDateIsConvertedWithFormat(configuration.parameterConverters(), new SimpleDateFormat("yyyy-MM-dd"));
    assertThat(configuration.storyReporterBuilder().formats(), hasItems(CONSOLE, HTML, TXT, XML, STATS));
    Keywords keywords = configuration.storyReporterBuilder().keywords();
    assertThat(keywords, instanceOf(LocalizedKeywords.class));
    assertThat(((LocalizedKeywords) keywords).getLocale(), equalTo(Locale.ITALIAN));
    assertThat(configuration.storyReporterBuilder().outputDirectory().getName(), equalTo("my-output-directory"));
    assertThat(configuration.storyReporterBuilder().viewResources().getProperty("index"), equalTo("my-reports-index.ftl"));
    assertThat(configuration.storyReporterBuilder().viewResources().getProperty("decorateNonHtml"), equalTo("true"));
    assertThat(configuration.storyReporterBuilder().reportFailureTrace(), is(true));
}
Also used : SilentlyAbsorbingFailure(org.jbehave.core.failures.SilentlyAbsorbingFailure) RegexPrefixCapturingPatternParser(org.jbehave.core.parsers.RegexPrefixCapturingPatternParser) LoadFromURL(org.jbehave.core.io.LoadFromURL) Keywords(org.jbehave.core.configuration.Keywords) LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 5 with RegexPrefixCapturingPatternParser

use of org.jbehave.core.parsers.RegexPrefixCapturingPatternParser in project jbehave-core by jbehave.

the class WeldAnnotationBuilderBehaviour method shouldBuildConfigurationFromAnnotations.

@Test
public void shouldBuildConfigurationFromAnnotations() {
    AnnotationBuilder builder = createBuilder(AnnotatedUsingWeld.class);
    Configuration configuration = builder.buildConfiguration();
    assertThat(configuration.storyControls().dryRun(), is(true));
    assertThat(configuration.storyControls().skipScenariosAfterFailure(), is(true));
    assertThat(configuration.failureStrategy(), instanceOf(SilentlyAbsorbingFailure.class));
    assertThat(configuration.storyLoader(), instanceOf(LoadFromURL.class));
    assertThat(configuration.stepPatternParser(), instanceOf(RegexPrefixCapturingPatternParser.class));
    assertThat(((RegexPrefixCapturingPatternParser) configuration.stepPatternParser()).getPrefix(), equalTo("MyPrefix"));
    assertThatCustomObjectIsConverted(configuration.parameterConverters());
    assertThatDateIsConvertedWithFormat(configuration.parameterConverters(), new SimpleDateFormat("yyyy-MM-dd"));
    assertThat(configuration.storyReporterBuilder().formats(), hasItems(CONSOLE, HTML, TXT, XML, STATS));
    Keywords keywords = configuration.storyReporterBuilder().keywords();
    assertThat(keywords, instanceOf(LocalizedKeywords.class));
    assertThat(((LocalizedKeywords) keywords).getLocale(), equalTo(Locale.ITALIAN));
    assertThat(configuration.storyReporterBuilder().outputDirectory().getName(), equalTo("my-output-directory"));
    assertThat(configuration.storyReporterBuilder().viewResources().getProperty("index"), equalTo("my-reports-index.ftl"));
    assertThat(configuration.storyReporterBuilder().viewResources().getProperty("decorateNonHtml"), equalTo("true"));
    assertThat(configuration.storyReporterBuilder().reportFailureTrace(), is(true));
}
Also used : SilentlyAbsorbingFailure(org.jbehave.core.failures.SilentlyAbsorbingFailure) RegexPrefixCapturingPatternParser(org.jbehave.core.parsers.RegexPrefixCapturingPatternParser) LoadFromURL(org.jbehave.core.io.LoadFromURL) Keywords(org.jbehave.core.configuration.Keywords) LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) AnnotationBuilder(org.jbehave.core.configuration.AnnotationBuilder) LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Aggregations

RegexPrefixCapturingPatternParser (org.jbehave.core.parsers.RegexPrefixCapturingPatternParser)8 MostUsefulConfiguration (org.jbehave.core.configuration.MostUsefulConfiguration)6 LocalizedKeywords (org.jbehave.core.i18n.LocalizedKeywords)6 SimpleDateFormat (java.text.SimpleDateFormat)5 SilentlyAbsorbingFailure (org.jbehave.core.failures.SilentlyAbsorbingFailure)5 LoadFromURL (org.jbehave.core.io.LoadFromURL)5 Test (org.junit.Test)5 Keywords (org.jbehave.core.configuration.Keywords)4 Configuration (org.jbehave.core.configuration.Configuration)3 TableTransformers (org.jbehave.core.model.TableTransformers)3 AnnotationBuilder (org.jbehave.core.configuration.AnnotationBuilder)2 LoadFromClasspath (org.jbehave.core.io.LoadFromClasspath)2 StoryReporterBuilder (org.jbehave.core.reporters.StoryReporterBuilder)2 ParameterConverters (org.jbehave.core.steps.ParameterConverters)2 StepsContext (org.jbehave.core.steps.context.StepsContext)2 Method (java.lang.reflect.Method)1 Properties (java.util.Properties)1 Produces (javax.enterprise.inject.Produces)1 WeldConfiguration (org.jbehave.core.annotations.weld.WeldConfiguration)1 StartingWordNotFound (org.jbehave.core.configuration.Keywords.StartingWordNotFound)1