This project is read-only.

Condition in a template

This feature is only available with the release 1.6.1 and next versions!

It can be useful to specify that a few xml fragments must only be rendered in specific cases. To achieve this, NBi uses the syntax and features provided by the external library StringTemplate and detailed here.

NBi will not assign a value to a variable in two cases:
  • The value provided for this variable in the test-case is "(none)"
  • The value provided as a length of 0 characters (an empty string).

Conditionally rendering the ignore element

Suppose that in your test-cases, you've a column named ignoreReason and you want to add an xml element <ignore> only if an ignoreReason has been provided.

Your test-cases are defined in a CSV file as:
perspective;dimension;ignoreReason
Internet Sales;Customer;(none)
Internet Sales;Geography;To be released in a next version

and you're expecting the following result after the execution of the generation (note that the ignore tags are available in the second test but not on the first!):
<test name="A dimension named 'Customer' exists in perspective 'Internet Sales'.">
	<system-under-test>
		<structure>	
			<dimension caption="Customer" perspective="Internet Sales"/>
		</structure>
	</system-under-test>
	<assert>
		<exists/>
	</assert>
</test>
<test name="A dimension named 'Geography' exists in perspective 'Internet Sales'.">
	<ignore>To be released in a next version</ignore>
	<system-under-test>
		<structure>	
			<dimension caption="Geography" perspective="Internet Sales"/>
		</structure>
	</system-under-test>
	<assert>
		<exists/>
	</assert>
</test>

To achieve this, you'll need to make usage of the if statement provided by StringTemplate. To specify that a part of a template must be rendered only if a value is assigned to a variable simply write:

$if(ignoreReason)$<ignore>$ignoreReason$</ignore>$endif$
Take care of following details:
  • if and endif are surrounded by $ symbols
  • in the if statement, the name of the variable is not surrounded by $ symbols
  • there is no comparison in the the if statement, just the name of the variable. The if statement check if the provided variable is assigned or not.

The following template should have been provided to succesfully build the test-suite described above:
<test name="A dimension named '$dimension$' exists in perspective '$perspective$'.">
	$if(ignoreReason)$<ignore>$ignoreReason$</ignore>$endif$
	<system-under-test>
		<structure>	
			<dimension caption="$dimension$" perspective="$perspective$"/>
		</structure>
	</system-under-test>
	<assert>
		<exists/>
	</assert>
</test>

Last edited Aug 5, 2014 at 10:36 AM by Seddryck, version 3

Comments

No comments yet.