Included page: .RestFixtureTests.SetUp (edit)
| script | smartrics.rest.test.fitnesse.fixture.HttpServerFixture | |
| check | is started | true |
| reset resources database | ||
Usages of LET (See also PostTests for more examples)
LET used to extract values from header, using regular expressions
| Table: Rest Fixture | http://localhost:9876 | |||
| setBody | <resource><name>Bill</name><data>Some data on Bill</data></resource> | |||
| POST | 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.
| Table: Rest Fixture | http://localhost:9876 | |||
| GET | 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'] expected <resource><name>Bill</name><data>Some data on Bill</data></resource> actual |
|
| let | name | body | /resource/name/text() |
Bill |
...or from a JSON body
| Table: Rest Fixture | http://localhost:9876 | |||
| GET | 200 |
Content-Type : application/json 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 |
|
| let | name | body | /resource/name/text() |
a funky name |
LET resolves names from Fixture Symbol map if not found in the local map
LetTestSupport allows to get/set values in the Fixture Symbol map
| script | smartrics.rest.test.fitnesse.fixture.LetTestSupport |
| assign | /resources |
| $resType<-[/resources] | value |
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%
| Table: Rest Fixture | http://localhost:9876 | |||
| GET | 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 |
| script | smartrics.rest.test.fitnesse.fixture.LetTestSupport | |
| assign | $theName | |
| check | value | 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...
| script | smartrics.rest.test.fitnesse.fixture.LetTestSupport |
| assign | /resources |
| $aNameOfASymbol<-[/resources] | value |
... then the value is used by the .RestFixture
| Table: Rest Fixture | http://localhost:9876 | |||
| GET | 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> |
|