MashZone NextGen 10.2 | Appendix | Legacy Presto components | Mashables and Mashups | Mashups in EMML | Writing Mashups in EMML | Supporting Debugging | <assert> | <assert> Examples
 
<assert> Examples
All the assertion examples in this section are based on the following variable definitions:

<variable name="emailA" type="string" default="nwatts@myorg.com" />
<variable name="emailB" type="string" default="nwatts@myorg.com" />
<variable name="boolA" type="boolean" default="true"/>
<variable name="numberA" type="number" default="3"/>

<variable name="doc1" type="document">
<matches>
<match>
<team1>India</team1>
<team2>Bermuda</team2>
<venue>Trinidad</venue>
</match>
<match>
<team1>India</team1>
<team2>Sri Lanka</team2>
<venue>Port of Spain</venue>
</match>
<match>
<team1>England</team1>
<team2>Canada</team2>
<venue>St Lucia</venue>
</match>
</matches>
</variable>

<variable name="doc2" type="document">
<bets>
<odds>
<for>15</for>
<against>30</against>
</odds>
<odds>
<for>25</for>
<against>20</against>
</odds>
<odds>
<for>18</for>
<against>30</against>
</odds>
</bets>
</variable>

<variable name="doc3" type="document">
<odds>
<for>18</for>
<against>30</against>
</odds>
</variable>
<variable name="doc4" type="document">
<tracking>
<stats team="Bermuda">
<wins>3</wins>
<losses>5</losses>
<past-div-winner>false</past-div-winner>
<good-reviews>
<newspaper>3</newspaper>
<magazine>0</magazine>
<online>5</online>
</good-reviews>
</stats>
<stats team="India">
<wins>6</wins>
<losses>2</losses>
<past-div-winner>true</past-div-winner>
<good-reviews>
<newspaper>4</newspaper>
<magazine>1</magazine>
<online>7</online>
</good-reviews>
</stats>
</tracking>
</variable>

<variable name="doc5" type="document">
<matches>
<match>
<team1>England</team1>
<team2>Canada</team2>
<venue>St Lucia</venue>
</match>
<match>
<team1>India</team1>
<team2>Sri Lanka</team2>
<venue>Port of Spain</venue>
</match>
</matches>
</variable>
Assertions for Simple Types
The first assertion in this example compares a variable to a literal and expects the result to be false. The second assertion compares two variables that are simple string values with an expected result to true.

<assert actualvar="$numberA" literal="10" equals="false"/>
<assert actualvar="$emailA" expectedvar="$emailB" equals="true"/>
<assert actualexpr="$doc4/tracking/stats[@team='India']/past-div-winner" expectedvar="$boolA" equals="true"/>
The last assertion compares an expression that resolves to one node with a simple value within a document-type variable to a variable with a simple type.
Assertions for Document Types
The first document-type assertion compares one expression to a variable. Every node in the variable must be present and equal in both name and value in the node set defined by the expression and vice versa.

<assert actualexpr="$doc2/bets/odds[last()]" expectedvar="doc3" equals="true"/>
<assert actualexpr="$doc1/matches/match[last()]" expectedexpr="$doc5/matches/match[position()=1]" equals="true"/>
The next document-type assertion compares two expressions which both result in node sets. Again, all nodes from the first expression must be present and equal to the nodes in the second expression and vice versa.
Counts and Element Depths in Assertions
Assertions using count are fairly simple, as the first example assertion shows. The number of nodes in the variable or expression being compared are counted and compared against the value of the count attribute.

<assert actualexpr="$doc2/bets/odd" count="3" equals="true"/>
<assert actualexpr="$doc4/tracking/stats" elementdepth="3" equals="true"/>
With element depth, the number of levels of descendants found in the variable or expression being compared including the root level of the variable or expression is compared to the value of the elementdepth attribute.
Working Samples
The AssertSample (assert.emml) sample mashup uses the <assert> statement. See Mashup Samples for a list of MashZone NextGen mashup samples and where to find them.

Copyright © 2013-2018 | Software AG, Darmstadt, Germany and/or Software AG USA, Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.
Innovation Release