Archive for the 'grails' Category

Mar 31st 2008 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.
Continue Reading »

17 Comments » Posted by tednaleid / command line and grails and groovy

Mar 25th 2008 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.

Continue Reading »

6 Comments » Posted by tednaleid / command line and grails and osx

Mar 24th 2008 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).

Continue Reading »

2 Comments » Posted by tednaleid / grails and groovy and unit testing

Mar 19th 2008 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:

Continue Reading »

11 Comments » Posted by tednaleid / grails and groovy

Mar 13th 2008 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?

Continue Reading »

4 Comments » Posted by tednaleid / grails and groovy and osx and unit testing

« Prev