Search in sources :

Example 1 with TableTransformers

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

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

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

the class ParameterConvertersBehaviour method shouldConvertMultilineTable.

@Test
public void shouldConvertMultilineTable() {
    ParameterConverter<ExamplesTable> converter = new ExamplesTableConverter(new ExamplesTableFactory(new LoadFromClasspath(), new TableTransformers()));
    Type type = ExamplesTable.class;
    assertThatTypesAreAccepted(converter, type);
    String value = "|col1|col2|\n|row11|row12|\n|row21|row22|\n";
    ExamplesTable table = converter.convertValue(value, type);
    assertThat(table.getRowCount(), is(2));
    Map<String, String> row1 = table.getRow(0);
    assertThat(row1.get("col1"), is("row11"));
    assertThat(row1.get("col2"), is("row12"));
    Map<String, String> row2 = table.getRow(1);
    assertThat(row2.get("col1"), is("row21"));
    assertThat(row2.get("col2"), is("row22"));
}
Also used : Type(java.lang.reflect.Type) LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath) ExamplesTable(org.jbehave.core.model.ExamplesTable) ExamplesTableFactory(org.jbehave.core.model.ExamplesTableFactory) ExamplesTableConverter(org.jbehave.core.steps.ParameterConverters.ExamplesTableConverter) TableTransformers(org.jbehave.core.model.TableTransformers) Test(org.junit.Test)

Example 4 with TableTransformers

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

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

the class ConcurrencyBehaviour method shouldAllowConcurrentAdditionOfParameterConvertersInThreadSafeMode.

@Test
public void shouldAllowConcurrentAdditionOfParameterConvertersInThreadSafeMode() {
    final ParameterConverters parameterConverters = new ParameterConverters(new LoadFromClasspath(), new ParameterControls(), new TableTransformers(), true);
    final boolean[] active = new boolean[] { true };
    final ParameterConverter[] toAdd = new ParameterConverter[] { mock(ParameterConverter.class, "one"), mock(ParameterConverter.class, "two"), mock(ParameterConverter.class, "three") };
    Thread t = new Thread(new Runnable() {

        @Override
        public void run() {
            while (active[0]) {
                parameterConverters.addConverters(toAdd);
            }
        }
    });
    t.start();
    parameterConverters.convert("test", String.class);
    active[0] = false;
}
Also used : ParameterConverter(org.jbehave.core.steps.ParameterConverters.ParameterConverter) LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath) 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