Search in sources :

Example 1 with Embedder

use of org.jbehave.core.embedder.Embedder in project jbehave-core by jbehave.

the class ConfigurableEmbedderBehaviour method shouldAllowAdditionOfSteps.

@Test
public void shouldAllowAdditionOfSteps() throws Throwable {
    // Given
    Embedder embedder = mock(Embedder.class);
    Configuration configuration = mock(Configuration.class);
    StoryPathResolver pathResolver = mock(StoryPathResolver.class);
    when(embedder.configuration()).thenReturn(configuration);
    when(configuration.storyPathResolver()).thenReturn(pathResolver);
    Class<MyStory> storyClass = MyStory.class;
    String storyPath = "/path/to/story";
    when(pathResolver.resolve(storyClass)).thenReturn(storyPath);
    CandidateSteps steps = mock(CandidateSteps.class);
    // When
    MyStory story = new MyStory(configuration, steps);
    story.useEmbedder(embedder);
    story.run();
    // Then
    verify(embedder).runStoriesAsPaths(asList(storyPath));
}
Also used : StoryPathResolver(org.jbehave.core.io.StoryPathResolver) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) Configuration(org.jbehave.core.configuration.Configuration) Embedder(org.jbehave.core.embedder.Embedder) CandidateSteps(org.jbehave.core.steps.CandidateSteps) Test(org.junit.Test)

Example 2 with Embedder

use of org.jbehave.core.embedder.Embedder in project jbehave-core by jbehave.

the class InjectableEmbedderBehaviour method shouldRunStoriesAsPathsUsingInjected.

@Test
public void shouldRunStoriesAsPathsUsingInjected() throws Throwable {
    // Given
    Embedder embedder = mock(Embedder.class);
    // When
    StoriesAsPaths stories = new StoriesAsPaths();
    stories.useEmbedder(embedder);
    stories.run();
    // Then
    verify(embedder).runStoriesAsPaths(asList("org/jbehave/core/story1", "org/jbehave/core/story2"));
}
Also used : Embedder(org.jbehave.core.embedder.Embedder) Test(org.junit.Test)

Example 3 with Embedder

use of org.jbehave.core.embedder.Embedder in project jbehave-core by jbehave.

the class AnnotationBuilderBehaviour method shouldCreateEmbeddableInstanceFromInjectableEmbedderWithoutStepsFactory.

@Test
public void shouldCreateEmbeddableInstanceFromInjectableEmbedderWithoutStepsFactory() {
    AnnotationBuilder annotatedInjectable = new AnnotationBuilder(AnnotedInjectableWithoutStepsFactory.class);
    Object instance = annotatedInjectable.embeddableInstance();
    assertThat(instance, Matchers.instanceOf(InjectableEmbedder.class));
    Embedder embedder = ((InjectableEmbedder) instance).injectedEmbedder();
    assertThat(embedder.configuration().keywords(), instanceOf(MyKeywords.class));
    assertThat(embedder.metaFilters(), equalTo(asList("+embedder injectable")));
    assertThatStepsInstancesAre(embedder.candidateSteps(), MySteps.class);
}
Also used : InjectableEmbedder(org.jbehave.core.InjectableEmbedder) UsingEmbedder(org.jbehave.core.annotations.UsingEmbedder) ConfigurableEmbedder(org.jbehave.core.ConfigurableEmbedder) InjectableEmbedder(org.jbehave.core.InjectableEmbedder) Embedder(org.jbehave.core.embedder.Embedder) Test(org.junit.Test)

Example 4 with Embedder

use of org.jbehave.core.embedder.Embedder in project jbehave-core by jbehave.

the class AnnotationBuilderBehaviour method shouldCreateEmbeddableInstanceFromInjectableEmbedder.

@Test
public void shouldCreateEmbeddableInstanceFromInjectableEmbedder() {
    AnnotationBuilder annotatedInjectable = new AnnotationBuilder(AnnotedInjectable.class);
    Object instance = annotatedInjectable.embeddableInstance();
    assertThat(instance, Matchers.instanceOf(InjectableEmbedder.class));
    Embedder embedder = ((InjectableEmbedder) instance).injectedEmbedder();
    assertThat(embedder.configuration().keywords(), instanceOf(MyKeywords.class));
    assertThat(embedder.metaFilters(), equalTo(asList("+embedder injectable")));
    assertThat(embedder.systemProperties().getProperty("one"), equalTo("One"));
    assertThat(embedder.systemProperties().getProperty("two"), equalTo("Two"));
    assertThatStepsInstancesAre(embedder.stepsFactory().createCandidateSteps(), MySteps.class);
}
Also used : InjectableEmbedder(org.jbehave.core.InjectableEmbedder) UsingEmbedder(org.jbehave.core.annotations.UsingEmbedder) ConfigurableEmbedder(org.jbehave.core.ConfigurableEmbedder) InjectableEmbedder(org.jbehave.core.InjectableEmbedder) Embedder(org.jbehave.core.embedder.Embedder) Test(org.junit.Test)

Example 5 with Embedder

use of org.jbehave.core.embedder.Embedder 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)

Aggregations

Embedder (org.jbehave.core.embedder.Embedder)56 Test (org.junit.Test)33 InjectableEmbedder (org.jbehave.core.InjectableEmbedder)25 ConfigurableEmbedder (org.jbehave.core.ConfigurableEmbedder)10 MojoFailureException (org.apache.maven.plugin.MojoFailureException)8 EmbedderControls (org.jbehave.core.embedder.EmbedderControls)7 Configuration (org.jbehave.core.configuration.Configuration)6 MostUsefulConfiguration (org.jbehave.core.configuration.MostUsefulConfiguration)6 File (java.io.File)5 Properties (java.util.Properties)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 UsingEmbedder (org.jbehave.core.annotations.UsingEmbedder)5 CandidateSteps (org.jbehave.core.steps.CandidateSteps)5 StoryPathResolver (org.jbehave.core.io.StoryPathResolver)4 HashSet (java.util.HashSet)3 Artifact (org.apache.maven.artifact.Artifact)3 Build (org.apache.maven.model.Build)3 MavenProject (org.apache.maven.project.MavenProject)3 ArchiverManager (org.codehaus.plexus.archiver.manager.ArchiverManager)3 StoryFinder (org.jbehave.core.io.StoryFinder)3