XML Functions Plugin - Macros - Check XML¶
Contents :
# CHECK IF XML FILE {actual} FILTERED BY {xslt_filter} EQUALS {expected}¶
What ?
This macro apply a xslt filter to an actual and an expected xml file and then checks if the resulting resources match.
Underlying instructions :
LOAD {xslt_filter} AS __xslt_filter{%%r1}.file
CONVERT __xslt_filter{%%r1}.file TO xml(structured) AS __xslt_filter{%%r1}.xml
CONVERT __xslt_filter{%%r1}.xml TO xslt AS __xslt_filter{%%r1}.xslt
LOAD {actual} AS __actual{%%r1}.file
CONVERT __actual{%%r1}.file TO xml(structured) AS __actual{%%r1}.xml
CONVERT __actual{%%r1}.xml TO xml(xslt) USING __xslt_filter{%%r1}.xslt,$(normalize:true) AS __filtered_actual{%%r1}.xml
LOAD {expected} AS __expected{%%r1}.file
CONVERT __expected{%%r1}.file TO xml(structured) AS __expected{%%r1}.xml
CONVERT __expected{%%r1}.xml TO xml(xslt) USING __xslt_filter{%%r1}.xslt,$(normalize:true) AS __filtered_expected{%%r1}.xml
ASSERT __filtered_expected{%%r1}.xml IS similaire WITH __filtered_actual{%%r1}.xml USING $(comparateur:xmlunit)
> Input :
{xslt_filter}
: The name of the filter to apply (xslt
type file).{actual}
: The name of the file to compare (xml
type file).{expected}
: The name of the file to be compared to (xml
type file).
Example :
# CHECK IF XML FILE sample-dataset-1.xml FILTERED BY table1n2sorted.xslt EQUALS sample-dataset-2.xml Resources :
SKF script :
# CHECK IF XML {actual} FILTERED BY {xslt_filter} EQUALS {expected}¶
What ?
This macro apply a xslt filter to an actual and an expected loaded xml resources and then checks if the resulting resources match.
Underlying instructions :
LOAD {xslt_filter} AS __xslt_filter{%%r1}.file
CONVERT __xslt_filter{%%r1}.file TO xml(structured) AS __xslt_filter{%%r1}.xml
CONVERT __xslt_filter{%%r1}.xml TO xslt AS __xslt_filter{%%r1}.xslt
CONVERT {expected} TO xml(xslt) USING __xslt_filter{%%r1}.xslt,$(normalize:true) AS __filtered_expected{%%r1}.xml
CONVERT {actual} TO xml(xslt) USING __xslt_filter{%%r1}.xslt,$(normalize:true) AS __filtered_actual{%%r1}.xml
ASSERT __filtered_actual{%%r1}.xml IS similaire WITH __filtered_expected{%%r1}.xml USING $(comparateur:xmlunit)
> Input :
{xslt_filter}
: The name of the filter to apply (xslt
type file).{actual}
: The name of the loaded resource to compare (xml
type resource).{expected}
: The name of the loaded resource to be compared to (xml
type resource).
Example :
# CHECK IF XML sample-dataset-1-modified-resource.xml FILTERED BY table1n2sorted.xslt EQUALS sample-dataset-2-resource.xml Resources :
SKF script :
In the SETUP phase, we load the sample-dataset-1.xml and replace all the occurrences of ‘${hello}’ by ‘Goodbye’ with a SUBSTITUTE KEYS macro. The resulting resource is then converted to a xml type resource and used in the CHECK IF XML macro.
# CHECK IF XML {actual} FILTERED BY {xslt_filter} EQUALS {expected} USING {config}¶
What ?
This macro apply a xslt filter to an actual and an expected loaded xml resources and then checks if the resulting resources match. Additional configurations can be done with a config file.
Underlying instructions :
LOAD {xslt_filter} AS __xslt_filter{%%r1}.file
CONVERT __xslt_filter{%%r1}.file TO xml(structured) AS __xslt_filter{%%r1}.xml
CONVERT __xslt_filter{%%r1}.xml TO xslt AS __xslt_filter{%%r1}.xslt
CONVERT {expected} TO xml(xslt) USING __xslt_filter{%%r1}.xslt,$(normalize:true) AS __filtered_expected{%%r1}.xml
CONVERT {actual} TO xml(xslt) USING __xslt_filter{%%r1}.xslt,$(normalize:true) AS __filtered_actual{%%r1}.xml
LOAD {config} AS config.file
CONVERT config.file TO properties(structured) AS config.properties
DEFINE $(comparateur=xmlunit) AS default_comparator
CONVERT default_comparator TO properties(structured) AS default_comparator.properties
DEFINE $(comparateur:${comparateur}) AS comparateur.pattern
CONVERT comparateur.pattern TO file(param) AS comparateur.conf.in USING config.properties
CONVERT comparateur.conf.in TO file(param) AS comparateur.conf USING default_comparator.properties
ASSERT __filtered_actual{%%r1}.xml IS similaire WITH __filtered_expected{%%r1}.xml USING comparateur.conf,config.properties
> Input :
{xslt_filter}
: The name of the filter to apply (xslt
type resource).{actual}
: The name of the loaded resource to compare (xml
type resource).{expected}
: The name of the loaded resource to be compared to (xml
type resource).{config}
: The name of the configuration file. It can be used to change the default comparison engine from xmlunit to jxb, through a ‘comparateur = jaxb’ entry, or to give a name to the actual and expected resource (actualName = <put name here>, expectedName = <put name here>).
Example :
# CHECK IF XML sample-dataset-1-resource.xml FILTERED BY table1n2sorted.xslt EQUALS sample-dataset-2-resource.xml USING config.properties Resources :
SKF script :
In the SETUP phase, we load the sample-dataset-1.xml and replace all the occurrences of ‘${hello}’ by ‘Goodbye’ with a SUBSTITUTE KEYS macro. The resulting resource is then converted to a xml type resource and used in the CHECK IF XML macro.
Console output in DEBUG mode :