FitNesseRoot.RestFixtureFitTests.LetTests.content.txt Maven / Gradle / Ivy
!3 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://${jettyHost}:${jettyPort}|
|setBody|Bill Some data on Bill |
|POST | /resources/ | 201 | | no-body |
|let | id | header | Location:/resources/(.+) | |
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://${jettyHost}:${jettyPort}|
|GET | /resources/%id% | 200 | |!-
/resource/name[text()='Bill']
/resource/data[text()='Some data on Bill']
-! |
|let | name | body | /resource/name/text() | |
...or from a JSON body
| Fit Rest Fixture |http://${jettyHost}:${jettyPort}|
|GET | /resources/1.json | 200 |Content-Type : application/json|!-
jsonbody.resource.name=='a funky name'
jsonbody.resource.data=='an important message'
-! |
|let | name | body | /resource/name/text() | |
!*** Note
Label values can be accessed from code using '''new Variables().get("labelname");'''
***!
''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%'''
***!
| Fit Rest Fixture |http://${jettyHost}:${jettyPort}|
|GET | %resType%/%id% | 200 | | |
|let | theName | body | /resource/name/text() | |
|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://${jettyHost}:${jettyPort}|
|GET | %aNameOfASymbol%/%id% | 200 | | |