Blog has been moved to http://naleid.com/blog

I’ve set up a new server on slicehost and moved the existing posts over there to a new wordpress instance.

I’ve set up redirection for the next year from http://tednaleid.wordpress.com to http://naleid.com/blog.

If you’re seeing this message, please update your links to the new host.

Monitoring HTTP traffic to debug your Grails application

I’m often surprised when I run across developers who don’t have a variety of HTTP traffic monitoring apps as an integral part of their toolkit. When doing Grails development (or any web development really), being able to see the actual information that is going over the wire is invaluable.

Firebug

These days, more and more people are familiar with the amazing Firefox plugin Firebug. It allows you to view request and response information along with many other tricks.

Read More »

Using Gant to execute a groovy script within the Grails context (updated)

In a previous post I showed a script that I had created to allow the execution of a groovy script within a grails application context (including access to domain objects, controllers, services, etc). A couple of people reported a problem with the script where they were getting lazy initialization exceptions. I finally tracked this issue down to one where many-to-many relationships are being used between two domain classes.

Here is an updated script that fixes this issue by setting up the hibernate session in the Gant script.
Read More »

Autocomplete Grails Script Names in bash/zsh

Jesse over at Refactr posted a nice tip about using tab completion for the ssh command. It grabs host names and IPs out of the ssh known_hosts file.

That got me to thinking that it would be pretty useful to have tab completion of Grails commands available. At my company, we’ve written about 20 custom Gant scripts and it can sometimes be a problem to remember their names. Running “grails help” often takes too long, so I probably ls scripts once a day or so to remind myself if it’s clean-db or clear-db.

I did a quick google search and found that Scott Davis posted some instructions about a year ago (originally by Doyle@DoyleCentral).

It was a good start, but there were two issues I had with the solution. The first is that it only worked in bash (I prefer zsh) and the second is that it used a static list of script names stored in the GRAILS_HOME directory. Any new scripts, or app specific scripts would need to be manually added to the static list.

Grails Gant scripts can exist in 4 possible locations:

  • $GRAILS_HOME/scripts
  • $USER_HOME/.grails/scripts
  • $PROJECT_HOME/scripts
  • $PROJECT_HOME/plugins/*/scripts

After some playing around, I was able to come up with a bash script that allows for real-time completion of all four potential script repositories. $PROJECT_HOME is considered to be the current directory, so if you’re not in a grails app, you’ll only see completion scripts for the first two.

Read More »

Unit Testing Isolated Methods with Groovy

Glen Smith has been running a great series of posts this month to help people get started with unit testing. In that sprit, I thought I’d put out a post on some unit testing work that I’ve been doing recently.

There are a number of libraries and techniques for unit testing with groovy. It comes with MockFor and StubFor out of the box, and you can also leverage Java libraries like EasyMock and Mockito if your needs aren’t satisfied by the built-in constructs.

The mock and stub implementations that I mention above work well for allowing you to control the behavior of any collaborators, but what if your method calls another method within the same class? None of those solutions (as far as I’m aware) allow you to replace the behavior of other methods on the Class Under Test (CUT). If you are trying to unit test your method in true isolation, you need the ability to stub out the behavior of internal methods on the class (for example, to throw an exception to test try/catch logic).

Read More »

Using Gant to execute a groovy script within the Grails context

(3/30/08 I’ve posted an update to this script that fixes the problems noted in the comments)

I’ve been working with Gant recently and wanted the ability to be able to execute a script within the grails context, but not add it as part of a controller or needing to paste it every time in a grails console/shell.

After a little playing around, I came up with this:

Read More »

Using the OSX Console.app to aid Grails Test Driven Development

With Groovy built-in, Grails is one of the best platforms running on the JVM for doing unit testing.

One limitation that it does have is that the current testing scripts seem to be oriented more towards creating test reports rather than giving the user the quick feedback that is helpful when doing Test Driven Development.

Here’s an example of the output that you get on a failed test after running “grails test-app”:

-------------------------------------------------------
Running 1 Integration Test...
Running test BookTests...
testBookHasExpectedTitle...FAILURE
Integration Tests Completed in 622ms
-------------------------------------------------------
[junitreport] Transform time: 944ms

Tests failed: 0 errors, 1 failures, 0 compilation errors. View reports in /Users/ted/Documents/workspace/foobar/test/reports

Ok, that’s great…a test failed. But why? Where is the stacktrace and any output generated during the test?

Read More »