Automatic Testing

When you map process data elements to activity input elements, the behavior of the mapping depends upon the types of elements you are mapping. In the simplest case of mapping a required element in the process data schema to a required activity input element, the value of the process data element is assigned to the required activity input element.

However, when elements are optional or nillable, more complex tests are necessary. When you drag the process data element to the activity input element, the necessary tests are automatically placed into the activity input XSLT template.

This section describes the result of mapping different types of elements. The types of mappings are described, then an example is given that illustrates these mappings and shows the XSLT code that is generated automatically when these mappings are performed.

Required to Required

Specifies that the statement should always include the required activity input element and its value should be obtained from the required process data element that the element is mapped to.

Optional to Optional

Specifies that the statement should test if the process data element is present, and if so, include the optional element in the activity’s input. If the process data element is not present, the optional element is omitted from the activity’s input.

Nillable to Nillable

Specifies that both the process data and activity input elements can be nil. Therefore, the value of the activity input element is set to the value of the process data element. The value of the activity input element is set explicitly to nil if that is the value of the process data element.

Optional to Nillable

Specifies that the statement should test if the optional process data element exists. If the element exists, the activity input element should be created and set to the value of the process data element. If the process data element does not exist, the element is omitted from the activity input schema.

Nillable to Optional

Specifies that the statement should test if the process data element has a value specified, and if so, the optional element in the activity input should be set to the value of the process data element. Otherwise, if the process data element is nil, the optional element is omitted from the activity input.

Optional & Nillable to Optional & Nillable

Specifies that if the optional process data element exists, then include the optional activity input element in the input schema. If the process data element is nil, set the value of the activity input element explicitly to nil. If the process data element is not nil, set the value of the activity input element to the value of the process data element. If the process data element is not present, then omit the optional element from the activity input schema.

Example of Mapping Required, Optional, and Nillable Elements

The following figure illustrates the different types of mappings when elements are required, optional, or nillable.

Examples of mapping required, optional, and nillable elements

In the example above, Item and Amount illustrate mapping required elements to other required elements. The OnSale element illustrates mapping a nillable element to an optional element. The Discount element illustrates mapping an optional element to an optional element. The Pickup element illustrates mapping an optional element to a nillable element. The CustomerAddr and ShipTo elements illustrate mapping an optional and nillable element to an optional and nillable element.

Below is the XSLT template illustrated by the mappings in the above figure. You can see from the XSLT code that certain mappings are automatically surrounded by tests to create the appropriate input schema.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:template xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:pd="http://xmlns.tibco.com/bw/process/2003"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:pfx="http://www.tibco.com/xmlns/ae2xsd/2002/05/ae/Order">
   <Order>
      <Item>
          <xsl:value-of select="$RetrieveOrder/IncomingOrder/Order/Item"/>
      </Item>
      <Amount>
         <xsl:value-of select="$RetrieveOrder/IncomingOrder/Order/Amount"/>
      </Amount>
      <xsl:if test="$RetrieveOrder/IncomingOrder/Order/OnSale/@xsi:nil!=
            (&quot;true&quot;,&quot;1&quot;)">
         <OnSale>
            <xsl:value-of select="$RetrieveOrder/IncomingOrder/Order/OnSale"/>
         </OnSale>
      </xsl:if>
      <xsl:if test="$RetrieveOrder/IncomingOrder/Order/Discount">
         <Discount>
            <xsl:value-of select="$RetrieveOrder/IncomingOrder/Order/Discount"/>
         </Discount>
      </xsl:if>
      <pfx:ShipTo>
         <Pickup>
            <xsl:choose>
               <xsl:when test=
                       "exists($RetrieveOrder/IncomingOrder/Order/Pickup)">
                  <xsl:value-of select=
                       "$RetrieveOrder/IncomingOrder/Order/Pickup"/>
               </xsl:when>
               <xsl:otherwise>
                  <xsl:attribute name="xsi:nil">true</xsl:attribute>
               </xsl:otherwise>
            </xsl:choose>
         </Pickup>
         <xsl:if test="$RetrieveOrder/IncomingOrder/Order/StoreLocation">
            <StoreLocation>
               <xsl:value-of select=
                      "$RetrieveOrder/IncomingOrder/Order/StoreLocation"/>
            </StoreLocation>
         </xsl:if>
         <xsl:if test="$RetrieveOrder/IncomingOrder/Order/CustomerAddr">
            <ShipTo>
               <xsl:copy-of select=
                      "$RetrieveOrder/IncomingOrder/Order/CustomerAddr/@xsi:nil"/>
               <xsl:value-of select=
                      "$RetrieveOrder/IncomingOrder/Order/CustomerAddr"/>
            </ShipTo>
         </xsl:if>
      </pfx:ShipTo>
   </Order>
</xsl:template>
Note: The Mapping Wizard creates empty tags for each optional element even if the optional elements do not appear in the input data. In order to avoid the empty tags in the output when the input does not contain the optional element, the user has to manually create xsl:if statement.

To overcome this issue, users can use the system property automatic_mapper_if_surround. Set this property to 'True' to surround all new optional-to-optional mappings (including child elements) by an xsl:if statement. If the system property is false or not present, child elements will not be surrounded with the xsl:if statement.