2014-01-15 52 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; 
} 

所以你的答案被列入了第二個選項;-)