webtestcanoocanoo-webtest

Grails Canoo Webtest plugin: invoke() fails to send JSON data in POST request


I'm evaluating Canoo Webtest for automated integration/functional testing as a Grails plugin.

I have a REST app which I'm attempting to test, but Canoo Webtest doesn't seem to properly send the JSON data in POST request. My test code is like below

invoke( description:"Add a product to shopping cart", 
        url:'shoppingCart/add', method:'POST', 
        content:'{"class":"shop.service.Product", "name":"A product", "description":"Manufactured by X", "price":99.9}'
        //contentFile: '../product.json'
        )

The request body is empty no matter whether I use contentFile approach or inline the data as content attribute. The test report shows the data as being sent correctly, but error page shows an error stating 'JSONException: Missing value. at character 0 of '. JSON data as a response of GET request is coming back fine.

I have tested the same functionality with curl and it works perfectly fine. Is there something I'm missing in the Canoo Webtest setup?

Thanks.

EDIT: I'm using Grails 1.3.7 in case that makes any difference


Solution

  • OK. I started to just experiment with the invoke() and seems that setting attribute soapAction value to true does the trick.

    I have no clue why this works. The documentation of invoke() for the attribute says

    soapAction
      Required? no
      If the HTTP method is POST and is in fact a SOAP POST request, 
      this allows the SOAP Action header to be set. Ignored for GETs.
    

    Apparently it sets some needed request header. Haven't checked which one.

    Thank you for reading :)

    Cannot yet mark this answer as the correct one, but will do so when it's possible.