Search in sources :

Example 1 with LocalizedKeywords

use of org.jbehave.core.i18n.LocalizedKeywords 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 2 with LocalizedKeywords

use of org.jbehave.core.i18n.LocalizedKeywords 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 3 with LocalizedKeywords

use of org.jbehave.core.i18n.LocalizedKeywords in project jbehave-core by jbehave.

the class RegexStoryParserBehaviour method shouldParseStoryWithSynonymsOfStartingWords.

@Test
public void shouldParseStoryWithSynonymsOfStartingWords() {
    StoryParser parser = new RegexStoryParser(new LocalizedKeywords(new Locale("sy")));
    String wholeStory = "Given a scenario" + NL + "When I parse it" + NL + "And I parse it again" + NL + "With another parse as well" + NL + "!-- ignore me" + NL + "Giveth another scenario" + NL + "With a merry go round";
    Story story = parser.parseStory(wholeStory, storyPath);
    List<String> steps = story.getScenarios().get(0).getSteps();
    assertThat(steps.get(0), equalTo("Given a scenario"));
    assertThat(steps.get(1), equalTo("When I parse it"));
    assertThat(steps.get(2), equalTo("And I parse it again"));
    assertThat(steps.get(3), equalTo("With another parse as well"));
    assertThat(steps.get(4), equalTo("!-- ignore me"));
    assertThat(steps.get(5), equalTo("Giveth another scenario"));
    assertThat(steps.get(6), equalTo("With a merry go round"));
}
Also used : Locale(java.util.Locale) LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) Matchers.containsString(org.hamcrest.Matchers.containsString) GivenStory(org.jbehave.core.model.GivenStory) Story(org.jbehave.core.model.Story) Test(org.junit.Test)

Example 4 with LocalizedKeywords

use of org.jbehave.core.i18n.LocalizedKeywords in project jbehave-core by jbehave.

the class CrossReferenceBehaviour method performableRoot.

private PerformableRoot performableRoot() {
    PerformableRoot root = new PerformableRoot();
    Story story = new Story("/path/to/story", new Description("An interesting story"), new Meta(Arrays.asList("+theme testing", "+author Mauro")), new Narrative("renovate my house", "customer", "get a loan"), new ArrayList<Scenario>());
    PerformableStory performableStory = new PerformableStory(story, new LocalizedKeywords(), false);
    root.add(performableStory);
    Scenario scenario = new Scenario(Arrays.asList(""));
    PerformableScenario performableScenario = new PerformableScenario(scenario, story.getPath());
    performableStory.add(performableScenario);
    List<StepMatch> stepMatches = new ArrayList<>();
    stepMatches.add(new StepMatch(new StepPattern(StepType.GIVEN, "(def)", "[abc]")));
    NormalPerformableScenario normalScenario = new NormalPerformableScenario(scenario);
    normalScenario.addSteps(new PerformableSteps(null, stepMatches));
    performableScenario.useNormalScenario(normalScenario);
    return root;
}
Also used : ArrayList(java.util.ArrayList) LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) StepMatch(org.jbehave.core.embedder.MatchingStepMonitor.StepMatch)

Example 5 with LocalizedKeywords

use of org.jbehave.core.i18n.LocalizedKeywords 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)

Aggregations

LocalizedKeywords (org.jbehave.core.i18n.LocalizedKeywords)35 Test (org.junit.Test)23 Properties (java.util.Properties)14 MostUsefulConfiguration (org.jbehave.core.configuration.MostUsefulConfiguration)10 Locale (java.util.Locale)8 Keywords (org.jbehave.core.configuration.Keywords)8 SimpleDateFormat (java.text.SimpleDateFormat)7 UUIDExceptionWrapper (org.jbehave.core.failures.UUIDExceptionWrapper)7 TableTransformers (org.jbehave.core.model.TableTransformers)7 Configuration (org.jbehave.core.configuration.Configuration)6 LoadFromClasspath (org.jbehave.core.io.LoadFromClasspath)6 RegexPrefixCapturingPatternParser (org.jbehave.core.parsers.RegexPrefixCapturingPatternParser)6 SilentlyAbsorbingFailure (org.jbehave.core.failures.SilentlyAbsorbingFailure)5 LoadFromURL (org.jbehave.core.io.LoadFromURL)5 StoryReporterBuilder (org.jbehave.core.reporters.StoryReporterBuilder)5 ParameterConverters (org.jbehave.core.steps.ParameterConverters)5 RegexStoryParser (org.jbehave.core.parsers.RegexStoryParser)4 ArrayList (java.util.ArrayList)3 StoryLocation (org.jbehave.core.io.StoryLocation)3 ExamplesTableFactory (org.jbehave.core.model.ExamplesTableFactory)3