Я пытаюсь написать некоторые модульные тесты с помощью DBUnit. Я хочу использовать базу данных HSQL в памяти. Сначала в моих свойствах Hibernate я используюHSQL и DBUnit - данная схема «SA» не существует
<prop key="hibernate.hbm2ddl.auto">create</prop>
для создания таблиц из моих сущностей.
Тогда я могу настроить источник данных, как это (файл тест-зимуют-config.xml):
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>org.hsqldb.jdbcDriver</value>
</property>
<property name="url">
<value>jdbc:hsqldb:mem:test;sql.syntax_ora=true</value>
</property>
<property name="username">
<value>SA</value>
</property>
<property name="password">
<value></value>
</property>
</bean>
И тогда мой тестовый класс выглядеть следующим образом:
@Override
protected String[] getConfigLocations() {
return new String[] {"batch-spring-daos.xml",
"test-hibernate-config.xml",
"batch-spring-transactionManager.xml"};
}
public void setLivraisonDAO(ILivraisonDAO livraisonDAO) {
this.livraisonDAO = livraisonDAO;
}
@Test(expected=IllegalArgumentException.class)
@InsertDBUnitData(dataLocations={ "data/data_release" })
public void shouldThrowIllegalArgumentExceptionWhenReleaseDoesntExists(){
livraisonDAO.getAllLivraisons("1");
}
@Test
@InsertDBUnitData(dataLocations={ "data/data_release", "data/data_livraison"})
public void shouldRetrieveOneRelease(){
List<LivraisonEntity> allLivraisons = livraisonDAO.getAllLivraisons("2.5.0.0");
assertTrue(!allLivraisons.isEmpty());
}
Файл пакетного пружинный -dao.xml и batch-spring-transactionManager.xml - это те, которые я использую в своем приложении.
Но когда я пытаюсь запустить мой тест, я получил эти журналы:
[2014-11-03 10:06:41,349] ERROR [main] org.hibernate.tool.hbm2ddl.SchemaExport.create:348 : Unsuccessful: alter table IMPACTPARAMDEFECT add constraint FK7327F18F2A1C61A foreign key (IDPARAMETRAGE) references PARAMETRAGE
[2014-11-03 10:06:41,349] ERROR [main] org.hibernate.tool.hbm2ddl.SchemaExport.create:349 : a FOREIGN KEY constraint already exists on the set of columns: FK7327F18F2A1C61A in statement [alter table IMPACTPARAMDEFECT add constraint FK7327F18F2A1C61A foreign key (IDPARAMETRAGE) references PARAMETRAGE]
[2014-11-03 10:06:41,349] ERROR [main] org.hibernate.tool.hbm2ddl.SchemaExport.create:348 : Unsuccessful: alter table IMPACTPARAMDEFECT add constraint FK7327F1848CCEB7F foreign key (IDPARAMETRAGE) references PARAMETRAGE
[2014-11-03 10:06:41,364] ERROR [main] org.hibernate.tool.hbm2ddl.SchemaExport.create:349 : a FOREIGN KEY constraint already exists on the set of columns: FK7327F1848CCEB7F in statement [alter table IMPACTPARAMDEFECT add constraint FK7327F1848CCEB7F foreign key (IDPARAMETRAGE) references PARAMETRAGE]
[2014-11-03 10:06:41,364] ERROR [main] org.hibernate.tool.hbm2ddl.SchemaExport.create:348 : Unsuccessful: alter table IMPACTPARAMDEFECT add constraint FK7327F18DAE59D90 foreign key (IDPARAMETRAGE) references PARAMETRAGE
[2014-11-03 10:06:41,364] ERROR [main] org.hibernate.tool.hbm2ddl.SchemaExport.create:349 : a FOREIGN KEY constraint already exists on the set of columns: FK7327F18DAE59D90 in statement [alter table IMPACTPARAMDEFECT add constraint FK7327F18DAE59D90 foreign key (IDPARAMETRAGE) references PARAMETRAGE]
[2014-11-03 10:06:41,364] ERROR [main] org.hibernate.tool.hbm2ddl.SchemaExport.create:348 : Unsuccessful: alter table IMPACTPARAMDEFECT add constraint FK7327F188951F74F foreign key (IDPARAMETRAGE) references PARAMETRAGE
[2014-11-03 10:06:41,364] ERROR [main] org.hibernate.tool.hbm2ddl.SchemaExport.create:349 : a FOREIGN KEY constraint already exists on the set of columns: FK7327F188951F74F in statement [alter table IMPACTPARAMDEFECT add constraint FK7327F188951F74F foreign key (IDPARAMETRAGE) references PARAMETRAGE]
3 nov. 2014 10:06:41 org.springframework.orm.hibernate3.HibernateTransactionManager afterPropertiesSet
INFO: Using DataSource [[email protected]6796] of Hibernate SessionFactory for HibernateTransactionManager
[2014-11-03 10:06:41,442] INFO [main] ch.gma.commons.test.AbstractGmaTest.insertData:183 : insertData - *** Inserting test data : file path = data/data_release, schema = ***
[2014-11-03 10:06:41,458] WARN [main] org.dbunit.database.DatabaseConnection.validateSchema:195 : The given schema 'SA' does not exist.
[2014-11-03 10:06:41,489] ERROR [main] org.dbunit.database.DatabaseDataSet.getTableMetaData:286 : Table 'RELEASE' not found in tableMap=org.dbunit.dataset.OrderedTableNameMap[_tableNames=[], _tableMap={}, _caseSensitiveTableNames=false]
[2014-11-03 10:06:41,489] INFO [main] ch.gma.commons.test.AbstractGmaTest.insertData:189 : insertData - *** Finished inserting test data ***
[2014-11-03 10:06:41,489] INFO [main] ch.gma.commons.test.AbstractGmaTest.insertData:183 : insertData - *** Inserting test data : file path = data/data_release, schema = ***
[2014-11-03 10:06:41,489] WARN [main] org.dbunit.database.DatabaseConnection.validateSchema:195 : The given schema 'SA' does not exist.
[2014-11-03 10:06:41,505] ERROR [main] org.dbunit.database.DatabaseDataSet.getTableMetaData:286 : Table 'RELEASE' not found in tableMap=org.dbunit.dataset.OrderedTableNameMap[_tableNames=[], _tableMap={}, _caseSensitiveTableNames=false]
[2014-11-03 10:06:41,505] INFO [main] ch.gma.commons.test.AbstractGmaTest.insertData:189 : insertData - *** Finished inserting test data ***
Спасибо за вашу помощь!
Какую версию dbunit вы используете? – netik
Я использую DBUnit 2.4.8 – bryce