简体   繁体   中英

Unitils - Dbunit ExpectedDataSet fail / blocked

I'm creating a web application with Spring 3.1.0.RELEASE and JPA 2 with Hibernate Provider. I'm doing the test with 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:

@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 :

@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:

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.

When i launch the test with ExpectedDataSet, the insert works but the test never finish. 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"

This is the last line on debug.

My unitils.properties is :

# 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-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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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