2014-01-15 53 views
0

我有一个web maven应用程序,其中有数据库 EJB jar作为依赖关系。在arquillian测试中添加来自EJB依赖关系的persistence.xml

数据库 EJB是具有所有JPA实体和persistence.xml文件的EJB,因此它由所有数据库操作负责。

我刚刚读了http://arquillian.org/guides/testing_java_persistence/,它解释了如何使用arquillian测试持久性。

本教程认为persistence.xml文件位于webapp路径中,因此它将META-INF/persistence.xml添加为资源。

所以我想知道,在我的webapp运行arquillian测试时,如何添加数据库的persistence.xml?那可能吗?

回答

0

也许答案来得有点晚了,但无论如何,我希望它仍然是有价值的你:

你有两个选择,要么从文件中读取存档(可能产生我MVN封装)或创建归档用自己拆封:

选项(1),从@Deployment某处注释称为:

/** maven did it for us .. we just have to read the file */ 
private static Archive<?> getArchiveFromFile() { 
    JavaArchive artifact = ShrinkWrap.create(ZipImporter.class, ARCHIVE_NAME).importFrom(ARCHIVE_FILE) 
      .as(JavaArchive.class); 

    return artifact; 
} 

选择(2),我认为有必要从时刻的文件,检查时间,以便有一个选项将其写入文件系统:

/** doing it the hard way ... guess you won't like it as EVERY class plus related stuff needs to be specified */ 
private static Archive<?> getArchiveManually() { 
    // creating archive manually 
    JavaArchive artifact = ShrinkWrap.create(JavaArchive.class, ARCHIVE_NAME) 

      .addPackage(FooServiceBean.class.getPackage()).addPackage(Foo.class.getPackage()) 
      .addPackage(FooService.class.getPackage()).addAsResource("META-INF/persistence.xml") 
      .addAsResource("META-INF/beans.xml"); 

    // so we might write it for further inspection 
    if (WRITE_ARCHIVE) { 
     artifact.as(ZipExporter.class).exportTo(new File("D:/abc/xyz/tmp/" + ARCHIVE_NAME), true); 
    } 

    return artifact; 
} 

所以你的答案被列入了第二个选项;-)