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();
}
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()));
}
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 ...
}
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()));
}
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;
}
Aggregations