Tuesday, April 24, 2007

DBUnit + Sequence numbers + Foreign keys = Nightmare!

Setting up my unit tests with reliable fixtures is turning out to be quite a headache.

Sparing you arcane application-speak let me use the classic simple EMPLOYEE-DEPARTMENT example to illustrate my problem.

Facts:
  • We have the typical EMPLOYEE table and the DEPARTMENT table
  • Both use database-generated ids (sequence numbers) as primary keys.
  • An EMPLOYEE belongs to a DEPARMENT.
  • The DEPT_ID field in the EMPLOYEE table is a foreign key into the ID field of the DEPARTMENT table.
So far, so good.

Now, consider a method in the EmploymentDao class that returns all known employments. In SQL speak, it executes

Select e.emp_name, d.dept_name
From employee e, department d
Where e.dept_id=d.id

In order to test this method I need to set up the database with necessary data. I would like to be able to use something like DBUnit to set up my fixtures. However, I have to populate the DEPARTMENT table with at least one department record. Then, I need to get the ID field of that record to insert a record into the EMPLOYEE table. How does one do that ? This is crucial for a test such as

public void testGettingAllEmployments() {
List employments = employmentDao.getAllEmployments();
assertNotNull("Empty list of employments", employments);
}

Even with a simplification of suppressing foreign key constraints, I will have to do something like:
  • Insert a record into the DEPARTMENT table with a DBUnit fixture.
  • Insert a record in the EMPLOYEE table (with a bogus dept_id)
  • Then read the record, from the DEPARTMENT table to get at its id
  • Update the record in theEMPLOYEE table to set the dept_id
Wow! That's a lot of preamble -- not to mention using of the very DAO methods I want to test!!

Wednesday, February 21, 2007

Hello Google Reader. Goodbye Bloglines

I have been a longtime user of Bloglines. Sometime last year when Google introduced the Google Reader (GR) I took a looksee and was severely underwhelmed and so I stayed with Bloglines. One of my primary reasons was that GR did not work with my reading style. You see I like the blog posts grouped by feed -- all Slashdot posts together, all Javablogs together -- separated from the Slashdot posts.

Of course, the choice of Bloglines over over a locally installed reader was a no-brainer; I did not want to have to maintain a copy of my blogroll on each machine that I used during a typical day.

I recently peeked over to Google-land and lo and behold, this one feature that had been the deal-breaker for me had been added. In addition, were some very useful features that won me over. Here are the things that clinched the deal for me:

  • List view -- This allows me to glance at about 50-60 posts in a group at a time. If I am interested, I click on it to expand it and read a synopsis.
  • Ability to "star an item"
  • Keyboard shortcuts -- Boy! Do they ever have shortcuts. I haven't mastered them all yet
  • Ease of renaming feeds
  • Ability to selectively mark items as having been read -- Bloglines has a severe problem in that when you select a blog, every unread article in the blog is displayed and (this is the problem) they are all immediately marked as "read". Very often I start looking at feeds from a blog and before I can finish scanning all the unread posts, I am called away. With GR, I know where I left off
  • Progressive loading -- The reader doesn't attempt to load every article in the selected grouping in one fell swoop
  • Configurable start page -- I like my starred items to be displayed when I bring up the reader since well, I starred the item for a reason -- so that I can read them later!
Of course there is always a wishlist. Here's mine:

  • Ability to choose the order of display in the list view
    • [UPDATE] Anonymous commenter has shown me how! However I wish this wouldn't be a per-feed setting. OK, have a per-feed setting if you must but the one must be able to customize the default at a blogroll level.
  • Ability to mark an item as unread (I wouldn't at all be surprised if this feature is already there and that I just haven't figured out the keyboard shortcut)
    • [UPDATE] Thank you, Anonymous commenter for showing me the way!
  • Speed it up, please! Were it not for the features, GR's sluggishness would've be a deal-breaker!





powered by performancing firefox

Tweety thoughts

    follow me on Twitter