Response Code¶
The following assertions can be performed on response
variable offered by the Touchstone Rules-Engine.
They would validate the response status code. See Status Code Definitions and List of HTTP status codes.
assertResponseCodeEquals(expectedValue)
Asserts that the status code of the response matches the provided expectedValue
Example:
response.assertResponseCodeEquals(200)
Equivalent to these:
assertResponseCodeEquals(200, response)
// expected status code and operator can be passed as parameters from test script. assertResponseCode(200, "equals", response)
assert response.responseCodeInt==200: "The actual value \""+response.responseCodeInt+"\" did not match the expected value \"200\" for response code in response"
assert equals(200, response.responseCode): "The actual value \""+response.responseCode+"\" did not match the expected value \"200\" for response code in response"
assert equals(200, responseCode): "The actual value \""+responseCode+"\" did not match the expected value \"200\" for response code in response"
Note that in the last example above, we’re using the responseCode binding directly. See Bindings.
assertResponseCodeNotEquals(expectedValue)
Asserts that the status code of the response does not match the provided expectedValue
Example:
response.assertResponseCodeNotEquals(200)
Equivalent to these:
assertResponseCodeNotEquals(200, response)
// expected status code and operator can be passed as parameters from test script. assertResponseCode(200, "notEquals", response)
assert response.responseCodeInt==200: "The actual value \""+response.responseCodeInt+"\" matched the expected value \"200\" for response code with operator 'notEquals' in response"
assert notEquals(200, response.responseCode): "The actual value \""+response.responseCode+"\" matched the expected value \"200\" for response code with operator 'notEquals' in response"
assert notEquals(200, responseCode): "The actual value \""+response.responseCode+"\" matched the expected value \"200\" for response code with operator 'notEquals' in response"
assertResponseCodeGreaterThan(expectedValue)
Asserts that the status code of the response is greater than the provided expectedValue
Example:
response.assertResponseCodeGreaterThan(399)
Equivalent to each of these:
assertResponseCodeGreaterThan(399, response)
// expected status code and operator can be passed as parameters from test script. assertResponseCode(399, "greaterThan", response)
assert response.responseCodeInt > 399: "Expected response code to be greater than 399 but was "+response.responseCodeInt+" in response"
assert greaterThan(399, response.responseCode) : "Expected response code to be greater than 399 but was "+response.responseCode+" in response"
assertResponseCodeLessThan(expectedValue)
Asserts that the status code of the response is less than the provided expectedValue
Example:
response.assertResponseCodeLessThan(300)
Equivalent to each of these:
assertResponseCodeLessThan(300, response)
// expected status code and operator can be passed as parameters from test script. assertResponseCode(300, "lessThan", response)
assert response.responseCodeInt < 300: "Expected response code to be less than 300 but was "+response.responseCodeInt+" in response"
assert lessThan(300, response.responseCode) : "Expected response code to be less than 300 but was "+response.responseCode+" in response"
assertResponseCodeIn(expectedValues)
Asserts that the status code of the response is one of the provided expectedValues where each value is separated by a comma.
Example:
// Asserts that the response code is either 200 or 201 response.assertResponseCodeIn("200,201")
Equivalent to each of these:
assertResponseCodeIn("200,201", response)
// expected status code and operator can be passed as parameters from test script. assertResponseCode("200,201", "in", response)
assert isIn("200,201", response.responseCode): "Expected one of the values in [200, 201] for response code but encountered \""+response.responseCode+"\" in response"
assertResponseCodeNotIn(expectedValues)
Asserts that the status code of the response is none of the provided expectedValues where each value is separated by a comma.
Example:
// Asserts that the response code is neither 200 nor 201 response.assertResponseCodeNotIn("200,201")
Equivalent to each of these:
assertResponseCodeNotIn("200,201", response)
// expected status code and operator can be passed as parameters from test script. assertResponseCode("200,201", "notIn", response)
assert isNotIn("200,201", response.responseCode): "Expected none of the values in [200, 201] for response code but encountered \""+response.responseCode+"\" with operator 'notIn' in response"