I am writing some functional tests for the Grails controller, and I feel that it becomes messy when testing query parameters.
I know I can do it, but it just seems awkward.
Map getParms = [id:1, x:foo, y:bar, z:baz]
RestResponse response = builder.get("http://example.com/api/{id}?x={x}&y={y}&z={z}") {
urlVariables getParams
}
Ideally, I would like to:
- Fill in the base URL (i.e. identifier) with the argument
urlVariablesabove - Pass in another query parameter map that adds each as a pair of key values
Sort of:
Map queryParms = [x:foo, y:bar, z:baz]
RestResponse response = builder.get("http://example.com/api/{id}") {
urlVariables id:1
queryVariables queryParams
}
I feel it will be much more “DRY” and easier to read / write.
Does anyone know if such a mechanism exists? I know that I could put together a class for this, but I was hoping to avoid this if there is an existing implementation.
source
share