Included page: .RestFixtureFitTests.SetUp (edit)
| Action Fixture | ||
| start | smartrics.rest.test.fitnesse.fixture.HttpServerFixture | |
| check | is started | true |
| press | reset resources database | |
GET
Notes
A GET request is performed on the resource whose URI is specified in the second cell.
The following cell indicate:
1) the expected return HTTP code,
2) a subset of headers - regular expressions are allowed
3) a list of XPaths to be executed in the body. Each XPath is run and it suceedes only if the result of the execution
returns at least one node
The following cell indicate:
1) the expected return HTTP code,
2) a subset of headers - regular expressions are allowed
3) a list of XPaths to be executed in the body. Each XPath is run and it suceedes only if the result of the execution
returns at least one node
| Fit Rest Fixture | http://localhost:7654 | |||
| GET | /resources/0 | 200 | Content-Length : [\d]+ | /resource/name[text()='a funky name'] <br/> /resource/data[text()='an important message'] |
| Fit Rest Fixture | http://localhost:7654 | |||
| GET | /resources/0 | 200 | Content-Length : [\d]+ | /resource/name[text()='a funky name'] <br/> /resource/data[text()='an important message'] |
A GET request properly handles query strings. In this example the stub resource echoes the query string in a Query-String header
| Fit Rest Fixture | http://localhost:7654 | |||
| GET | /resources/0?param=echome&something=else&another=parameter | 200 | Content-Length : [\d]+ Query-String : param=echome&something=else&another=parameter |
/resource/name[text()='a funky name'] <br/> /resource/data[text()='an important message'] |
Get a non existing resource should not find it
Note
Instead of XPaths you can specify 'no-body' if the operation is expected to return an empty body
| Fit Rest Fixture | http://localhost:7654 | |||
| GET | /resources/20 | 404 | Content-Length : 0 | no-body |
| GET | /resources/20.json | 404 | Content-Length : 0 | no-body |
XPaths and namespaces
Namespaces are supported by declaring the alias/uri map in the RestFixtureConfig[?], using the key restfixture.xml.namespace.context (See SuiteSetup)
| Fit Rest Fixture | http://localhost:7654 | |||
| GET | /resources/0 | 200 | Content-Length : [\d]+ | /resource/nstag/ns1alias:number[text()='3'] |
Json
Expectations can be asserted also in json format for responses whose content type is 'application/json' or 'application/x-javascript'
| Fit Rest Fixture | http://localhost:7654 | |||
| GET | /resources/1.json | 200 | Content-Type : application/json;charset=ISO-8859-1 | jsonbody.resource.name=='a funky name' <br/> jsonbody.resource.data=='an important message' |
Rest requests with query string containing array parameters
A query string can contain parameter arrays and they are correctly handled by Rest Fixture.
To allow correct handling of array parameters a new configuration option must be set: *http.client.use.new.http.uri.factory*
| smartrics.rest.fitnesse.fixture.RestFixtureConfig | withArrayParametersSupport |
| http.client.use.new.http.uri.factory | true |
| Fit Rest Fixture | http://localhost:7654 | withArrayParametersSupport | ||
| GET | /resources/0?a[0]=2&a[1]=4 | 200 | Query-String : a[0]=2&a[1]=4 Set-Cookie : JID="ABC.${a.y}"; Content-Type : application/xml;charset=ISO-8859-1 Content-Length : 183 Server : Jetty(6.0.2) |
<resource> <name>a funky name</name> <data>an important message</data> <nstag xmlns:ns1='http://smartrics/ns1'> <ns1:number>3</ns1:number> </nstag> </resource> |
Follow redirects setting
To allow redirects to be followed automatically or not the configuration paramerer
restfixture.requests.follow.redirectsneeds to be set (defaults to true)
| Rest Fixture Config | withFollowRedirect |
| restfixture.requests.follow.redirects | false |
| Fit Rest Fixture | http://localhost:7654 | withFollowRedirect | ||
| GET | /resources/redirect/0 | 301 | Location: /resources/0 | no-body |
| Rest Fixture Config | withFollowRedirect |
| restfixture.requests.follow.redirects | true |
| Fit Rest Fixture | http://localhost:7654 | withFollowRedirect | ||
| GET | /resources/redirect/0 | 200 | Set-Cookie : JID="ABC.${a.y}"; Content-Type : application/xml;charset=ISO-8859-1 Content-Length : 183 Server : Jetty(6.0.2) |
<resource> <name>a funky name</name> <data>an important message</data> <nstag xmlns:ns1='http://smartrics/ns1'> <ns1:number>3</ns1:number> </nstag> </resource> |