Included page: .RestFixtureTests.SetUp (edit)
| script | smartrics.rest.test.fitnesse.fixture.HttpServerFixture | |
| check | is started | true |
| reset resources database | ||
Posting an XML should create a resource
Note
You set the body for the POST operation with the setBody.
Here you can see how let is used. The first cell is the label of the variable.
The follwoing cell indicates where to get the data from. That is either the header or the _body_ of the last successful HTTP response
Then the expression to extract the value to be assigned to he variable. For header it has to be a regular expression, for _body_ it
has to be an XPath whose execution must return a String node.
Here you can see how let is used. The first cell is the label of the variable.
The follwoing cell indicates where to get the data from. That is either the header or the _body_ of the last successful HTTP response
Then the expression to extract the value to be assigned to he variable. For header it has to be a regular expression, for _body_ it
has to be an XPath whose execution must return a String node.
| Table: Rest Fixture | http://localhost:9876 | |||
| let | name | const | test post |
test post |
| setBody | <resource><name>test post</name><data>some data</data></resource> |
|||
| POST | 201 |
Location : /resources/2 Content-Length : 0 Server : Jetty(6.0.2) |
no-body |
|
| let | id | header | Location:/resources/(.+) |
2 |
Note
Variables are global: here the GET op is executed on an URI containing %id% where the label 'id' is defined in the test above.
The test succeedes only if the resulting XPath match the XML used for the creation of the resource.
You can also put variables in the expected result
The subsequent let operation shows how to use XPaths in the body.
Label values can be accessed from code using new Variables().get("labelname");
The test succeedes only if the resulting XPath match the XML used for the creation of the resource.
You can also put variables in the expected result
The subsequent let operation shows how to use XPaths in the body.
Label values can be accessed from code using new Variables().get("labelname");
Note on fit.Fixture symbol map
Labels are implemented on top of the Fitnesse symbols map. So every label set via .RestFixture is accessible via fit.Fixture.getSymbol().
If a label starts with $, the $ is ignored.
If a label starts with $, the $ is ignored.
| Table: Rest Fixture | http://localhost:9876 | |||
| GET | 200 |
Set-Cookie : JID="ABC.${a.y}"; Content-Type : application/xml;charset=ISO-8859-1 Content-Length : 65 Server : Jetty(6.0.2) |
/resource/name[text()='test post']<br/> /resource/data[text()='some data'] expected <resource><name>test post</name><data>some data</data></resource> actual |
|
| let | name | body | /resource/name/text() |
test post |
| let | $symName | body | /resource/name/text() |
test post |
Labels that are set to null are rendered using the default value for null, e.g. the string "null"
| Table: Rest Fixture | http://localhost:9876 | |||
| GET | 200 |
Set-Cookie : JID="ABC.${a.y}"; Content-Type : application/xml;charset=ISO-8859-1 Content-Length : 65 Server : Jetty(6.0.2) |
<resource><name>test post</name><data>some data</data></resource> |
|
| let | thisIsNull | body | /resource/somewhereelse/text() |
|
| comment | this is null: 'null' |
|||
Albeit, the value can be overridden
| Table: Rest Fixture Config | withBespokeNullRepresentation |
| restfixture.null.value.representation |
| Table: Rest Fixture | http://localhost:9876 | withBespokeNullRepresentation | ||
| GET | 200 |
Set-Cookie : JID="ABC.${a.y}"; Content-Type : application/xml;charset=ISO-8859-1 Content-Length : 65 Server : Jetty(6.0.2) |
<resource><name>test post</name><data>some data</data></resource> |
|
| let | thisIsNull | body | /resource/somewhereelse/text() |
|
| comment | this is null: '' |
|||
| Table: Rest Fixture Config | withBespokeNullRepresentation |
| restfixture.null.value.representation | NIL |
| Table: Rest Fixture | http://localhost:9876 | withBespokeNullRepresentation | ||
| GET | 200 |
Set-Cookie : JID="ABC.${a.y}"; Content-Type : application/xml;charset=ISO-8859-1 Content-Length : 65 Server : Jetty(6.0.2) |
<resource><name>test post</name><data>some data</data></resource> |
|
| let | thisIsNull | body | /resource/somewhereelse/text() |
|
| comment | this is null: 'NIL' |
|||
Json
Expectations can be asserted also in json format for responses whose content type is 'application/json'
Variables may be substitued in the expected result
Variables may be substitued in the expected result
| Table: Rest Fixture | http://localhost:9876 | |||
| setBody | { "resource" : { "name" : "test post", "data" : "some data" } } | |||
| POST | 201 |
Location : /resources/3 Content-Length : 0 Server : Jetty(6.0.2) |
no-body |
|
| let | id | header | Location:/resources/(.+) |
3 |
| 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 : 65 Server : Jetty(6.0.2) actual |
jsonbody.resource.name=='test post' <br/> jsonbody.resource.data=='some data' expected { "resource" : { "name" : "test post", "data" : "some data" } } actual |
|
Other than the aforementioned content types you can emulate form POSTs.
Remember to escape the setBody content cell with
| Table: Rest Fixture | http://localhost:9876 | |||
| setHeader | Content-Type : application/x-www-form-urlencoded;charset=UTF-8 |
|||
| setBody | name=test%20post&data=some%20data | |||
| POST | 201 |
Location : /resources/4 Content-Length : 0 Server : Jetty(6.0.2) |
no-body |
|
| let | id | header | Location:/resources/(.+) |
4 |
| 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()='test post'] /resource/data[text()='some data'] expected <resource> <name>test post</name> <data>some data</data> </resource> actual |
|
Header values can also be substituted with symbols previously defined:
| Table: Rest Fixture | http://localhost:9876 | |||
| let | contenttype | const | application/x-www-form-urlencoded;charset=UTF-8 |
application/x-www-form-urlencoded;charset=UTF-8 |
| setHeader | Content-Type : application/x-www-form-urlencoded;charset=UTF-8 |
|||
| setBody | name=test%20post&data=some%20data | |||
| POST | 201 |
Location : /resources/5 Content-Length : 0 Server : Jetty(6.0.2) |
no-body |
|
| let | id | header | Location:/resources/(.+) |
5 |
| 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()='test post'] /resource/data[text()='some data'] expected <resource> <name>test post</name> <data>some data</data> </resource> actual |
|