Friday Repost: Groovy Test Data Builder Pattern

Posted by on Sep 16, 2011 in Groovy | 0 comments

The Friday Repost series are copies from my earlier writings. Since I don’t want to loose them, and they might prove useful to others, I’m reposting them on this blog Most of us value the quality of our code highly. I do, and I expect you, as a reader, also to care for the quality of your code. Because of that, we write tests. Test which usually contain of 3 parts: the setup, the execution and the verification. And sometimes some cleanup. In this blog, I’d like to focus on the setup part, and try to get rid of some...

read more

Friday Repost: Preventing spam with Groovy and Grails

Posted by on Sep 9, 2011 in Grails, Groovy | 0 comments

The Friday Repost series are copies from my earlier writings. Since I don’t want to loose them, and they might prove useful to others, I’m reposting them on this blog When I created the jworks.nl website in Grails, one of my requirements was to have a blog. Since the website is created in Grails, and the Grails application doesn’t integrate easily with a standard blogging solution like WordPress, I decided to create my own blogging solution. But, since this proved to be much more painful than initially anticipated, I migrated...

read more

Friday Repost: Indexing documents with Tika and Grails

Posted by on Sep 2, 2011 in Grails, Groovy | 0 comments

The Friday Repost series are copies from my earlier writings. Since I don’t want to loose them, and they might prove useful to others, I’m reposting them on this blog In one of the previous blogposts, I described a way to easily upload images by using Grails commands. This blogpost further builds on that, by providing a generic way to index uploaded documents. These documents can later be retrieved by using the search option provided by the Grails Search plugin. To index documents, we’re going to need two components: one of...

read more

GStringImpl cannot be cast to java.lang.String

Posted by on Aug 29, 2011 in Grails, Groovy | 1 comment

Last week, we got a nasty error in our application: java.lang.ClassCastException: org.codehaus.groovy.runtime.GStringImpl cannot be cast to java.lang.String The stacktrace was not helpful at all, and showed that the error was caused by a NullPointerException in Melody, which was a false message. After some searching around, we found the following code to be the culprit: render(view: 'index', model: ["${command.class.simpleName}": command) What happens here, is that a GString is used as a map key for rendering the model in the view....

read more

Friday Repost: Groovy’s @Immutable pitfalls

Posted by on Aug 26, 2011 in Groovy | 0 comments

The Friday Repost series are copies from my earlier writings. Since I don’t want to loose them, and they might prove useful to others, I’m reposting them on this blog. Groovy 1.6 introduced some Groovy AST transformations like @Lazy, @Delegate and @Immutable, and there are more. This blog describes some pitfalls of using @Immutable, but to do that, a proper example of @Immutable seems well deserved. A first introduction @Immutable, like the name suggests, makes your classes immutable. This means that state changes from the...

read more

Testing Grails applications with Geb and JsTestDriver on a headless Bamboo CI server

Posted by on Aug 24, 2011 in Uncategorized | 0 comments

In our project we are using two testing tools – Geb and JsTestDriver. Geb is a tool for functional testing of web applications and is basically a layer on the top of Selenium’s WebDriver so that the test you write are more groovy and more fun to write. JsTestDriver on the other hand is a tool for unit testing javascript in your project. Together with Sinon.JS which is a javascript mocking framework they give you an easy solution to get your javascript code unit tested. Both of the aforementioned frameworks need real browsers to...

read more

Our Grails Stats: but what are yours?

Posted by on Aug 22, 2011 in Grails | 8 comments

We’re currently working on a Grails project for over a year now, with, on average, around 8 people including testers. I thought it would be nice to share our project statistics, but I’m wondering how our statistics compare to yours. +----------------------+-------+-------+ | Name | Files | LOC | +----------------------+-------+-------+ | Controllers | 73 | 8394 | | Domain Classes | 122 | 4571 | | Jobs | 2 | 27 | | Services | ...

read more

Friday Repost: Groovy and Null

Posted by on Aug 19, 2011 in Groovy | 2 comments

The Friday Repost series are copies from my earlier writings. Since I don’t want to loose them, and they might prove useful to others, I’m reposting them on this blog To start, I find it surprising that there’s so little information to be found about this topic. Maybe it’s just me, so let’s start with a test. If you pass all questions, you don’t win much, but then there’s no need to further read this blog I guess. So, without further ado, question 1. Question 1 What’s the result of the following...

read more

Excluding fields and properties from marshalling using annotations in Grails

Posted by on Aug 15, 2011 in Grails, Groovy | 0 comments

Recently the flexible and configurable marshalling system of Grails was mentioned on Twitter by Graeme Rocher as needing some more documentation. That was probably the outcome of the interesting blog post by J-Wicz on the matter. Rob Fletcher has also blogged about it quite some time ago. The issue got my attention because in our project I needed to exclude some fields from marshalling on a DTO. The reason for that might be various, for me it was a fact that the DTO contained some intermediate data which was then used to determine a value that...

read more

Friday Repost: Remove Groovy MetaClass methods

Posted by on Aug 12, 2011 in Grails, Groovy | 0 comments

The Friday Repost series are copies from my earlier writings. Since I don’t want to loose them, and they might prove useful to others, I’m reposting them on this blog Whenever you are using metaclasses in Groovy or Grails unit tests, you might use Groovy’s metaClass power to mock the behavior of methods. However, Grails doesn’t fork the JVM for each test, so a nice side effect of this is that the mocked method will be available for the complete lifetime of the VM. Since Grails first executes unit tests (the test which...

read more