Search in sources :

Example 41 with Embedder

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

the class EmbedderMojoBehaviour method shouldUnpackViewResources.

@Test
public void shouldUnpackViewResources() 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 coreFile = new File("core");
    Artifact coreResources = mock(Artifact.class);
    when(coreResources.getArtifactId()).thenReturn("jbehave-core");
    when(coreResources.getType()).thenReturn("zip");
    when(coreResources.getFile()).thenReturn(coreFile);
    File siteFile = new File("site");
    Artifact siteResources = mock(Artifact.class);
    when(siteResources.getArtifactId()).thenReturn("jbehave-site-resources");
    when(siteResources.getType()).thenReturn("zip");
    when(siteResources.getFile()).thenReturn(siteFile);
    Set<Artifact> allArtifacts = new HashSet<>();
    allArtifacts.add(coreResources);
    allArtifacts.add(siteResources);
    String buildDirectory = "target";
    Build build = new Build();
    build.setDirectory(buildDirectory);
    UnArchiver coreArchiver = mock(UnArchiver.class);
    UnArchiver siteArchiver = mock(UnArchiver.class);
    // When
    mojo.project = project;
    mojo.archiverManager = archiveManager;
    mojo.resourceIncludes = "ftl/*";
    mojo.resourcesExcludes = "com/*";
    when(project.getArtifacts()).thenReturn(allArtifacts);
    when(project.getBuild()).thenReturn(build);
    when(archiveManager.getUnArchiver(coreFile)).thenReturn(coreArchiver);
    when(archiveManager.getUnArchiver(siteFile)).thenReturn(siteArchiver);
    // default view directory
    unpackTo(mojo, null);
    unpackTo(mojo, new File(System.getProperty("java.io.tmpdir") + "/jbehave/view"));
    // Then
    verify(coreArchiver, times(2)).extract();
    verify(siteArchiver, times(2)).extract();
}
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) UnArchiver(org.codehaus.plexus.archiver.UnArchiver) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 42 with Embedder

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

the class EmbedderMojoBehaviour method shouldAllowSpecificationOfEmbedderClass.

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

        public void execute() throws MojoExecutionException, MojoFailureException {
        }
    };
    // When
    mojo.embedderClass = MyEmbedder.class.getName();
    Embedder embedder = mojo.newEmbedder();
    // Then
    assertThat(embedder.getClass().getName(), equalTo(MyEmbedder.class.getName()));
}
Also used : Embedder(org.jbehave.core.embedder.Embedder) InjectableEmbedder(org.jbehave.core.InjectableEmbedder) Test(org.junit.Test)

Example 43 with Embedder

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

the class EmbedderMojoBehaviour method shouldNotIgnoreFailureInUnpackingViewResources.

@Test(expected = MojoExecutionException.class)
public void shouldNotIgnoreFailureInUnpackingViewResources() 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 coreFile = new File("core");
    Artifact coreResources = mock(Artifact.class);
    when(coreResources.getArtifactId()).thenReturn("jbehave-core");
    when(coreResources.getType()).thenReturn("zip");
    when(coreResources.getFile()).thenReturn(coreFile);
    File siteFile = new File("site");
    Artifact siteResources = mock(Artifact.class);
    when(siteResources.getArtifactId()).thenReturn("jbehave-site-resources");
    when(siteResources.getType()).thenReturn("zip");
    when(siteResources.getFile()).thenReturn(siteFile);
    Set<Artifact> allArtifacts = new HashSet<>();
    allArtifacts.add(coreResources);
    allArtifacts.add(siteResources);
    String buildDirectory = "target";
    Build build = new Build();
    build.setDirectory(buildDirectory);
    UnArchiver coreArchiver = mock(UnArchiver.class);
    UnArchiver siteArchiver = mock(UnArchiver.class);
    // When
    mojo.project = project;
    mojo.archiverManager = archiveManager;
    when(project.getArtifacts()).thenReturn(allArtifacts);
    when(project.getBuild()).thenReturn(build);
    when(archiveManager.getUnArchiver(coreFile)).thenReturn(coreArchiver);
    when(archiveManager.getUnArchiver(siteFile)).thenReturn(siteArchiver);
    Mockito.doThrow(new ArchiverException("bum")).when(siteArchiver).extract();
    mojo.execute();
    // Then
    verify(coreArchiver).extract();
// and fail as expected ...
}
Also used : ArchiverManager(org.codehaus.plexus.archiver.manager.ArchiverManager) MavenProject(org.apache.maven.project.MavenProject) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) 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) UnArchiver(org.codehaus.plexus.archiver.UnArchiver) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 44 with Embedder

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

the class EmbedderMojoBehaviour method shouldAllowSpecificationOfInjectableEmbedderClass.

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

        public void execute() throws MojoExecutionException, MojoFailureException {
        }
    };
    // When
    mojo.injectableEmbedderClass = MyInjectableEmbedder.class.getName();
    Embedder embedder = mojo.newEmbedder();
    // Then
    assertThat(embedder.getClass().getName(), equalTo(MyEmbedder.class.getName()));
}
Also used : Embedder(org.jbehave.core.embedder.Embedder) InjectableEmbedder(org.jbehave.core.InjectableEmbedder) Test(org.junit.Test)

Example 45 with Embedder

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

the class AbstractEmbedderMojo method newEmbedder.

/**
 * Creates an instance of Embedder, either using
 * {@link #injectableEmbedderClass} (if set) or defaulting to
 * {@link #embedderClass}.
 *
 * @return An Embedder
 */
protected Embedder newEmbedder() {
    Embedder embedder = null;
    EmbedderClassLoader classLoader = classLoader();
    if (injectableEmbedderClass != null) {
        embedder = classLoader.newInstance(InjectableEmbedder.class, injectableEmbedderClass).injectedEmbedder();
    } else {
        embedder = classLoader.newInstance(Embedder.class, embedderClass);
    }
    URL codeLocation = codeLocation();
    if (codeLocation != null) {
        embedder.configuration().storyReporterBuilder().withCodeLocation(codeLocation);
    }
    embedder.useClassLoader(classLoader);
    embedder.useEmbedderControls(embedderControls());
    if (executorsClass != null) {
        ExecutorServiceFactory executorServiceFactory = classLoader.newInstance(ExecutorServiceFactory.class, executorsClass);
        embedder.useExecutorService(executorServiceFactory.create(embedder.embedderControls()));
    }
    embedder.useEmbedderMonitor(embedderMonitor());
    if (isNotEmpty(metaFilters)) {
        List<String> filters = new ArrayList<>();
        for (String filter : metaFilters) {
            if (filter != null) {
                filters.add(filter);
            }
        }
        embedder.useMetaFilters(filters);
    }
    if (!systemProperties.isEmpty()) {
        embedder.useSystemProperties(systemProperties);
    }
    return embedder;
}
Also used : EmbedderClassLoader(org.jbehave.core.embedder.EmbedderClassLoader) ArrayList(java.util.ArrayList) Embedder(org.jbehave.core.embedder.Embedder) ConfigurableEmbedder(org.jbehave.core.ConfigurableEmbedder) InjectableEmbedder(org.jbehave.core.InjectableEmbedder) URL(java.net.URL) ExecutorServiceFactory(org.jbehave.core.embedder.executors.ExecutorServiceFactory)

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