Test Instructions

The Test instruction is a special statement used to execute tests on a specific component. If the test matches the condition, the return value is set to true, otherwise to false. If the test returns true, all child/nested instructions of it will be executed.

This topic describes the <test> XML element.

This page discusses:

Test Aliases

This table lists aliases (shortcuts) for the full test instruction.

Type Full Instructions Alias Instructions
attribute Element
<test type="attribute" name="SYMBOL" />
<attribute name="SYMBOL" />
specialAttribute Element
<test type="specialAttribute" 
      name="part.number" 
      value="123" />
<specialAttribute 
   name="part.number" 
   value="123" />
class Element
<test type="class" name="MY_CLASS" />
<class name="MY_CLASS" />
type Element
<test type="type" name="MY_TYPE" />
<type name="MY_TYPE" />
group Element
<test type="group" name="MY_GROUP" />
<group name="MY_GROUP" />

test Element

General syntax
<test type="typename" name="regexp" [value="regexp" regexpid="id_name"] />
Description Is used to execute tests on a specific component. If the test matches the condition, the return value is set to true, otherwise to false.
Attributes Name Use Annotation
type required

Defines the type on which the test is executed.

Valid values:

Alternatively, the test aliases mentioned above can be used.

name required

Defines the name of ‘type’. The value can be either a string or any Regular Expression.

value optional

Defines the value of ‘name’. The value can be either a string or any Regular Expression reference. If the optional attribute value is omitted, the test will execute an existence check. If the value attribute is defined, then the test result is true if the value matches the pattern.

regexpid optional

Defines the unique id within the namespace to reference the test using regular expressions. Using the regular expression, the reference of the regexpid can be divided into matching groups, for example, “(g_1)(g_2)(g_n)”. If the regular expression of an attribute name or value is set to “(test_)([0-9]), the first matching group is “test_” and the second matching group is “[0-9]”. If only one matching group exist, such as “test_([0-9])”, then the first matching group is “[0-9]”.

To get the value of any matching group, you must know if the value should come from the attribute name or from the attribute value:

MyRegexpid.name[1] returns the value of the first matching group from the attribute name.

MyRegexpid.value[2] returns the value of the second matching group from the attribute value.

The matching group [0] returns the complete value.

Allowed character set: [p{Alnum}\_\-] = [a-z A-Z 0-9 _ -].

invert optional Inverts the behavior of the test. If set to true and the criteria do not match, the child instructions will be executed.
Examples
<!--tests the given class if the value equals AC, this is equivalent to a simple existence check --> 
<test type="class" value="AC" /> 

<!--tests the given class if the name starts with AC by using a regular expression --> 
<test type="class" value="AC.*" /> 

<!--tests the given attribute if the name starts with SYMBOL_ by using a regular expression--> 
<test type="attribute" name="SYMBOL_(.*)" > 
     <!-- add instructions here, if the name of the attribute starts with "SYMBOL_" then the 
          instructions included here are executed--> 
</test> 

<!-- tests if an attribute exist where the name starts with "SYMBOL_" by using a regular expression 
     SYMBOL_(.*) and the value starts with "4". If this is the case, it executes all child instructions
     in this test statement. The regexpid for the backreference is also configured which can be used 
     in the child instructions to get the values of the attributes--> 
<test type="attribute" name="(SYMBOL_)(.*)" value="(4)(.*)" 
      regexpid="backreference1" >
   <!-- tests if an attribute with the name SUB_SYMBOL exist and also the value which contains the 
        second matching group of the currently processed attribute SYMBOL_(.*) by using the
        backreference and regular expression. 

        Following attributes exists: SYMBOL_1=4711 and SUB_SYMBOL=1. The mapping 
        finds for e.g. the attribute with the name SYMBOL_1 and SUB_SYMBOL=1. Then all child 
        instructions in this test statement will be executed, because the second matching group of 
        the regexpid "backreference1.name[2]" returns the value 1. --> 

   <test type="attribute" name="SUB_SYMBOL" value="${backreference1.name[2]}"> 
  
        <!-- value modification of an existing attribute with the name SYM. Using the matching group 
             [0] in this example the new value from the attribute SYMBOL_1 is changed to 4711. " --> 
  
        <modify target="attribute.value" name="SYM" 
                value="${backreference1.value[0]}" /> 
   </test> 

</test>