アプリケーションの単体テストをセットアップしようとしています。Unitils データセットでテストしたいのですが、これまでのところ多くの問題に遭遇しています。セットアップが間違っていると確信しています。誰でも問題を確認できます。
私は hibernate.cfg.xml を持っています
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- database connection settings -->
<property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
<property name="hibernate.connection.driver_class">org.hsqldb.jdbc.JDBCDriver</property>
<property name="hibernate.connection.url">jdbc:hsqldb:mem:testdb</property>
<!--<property name="hibernate.hbm2ddl.auto">create</property>-->
<!-- Enable Hibernate's second level cache -->
<property name="hibernate.cache.use_second_level_cache">false</property>
<property name="hibernate.cache.provider_class">net.sf.ehcache.hibernate.EhCacheProvider</property>
<!-- helper debug settings -->
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
<mapping class="cz.test.Request"/>
</session-factory>
</hibernate-configuration>
Unitils のプロパティは次のとおりです。
database.dialect=hsqldb
database.driverClassName=org.hsqldb.jdbc.JDBCDriver
database.url=jdbc:hsqldb:mem:testdb
database.schemaNames=PUBLIC
そして最後に私のテストは
@DataSet("DaoTest.xml")
@HibernateSessionFactory({"test_hibernate.cfg.xml"})
public class DaoTest extends UnitilsJUnit4 {
private SessionFactory sessionFactory;
private Session session = null;
@Test
public void testMappingToDatabase() {
HibernateUnitils.assertMappingWithDatabaseConsistent();
}
}
私は得ています
SEVERE: Table 'TrnRequest' not found in tableMap=org.dbunit.dataset.OrderedTableNameMap[_tableNames=[], _tableMap={}, _caseSensitiveTableNames=false]
Caused by: org.dbunit.dataset.NoSuchTableException: Request
スキーマが作成されていないと思います.hibernate.cfg.xmlに何かを設定しても、このエラーの後に作成が行われ、とにかく失敗するため、役に立ちません
X 15, 2015 9:44:19 DOP. org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: exporting generated schema to database
X 15, 2015 9:44:19 DOP. org.hibernate.tool.hbm2ddl.SchemaExport create
SEVERE: Unsuccessful: create table Request (id bigint generated by default as identity (start with 1), amount bigint, amountCbk bigint, applicationId varchar(4), batch integer, cardIssuer varchar(20), cardSeq integer, currency varchar(3), emvData varchar(1024), entryMode varchar(3), exp varchar(4), maskedPan varchar(32), originalTime timestamp, ORIGINALTIME_UTC timestamp, pan varchar(64), panKey varchar(64), posData varchar(512), repeated NUMBER(1,0) DEFAULT 0 NOT NULL, reqFlag varchar(255), reqProcessing varchar(255), reqType varchar(255), requestTime timestamp, REQUESTTIME_UTC timestamp, sequenceNumber varchar(10), stan bigint, termid varchar(16), transactionTime timestamp, primary key (id))
X 15, 2015 9:44:19 DOP. org.hibernate.tool.hbm2ddl.SchemaExport create
SEVERE: type not found or user lacks privilege: NUMBER
X 15, 2015 9:44:19 DOP. org.hibernate.tool.hbm2ddl.SchemaExport create
SEVERE: Unsuccessful: alter table TrnReleatedTrn add constraint FK135128224355CCD7 foreign key (releatedRequest_id) references TrnRequest
X 15, 2015 9:44:19 DOP. org.hibernate.tool.hbm2ddl.SchemaExport create
SEVERE: user lacks privilege or object not found: REQUEST
X 15, 2015 9:44:19 DOP. org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: schema export complete