Grails Tip: Getting JSON directly from Grails MongoDB-GORM Low Level API

One of the nice things about MongoDB is that documents are returned in JSON format.

If you use the Mongo-GORM plugin, however, the driver conveniently converts the returned results into a Grails domain class instance. You then have to serialize this domain class to get a JSON result back.

In this post, I will show how to use the low level mongodb API to just get a JSON response back in your controllers.

Continue reading

12 New Things I Learned From a Three Day Gradle Training

During the last three days, Sky was able to engage Luke Daley from Gradleware to come teach us about Gradle.

There was a lot of material covered. But the class format, short slides combined with 25 digestable exercises, made it fairly enjoyable. I would highly recommend this training to any team looking to elevate their understanding of Gradle. You can see a list of upcoming training courses on their website.

In this blog post, I will highlight 12 new things I learned from this training.
Continue reading

How to configure WebDriver in Grails for your Geb Tests.

There has been a bit of discussion in the Grails mailing list about the lack of documentation on configuring webdriver for Geb.

In this post, I will outline the steps you will need to configure the following browsers:

  • Firefox
  • Chrome
  • Internet Explorer
  • Sauce Labs / Remote Webdriver
  • PhantomJS

HTMLUnit won’t be covered because it is broken for grails 2.2 and you shouldn’t be using HTMLUnit.

Continue reading

Gradle Madness – ExecWait: A task that waits for command line calls to be ready

We’re using Gradle as a test runner for our fairly heterogenous project ( built with grails, dropwizard and yeoman ).

One of the problems we ran into is that we wanted to execute our tests when all our services were ready.

There doesn’t seem to be a way to do so with the standard Exec task. There are plugins that allow you to start, say, Tomcat, Vert.X or the Google App Engine.

But it felt really cumbersome to have to write a task that simply starts yeoman or grails. This seems to be a common question around testing. Both being asked before in the mailing list, StackOverflow and Gradle JIRA.

In this post, I write about a hack we wrote to allow Exec to wait for a service to be ready and ask for better ways of doing this type of work in Gradle.

Continue reading

Testing DropWizard Applications with Spock and Groovy

DropWizard is a really cool framework / library that allows you to quickly build production-ready HTTP+JSON REST services. It is built on mature libraries like Jetty, Jersey, Jackson and Metrics.

The framework bring together a lot of neat ideas for API monitoring like Health checks and simple application metrics via Metrics. DropWizard is very performant, claiming to be able to handle 15,000-20,000 requests per second. There is a pretty good video hailing the benefits of  DropWizard here. The MongoDB-DropWizard slideshow is also very good to see what is possible with the framework.

Compared to Grails, DropWizard feels slightly more lightweight and perfect for services that don’t really have much of a front-end. DropWizard and JavaScript fat clients is the new black.

In this post, I will share how you can use Spock and Groovy instead of the Java / JUnit / Mockito examples provided by the DropWizard User Manual.

If you are not familiar with DropWizard or the testing of DropWizard applications, I suggest reading their Quick Start Guide and User Manual. I will use the Representations and Resources in the Testing DropWizard chapter of their user guide as the basis for this post.

Continue reading

Nested dynamic attributes with Grails Mongodb Plugin

Of the cool features of the Grails MongoDB gorm plugin is dynamic attributes – the ability to define properties in domain classes in an ad-hoc manner. This is actually quite cool since you can have very light domain classes in grails and keep your schemas fairly flexible.

In this post, I will show you how to use nested dynamic attributes with the grails mongodb plugin. Continue reading