HISPACTA Hell

Monday, May 18, 2009

DBUnit does what??

I found out today that if you don't define all the columns you want to use in the very first row of a DBUnit XML file that you define, then you can't define values for any undeclared columns later.

I knew DBUnit nulled out things I didn't declare by default, but I didn't realize you couldn't re-defined them later. For example, if the cancel_date is null, that has a special meaning...so I defined this:

<commitment id="1" customer_id="1" sign_up_date="2009-1-1" start_date="2009-2-1" end_date="2009-4-30" percent="0.05">
<commitment id="2" customer_id="1" sign_up_date="2008-11-15" start_date="2008-11-1" end_date="2009-1-1" percent="0.10">
<commitment id="3" customer_id="2" sign_up_date="2005-2-22" start_date="2005-3-1" end_date="2020-7-30" percent="0.20" cancel_date="2009-5-15">

Because "cancel_date" only shows up on the 3rd row (and not explicitly in the first row where I'd set it to null for declarative purposes only), DBUnit passes cancel_date as null even when parsing the 3rd row.

If I instead re-order my rows so that the row with the superset of attributes I want to use shows up first, then it's ok (e.g., see below)

Note that I couldn't find an easy way of just saying "cancel_date=[null]" on the initial rows #1 and #2 in the above block, or I would have done that instead of re-ordering the rows.

<commitment id="1" customer_id="2" sign_up_date="2005-2-22" start_date="2005-3-1" end_date="2020-7-30" percent="0.20" cancel_date="2009-5-15">
<commitment id="2" customer_id="1" sign_up_date="2009-1-1" start_date="2009-2-1" end_date="2009-4-30" percent="0.05">
<commitment id="3" customer_id="1" sign_up_date="2008-11-15" start_date="2008-11-1" end_date="2009-1-1" percent="0.10">