2011-11-25 26 views
1

我在曼寧閱讀EJB 3,第二版中間時遇到運行源測試中的IntelliJ如何與Hibernate

測試一個艱難的時間與運行的Arquillian IN_CONTAINER模式測試是: 全部源代碼,可以發現here

@RunWith(Arquillian.class) 
@Run(RunModeType.IN_CONTAINER) 
.... 
..... 
    @Deployment 
    public static Archive<?> createDeployment() { 
     return ShrinkWrap.create(JavaArchive.class, "foo.jar").addClasses(OrderProcessor.class, 
       OrderProcessorBean.class, 
       ItemService.class, 
       ItemServiceBean.class, Bid.class, Bidder.class, Item.class).addManifestResource("test-persistence.xml", ArchivePaths.create("persistence.xml")); 
    } 

的persistence.xml是:

<?xml version="1.0" encoding="UTF-8"?> 
<persistence version="1.0" 
    xmlns="http://java.sun.com/xml/ns/persistence" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation=" 
     http://java.sun.com/xml/ns/persistence 
     http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"> 
    <persistence-unit name="users" transaction-type="JTA"> 
     <provider>org.hibernate.ejb.HibernatePersistence</provider> 
     <jta-data-source>jdbc/chapter2</jta-data-source> 
     <properties> 
     <property name="hibernate.hbm2ddl.auto" value="create-drop" /> 
     <property name="hibernate.dialect" value="org.hibernate.dialect.DerbyDialect" /> 
     </properties> 
    </persistence-unit> 
</persistence> 

錯誤,同時運行測試:

WARNING: Could not obtain connection to query metadata 
java.sql.SQLException: Error in allocating a connection. Cause: Connection could not be allocated because: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused. 
    at com.sun.gjc.spi.base.DataSource.getConnection(DataSource.java:112) 
    at org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider.getConnection(InjectedDataSourceConnectionProvider.java:71) 

UPDATE

domain.xml中位於here

從它看起來像一個數據庫連接不能建立的錯誤。但是,我不確定爲什麼它無法連接到內存德比數據庫。由於domain.xml具有create=true屬性,所以應該簡單地創建數據庫。

回答

0

從錯誤,似乎無法建立數據庫連接。但是,我不確定它試圖連接到哪個數據庫。我沒有數據庫在我的系統上運行。

Do I need to have a database running specifically or will the test run a database on it's own? 
If so, which one? 

試驗應嘗試連接到作爲配置/test/resources/glassfish/config/domain.xml在內存中的Derby數據庫實例,所以我不認爲你需要任何進一步的設置。

Brian's comments at this arquillian doc在arquillian.xml中提示了一些更改。也許值得一試。

+0

謝謝,這清除了事情。但是我仍然無法看到'domain.xml',即使添加了命名空間,我也會得到相同的錯誤。 – Omnipresent