Search in sources :

Example 21 with LoadFromClasspath

use of org.jbehave.core.io.LoadFromClasspath in project jbehave-core by jbehave.

the class TransformingStoryParserBehaviour method shouldTransformAndParseStory.

@Test
public void shouldTransformAndParseStory() {
    StoryParser delegate = new RegexStoryParser(new LoadFromClasspath(), new TableTransformers());
    StoryTransformer transformer = new StoryTransformer() {

        @Override
        public String transform(String storyAsText) {
            return storyAsText.replaceAll(",", "|");
        }
    };
    StoryParser parser = new TransformingStoryParser(delegate, transformer);
    String storyAsText = "Scenario: a scenario " + NL + "Given a scenario Given" + NL + "When I parse it to When" + NL + "And I parse it to And" + NL + "!-- And ignore me too" + NL + "Then I should get steps Then" + NL + "Examples:" + NL + ",Given,When,Then,And," + NL + ",Dato che,Quando,Allora,E,";
    Story story = parser.parseStory(storyAsText);
    assertThat(story.getScenarios().get(0).getExamplesTable().getRowCount(), equalTo(1));
}
Also used : LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath) Story(org.jbehave.core.model.Story) TableTransformers(org.jbehave.core.model.TableTransformers) Test(org.junit.Test)

Example 22 with LoadFromClasspath

use of org.jbehave.core.io.LoadFromClasspath in project jbehave-core by jbehave.

the class StoryRunnerBehaviour method configurationWithPendingStrategy.

private Configuration configurationWithPendingStrategy(StepCollector collector, StoryReporter reporter, PendingStepStrategy strategy) {
    LoadFromClasspath resourceLoadder = new LoadFromClasspath();
    RegexStoryParser storyParser = new RegexStoryParser(resourceLoadder, new TableTransformers());
    return configurationWith(storyParser, resourceLoadder, reporter, collector, new RethrowingFailure(), strategy);
}
Also used : RegexStoryParser(org.jbehave.core.parsers.RegexStoryParser) LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath)

Example 23 with LoadFromClasspath

use of org.jbehave.core.io.LoadFromClasspath in project jbehave-core by jbehave.

the class StoryRunnerBehaviour method configurationWith.

private Configuration configurationWith(StoryReporter reporter, StepCollector collector, FailureStrategy failureStrategy) {
    LoadFromClasspath resourceLoadder = new LoadFromClasspath();
    RegexStoryParser storyParser = new RegexStoryParser(resourceLoadder, new TableTransformers());
    return configurationWith(storyParser, resourceLoadder, reporter, collector, failureStrategy);
}
Also used : RegexStoryParser(org.jbehave.core.parsers.RegexStoryParser) LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath)

Example 24 with LoadFromClasspath

use of org.jbehave.core.io.LoadFromClasspath in project jbehave-core by jbehave.

the class ExamplesTableBehaviour method shouldParseTableWithDifferentSeparators.

@Test
public void shouldParseTableWithDifferentSeparators() {
    String headerSeparator = "||";
    String valueSeparator = "|";
    String tableWithCustomSeparator = wikiTableAsString;
    TableTransformers tableTransformers = new TableTransformers();
    ParameterControls parameterControls = new ParameterControls();
    ParameterConverters parameterConverters = new ParameterConverters(new LoadFromClasspath(), parameterControls, tableTransformers, true);
    ExamplesTable table = new ExamplesTable(tableWithCustomSeparator, headerSeparator, valueSeparator, parameterConverters, parameterControls, tableTransformers);
    assertThat(table.getHeaderSeparator(), equalTo(headerSeparator));
    assertThat(table.getValueSeparator(), equalTo(valueSeparator));
    ensureColumnOrderIsPreserved(table);
    assertThat(table.asString(), equalTo(tableWithCustomSeparator));
}
Also used : ParameterControls(org.jbehave.core.steps.ParameterControls) LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath) ParameterConverters(org.jbehave.core.steps.ParameterConverters) Test(org.junit.Test)

Example 25 with LoadFromClasspath

use of org.jbehave.core.io.LoadFromClasspath in project jbehave-core by jbehave.

the class ExamplesTableBehaviour method shouldParseTableWithCustomTransformerSpecifiedViaProperties.

@Test
public void shouldParseTableWithCustomTransformerSpecifiedViaProperties() {
    String tableWithProperties = "{transformer=myTransformer, trim=false}\n" + tableWithCommentsAsString;
    TableTransformers tableTransformers = new TableTransformers();
    tableTransformers.useTransformer("myTransformer", new TableTransformer() {

        @Override
        public String transform(String tableAsString, ExamplesTableProperties properties) {
            return tableWithSpacesAsString;
        }
    });
    ExamplesTable table = new ExamplesTableFactory(new LoadFromClasspath(), tableTransformers).createExamplesTable(tableWithProperties);
    Properties properties = table.getProperties();
    assertThat(properties.getProperty("transformer"), equalTo("myTransformer"));
    ensureWhitespaceIsPreserved(table);
}
Also used : TableTransformer(org.jbehave.core.model.TableTransformers.TableTransformer) LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath) Test(org.junit.Test)

Aggregations

LoadFromClasspath (org.jbehave.core.io.LoadFromClasspath)39 Test (org.junit.Test)27 TableTransformers (org.jbehave.core.model.TableTransformers)22 MostUsefulConfiguration (org.jbehave.core.configuration.MostUsefulConfiguration)9 ParameterConverters (org.jbehave.core.steps.ParameterConverters)9 Type (java.lang.reflect.Type)8 StoryReporterBuilder (org.jbehave.core.reporters.StoryReporterBuilder)8 ExamplesTableFactory (org.jbehave.core.model.ExamplesTableFactory)7 RegexStoryParser (org.jbehave.core.parsers.RegexStoryParser)7 ParameterControls (org.jbehave.core.steps.ParameterControls)7 LocalizedKeywords (org.jbehave.core.i18n.LocalizedKeywords)6 SimpleDateFormat (java.text.SimpleDateFormat)5 RegexStepMatcher (org.jbehave.core.parsers.RegexStepMatcher)5 StepMatcher (org.jbehave.core.parsers.StepMatcher)5 DateConverter (org.jbehave.core.steps.ParameterConverters.DateConverter)5 ParametrisedStep (org.jbehave.core.steps.StepCreator.ParametrisedStep)5 ExamplesTableConverter (org.jbehave.core.steps.ParameterConverters.ExamplesTableConverter)4 ParameterConverter (org.jbehave.core.steps.ParameterConverters.ParameterConverter)4 HashMap (java.util.HashMap)3 Properties (java.util.Properties)3