Search in sources :

Example 11 with TableTransformers

use of org.jbehave.core.model.TableTransformers in project jbehave-core by jbehave.

the class CoreStory method configuration.

@Override
public Configuration configuration() {
    Class<? extends Embeddable> embeddableClass = this.getClass();
    Properties viewResources = new Properties();
    viewResources.put("decorateNonHtml", "true");
    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().useStoryControls(new StoryControls().doDryRun(false).doSkipScenariosAfterFailure(false)).useStoryLoader(resourceLoader).useStoryParser(new RegexStoryParser(examplesTableFactory)).useStoryPathResolver(new UnderscoredCamelCaseResolver()).useStoryReporterBuilder(new StoryReporterBuilder().withCodeLocation(CodeLocations.codeLocationFromClass(embeddableClass)).withDefaultFormats().withPathResolver(new ResolveToPackagedName()).withViewResources(viewResources).withFormats(CONSOLE, TXT, HTML_TEMPLATE, XML).withCrossReference(xref).withFailureTrace(true).withFailureTraceCompression(true)).useParameterConverters(parameterConverters).useParameterControls(parameterControls).useTableTransformers(tableTransformers);
}
Also used : StoryReporterBuilder(org.jbehave.core.reporters.StoryReporterBuilder) 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) StoryControls(org.jbehave.core.embedder.StoryControls) Properties(java.util.Properties) TableTransformers(org.jbehave.core.model.TableTransformers) UnderscoredCamelCaseResolver(org.jbehave.core.io.UnderscoredCamelCaseResolver) 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) ResolveToPackagedName(org.jbehave.core.reporters.FilePrintStreamFactory.ResolveToPackagedName)

Example 12 with TableTransformers

use of org.jbehave.core.model.TableTransformers in project jbehave-core by jbehave.

the class RegexStoryParserBehaviour method shouldParseStoryWithLifecycleAfterUponOutcomeInNonEnglishLocale.

@Test
public void shouldParseStoryWithLifecycleAfterUponOutcomeInNonEnglishLocale() {
    String wholeStory = "Lebenszyklus: " + NL + "Nach:" + NL + NL + "Ergebnis: JEDES " + NL + "Gegeben im Lager sind 200 T-Shirts" + NL + "Ergebnis: ERFOLG " + NL + "Gegeben im Lager sind 300 T-Shirts" + NL + "Ergebnis: FEHLER " + NL + "Gegeben im Lager sind 400 T-Shirts" + NL + "Szenario:" + NL + "Wenn ein Kunde 20 T-Shirts bestellt";
    parser = new RegexStoryParser(new LocalizedKeywords(Locale.GERMAN), new LoadFromClasspath(), new TableTransformers());
    Story story = parser.parseStory(wholeStory, storyPath);
    List<String> beforeSteps = story.getLifecycle().getBeforeSteps();
    assertThat(beforeSteps.isEmpty(), equalTo(true));
    Lifecycle lifecycle = story.getLifecycle();
    List<String> afterSteps = lifecycle.getAfterSteps();
    assertThat(afterSteps.get(0), equalTo("Gegeben im Lager sind 200 T-Shirts"));
    assertThat(afterSteps.get(1), equalTo("Gegeben im Lager sind 300 T-Shirts"));
    assertThat(afterSteps.get(2), equalTo("Gegeben im Lager sind 400 T-Shirts"));
    assertThat(lifecycle.getAfterSteps(Outcome.ANY).size(), equalTo(1));
    assertThat(lifecycle.getAfterSteps(Outcome.ANY).get(0), equalTo("Gegeben im Lager sind 200 T-Shirts"));
    assertThat(lifecycle.getAfterSteps(Outcome.SUCCESS).size(), equalTo(1));
    assertThat(lifecycle.getAfterSteps(Outcome.SUCCESS).get(0), equalTo("Gegeben im Lager sind 300 T-Shirts"));
    assertThat(lifecycle.getAfterSteps(Outcome.FAILURE).size(), equalTo(1));
    assertThat(lifecycle.getAfterSteps(Outcome.FAILURE).get(0), equalTo("Gegeben im Lager sind 400 T-Shirts"));
    Scenario scenario = story.getScenarios().get(0);
    List<String> steps = scenario.getSteps();
    assertThat(steps.get(0), equalTo("Wenn ein Kunde 20 T-Shirts bestellt"));
}
Also used : LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath) Lifecycle(org.jbehave.core.model.Lifecycle) LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) Matchers.containsString(org.hamcrest.Matchers.containsString) GivenStory(org.jbehave.core.model.GivenStory) Story(org.jbehave.core.model.Story) TableTransformers(org.jbehave.core.model.TableTransformers) Scenario(org.jbehave.core.model.Scenario) Test(org.junit.Test)

Example 13 with TableTransformers

use of org.jbehave.core.model.TableTransformers 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 14 with TableTransformers

use of org.jbehave.core.model.TableTransformers in project jbehave-core by jbehave.

the class StepCreatorBehaviour method shouldMatchParametersByDelimitedNameWithDistinctNamedAnnotations.

@SuppressWarnings("unchecked")
@Test
public void shouldMatchParametersByDelimitedNameWithDistinctNamedAnnotations() throws Exception {
    // Given
    SomeSteps stepsInstance = new SomeSteps();
    parameterConverters = new ParameterConverters(new LoadFromClasspath(), new TableTransformers());
    StepMatcher stepMatcher = mock(StepMatcher.class);
    ParameterControls parameterControls = new ParameterControls().useDelimiterNamedParameters(true);
    StepCreator stepCreator = stepCreatorUsing(stepsInstance, stepMatcher, parameterControls);
    Map<String, String> params = new HashMap<>();
    params.put("t", "distinct theme");
    params.put("v", "distinct variant");
    when(stepMatcher.parameterNames()).thenReturn(params.keySet().toArray(new String[params.size()]));
    when(stepMatcher.parameter(1)).thenReturn("<t>");
    when(stepMatcher.parameter(2)).thenReturn("<v>");
    // When
    Step step = stepCreator.createParametrisedStep(SomeSteps.methodFor("aMethodWithANamedParameter"), "When I use parameters <t> and <v>", "I use parameters <t> and <v>", params);
    step.perform(null);
    // Then
    Map<String, String> results = (Map<String, String>) stepsInstance.args;
    assertThat(results.get("theme"), equalTo("distinct theme"));
    assertThat(results.get("variant"), equalTo("distinct variant"));
}
Also used : RegexStepMatcher(org.jbehave.core.parsers.RegexStepMatcher) StepMatcher(org.jbehave.core.parsers.StepMatcher) HashMap(java.util.HashMap) LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath) Matchers.anyString(org.mockito.Matchers.anyString) ParametrisedStep(org.jbehave.core.steps.StepCreator.ParametrisedStep) HashMap(java.util.HashMap) Map(java.util.Map) TableTransformers(org.jbehave.core.model.TableTransformers) Test(org.junit.Test)

Example 15 with TableTransformers

use of org.jbehave.core.model.TableTransformers in project jbehave-core by jbehave.

the class StepCreatorBehaviour method shouldMatchParametersByDelimitedNameWithNoNamedAnnotations.

@Test
public void shouldMatchParametersByDelimitedNameWithNoNamedAnnotations() throws Exception {
    // Given
    SomeSteps stepsInstance = new SomeSteps();
    parameterConverters = new ParameterConverters(new LoadFromClasspath(), new TableTransformers());
    StepMatcher stepMatcher = mock(StepMatcher.class);
    ParameterControls parameterControls = new ParameterControls().useDelimiterNamedParameters(true);
    StepCreator stepCreator = stepCreatorUsing(stepsInstance, stepMatcher, parameterControls);
    Map<String, String> params = Collections.singletonMap("param", "value");
    when(stepMatcher.parameterNames()).thenReturn(params.keySet().toArray(new String[params.size()]));
    when(stepMatcher.parameter(1)).thenReturn("<param>");
    // When
    Step step = stepCreator.createParametrisedStep(SomeSteps.methodFor("aMethodWithoutNamedAnnotation"), "When a parameter <param> is set", "a parameter <param> is set", params);
    step.perform(null);
    // Then
    assertThat((String) stepsInstance.args, equalTo("value"));
}
Also used : RegexStepMatcher(org.jbehave.core.parsers.RegexStepMatcher) StepMatcher(org.jbehave.core.parsers.StepMatcher) LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath) Matchers.anyString(org.mockito.Matchers.anyString) ParametrisedStep(org.jbehave.core.steps.StepCreator.ParametrisedStep) TableTransformers(org.jbehave.core.model.TableTransformers) Test(org.junit.Test)

Aggregations

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