Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6332907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:21:55+00:00 2026-05-24T18:21:55+00:00

I would appreciate some help with using dbunit. I use postgresql9 as db. I

  • 0

I would appreciate some help with using dbunit.
I use postgresql9 as db.

I created table book using hibernate’s hbm2ddl tool.

I wanted to create some xmldatasets for testing with dbunit.Using the ant DBUnit task I exported values from db to a
initialdataset.xml ,which I clean-insert to db before every test.Deleting some rows ,I created an expecteddataset.xml. If I am to compare a table created from db
with a table created from expecteddataset.xml ,I think I need to define a dtd.I used the following code to create dtd.

public static void createDTD(String dtdFileName) throws FileNotFoundException...{
        IDatabaseConnection connection = DbUnitUtils.createConnection();
        FlatDtdDataSet.write(connection.createDataSet(),new FileWriter("data/dbunit/"+dtdFileName));
        connection.close();
}
...
createDTD("myschema.dtd");

The created dtd is given below

...
<!ELEMENT book EMPTY>
<!ATTLIST book
    book_id CDATA #REQUIRED
    isbn CDATA #REQUIRED
    book_name CDATA #REQUIRED
    publish_date CDATA #IMPLIED
    price CDATA #REQUIRED
    description CDATA #IMPLIED
    publisher_id CDATA #IMPLIED
    author_id CDATA #IMPLIED
>
...

expecteddataset.xml is like this-expecteddataset xml

My postgres db table ‘book’ is of the form

   Column    |          Type          | Modifiers 
--------------+------------------------+-----------
 book_id      | bigint                 | not null
 isbn         | character varying(255) | not null
 book_name    | character varying(255) | not null
 publish_date | date                   | 
 price        | real                   | not null
 description  | character varying(255) | 
 publisher_id | bigint                 | 
 author_id    | bigint                 | 
Indexes:
    "book_pkey" PRIMARY KEY, btree (book_id)
    "book_isbn_key" UNIQUE, btree (isbn)
Foreign-key constraints:
    "fk1f32e959a9fc15" FOREIGN KEY (author_id) REFERENCES author(author_id)
    "fk1f32e9b6bbf81f" FOREIGN KEY (publisher_id) REFERENCES publisher(publisher_id)

What confuses me is that the publish_date field(which is a date type in postgres) , book_id( bigint type),price(real type)
are also treated as CDATA.How can a table made from fields which are String types equal to a table retrieved from db which
have fields varying as Long,Date etc?

In testcode I tried

removeSomeRowsFromBookTable();
ITable actualBookTable = connection.createQueryTable("book", "select BOOK_ID,ISBN,...from BOOK");
IDataSet expectedDataSet = DbUnitUtils.createDataSet("expecteddataset.xml.xml");
ITable expectedBookTable = expectedDataSet.getTable("book");
Assert.assertEquals(expectedBookTable, actualBookTable);

This causes AssertionFailedError.

The stacktrace is

junit.framework.AssertionFailedError: 

expected:<org.dbunit.dataset.DefaultTable@12d8ecd> 

but was:<org.dbunit.database.CachedResultSetTable@1fa5e5e>

at junit.framework.Assert.fail(Assert.java:47)
    at junit.framework.Assert.failNotEquals(Assert.java:282)
    at junit.framework.Assert.assertEquals(Assert.java:64)
    at junit.framework.Assert.assertEquals(Assert.java:71)
    at myapp.test.cascades.HibernateCascadeTests.testCascading(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:76)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:673)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:846)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1170)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
    at org.testng.TestRunner.runWorkers(TestRunner.java:1147)
    at org.testng.TestRunner.privateRun(TestRunner.java:749)
    at org.testng.TestRunner.run(TestRunner.java:600)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:317)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:312)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:274)
    at org.testng.SuiteRunner.run(SuiteRunner.java:223)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1039)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:964)
    at org.testng.TestNG.run(TestNG.java:900)
    at org.testng.TestNG.privateMain(TestNG.java:1182)
    at org.testng.TestNG.main(TestNG.java:1146)

Is there something wrong in what I am doing here?Do I have to provide some info about the column types for the table elements?
If someone can help me solve this,it would be nice.

DbUnitUtils class to create datasets

class DbUnitUtils {
    public static IDatabaseConnection createConnection(){
        ...
    }  
    public static IDataSet createDataSet(String file) throws DataSetException, IOException{
        return new FlatXmlDataSet(new File("data/dbunit/"+file));
    }
}

p.s:
I tried this with dbunit-2.2.2 and 2.4.8 versions with same results..So, it must be that I am missing something vital to running dbunit properly

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T18:21:55+00:00Added an answer on May 24, 2026 at 6:21 pm

    The error was because junit Assert does not know about equality of Dbunit classes(ITable etc) and was failing in assertEquals()..I should have used assertEquals() from dbunit's Assertion class.

    such a simple overlook of basic facts..caused me couple of days ‘ grief

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would appreciate some help with something I working on and have not done
I would appreciate some help with an UPDATE statement. I want to update tblOrderHead
I have a problem finding references to this subject and would appreciate some help.
I'm pretty new to Python programming and would appreciate some help to a problem
I would really appreciate it if some of you could help optimize my tables,
I am very new to WordPress, so I would appreciate some help. I am
I would appreciate some help here: What I want to do: remove &itemsperpage=10 from:
Would really appreciate some help with a search angine I'm trying to make for
I'm fairly new to SQL Server and would really appreciate some help with this.
I would greatly appreciate some help on anyone that has experience in working with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.