I use DBUnit to setup my database for test cases. Right now, I’m running HSQL in its “in memory” mode as the database. I’m using Hibernate mappings to connect my objects to the database, and I’ve got my Spring/Hibernate configuration setup to drop and create the tables at the beginning of my test run (and only once for all tests). I kept running into a problem with foreign keys, though. I couldn’t get past it, and no amount of wrestling with my mapping file eliminated my "Integrity constraint violation".
I tracked it down eventually to my DBUnit file. I have a Composite pattern in one of my objects, so items in the Chart table have a parent that is also a Chart; but the root element has no parent. The first record in my XML file referred to a parent that was later in the file. I swapped the records around so that they were all created in the right order. No problem. Run the tests, no error, but my test fails. NullPointerException. Hmm.
Another while of head-banging and incantations leads nowhere. So I decided to swap from in-memory DB to an actual DB I can look at. Thankfully, that’s pretty easy. I fire up an HSQLDB server instance inside Eclipse, and swap the comment on this line in my Spring properties file… (More about my environment another time, this is a bug hunt!)
Now I can easily see that none of the PARENT_ID colums are being populated. That’s really odd. So I fiddle a bit, and decide to add a parent reference to my root node to point to itself, et voilà. All of my parent references suddenly appear. Make the root one null again; they’re all gone. So I scratch my head for a bit, and then I make a guess.
DBUnit’s FlatXmlDataset requires you to eliminate a column if you want it left null. But it appears that it uses the first record’s data to fully define the schema it’ll use when creating its eventual insert sequence. I need that column to be null. And I need that record to be first. What to do? I decided to embed a DTD right in my xml dataset. I ran over to the right entry in the FAQ and quickly got a DTD for my database schema. Then I modified my xml dataset to look like this:
I ran the tests, and bingo! Green bar. I love tests that run.
Almost a year ago I wrote a blog entry about one way to standardize Eclipse plugins across your team. It represented our team’s best guess on how to share plugins. Now that some time has gone by, how good has our experience been with it? I’d give it an 8 overall, but I think we’ve outgrown it. What’s our next strategy? Listen and find out.
Eclipse 3.1 has some excellent new features. Chief among them for me is the JDK 1.5 support. They’ve got everything from enums to annotations supported, and done very well. Also of particular note is the first class support to the Rich Client Platform (RCP). Watch for the Web Tools Platform to finalize very soon as well.
In the last few months my little family’s been through a car accident, appendicitis, a move, and a new baby. I’ll be moving my domain to a server with more bandwidth this weekend, so I can afford to start podcasting again!! Look for shows on JMS, servlet classloading, and more stuff. If you’ve got a topic you want to hear about, drop in a comment!