Common definitions syntax

You can use the common definitions files to create definitions that can be referenced by entity loader and event sequence files. You can also reference a common definitions file from within another common definitions file.

Purpose

Common definitions are files that store definitions that can be used in other test files. You define the common definitions in the common definitions editor, and the file is stored in the test client project.

Syntax

The following syntax shows all of the constructs you can add to a common definitions file. All of the constructs are optional. Use as many constructs as it takes to define a test scenario or reusable subset of a scenario.

[using definitions from: 
   - "<common definitions file>" ;]

[define <variable> as <value> [where 
   <entity type> <entity id>
   <entity type> identified by <entity id>] ;]

[add <value> to <collection> ;]
[clear <list> of <object> ;]
[make it <true or false> that <object> is <boolean field>;]
[remove <an object> from <a list> ;]
[set <attribute> of <object> to <value>;]

If you use the optional using definitions from : <common definitions file> construct, it must be the first phrase in the test files. Do not create circular dependencies by which two common definitions files reference each other.

Table 1. Optional constructs for creating common definitions
Construct Description Example

<entity type> <entity id>

Short construct that specifies a relationship between the bound entity and the event.

the customer is the customer "Jane Doe" 

<entity type> identified by <entity id>

Specifies a relationship between the bound entity and the event.

the customer is the customer identified by "Jane Doe" 

add <value> to <collection> ;

Adds an object to a collection. The target of this construct cannot be a relationship.

add ( a new item where
the amount is 200 ,
the status is "expensive" )
to the items of 'the purchase' ;

define <variable> as <value> ;

Defines a variable. The value of the variable can be an object or a constant. Variables can be used in the definition of the event emission.

define 'customer name' as "Jane Doe" ;

clear <list> of <object> ;

Clears a collection or removes a relationship between two objects. The clear <list> keywords specify the collection or types of relationship, and the of <object> keywords define the entity or event that you want to clear from the relationship or collection.

clear the items of 'purchase1' ;

make it <true or false> that <object> is <boolean field>;

Replaces the value of a boolean attribute.

make it true that 'purchase1' is special delivery  ;

remove <an object> from <a list> ;

Removes an item from a list. The remove <object> keywords specify the object that you want to remove, and the from <a list> keywords define the collection from which you want to remove the object.

remove 'milk' from the items of 'purchase1' ;

set <attribute> of <object> to <value>;

Replaces the value of an attribute with the value of another type. Values can be simple, relationship, geospatial, or complex types.

set the customer of the 'purchase1' to 'example.com'  ;

using definitions from: - "<common definitions file>" ;

Specifies the common definitions file or files from which an entity loader, event sequence, or common definitions file uses the definitions. When you use this construct, it must be used in the header of the file and precede all of the other constructs.

using definitions from: 
   - "customer_ids" 
   - "items" ;

Examples

In the following example in which shopping cart 1 is defined, two common definition files (customer_ids and items) are referenced to provide the customer IDs and shopping cart items.

using definitions from:
   - "customer_ids" 
   - "items" ;
define 'shopping cart 1' as a new shopping cart where
   the id is '123',
   the customer is the customer identified by 'Jane';
add a new item identified by 'bread' to 'shopping cart 1';