*/
public class ProjectArtifactDeploymentGenerator implements DeploymentScenarioGenerator {
@Override
public List<DeploymentDescription> generate(TestClass testClass) {
if (testClass.isAnnotationPresent(DeployProjectArtifact.class)) {
DeployProjectArtifact config = testClass.getAnnotation(DeployProjectArtifact.class);
String archiveName = config.value();
if (archiveName.length() == 0) {
archiveName = getArchiveNameFromPom();
}
Class<? extends Archive<?>> type = JavaArchive.class;
if (archiveName.endsWith(".war")) {
type = WebArchive.class;
}
else if (archiveName.endsWith(".ear")) {
type = EnterpriseArchive.class;
}
File archiveFile = new File("target/" + archiveName);
if (!archiveFile.exists()) {
throw new IllegalStateException("Project artifact has not been generated: " + archiveFile.getAbsolutePath());
}
Archive<?> archive = ShrinkWrap.create(type, archiveName).as(ZipImporter.class)
.importFrom(new File("target/" + archiveName)).as(type);
DeploymentDescription dd = new DeploymentDescription("application", archive);
dd.shouldBeTestable(config.testable());
return Arrays.asList(dd);
}
return Collections.emptyList();
}