tags:

views:

32

answers:

1

I'd like to test the URL Mappings for a simple REST web service that I'm setting up in Grails. The problem is that the URL mappings are defined with the HTTP method:

class UrlMappings {
    static mappings = {
        "/blah/$city/$date"(controller:"blah"){
            action = [GET:"show", PUT:"update", POST:"save"]
        }
    }
}

The GrailsUrlMappingsTestCase doesn't seem to support passing in an HTTP method, it just takes a URL and a list of assertions.

Is there a way to get the GrailsUrlMappingsTestCase to play nice with RESTful webservice mappings? Or, is there a different way or better to test URL mappings?

+1  A: 

The original code has not this feature. I see two possibilities how to do test REST service.

1) Functional test

You can setup a functional test which tests your app on running web container. Your application will be deployed and functional test will run. The tests are Unit tests again. Take a look on grails functional testing or functional testing plugin.

2) Extend GrailsUrlMappingsTestCase

Since grails is open source you can extend GrailsUrlMappingsTestCase and add this feature. The source code for this class looks quite simple.

amra
Thanks for the answer. Yes, I'm going to try to extend GrailsUrlMappingTestCase as soon as I get a chance. It is currently covered with functional tests.
Javid Jamae
And when you finish it commit it also into grails project.
amra