![JAR search and dependency download from the Maven repository](/logo.png)
FitNesseRoot.RestFixtureFitTests.JavascriptExpectations.content.txt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of smartrics-RestFixture-LiveDoc Show documentation
Show all versions of smartrics-RestFixture-LiveDoc Show documentation
FitNesse tests documenting the RestFixture
!3 Expectations in Javascript on responses with content type application/json
As of .RestFixture Version 2, a javascript engine is embedded to allow expectations in Javascript on response body contents in JSON format.
!**** XPaths and JSON
For backward compatibility XPath expressions are maintained and executed
****!
After a successful response is received with content type "application/json" the expectation cell in a .RestFixture row is
interpreted as a string with Javascript and executed within the context of the response body.
| Fit Rest Fixture |http://${jettyHost}:${jettyPort}|
|setBody|!- { "resource" : { "name" : "test post", "data" : "some data" } } -!|
|POST | /resources/ | 201 | | no-body |
|let | id | header | Location:/resources/(.+) | |
A variable jsonbody
is defined holding the JSON in the response.
The test passes if the result of the evaluation of the cell is a boolean.
| Fit Rest Fixture |http://${jettyHost}:${jettyPort}|
|GET | /resources/%id%.json | 200 |Content-Type : application/json |!-
jsonbody.resource.name=="test post" && jsonbody.resource.data=="some data"
-!|
It is possible to specify multiple assertions, one for each line.
The test passes if each line evaluates to true.
| Fit Rest Fixture |http://${jettyHost}:${jettyPort}|
|GET | /resources/%id%.json | 200 |Content-Type : application/json |!-
jsonbody.resource.name.length>=0
jsonbody.resource.name.length<1000
-!|
| let | content | js | response.body | |
| Fit Rest Fixture |http://${jettyHost}:${jettyPort}|
|setBody| %content% |
|POST | /resources/ | 201 | | no-body |
|let | id | header | Location:/resources/(.+) | |
In some cases may be useful to force evaluation of the expectation cell as a javascript block.
By embedding the /* javascript */
comment, the whole expectation cell will be parsed and evaluated entirely using the javascript interpreter.
| Fit Rest Fixture |http://${jettyHost}:${jettyPort}|
|GET | /resources/%id%.json | 200 |Content-Type : application/json |!-
/* javascript */
var concat = jsonbody.resource.name + " and " + jsonbody.resource.data
concat=="test post and some data"
-!|
| let | content | js | response.body | |
© 2015 - 2025 Weber Informatics LLC | Privacy Policy