Search in sources :

Example 11 with LoadFromClasspath

use of org.jbehave.core.io.LoadFromClasspath 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 12 with LoadFromClasspath

use of org.jbehave.core.io.LoadFromClasspath 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)

Example 13 with LoadFromClasspath

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

the class ReportTransformBehaviour method runStories.

private void runStories(String... storyPaths) {
    StoryReporterBuilder storyReporterBuilder = new StoryReporterBuilder().withDefaultFormats().withCodeLocation(CodeLocations.codeLocationFromClass(ReportTransformBehaviour.class)).withFormats(Format.XML);
    Configuration configuration = new MostUsefulConfiguration().useStoryLoader(new LoadFromClasspath(this.getClass())).useStoryReporterBuilder(storyReporterBuilder).useFailureStrategy(new SilentlyAbsorbingFailure()).useStepCollector(new MarkUnmatchedStepsAsPending(new StepFinder(new ByLevenshteinDistance())));
    Embedder embedder = new Embedder();
    embedder.useEmbedderControls(new EmbedderControls().doGenerateViewAfterStories(false));
    embedder.useConfiguration(configuration);
    embedder.useCandidateSteps(new InstanceStepsFactory(configuration, new MySteps()).createCandidateSteps());
    embedder.useMetaFilters(asList("-skip true"));
    try {
        embedder.runStoriesAsPaths(asList(storyPaths));
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : StoryReporterBuilder(org.jbehave.core.reporters.StoryReporterBuilder) StepFinder(org.jbehave.core.steps.StepFinder) Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) Embedder(org.jbehave.core.embedder.Embedder) FileNotFoundException(java.io.FileNotFoundException) SilentlyAbsorbingFailure(org.jbehave.core.failures.SilentlyAbsorbingFailure) ByLevenshteinDistance(org.jbehave.core.steps.StepFinder.ByLevenshteinDistance) LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath) InstanceStepsFactory(org.jbehave.core.steps.InstanceStepsFactory) EmbedderControls(org.jbehave.core.embedder.EmbedderControls) MarkUnmatchedStepsAsPending(org.jbehave.core.steps.MarkUnmatchedStepsAsPending)

Example 14 with LoadFromClasspath

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

the class ReportTransformBehaviour method runStories.

private void runStories(String... storyPaths) {
    StoryReporterBuilder storyReporterBuilder = new StoryReporterBuilder().withDefaultFormats().withCodeLocation(CodeLocations.codeLocationFromClass(ReportTransformBehaviour.class)).withFormats(Format.XML);
    Configuration configuration = new MostUsefulConfiguration().useStoryLoader(new LoadFromClasspath(this.getClass())).useStoryReporterBuilder(storyReporterBuilder).useFailureStrategy(new SilentlyAbsorbingFailure()).useStepCollector(new MarkUnmatchedStepsAsPending(new StepFinder(new ByLevenshteinDistance())));
    Embedder embedder = new Embedder();
    embedder.useEmbedderControls(new EmbedderControls().doGenerateViewAfterStories(false));
    embedder.useConfiguration(configuration);
    embedder.useCandidateSteps(new InstanceStepsFactory(configuration, new MySteps()).createCandidateSteps());
    embedder.useMetaFilters(asList("-skip true"));
    try {
        embedder.runStoriesAsPaths(asList(storyPaths));
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : StoryReporterBuilder(org.jbehave.core.reporters.StoryReporterBuilder) StepFinder(org.jbehave.core.steps.StepFinder) Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) Embedder(org.jbehave.core.embedder.Embedder) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SilentlyAbsorbingFailure(org.jbehave.core.failures.SilentlyAbsorbingFailure) ByLevenshteinDistance(org.jbehave.core.steps.StepFinder.ByLevenshteinDistance) LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath) InstanceStepsFactory(org.jbehave.core.steps.InstanceStepsFactory) EmbedderControls(org.jbehave.core.embedder.EmbedderControls) MarkUnmatchedStepsAsPending(org.jbehave.core.steps.MarkUnmatchedStepsAsPending)

Example 15 with LoadFromClasspath

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

the class LocalizedStories method configuration.

@Override
public Configuration configuration() {
    ClassLoader classLoader = this.getClass().getClassLoader();
    URL codeLocation = CodeLocations.codeLocationFromClass(this.getClass());
    Keywords keywords = new LocalizedKeywords(locale());
    Properties properties = new Properties();
    properties.setProperty("reports", "ftl/jbehave-reports.ftl");
    properties.setProperty("encoding", "UTF-8");
    LoadFromClasspath resourceLoader = new LoadFromClasspath(classLoader);
    TableTransformers tableTransformers = new TableTransformers();
    ParameterControls parameterControls = new ParameterControls();
    ParameterConverters parameterConverters = new ParameterConverters(resourceLoader, parameterControls, tableTransformers, true).addConverters(customConverters(keywords, resourceLoader, tableTransformers));
    return new MostUsefulConfiguration().useKeywords(keywords).useStepCollector(new MarkUnmatchedStepsAsPending(keywords)).useStoryParser(new RegexStoryParser(keywords, resourceLoader, tableTransformers)).useStoryLoader(resourceLoader).useStoryReporterBuilder(new StoryReporterBuilder().withCodeLocation(codeLocation).withPathResolver(new ResolveToSimpleName()).withDefaultFormats().withFormats(CONSOLE, TXT, HTML, XML).withFailureTrace(false).withViewResources(properties).withKeywords(keywords)).useParameterConverters(parameterConverters).useParameterControls(parameterControls).useTableTransformers(tableTransformers);
}
Also used : StoryReporterBuilder(org.jbehave.core.reporters.StoryReporterBuilder) Keywords(org.jbehave.core.configuration.Keywords) LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) ParameterControls(org.jbehave.core.steps.ParameterControls) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) Properties(java.util.Properties) URL(java.net.URL) TableTransformers(org.jbehave.core.model.TableTransformers) RegexStoryParser(org.jbehave.core.parsers.RegexStoryParser) LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath) ParameterConverters(org.jbehave.core.steps.ParameterConverters) MarkUnmatchedStepsAsPending(org.jbehave.core.steps.MarkUnmatchedStepsAsPending) ResolveToSimpleName(org.jbehave.core.reporters.FilePrintStreamFactory.ResolveToSimpleName)

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