dspies / grails-rest-example

Shows a few simple ways to setup a REST backend in Grails
2 stars 2 forks source link

how to test the services #2

Open txpokey opened 10 years ago

txpokey commented 10 years ago

none of the tests in the project do anything, except for the reviews controller. that code came out of the scaffolding.

then I run "/stores" from the browser, it wants to render to show.gsp, which doesn't exist. this is exactly the problem I am seeing in my own, 1st attempt at using RestfulController. (After digging out curl(1), and re-reading the grails documentation, I was able to run some use cases by hand, which I document in a follow up comment).

So the reasons I opened this ticket :

  1. the README.md should be updated with the uri and output one should expect emitted just using the bootstrapped objects.
  2. the test code should actually test something, starting with running the controller actions and also running the controllers as controllers; seeing the uris being mapped.
  3. please put a link or include further documentation on how the HAL feature works in the stores controller, so the end user can run the correct test of that feature. again, there's no automated testing here except for the reviews controller.

p.s. here's a nice link I used w.r.t to testing out the REST via curl

txpokey commented 10 years ago

Ok, so I got these test by hand results... I didn't do all of the uri in the grails documentation

curl -i -H "Accept: application/json" -X GET http://localhost:8080/rest/stores # index will run
curl -i -H "Accept: application/json" -X GET http://localhost:8080/rest/stores/2 # show will run
curl -i -H "Accept: application/json" -X DELTE http://localhost:8080/rest/stores/2 # delete

so when the "stores" curl command is run you get:

curl -i -H "Accept: application/json" -X GET http://localhost:8080/8080/sci.reststore/stores
HTTP/1.1 200 OK Server: Apache-Coyote/1.1 Content-Type: application/json;charset=UTF-8 Transfer-Encoding: chunked Date: Sun, 24 Aug 2014 01:46:08 GMT

[{"class":"demo.Store","id":1,"location":"Tucson, AZ","name":"Store 1"},{"class":"demo.Store","id":2,"location":"Los Angeles, CA","name":"Store 2"}]

so when the delete runs:

... HTTP/1.1 204 No Content Server: Apache-Coyote/1.1 Date: Sun, 24 Aug 2014 01:48:44 GMT

and if you re-run the get on the deleted store:

HTTP/1.1 404 Not Found Server: Apache-Coyote/1.1 Content-Length: 0 Date: Sun, 24 Aug 2014 01:49:16 GMT

txpokey commented 10 years ago

I got this while testing for HAL :

curl -i -H "Accept: application/hal+json" http://localhost:8080/rest/stores
HTTP/1.1 406 Not Acceptable Server: Apache-Coyote/1.1 Content-Length: 0 Date: Sun, 24 Aug 2014 02:21:56 GMT