简体   繁体   English

Unitils-Dbunit ExpectedDataSet失败/被阻止

[英]Unitils - Dbunit ExpectedDataSet fail / blocked

I'm creating a web application with Spring 3.1.0.RELEASE and JPA 2 with Hibernate Provider. 我正在使用Spring 3.1.0.RELEASE和带有Hibernate Provider的JPA 2创建一个Web应用程序。 I'm doing the test with junit 4.10 , dbunit 2.4.8, unitils 3.3, hsqldb 2.2.8. 我正在使用junit 4.10,dbunit 2.4.8,unitils 3.3,hsqldb 2.2.8进行测试。

I try to test the service layer, a create operation. 我尝试测试服务层,即创建操作。 In my DAO i have this method: 在我的DAO中,我有以下方法:

@Override
    @Transactional
    public void createQuestion(Question question) {
        logger.debug("createQuestion");

        entityManager.persist(question);
        logger.info("New question created  [id] {}", question.getId());

    }

My QuestionServiceTest test class : 我的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);
    }
}

I use the property hibernate.hbm2ddl.auto = create-drop for generate the schema, the question table is: 我使用属性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 is a foreign key to table theme. theme_id是表主题的外键。

When i launch the test with ExpectedDataSet, the insert works but the test never finish. 当我使用ExpectedDataSet启动测试时,插入工作正常,但测试从未完成。 The test block on : 测试块位于:

DEBUG: org.dbunit.database.AbstractResultSetTable - Query: select "ID", "COUNTRY_CODE", "CREATION_DATE", "EMAIL", "FIRSTNAME", "LASTNAME", "ORIGINAL_LANG", "ORIGINAL_QUESTION", "THEME_ID" from "PUBLIC"."QUESTION" order by "ID" 调试:org.dbunit.database.AbstractResultSetTable-查询:从“”中选择“ ID”,“ COUNTRY_CODE”,“ CREATION_DATE”,“ EMAIL”,“ FIRSTNAME”,“ LASTNAME”,“ ORIGINAL_LANG”,“ ORIGINAL_QUESTION”,“ THEME_ID” PUBLIC”。按“ ID”的“ QUESTION”顺序

This is the last line on debug. 这是调试的最后一行。

My unitils.properties is : 我的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

My persistence.xml : 我的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>

What should I do? 我该怎么办? I already try previous release of dbunit or unitils but it doesn't change anything. 我已经尝试过dbunit或unitils的先前版本,但它没有任何改变。 Expected Dataset is really cool feature. 预期的数据集确实是很酷的功能。

Thanks. 谢谢。

I had the same issue and failed to solve it. 我遇到了同样的问题,但未能解决。 Then I gave a try to spring-test-dbunit and this lib run smoothly. 然后,我尝试了spring-test-dbunit,此lib运行顺利。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM