Search code examples
javaxmlpostgresqlpostgresql-9.2dbunit

DBUnit ignores xml element


I am using DBUnit (version 2.4.9) for loading the data for integration tests. I'm getting a weird problem that 1 field (deleted) is not being set in the DB (postgres).

Here is my XML data load:

<dataset>
    ...
    <workgroup id="100" created="2013-10-08 14:15:00.000" deleted="2013-10-08 14:15:00.000" version="0" name="Name1" org_id="100"/>
    ...
</dataset>

Here is my schema definition:

CREATE TABLE workgroup
(
  deleted timestamp without time zone,
  ... some constraints
)

All other fields are being set-up correctly. Any ideas what can be causing this? Thanks!

EDIT:

I narrowed down the problem and it has to do something with entries in XML file order. If I have:

<workgroup id="101" version="0" name="Name1"/>
<workgroup id="100" version="0" name="Name1" deleted="2013-10-08 />

it doesn't work, but this:

<workgroup id="100" version="0" name="Name1" deleted="2013-10-08 />
<workgroup id="101" version="0" name="Name1"/>

works correctly. DBUnit bug?

EDIT: Another example, that I cannot overcome:

<organisation id="1"/>
<organisation id="2" parent_id="1"/>

Organisation needs to exists before we can assign it value, so workaround, like this:

<organisation id="2" parent_id="1"/>
<organisation id="1"/>

will not work.


Solution

  • It appears that this is a "feature" of dbunit. To avoid this behavior you must provide a dtd to define the columns.

    <!ATTLIST organisation  
        id CDATA #REQUIRED  
        parent_id CDATA #IMPLIED  
    >