Archive of articles classified as' "grails"

Back home

Interrogating Arbitrary Groovy Closures for Values

2010/01/24

Inspired by this question on stackoverflow, I decided to create a utility class that allowed me to determine generically what calls a closure makes (without actually letting it make any calls). This lets me see what it’s trying to do before letting it actually do it.
Read the rest of this article »

4 Comments

Grails Testing Alias to Rerun Failed Tests

2009/11/3

A while ago I blogged about my grails testing aliases and how much time they save me.

I’ve made some enhancements to them in the interim that have made them even easier to use.

The most important alias is gtaf, which is short for “grails test-app” for failed tests.

It will search through your test output directory and look for any tests that failed. If it finds any, it will rerun only those tests. Otherwise, it will rerun all tests. That makes it easy to just use gtaf all the time. If any tests fail, it will open them up using Console.app.

If you’re not on OSX, or would like to use something else to view the failed test logs, just modify the testlog alias to do something different.
Read the rest of this article »

7 Comments

Grails Markdown Plugin 0.1 Released

2009/10/6

I’ve just released a quick plugin that I put together tonight to help render markdown text as HTML within a grails application. It leverages the MarkdownJ library.

I’m a big fan of storing information in markdown format as it is easy to read, easy to write, and easy to transform. A number of big websites like stackoverflow.com support the entry and display of markdown text to help people format their questions and answers without having to remember to properly format HTML.

If you’re unfamiliar with Markdown there are a number of good references on it’s use.

The grails markdown plugin is a very basic plugin. Currently, it just wraps the markdown libarary with a single TagLib that lets you easily render html from a markdown string within your gsp pages.

To install it, just type:

grails install-plugin markdown

To use it in your gsp file:

<markdown:renderHtml>
The *four* cardinal directions are
 
- North
- South
- East
- West
</markdown:renderHtml>

renders the html:

<p>The <em>four</em> cardinal directions are</p>
<ul>
    <li>North</li>
    <li>South</li>
    <li>East</li>
    <li>West</li>
</ul>

Or you can use the “text” attribute of the taglib:

<markdown:renderHtml text="${post.body}"/>

See the Grails Markdown Wiki and source for more details.


3 Comments

Batch Import Performance with Grails and MySQL

2009/10/1

I’ve spent some time over the last couple of weeks working on a Grails service that allows us to import new records into our MySQL database.

A number of interesting techniques have popped out of this that I think would be useful for others doing similar types of importing using GORM/Hibernate/MySQL. Read the rest of this article »

29 Comments

Grails build-test-data plugin version 0.2.3 released

2009/08/25

I’ve just released the latest version of the grails build-test-data plugin. This version has a couple of bugfixes that were reported by users. Including one with a nice patch including a test from Robert Fletcher (patches with tests are always appreciated).

For those that aren’t familiar with the plugin, it make creating testing data easy.

It automatically adapts to changes in your domain classes and makes your integration tests easier to write and much less fragile.

Resources

Overall, the plugin has been very stable for the past few releases and I’m thinking about just bumping the version up to 1.0 fairly soon. The plugin seems pretty feature complete when balanced with it’s ease of use. Most of the other features I’ve thought of would explode the complexity level of the plugin and defeat it’s purpose. Might be best to leave well enough alone for now :).

I had a hell of a time with the current grails release-plugin cycle (6 attempts before it finally went through). The grails release-plugin command uses an old version of svnkit that’s only compatible with svn 1.5. I’ve long since upgraded to 1.6 on my mac, though luckily I did it through macports and still had the old version available to activate (sudo port deactivate subversion && sudo port activate subversion @1.5.6_0).

I did some searching around to find out how to install an old version of subversion, but didn’t come up with anything after a quick google so I might be screwed after my wipe/reinstall for snow leopard next week till Grails patches things with svnkit 1.3.

I did open up a JIRA ticket for grails to upgrade to svnkit 1.3, and I was surprised that there wasn’t already a ticket open on it (and that trunk still had svnkit 1.2 in it).

4 Comments

Modularizing Groovy Config Files With a Dash of Meta-Programming

2009/07/30

This is a continuation of a sporadic set of blog posts about some practical uses for groovy metaprogramming.

Groovy Config DSL Overview

In Java, configuration is normally done with properties files. They’re kind of a pain because they’re inflexible, don’t allow executable code, and don’t easily provide a heirarchy.

Groovy greatly improves on Java by building in support for a simple configuration DSL using the ConfigSlurper. Read the rest of this article »

3 Comments

Grails build-test-data presentation

2009/07/14

I gave a presentation tonight on the build-test-data grails plugin at the Groovy Users of Minnesota (GUM) meeting that was well received.

Lots of good questions from the people in attendance. Thanks to everyone for showing up.

Here’s a version of it on slideshow: Read the rest of this article »

5 Comments

Groovy closures make unit testing with “soft asserts” simple

2009/06/25

A recent blog post, Cedric Beust asks about how to cleanly implement “soft asserts”. Soft asserts are test assertions that don’t “fail fast”. Instead, all of the assertion failures in the test method are collected and reported at the end of the test.

So far, the proposals in the comments look fairly clunky to me and include defining whole sets of new methods like “assertEqualsButContinue(“foo”, “foo”)”, chaning assertions together jQuery-style, or using lists to hold all of our assertions.

Wouldn’t it be a lot nicer if we could continue to use the same methods that we’re already using?

In groovy, enabling soft assertions is easy with a little closure magic. Read the rest of this article »

6 Comments

Grails plugin build-test-data 0.2.1 released

2009/06/15

I’ve just released version 0.2.1 of the build-test-data grails plugin.

The build-test-data plugin makes creating integration test data easy. It decorates your domain objects with a “build” method that will create new domain instances and will automatically populate required fields with data and save it to the database. This enables you to create more maintainable tests where the data you create is targeted specifically at the situations you’re trying to test, without having to go through all of the ceremony of creating the rest of the object graph that you don’t care about.

// creates a new Book instance with all required fields 
// (like the Author that the book belongsTo) populated
def b = Book.build()

To learn more about the basics of the build-test-data plugin, see this blog post and check out the Basic Usage and Sample Code wiki pages.
Read the rest of this article »

1 Comment

Grails Testing Command Line Aliases

2009/06/14

I’ve recently thrown together a few different command line aliases that have been very helpful in my grails development and I thought others might benefit from them.

The aliases are primarily just the first letter of the words in the command, which makes them easy to remember (and saves on typing). Some examples:

gta                   # grails test-app
gtai                  # grails test-app -integration
gtaud AuthorService   # grails-debug-suspend test-app -unit AuthorService

Read the rest of this article »

5 Comments