Dashboard > GreenPepper Open Documentation Refactoring > ... > 8. Developer examples > RestFixture
  GreenPepper Open Documentation Refactoring Log In View a printable version of the current page.  
  RestFixture
Added by Laurent Cobos, last edited by Laurent Cobos on Aug 13, 2009  (view change)
Labels: 
(None)

Rest Fixture sample

Only available in Java

Here is an example of a fixture to test Rest web services.
RestFixture code can be found in greenpepper-extension-sandbox : RestFixture.java

RestFixture support GET POST DELETE PUT HEAD HTTP methods.
Available readable properties are responseHeader(headerName) responseBody responseStatus

Import
com.greenpepper.extensions
do with Rest Fixture on http://localhost:9998

GET example

GET /helloworld
check response status 200
check response header Content-Type text/plain
check response body Hello World
GET /unknown
check response status 404

POST example (create resource)

set request body Hello GreenPepper
POST /messages
check response status 201
check response header Location http://localhost:9998/messages/0
GET /messages/0
check response status 200
check response body Hello GreenPepper

Request with custom header example

set request header Accept as application/xml
GET /messages/0
check response status 200
check response body
<?xml version="1.0"><message id="0" value="Hello GreenPepper" />

PUT example (update resource)

set request body Hello from GreenPepper
PUT /messages/0
check response status 200
GET /messages/0
check response body Hello from GreenPepper

HEAD example (check if specified resource exists)

HEAD /messages/0
check response status 200
HEAD /messages/1
check response status 404

DELETE example

DELETE /messages/0
check response status 200
GET /messages/0
check response status 404
end

DEMONSTRATION LICENSE - This Confluence site is for demonstration purposes only. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.4.3 Build:#705 Mar 21, 2007) - Bug/feature request - Contact Administrators