HeaderΒΆ
The following assertions can be performed on both request
and response
variables offered by the Touchstone Rules-Engine.
They would validate the specified header in the request or response.
assertHeaderContains(headerName, expectedValue)
Asserts that the provided header headerName contains the provided expectedValue.
Example:
request.assertHeaderContains("Accept","xml")
response.assertHeaderContains("Content-Type","xml")
Equivalent to these:
assertHeaderContains("Accept", "xml", request)
assertHeaderContains("Content-Type", "xml", response)
// header, expectedValue, and operator can be passed as parameters from test script. assertHeader("Accept", "xml", "contains", request)
// header, expectedValue, and operator can be passed as parameters from test script. assertHeader("Content-Type", "xml", "contains", response)
assert request.header('Accept').contains('xml'): "The actual value '"+ request.header('Accept')?.value+"' did not contain the expected value 'xml' for 'Accept' in request"
assert response.header('Content-Type').contains('xml'): "The actual value '"+ request.header('Content-Type')?.value+"' did not contain the expected value 'xml' for 'Content-Type' in response"
assert contains('xml', request.header('Accept').value): "The actual value '"+ request.header('Accept')?.value+"' did not contain the expected value 'xml' for 'Accept' in request"
assert contains('xml', response.header('Content-Type').value): "The actual value '"+ request.header('Content-Type')?.value+"' did not contain the expected value 'xml' for 'Content-Type' in response"
assertHeaderNotContains(headerName, expectedValue)
Asserts that the provided header headerName does not contain the provided expectedValue.
Example:
response.assertHeaderNotContains("Content-Type","xml")
Equivalent to these:
assertHeaderNotContains("Content-Type", "xml", response)
// header, expectedValue, and operator can be passed as parameters from test script. assertHeader("Content-Type", "xml", "notContains", response)
assert response.header('Content-Type').notContains('xml'): "The actual value '"+ request.header('Content-Type')?.value+"' contained the expected value 'xml' for 'Content-Type' in response"
assert notContains('xml', response.header('Content-Type').value): "The actual value '"+ request.header('Content-Type')?.value+"' contained the expected value 'xml' for 'Content-Type' in response"
assertHeaderEmpty(headerName)
Asserts that the provided header headerName is absent or empty.
Example:
response.assertHeaderEmpty("Content-Type")
Equivalent to these:
assertHeaderEmpty("Content-Type", response)
// header and operator can be passed as parameters from test script. assertHeader("Content-Type", "empty", response)
assert response.header('Content-Type').empty(): "Found 'Content-Type' header when it was not expected in response"
assert empty(response.header('Content-Type').value): "Found 'Content-Type' header when it was not expected in response"
assertHeaderNotEmpty(headerName)
Asserts that the provided header headerName is present and not empty.
Example:
response.assertHeaderNotEmpty("Content-Type")
Equivalent to these:
assertHeaderNotEmpty("Content-Type", response)
// header and operator can be passed as parameters from test script. assertHeader("Content-Type", "notEmpty", response)
assert response.header('Content-Type').notEmpty(): "Expected 'Content-Type' header but did not find it in response"
assert notEmpty(response.header('Content-Type').value): "Expected 'Content-Type' header but did not find it in response"
assertHeaderEquals(headerName, expectedValue)
Asserts that the provided header headerName matches the provided expectedValue
Example:
response.assertHeaderEquals("Content-Type","text/html")
Equivalent to these:
assertHeaderEquals("Content-Type","text/html", response)
// header, expectedValue, and operator can be passed as parameters from test script. assertHeader("Content-Type", "text/html", "equals", response)
assert response.header('Content-Type').equals("text/html"): "The actual value '"+ request.header('Content-Type')?.value+"' did not match the expected value 'text/html' for 'Content-Type' in response"
assert equals("text/html", response.header('Content-Type').value): "The actual value '"+ request.header('Content-Type')?.value+"' did not match the expected value 'text/html' for 'Content-Type' in response"
assertHeaderNotEquals(headerName, expectedValue)
Asserts that the provided header headerName does not match the provided expectedValue
Example:
response.assertHeaderNotEquals("Content-Type","text/html")
Equivalent to these:
assertHeaderNotEquals("Content-Type","text/html", response)
// header, expectedValue, and operator can be passed as parameters from test script. assertHeader("Content-Type", "text/html", "notEquals", response)
assert response.header('Content-Type').notEquals("text/html"): "The actual value '"+ request.header('Content-Type')?.value+"' matched the expected value 'text/html' for 'Content-Type' in response"
assert notEquals("text/html", response.header('Content-Type').value): "The actual value '"+ request.header('Content-Type')?.value+"' matched the expected value 'text/html' for 'Content-Type' in response"
assertHeaderGreaterThan(headerName, expectedValue)
Asserts that the provided header headerName is greater than the provided expectedValue
Example:
response.assertHeaderGreaterThan("Content-Length", 0)
Equivalent to each of these:
assertHeaderGreaterThan("Content-Length", 0, response)
// header, expectedValue, and operator can be passed as parameters from test script. assertHeader("Content-Length", 0, "greaterThan", response)
assert response.header('Content-Length').greaterThan(0): "Expected 'Content-Length' header to be greater than 0 but was "+ response.header('Content-Length')?.value +" in response"
assert greaterThan(0, response.header('Content-Length').value): "Expected 'Content-Length' header to be greater than 0 but was "+ response.header('Content-Length')?.value +" in response"
assertHeaderLessThan(headerName, expectedValue)
Asserts that the provided header headerName is less than the provided expectedValue
Example:
response.assertHeaderLessThan("Content-Length", 100)
Equivalent to each of these:
assertHeaderLessThan("Content-Length", 100, response)
// header, expectedValue, and operator can be passed as parameters from test script. assertHeader("Content-Length", 100, "lessThan", response)
assert response.header('Content-Length').lessThan(100): "Expected 'Content-Length' header to be less than 100 but was "+ response.header('Content-Length')?.value +" in response"
assert lessThan(100, response.header('Content-Length').value): "Expected 'Content-Length' header to be less than 100 but was "+ response.header('Content-Length')?.value +" in response"
assertHeaderIn(headerName, expectedValues)
Asserts that the provided header headerName is one of the provided expectedValues where each value is separated by a comma.
Example:
// Asserts that 'Content-Type' header is 'application/fhir+json' or 'application/fhir+json;charset=UTF-8' response.assertHeaderIn("Content-Type", "application/fhir+json,application/fhir+json;charset=UTF-8")
Equivalent to each of these:
assertHeaderIn("Content-Type", "application/fhir+json,application/fhir+json;charset=UTF-8", response)
// header, expectedValue, and operator can be passed as parameters from test script. assertHeader("Content-Type", "application/fhir+json,application/fhir+json;charset=UTF-8", "in", response)
assert response.header("Content-Type").in("application/fhir+json,application/fhir+json;charset=UTF-8"): "Expected one of the values in [application/fhir+json, application/fhir+json;charset=UTF-8] for 'Content-Type' header but encountered \""+ response.header('Content-Type')?.value +"\" in response"
assert isIn("application/fhir+json,application/fhir+json;charset=UTF-8", response.header("Content-Type").value): "Expected one of the values in [application/fhir+json, application/fhir+json;charset=UTF-8] for 'Content-Type' header but encountered \""+ response.header('Content-Type')?.value +"\" in response"
assertHeaderNotIn(headerName, expectedValues)
Asserts that the provided header headerName is none of the provided expectedValues where each value is separated by a comma.
Example:
// Asserts that 'Content-Type' header is neither 'text/plain' nor 'text/html' response.assertHeaderNotIn("Content-Type", "text/plain,text/html")
Equivalent to each of these:
assertHeaderNotIn("Content-Type", "text/plain,text/html", response)
// header, expectedValue, and operator can be passed as parameters from test script. assertHeader("Content-Type", "text/plain,text/html", "notIn", response)
assert response.header("Content-Type").notIn("text/plain,text/html") : "Expected none of the values in [text/plain, text/html] for 'Content-Type' header but encountered \""+ response.header('Content-Type')?.value +"\" with operator 'notIn' in response"
assert isNotIn("text/plain,text/html", response.header("Content-Type").value) : "Expected none of the values in [text/plain, text/html] for 'Content-Type' header but encountered \""+ response.header('Content-Type')?.value +"\" with operator 'notIn' in response"