All Downloads are FREE. Search and download functionalities are using the official Maven repository.

FitNesseRoot.RestFixtureTests.PostTests.content.txt Maven / Gradle / Ivy

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.
***!
| Table: Rest Fixture |http://${jettyHost}:${jettyPort}|
| let | name | const | test post | |
|setBody|%name%some data|
|POST   | /resources | 201 | | no-body |
|let    | id | header | Location:/resources/(.+) | |

!*** 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");'''
***!

!*** 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.
***!

| Table: Rest Fixture |http://${jettyHost}:${jettyPort}|
|GET    | /resources/%id% | 200 | |!-
 /resource/name[text()='test post']
/resource/data[text()='some data'] -! | |let | name | body | /resource/name/text() | | |let | $symName | body | /resource/name/text() | | Labels that are set to null are rendered using the default value for null, e.g. the string "null" | Table: Rest Fixture |http://${jettyHost}:${jettyPort}| |GET | /resources/%id% | 200 | | | |let | thisIsNull | body | /resource/somewhereelse/text() | | |comment| this is null: '%thisIsNull%' | Albeit, the value can be overridden | Table: Rest Fixture Config | withBespokeNullRepresentation | | restfixture.null.value.representation | !--! | | Table: Rest Fixture |http://${jettyHost}:${jettyPort}| withBespokeNullRepresentation | |GET | /resources/%id% | 200 | | | |let | thisIsNull | body | /resource/somewhereelse/text() | | |comment| this is null: '%thisIsNull%' | | Table: Rest Fixture Config | withBespokeNullRepresentation | | restfixture.null.value.representation | !-NIL-! | | Table: Rest Fixture |http://${jettyHost}:${jettyPort}| withBespokeNullRepresentation | |GET | /resources/%id% | 200 | | | |let | thisIsNull | body | /resource/somewhereelse/text() | | |comment| this is null: '%thisIsNull%' | !**** 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 ****! | Table: Rest Fixture |http://${jettyHost}:${jettyPort}| |setBody|!- { "resource" : { "name" : "test post", "data" : "some data" } } -!| |POST | /resources/ | 201 | | no-body | |let | id | header | Location:/resources/(.+) | | | Table: Rest Fixture |http://${jettyHost}:${jettyPort}| |GET | /resources/%id%.json | 200 |Content-Type : application/json |!- jsonbody.resource.name=='test post'
jsonbody.resource.data=='some data' -!| Other than the aforementioned content types you can emulate form POSTs. Remember to escape the setBody content cell with !- -! | Table: Rest Fixture |http://${jettyHost}:${jettyPort}| |setHeader|Content-Type : application/x-www-form-urlencoded;charset=UTF-8| |setBody|!-name=test%20post&data=some%20data-!| |POST | /resources | 201 | | no-body | |let | id | header | Location:/resources/(.+) | | | Table: Rest Fixture |http://${jettyHost}:${jettyPort}| |GET | /resources/%id% | 200 | |!- /resource/name[text()='test post'] /resource/data[text()='some data'] -! | Header values can also be substituted with symbols previously defined: | Table: Rest Fixture |http://${jettyHost}:${jettyPort}| |let | contenttype | const | application/x-www-form-urlencoded;charset=UTF-8| | |setHeader|Content-Type : %contenttype%| |setBody|!-name=test%20post&data=some%20data-!| |POST | /resources | 201 | | no-body | |let | id | header | Location:/resources/(.+) | | | Table: Rest Fixture |http://${jettyHost}:${jettyPort}| |GET | /resources/%id% | 200 | |!- /resource/name[text()='test post'] /resource/data[text()='some data'] -! |




© 2015 - 2024 Weber Informatics LLC | Privacy Policy