Included page: .RestFixtureFitTests.SetUp (edit)
| Action Fixture | ||
| start | smartrics.rest.test.fitnesse.fixture.HttpServerFixture | |
| check | is started | true |
| press | reset resources database | |
LET
Usages of LET (See also RestFixtureTests.FitTests.PostTests[?] for more examples)
LET used to extract values from header, using regular expressions
| Fit Rest Fixture | http://localhost:7654 | |||
| setBody | <resource><name>Bill</name><data>Some data on Bill</data></resource> | |||
| POST | /resources/ | 201 | Location : /resources/2 Content-Length : 0 Server : Jetty(6.0.2) |
no-body |
| let | id | header | Location:/resources/(.+) | 2 |
The regex is applied to each header. On the first match the first group is extracted and
assigned as value to the label id.
Labels are global and can be shared across rest fixture instances.
LET used to extract values from XML body via XPath
Values are re-usable across instances of .RestFixture
Here follows an usage of the previously extracted id.
This example also shows how to use let to extract data from the XML body of a response using XPath.
| Fit Rest Fixture | http://localhost:7654 | |||
| GET | /resources/2 | 200 | Set-Cookie : JID="ABC.${a.y}"; Content-Type : application/xml;charset=ISO-8859-1 Content-Length : 68 Server : Jetty(6.0.2) |
/resource/name[text()='Bill']<br/> /resource/data[text()='Some data on Bill'] |
| let | name | body | /resource/name/text() | Bill |
...or from a JSON body
| Fit Rest Fixture | http://localhost:7654 | |||
| GET | /resources/1.json | 200 | Content-Type : application/json | jsonbody.resource.name=='a funky name' <br/> jsonbody.resource.data=='an important message' |
| let | name | body | /resource/name/text() | a funky name |
LET resolves names from Fixture Symbol map if not found in the local map
LetTestActionFixture allows to get/set values in the Fixture Symbol map
| Action Fixture | ||
| start | smartrics.rest.test.fitnesse.fixture.LetTestActionFixture | |
| enter | symbolName | resType |
| enter | symbolValue | /resources |
Note
Look at the source code of this page to see that the resource URI
for the GET method below is defined as %resType%/%id%
for the GET method below is defined as %resType%/%id%
| Fit Rest Fixture | http://localhost:7654 | |||
| GET | /resources/2 | 200 | Set-Cookie : JID="ABC.${a.y}"; Content-Type : application/xml;charset=ISO-8859-1 Content-Length : 68 Server : Jetty(6.0.2) |
<resource><name>Bill</name><data>Some data on Bill</data></resource> |
| let | theName | body | /resource/name/text() | Bill |
| Action Fixture | ||
| start | smartrics.rest.test.fitnesse.fixture.LetTestActionFixture | |
| enter | symbolName | theName |
| check | symbolValue | Bill |
Other fixtures can set a value in the symbol map with Fixture.setSymbol.
The .RestFixture can then pick them up
This fixture sets symbolName=/resources...
| Action Fixture | ||
| start | smartrics.rest.test.fitnesse.fixture.LetTestActionFixture | |
| enter | symbolName | aNameOfASymbol |
| enter | symbolValue | /resources |
... then the value is used by the .RestFixture
| Fit Rest Fixture | http://localhost:7654 | |||
| GET | /resources/2 | 200 | Set-Cookie : JID="ABC.${a.y}"; Content-Type : application/xml;charset=ISO-8859-1 Content-Length : 68 Server : Jetty(6.0.2) |
<resource><name>Bill</name><data>Some data on Bill</data></resource> |