Search in sources :

Example 36 with Embedder

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

the class RunStoriesAsPaths method execute.

public void execute() throws MojoExecutionException, MojoFailureException {
    Embedder embedder = newEmbedder();
    getLog().info("Running stories as paths using embedder " + embedder);
    try {
        embedder.runStoriesAsPaths(storyPaths());
    } catch (RuntimeException e) {
        throw new MojoFailureException("Failed to run stories as paths", e);
    }
}
Also used : MojoFailureException(org.apache.maven.plugin.MojoFailureException) Embedder(org.jbehave.core.embedder.Embedder)

Example 37 with Embedder

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

the class RunStoriesWithAnnotatedEmbedderRunner method execute.

public void execute() throws MojoExecutionException, MojoFailureException {
    Embedder embedder = newEmbedder();
    getLog().info("Running stories with annotated embedder runner");
    try {
        embedder.runStoriesWithAnnotatedEmbedderRunner(classNames());
    } catch (RuntimeException e) {
        throw new MojoFailureException("Failed to run stories with annotated embedder runner", e);
    }
}
Also used : MojoFailureException(org.apache.maven.plugin.MojoFailureException) Embedder(org.jbehave.core.embedder.Embedder)

Example 38 with Embedder

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

the class EmbedderMojoBehaviour method shouldCreateNewEmbedderWithMavenMonitor.

@Test
public void shouldCreateNewEmbedderWithMavenMonitor() {
    // Given
    Log log = mock(Log.class);
    AbstractEmbedderMojo mojo = new AbstractEmbedderMojo() {

        public void execute() throws MojoExecutionException, MojoFailureException {
        }
    };
    mojo.setLog(log);
    // When
    Embedder embedder = mojo.newEmbedder();
    // Then
    EmbedderMonitor embedderMonitor = embedder.embedderMonitor();
    assertThat(embedderMonitor.toString(), containsString("MavenEmbedderMonitor"));
    // and verify monitor calls are propagated to Mojo Log
    BatchFailures failures = new BatchFailures();
    embedderMonitor.batchFailed(failures);
    verify(log).warn("Failed to run batch " + failures);
    String name = "name";
    Throwable cause = new RuntimeException();
    embedderMonitor.embeddableFailed(name, cause);
    verify(log).warn("Failed to run embeddable " + name, cause);
    List<String> classNames = asList("name1", "name2");
    embedderMonitor.embeddablesSkipped(classNames);
    verify(log).info("Skipped embeddables " + classNames);
    embedderMonitor.runningEmbeddable(name);
    verify(log).info("Running embeddable " + name);
    List<String> storyPaths = asList("/path1", "/path2");
    embedderMonitor.storiesSkipped(storyPaths);
    verify(log).info("Skipped stories " + storyPaths);
    String path = "/path";
    embedderMonitor.storyFailed(path, cause);
    verify(log).warn("Failed to run story " + path, cause);
    embedderMonitor.runningStory(path);
    verify(log).info("Running story " + path);
    Object annotatedInstance = new Object();
    Class<?> type = Object.class;
    embedderMonitor.annotatedInstanceNotOfType(annotatedInstance, type);
    verify(log).warn("Annotated instance " + annotatedInstance + " not of type " + type);
    File outputDirectory = new File("/dir");
    List<String> formats = asList(Format.CONSOLE.name(), Format.HTML.name());
    Properties viewProperties = new Properties();
    embedderMonitor.generatingReportsView(outputDirectory, formats, viewProperties);
    verify(log).info("Generating reports view to '" + outputDirectory + "' using formats '" + formats + "'" + " and view properties '" + viewProperties + "'");
    embedderMonitor.reportsViewGenerationFailed(outputDirectory, formats, viewProperties, cause);
    verify(log).warn("Failed to generate reports view to '" + outputDirectory + "' using formats '" + formats + "'" + " and view properties '" + viewProperties + "'", cause);
    int stories = 2;
    int storiesNotAllowed = 1;
    int storiesPending = 1;
    int scenarios = 4;
    int scenariosFailed = 1;
    int scenariosNotAllowed = 0;
    int scenariosPending = 1;
    int stepsFailed = 1;
    embedderMonitor.reportsViewGenerated(new ReportsCount(stories, storiesNotAllowed, storiesPending, scenarios, scenariosFailed, scenariosNotAllowed, scenariosPending, stepsFailed));
    verify(log).info("Reports view generated with " + stories + " stories (of which " + storiesPending + " pending) containing " + scenarios + " scenarios (of which " + scenariosPending + " pending)");
    verify(log).info("Meta filters excluded " + storiesNotAllowed + " stories and  " + scenariosNotAllowed + " scenarios");
    embedderMonitor.reportsViewNotGenerated();
    verify(log).info("Reports view not generated");
}
Also used : EmbedderMonitor(org.jbehave.core.embedder.EmbedderMonitor) Log(org.apache.maven.plugin.logging.Log) Embedder(org.jbehave.core.embedder.Embedder) InjectableEmbedder(org.jbehave.core.InjectableEmbedder) Matchers.containsString(org.hamcrest.Matchers.containsString) Properties(java.util.Properties) BatchFailures(org.jbehave.core.failures.BatchFailures) ReportsCount(org.jbehave.core.reporters.ReportsCount) File(java.io.File) Test(org.junit.Test)

Example 39 with Embedder

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

the class EmbedderMojoBehaviour method shouldCreateNewEmbedderWithGivenControls.

@Test
public void shouldCreateNewEmbedderWithGivenControls() {
    // Given
    AbstractEmbedderMojo mojo = new AbstractEmbedderMojo() {

        public void execute() throws MojoExecutionException, MojoFailureException {
        }
    };
    // When
    mojo.batch = true;
    mojo.generateViewAfterStories = false;
    mojo.ignoreFailureInStories = true;
    mojo.ignoreFailureInView = true;
    mojo.skip = true;
    mojo.storyTimeouts = "**/longs/BddTest2Long.feature:7";
    mojo.failOnStoryTimeout = true;
    mojo.threads = 2;
    Embedder embedder = mojo.newEmbedder();
    // Then
    EmbedderControls embedderControls = embedder.embedderControls();
    assertThat(embedderControls.batch(), is(true));
    assertThat(embedderControls.generateViewAfterStories(), is(false));
    assertThat(embedderControls.ignoreFailureInStories(), is(true));
    assertThat(embedderControls.ignoreFailureInView(), is(true));
    assertThat(embedderControls.skip(), is(true));
    assertThat(embedderControls.storyTimeouts(), is("**/longs/BddTest2Long.feature:7"));
    assertThat(embedderControls.threads(), is(2));
}
Also used : Embedder(org.jbehave.core.embedder.Embedder) InjectableEmbedder(org.jbehave.core.InjectableEmbedder) EmbedderControls(org.jbehave.core.embedder.EmbedderControls) Test(org.junit.Test)

Example 40 with Embedder

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

the class EmbedderMojoBehaviour method shouldNotUnpackViewResourcesThatDoNotMatchTheFilters.

@Test
public void shouldNotUnpackViewResourcesThatDoNotMatchTheFilters() throws MojoExecutionException, MojoFailureException, NoSuchArchiverException, ArchiverException {
    // Given
    UnpackViewResources mojo = new UnpackViewResources() {

        @Override
        protected Embedder newEmbedder() {
            return new Embedder();
        }
    };
    ArchiverManager archiveManager = mock(ArchiverManager.class);
    MavenProject project = mock(MavenProject.class);
    File resourcesFile = new File("some");
    Artifact someResources = mock(Artifact.class);
    when(someResources.getArtifactId()).thenReturn("some-resources");
    when(someResources.getType()).thenReturn("jar");
    when(someResources.getFile()).thenReturn(resourcesFile);
    Set<Artifact> allArtifacts = new HashSet<>();
    allArtifacts.add(someResources);
    String buildDirectory = "target";
    Build build = new Build();
    build.setDirectory(buildDirectory);
    // When
    mojo.project = project;
    mojo.archiverManager = archiveManager;
    mojo.resourceIncludes = "ftl/*";
    mojo.resourcesExcludes = "com/*";
    when(project.getArtifacts()).thenReturn(allArtifacts);
    when(project.getBuild()).thenReturn(build);
    mojo.execute();
    // Then
    verify(archiveManager, Mockito.never()).getUnArchiver(resourcesFile);
}
Also used : ArchiverManager(org.codehaus.plexus.archiver.manager.ArchiverManager) MavenProject(org.apache.maven.project.MavenProject) Build(org.apache.maven.model.Build) Embedder(org.jbehave.core.embedder.Embedder) InjectableEmbedder(org.jbehave.core.InjectableEmbedder) Matchers.containsString(org.hamcrest.Matchers.containsString) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact) HashSet(java.util.HashSet) Test(org.junit.Test)

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