[英]Unitils - Dbunit ExpectedDataSet fail / blocked
我正在使用Spring 3.1.0.RELEASE和带有Hibernate Provider的JPA 2创建一个Web应用程序。 我正在使用junit 4.10,dbunit 2.4.8,unitils 3.3,hsqldb 2.2.8进行测试。
我尝试测试服务层,即创建操作。 在我的DAO中,我有以下方法:
@Override
@Transactional
public void createQuestion(Question question) {
logger.debug("createQuestion");
entityManager.persist(question);
logger.info("New question created [id] {}", question.getId());
}
我的QuestionServiceTest测试类:
@SpringApplicationContext("test-applicationContext.xml")
public class QuestionServiceTest extends UnitilsJUnit4 {
@SpringBeanByName
private QuestionService questionService;
@SpringBeanByName
private ThemeService themeService;
@Test
@DataSet("QuestionServiceTest.testCreateQuestion.xml")
@ExpectedDataSet("QuestionServiceTest.testCreateQuestion-result.xml")
public void testCreateQuestion() {
final Question newQuestion = new Question();
newQuestion.setCountryCode("FR");
newQuestion.setEmail("test@mytest.com");
newQuestion.setFirstName("FirstTest");
newQuestion.setLastName("LastTest");
newQuestion.setOriginalLang(LanguageEnum.FR);
newQuestion.setOriginalQuestion("This is the original question");
final Calendar calendar = Calendar.getInstance();
calendar.set(2012, 5, 12);
newQuestion.setCreationDate(calendar.getTime());
final Theme theme = themeService.findThemeById(new Integer(1));
newQuestion.setTheme(theme);
questionService.createQuestion(newQuestion);
}
}
我使用属性hibernate.hbm2ddl.auto = create-drop生成模式,问题表为:
create table question (
id integer generated by default as identity (start with 1),
country_code varchar(10) not null,
creation_date timestamp not null,
email varchar(255) not null,
firstname varchar(100) not null,
lastname varchar(100) not null,
original_lang varchar(255) not null,
original_question clob not null,
theme_id integer not null,
primary key (id)
)
theme_id是表主题的外键。
当我使用ExpectedDataSet启动测试时,插入工作正常,但测试从未完成。 测试块位于:
调试:org.dbunit.database.AbstractResultSetTable-查询:从“”中选择“ ID”,“ COUNTRY_CODE”,“ CREATION_DATE”,“ EMAIL”,“ FIRSTNAME”,“ LASTNAME”,“ ORIGINAL_LANG”,“ ORIGINAL_QUESTION”,“ THEME_ID” PUBLIC”。按“ ID”的“ QUESTION”顺序
这是调试的最后一行。
我的unitils.properties是:
# Defaults and other keys with explanations can be found there: http://unitils.org/unitils-default.properties
database.driverClassName=org.hsqldb.jdbcDriver
database.url=jdbc:hsqldb:mem:testOpen
database.userName=sa
database.password=
database.dialect=hsqldb
# This schema is the initial schema when a new session is started in HSQLDB, don't change it or test won't works !
database.schemaNames=PUBLIC
dbUnit.datasetresolver.prefixWithPackageName=false
dbUnit.datasetresolver.pathPrefix=dataSets
我的persistence.xml:
<persistence-unit name="OpenTestPU" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver" />
<property name="hibernate.connection.username" value="sa" />
<property name="hibernate.connection.password" value="" />
<property name="hibernate.connection.url" value="jdbc:hsqldb:mem:testOpen" />
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
</properties>
</persistence-unit>
我该怎么办? 我已经尝试过dbunit或unitils的先前版本,但它没有任何改变。 预期的数据集确实是很酷的功能。
谢谢。
我遇到了同样的问题,但未能解决。 然后,我尝试了spring-test-dbunit,此lib运行顺利。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.