Validating scalar fields
Validation enables decisions about sent and received messages to be made automatically at test time. A validation is made up of one or more actions.
Under the Validate tab, the default configuration contains three validation actions, as follows:
Name | When checked, enables name validation (that is, valid when the name field is the same). |
Type | When checked, ensures that the field type is the same as what is specified (that is, String, Integer, and so on) |
Equality | When checked, validates that the value of the field equals what is expected. Equality is the default action, but it can be changed as described in Action types. |
You can add more validations by clicking New. To delete a validation that you added, select it and click Delete.
To duplicate any validation (except for the Name and Type validations), select it and click Clone. The validations that are in the editor can be enabled and disabled by selecting or clearing the selection.
Details about the different validation actions are provided in the following topics:
Equality
If Equality is chosen, the value to validate must be entered in the text field. The value can be pasted or loaded from a file, as described earlier.
Length
If the required validation type is Length, specify the minimum and maximum lengths of the field value in the appropriate fields.
Regex
If Regex is selected as the action type, the regular expression that is used to validate the field must be entered in the text field.
To help in building regular expressions, a testing utility is available. By clicking Test, you can verify your expression against any arbitrary content without waiting for a full test that is run to show the results.
Values to validate against can be entered in the Document field. Alternatively, you can click Browse to locate and select a test document, the contents of which are loaded in the Document field.
Schema
To validate the field value against a schema, select the Schema action type.
The From Document option indicates that the schema location is taken from the document (message) that is currently being processed. If the document does not define a schema location, the action will fail.
To select a different schema from the list of available schemas for the currently selected project, select the Specified schema source option and select the required schema.
Is null and not null
The Is Null and Not Null validations simply check whether the specified field is null or has some value.
XSD type
The XSD Type validation simply checks whether the field is of the correct type as specified by the XSD used to build the message.
Assert by using function
To validate by using an HCL OneTest™ API function, select the Assert using Function action.
Use the menu to select any function that returns a Boolean type, which determines whether the assertion passes or fails. You can access the value of the field within the message by using the FIELD/VALUE tag, as shown.
XPath
If XPath is selected as the action type, the XPath expression that is used to validate the field must be entered in the text field.
To help in building regular expressions and XPath expressions, a testing utility is available. By clicking Test, you can verify your expression against any arbitrary content without waiting for a full test that is run to show the results.
Values to validate against can be entered in the Document field. Alternatively, you can click Browse to locate and select a test document, the contents of which are loaded in the Document field.
JSONPath
If JSONPath is selected as the action type, the JSONPath expression that is used to validate the field must be entered in the text field.
To help in building JSONPath expressions, a testing utility is available. By clicking Test, you can verify your expression against any arbitrary content without waiting for a full test that is run to show the results.
Values to validate against can be entered in the Document field. Alternatively, you can click Browse to locate and select a test document, the contents of which are loaded in the Document field.