Included page: .RestFixtureTests.SetUp (edit)
| script | smartrics.rest.test.fitnesse.fixture.HttpServerFixture | |
| check | is started | true |
| reset resources database | ||
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
| Table: Rest Fixture | http://localhost:9876 | |||
| GET | 200 |
Content-Length : [\d]+ expected Set-Cookie : JID="ABC.${a.y}"; Content-Type : application/xml;charset=ISO-8859-1 Content-Length : 183 Server : Jetty(6.0.2) actual |
/resource/name[text()='a funky name'] <br/> /resource/data[text()='an important message'] expected <resource> <name>a funky name</name> <data>an important message</data> <nstag xmlns:ns1='http://smartrics/ns1'> <ns1:number>3</ns1:number> </nstag> </resource> actual |
|
| Table: Rest Fixture | http://localhost:9876 | |||
| GET | 200 |
Content-Length : [\d]+ expected Set-Cookie : JID="ABC.${a.y}"; Content-Type : application/xml;charset=ISO-8859-1 Content-Length : 183 Server : Jetty(6.0.2) actual |
/resource/name[text()='a funky name'] <br/> /resource/data[text()='an important message'] expected <resource> <name>a funky name</name> <data>an important message</data> <nstag xmlns:ns1='http://smartrics/ns1'> <ns1:number>3</ns1:number> </nstag> </resource> actual |
|
A GET request properly handles query strings. In this example the stub resource echoes the query string in a Query-String header
| Table: Rest Fixture | http://localhost:9876 | |||
| GET | 200 |
Content-Length : [\d]+ Query-String : param=echome&something=else&another=parameter expected Query-String : param=echome&something=else&another=parameter Set-Cookie : JID="ABC.${a.y}"; Content-Type : application/xml;charset=ISO-8859-1 Content-Length : 183 Server : Jetty(6.0.2) actual |
/resource/name[text()='a funky name'] <br/> /resource/data[text()='an important message'] expected <resource> <name>a funky name</name> <data>an important message</data> <nstag xmlns:ns1='http://smartrics/ns1'> <ns1:number>3</ns1:number> </nstag> </resource> actual |
|
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
| Table: Rest Fixture | http://localhost:9876 | |||
| GET | 404 |
Content-Length : 0 expected Set-Cookie : JID="ABC.${a.y}"; Content-Length : 0 Server : Jetty(6.0.2) actual |
no-body |
|
| GET | 404 |
Content-Length : 0 expected Set-Cookie : JID="ABC.${a.y}"; Content-Length : 0 Server : Jetty(6.0.2) actual |
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)
| Table: Rest Fixture | http://localhost:9876 | |||
| GET | 200 |
Content-Length : [\d]+ expected Set-Cookie : JID="ABC.${a.y}"; Content-Type : application/xml;charset=ISO-8859-1 Content-Length : 183 Server : Jetty(6.0.2) actual |
/resource/nstag/ns1alias:number[text()='3'] expected <resource> <name>a funky name</name> <data>an important message</data> <nstag xmlns:ns1='http://smartrics/ns1'> <ns1:number>3</ns1:number> </nstag> </resource> actual |
|
Json
Expectations can be asserted also in json format for responses whose content type is 'application/json' or 'application/x-javascript'
| Table: Rest Fixture | http://localhost:9876 | |||
| GET | 200 |
Content-Type : application/json;charset=ISO-8859-1 expected Set-Cookie : JID="ABC.${a.y}"; Content-Type : application/json;charset=ISO-8859-1 Content-Length : 77 Server : Jetty(6.0.2) actual |
jsonbody.resource.name=='a funky name' <br/> jsonbody.resource.data=='an important message' expected { "resource" : { "name" : "a funky name", "data" : "an important message" } } actual |
|
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*
| Table: Rest Fixture Config | withArrayParametersSupport |
| http.client.use.new.http.uri.factory | true |
| Table: Rest Fixture | http://localhost:9876 | withArrayParametersSupport | ||
| GET | 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)
| Table: Rest Fixture Config | withFollowRedirect |
| restfixture.requests.follow.redirects | false |
| Table: Rest Fixture | http://localhost:9876 | withFollowRedirect | ||
| GET | 301 |
Location: /resources/0 expected Location : /resources/0 Content-Length : 0 Server : Jetty(6.0.2) actual |
no-body |
|
| Table: Rest Fixture Config | withFollowRedirect |
| restfixture.requests.follow.redirects | true |
| Table: Rest Fixture | http://localhost:9876 | withFollowRedirect | ||
| GET | 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> |
|