Spring 3.1.0.RELEASEとJPA 2 with Hibernate Providerを使用してWebアプリケーションを作成しています。 私はjunit 4.10、dbunit 2.4.8、unitils 3.3、hsqldb 2.2.8でテストしています。Unitils - Dbunit ExpectedDataSetが失敗/ブロックされました
サービスレイヤの作成操作をテストしようとしています。
@Override
@Transactional
public void createQuestion(Question question) {
logger.debug("createQuestion");
entityManager.persist(question);
logger.info("New question created [id] {}", question.getId());
}
マイQuestionServiceTestテストクラス::私のDAOで、私はこの方法で持って
@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("[email protected]");
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 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でテストを開始すると、挿入は機能しますが、テストは完了しません。 のテストブロック:
DEBUG:org.dbunit.database.AbstractResultSetTable - クエリ: "ID"、 "COUNTRY_CODE"、 "CREATION_DATE"、 "EMAIL"、 "FIRSTNAME" を選択し、 "LASTNAME" を、 "ORIGINAL_LANG"、 "ORIGINAL_QUESTION"、 "THEME_ID" "PUBLIC"。 "QUESTION" ための "ID"
によってこれは、デバッグの最後の行です。
私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の以前のリリースを試していますが、何も変更されません。期待されるデータセットは本当にクールな機能です。
ありがとうございました。