RestFixtureFitTests.LetTestsV2

Included page: .RestFixtureFitTests.SetUp (edit)

Action Fixture
start smartrics.rest.test.fitnesse.fixture.HttpServerFixture
check is started true
press reset resources database


LET


LET can use now the full power of JavaScript to extract data from the last response parts. The additions
to support the new JavaScript extensions will not break the existing .RestFixture API.

The JavaScript extensions can be used to process more effectively JSON Content-Types.

LET can access the Fitnesse Symbols map to extract data previously stored

If the context of the let context is js the expression is evaluated as a javascript string. The value assigned
to the let label is the result of the evaluation of the content in the expression cell.

For example:

Fit Rest Fixture http://localhost:7654
let message js 'Hello, World!' Hello, World!
let sum js '2 + 5 = ' + (2 + 5) 2 + 5 = 7
let two_expressions js a=1;
'a is ' + a
a is 1
let json_expr js
json = {
    "widget": {
        "debug": "on",
        "window": {
            "title": "Sample Konfabulator Widget",
            "name": "main_window",
            "width": 500,
            "height": 500
        },
        "image": { 
            "src": "Images/Sun.png",
            "name": "sun1",
            "hOffset": 250,
            "vOffset": 250,
            "alignment": "center"
        },
        "text": {
            "data": "Click Here",
            "size": 36,
            "style": "bold",
            "name": "text1",
            "hOffset": 250,
            "vOffset": 100,
            "alignment": "center",
            "onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;"
        }
    }
};
json.widget.image.src
Images/Sun.png

(Example courtesy of http://json.org/example.html)

It's also possible to access the FitNesse symbols map. The scope where expression is evaluated contains the
'symbols' object

Fit Rest Fixture http://localhost:7654
setBody <resource><name>Bill</name><data>Some data on Bill</data></resource>
POST /resources/ 201 Location : /resources/2
Content-Length : 0
Server : Jetty(6.0.2)
no-body
let id header Location:/resources/(.+) 2
let id_string js 'The id is: ' + symbols.get('id') The id is: 2

The scope also contains the 'response' object, populated with the data from the last Rest response executed

For example

Fit Rest Fixture http://localhost:7654
GET /resources/1 200 Set-Cookie : JID="ABC.${a.y}";
Content-Type : application/xml;charset=ISO-8859-1
Content-Length : 77
Server : Jetty(6.0.2)
{ "resource" : { "name" : "a funky name", "data" : "an important message" } }
let body_value js response.body { "resource" : { "name" : "a funky name", "data" : "an important message" } }
setBody <resource><name>Bill</name><data>Some data on Bill</data></resource>
POST /resources/ 201 Location : /resources/3
Content-Length : 0
Server : Jetty(6.0.2)
no-body
let status_code_value js response.statusCode 201
let status_text_value js response.statusText Created
let c_len js response.header0('Content-Length') 0
let loc_again js response.header('Location', 0) /resources/3
let h_size js response.headerListSize('Location') 1
let all_h_size js response.headersSize() 3

A particoular case is when the response is JSON (Content-Type : application/json). In such case, the property jsonbody
contains the JSON object that can be accessed using the dot notation. For example

Fit Rest Fixture http://localhost:7654
GET /resources/1.json 200 Set-Cookie : JID="ABC.${a.y}";
Content-Type : application/json;charset=ISO-8859-1
Content-Length : 77
Server : Jetty(6.0.2)
{ "resource" : { "name" : "a funky name", "data" : "an important message" } }
let body_value js response.jsonbody [object Object]
let body_value js response.jsonbody.resource.name a funky name