Assertions
Browse implementations
- Assertions
- Validations
- Comparison
An assertion is a special case of action in Chutney :
- It does not make use of external services (see target).
- It does not have outputs as two only outcomes could happen : pass or fail.
- It should not have validations included as it is a validation in itself.
Assertions🔗
Assert🔗
This action could be replaced by a direct validation
This action takes a list of assertions evaluated to boolean using expressions and validates they are all true.
Required | Name | Type | Default |
---|---|---|---|
* | asserts |
List of List<Map<String, Boolean>> |
No outputs
Example🔗
Json assert🔗
Asserts that JSON nodes have expected values.
Required | Name | Type | Default | Description |
---|---|---|---|---|
* | document |
String | json's string representation | |
* | expected |
Map<String, Object> | Keys contain json paths used to extract json node's data. Values contain expected nodes values or assertions functions. |
No outputs
Example🔗
Xml assert🔗
Asserts that XML nodes have expected values.
Required | Name | Type | Default | Description |
---|---|---|---|---|
* | document |
String | xml's string representation | |
* | expected |
Map<String, Object> | keys contain xml paths used to extract xml node's data. Values contain expected nodes values or assertions functions. |
No outputs
Example🔗
Assertions functions🔗
Placeholders used by xml-assert and json-assert actions to assert actual values.
Placeholder | Description | Example |
---|---|---|
$isNull |
must be null | "$isNull" |
$isNotNull |
must be not null | "$isNotNull" |
$contains |
must contains given value | "$contains:abcde" |
$isBeforeDate |
must be before given date | "$isBeforeDate:2010-01-01T11:12:13.1230Z" |
$isAfterDate |
must be after given date | "$isAfterDate:1998-07-14T02:03:04.456Z" |
$isEqualDate |
must be equal to given date | "$isEqualDate:2000-01-01T11:11:12.123+01:00" |
$matches |
must match given regex | "$matches:\\d{4}-\\d{2}-\\d{2}" |
$isLessThan |
must be less than given number | $isLessThan:42000 |
$isGreaterThan |
must be greater than given number | $isGreaterThan:45 |
$isEmpty |
string or array must be empty | "$isEmpty" |
$lenientEqual |
must be equal to given json using lenient compare mode | "$lenientEqual:{\"object\": {\"att\": \"val\"}}" |
$value[index] |
array's element at index must have expected value | "$value[0]:three" |
Validations🔗
Step
For functional validations, it's recommended to use above actions. For technical validations, it's possible to do them on scenario step validation.
Json validation🔗
Validates JSON structure using a given schema.
Required | Name | Type | Default | Description |
---|---|---|---|---|
* | json |
String | json's string representation | |
* | schema |
String | json schema |
No outputs
Example🔗
Xml validation🔗
Validates XML structure using a given schema.
Required | Name | Type | Default | Description |
---|---|---|---|---|
* | xml |
String | xml's string representation | |
* | xsd |
String | xsd schema path |
No outputs
Example🔗
XSD files example
XSD schema can be loaded from different paths
prefix | description | example |
---|---|---|
empty | load xsd from classpath. It can load also from a jar in classpath | xsdPath = "/xsd_samples/employee.xsd" |
classpath: |
load xsd from classpath. It can load also from a jar in classpath | xsdPath = "classpath:/xsd_samples/employee.xsd" |
file: |
load xsd from file system | xsdPath = "file:C:/my_data/xsd_samples/employee.xsd" |
Comparison🔗
Compare🔗
Compares two strings using a comparison mode.
Required | Name | Type | Default | Description |
---|---|---|---|---|
* | actual |
String | actual string value | |
* | expected |
String | expected string value | |
* | mode |
String | comparison mode |
No outputs
Example🔗
Available modes
mode | description |
---|---|
equals |
actual and expected are equals |
not equals / not-equals |
actual and expected are not equals |
contains |
actual contains expected |
not-contains / not contains |
actual doesn't contain expected |
greater-than / greater than |
actual is greater than expected |
less-than / less than |
actual is less than expected |
Json compare🔗
Compares two JSON inputs (the whole content or only some nodes) using a comparison mode.
Required | Name | Type | Default | Description |
---|---|---|---|---|
* | document1 |
String | first json | |
* | document2 |
String | second json | |
* | comparingPaths |
Map<String, String> | Map.of("$", "$") | to be compared nodes json paths |
* | mode |
String | STRICT | comparison mode |
No outputs
Example🔗
Available modes
mode | description |
---|---|
STRICT |
strict comparison |
LENIENT |
even if the document1 contains extended fields (which document2 doesn't have), the test will still pass |