I have a service method that takes params as an input and creates a domain class passing in params for auto binding. Testing of this is simple by specifying params as a map of key value pairs. However, I don’t know how to simulate an array of associated objects in the params map.
I observed client side sending in params in the following format:
["description":"abc", "subTask[0].name": "first subtask name"]
How do I mock this type of params? Since this is not a controller test I can not use mockParams AFAIK.
The answer turns out to be this:
Since controller params map parsing is not available in a Service class you have to convert values and objects on your own. So in my example I have to manually create an array of associated objects within the params map. Here is an example:
Hope this helps somebody.