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

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

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-Type''s.

''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:

| Table: Rest Fixture |http://${jettyHost}:${jettyPort}|
|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

| Table: Rest Fixture |http://${jettyHost}:${jettyPort}|
|setBody|BillSome data on Bill|
|POST   | /resources/ | 201 | | no-body |
|let    | id | header | Location:/resources/(.+) | |
|let    | id_string | js | 'The id is: ' + symbols.get('id') |  The id is: %id% |

Symbols that don't exist return null (or, in fact, the null representation set via the
'restfixture.null.value.representation' confuguration variable.

|comment|
| Table: Rest Fixture Config | reassing_null_representation |
| restfixture.null.value.representation | da_nil_123 |

|comment|
| Table: Rest Fixture |http://${jettyHost}:${jettyPort}| reassing_null_representation |
|let    | x | js | String(symbols.get('doesnt_exist')) | da_nil_123 |

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

For example

| Table: Rest Fixture |http://${jettyHost}:${jettyPort}|
|GET    | /resources/1 | 200 | | |
|let    | body_value | js | response.body |  |
|setBody|BillSome data on Bill|
|POST   | /resources/ | 201 | | no-body |
|let    | status_code_value | js | response.statusCode |  |
|let    | status_text_value | js | response.statusText |  |
|let    | c_len | js | response.header0('Content-Length') | 0 |
|let    | loc_again | js | response.header('Location', 0) |  |
|let    | h_size | js | response.headerListSize('Location') | 1 |
|let    | all_h_size | js | response.headersSize() |  |

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

| Table: Rest Fixture |http://${jettyHost}:${jettyPort}|
|GET    | /resources/1.json | 200 | |!-
jsonbody.resource.name=="a funky name"
jsonbody.resource.data=="an important message"
-!|
|let    | body_value | js | response.jsonbody |  |
|let    | body_value | js | response.jsonbody.resource.name | a funky name |





© 2015 - 2024 Weber Informatics LLC | Privacy Policy