Arquillian不在JBOSS中部署war文件夹

时间:2016-09-03 13:02:45

标签: java maven jboss jboss-arquillian shrinkwrap

我正在使用JBoss EAP 6.1开发Java EE应用程序。

使用Arquillian运行测试我在使用测试中注入的方法时总是有一个空指针异常,我发现ShrinkWrap不能用我的类创建war文件夹。

这是我的Arquillian收缩包装,不会创建war文件夹。

@Deployment(name = "Test")
@OverProtocol("Servlet 3.0")
public static Archive<?> createDeployment() {

    WebArchive archive = ShrinkWrap
            .create(WebArchive.class, "test_archive.war")
            .addClass(ArquillianTest.class)
            .addPackages(true, "it.payroll.model")
            .addPackages(true, "it.payroll.dao")
            .addPackages(true, "it.payroll.controller")
            .addAsResource("META-INF/persistence.xml")
            .addAsWebInfResource(EmptyAsset.INSTANCE,
                    ArchivePaths.create("beans.xml"));

    archive.as(ZipExporter.class).exportTo(
            new File("target/test_archive.war"), true);

    return archive;
}

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

工作档案

@ArquillianSuiteDeployment
public class ArquillianDeploymentHelper {

public static final String DEPLOYMENT_NAME = "test";

private static final Logger LOGGER = LoggerFactory.getLogger(ArquillianDeploymentHelper.class);

private static final String WEBAPP_SRC = "src/main/webapp";
private static final String TEST_RESOURCES_SRC = "src/test/resources";
private static final String POM_FILE = "pom.xml";
private static final String ARCHIVE_NAME = "arquillian-test.war";

@Deployment(name = DEPLOYMENT_NAME)
public static Archive<?> generateDefaultDeployment() {

    // Generate the default WAR used by all *IT tests using @OperateOnDeployment("test") annotation
    LOGGER.info("Generating " + ARCHIVE_NAME + " archive ...");

    PomEquippedResolveStage pom = Maven.resolver().loadPomFromFile(POM_FILE);
    ScopeType[] scopes = {ScopeType.COMPILE, ScopeType.IMPORT, ScopeType.TEST}; // no SYSTEM and no PROVIDED
    File[] libs = pom.importDependencies(scopes).resolve().using(TransitiveStrategy.INSTANCE).asFile();

    WebArchive archive =  ShrinkWrap.create(WebArchive.class, ARCHIVE_NAME)
            .addAsLibraries(libs)
            //.addAsResource(new File(TEST_RESOURCES_SRC, "test-configuration.properties"), "configuration.properties")
            .addPackages(true, "com.test")
            //.addAsWebInfResource(new File(WEBAPP_SRC, "WEB-INF/web.xml"))
            .addAsWebInfResource(new File(WEBAPP_SRC, "WEB-INF/beans.xml"))
            .addAsWebInfResource(new File(WEBAPP_SRC, "WEB-INF/jboss-web.xml"))
            .addAsWebInfResource(new File(TEST_RESOURCES_SRC, "persistence.xml"), "classes/META-INF/persistence.xml");
            //.addAsManifestResource(new File(WEBAPP_SRC, "META-INF/jboss-deployment-structure.xml"));

    // No need to log the content anymore, the archive is kept in target directory 
    // "deploymentExportPath" variable in arquillian.xml
    // LOGGER.info(archive.toString(true));

    LOGGER.info(archive.toString(true));

    return archive;
}
}