Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Transactional problems in accessing data using spring mock, dbunit and HSQL  RSS feed

nagaraj kris
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I have setup a environment to write junits for my application(technology used :spring + hibernate + mysql + linux) using DBUnit and springmock.

I am finding trouble in accessing the data that was loaded by the DBUnit from a bean that was created by BeanFactory(SingletonBeanFactory).

Following is my setup:

I have a SampleTestCase class that extends AbstractTransactionalDataSourceSpringContextTests.

This class loads all the spring config files and data files which is used by DBUnit for data insertion. I am using HSQL in memory database, therefore all the tables are created on the fly using hibernate HBM2DDL option.

When i run this class with a method to test a create API, the following steps occur
- First all the tables are created using HBM
- Spring mock starts a new transaction
- Then DBUnit inserts all the data into tables
- Then the test method is executed
- Control goes to the ID generator class mentioned in the HBM file, id generator class creates another class CustomSequenceGenerator class using Beanfactory approach. This CustomSequenceGenerator queries the database for a sequence value that was loaded with DBUnit and scrambles it to return a primary key.

The problem is that the data loaded by dbunit is not visible for CustomSequenceGenerator class. But the same data can be accessed from the test class if i create CustomSequenceGenaratot object using applicationContext.

This particular use case uses both applicationContext and beanFactory approach of bean creation, which may be the reason for not being able to see the data loaded.

Can somebody help me in identifying the casuse and ways to overcome it.

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!