Super simple MessageDriven Beans in JBoss

Posted June 12, 2009 10:02 in Java by Andreas

If you ever need JMS-messages to trigger certain actions, a MessageDriven Bean is usually a good starting point. With EJB3 annotations it’s really as easy as it gets.

Just extend MessageListener and annotate your class with a @MessageDriven annotation and you are ready to go.

Package as jar and hot-deploy in JBoss.

Remember to add your dependencies in the lib folder as well.

3691 comments

Testing Rake tasks with Cucumber

Posted June 07, 2009 23:28 in Testing, Rails by Andreas

One great thing about Cucumber is that it provides a great entry-point for testing code not directly associated with your application, in example Rake tasks. And since nowadays everyone is
TATFT you should also be testing your Rake tasks.

The challenge

While developing this blog, I wanted to populate the database with some test data, first and foremost to see how the design managed larger amounts of data.

HTFDITT? (How The Fuck Do I Test This?)

First you need to write the feature. It could look something like this.

Then you need to implement the steps. I made a file called rake_task_steps.rb in features/step_definitions.

To make it work you need to require some rake libs, and load the rake-file you are testing. Don’t try to replace the rake step with something like `rake #{task}`, especialy if you’re using sqlite3 as your test database, I spent half a night trying to figure out why my test wasn’t working properly…

Aftermath

When the tests are red, then you just code one step at a time until they are all green. You could debate the granularity of the last step, since it actually passes if there are more than one record in the database, while my rake task generates a couple of hundred. If you would want to populate you own database, I’d recommed using either factory_girl or Machinist. Two great gems for mass production and fixture replacements.

3686 comments