2 Introduction to STAP Behavior-Driven Development Language

Learn about the Oracle Communications Solution Test Automation Platform (STAP) Behavior-Driven Development (BDD) language and its keywords.

Topics in this chapter:

Understanding STAP BDD Language

STAP BDD is a proprietary language developed by Oracle. It uses a set of special keywords to structure and give meaning to executable business use-case specifications. This approach ensures that the use cases are both human-readable and executable by the testing framework. Each line in a STAP BDD document that is not a blank line has to start with a STAP BDD keyword. Some keywords are followed by text.

There are two types of keywords in the STAP BDD language.
  • Primary keywords are alphabetic words and end with a colon (:).
  • Secondary keywords are words and special characters.

Note:

Most lines in a STAP BDD document start with one of the primary or secondary keywords. Any line that is not a blank line must begin with a STAP BDD keyword.

Table 2-1 lists the primary keywords in the STAP BDD language.

Table 2-1 Primary Keywords

Primary Keywords Description
Scenario Indicates the beginning of a specific situation or use case and is followed by a name for the scenario.
Description Describes the use case.
Tags Defines elements and structure within a use case.
Case Defines a specific use case.
Data Refers to the information.
Validate Indicates the beginning of the validation conditions for the data.
Save Allows you to specify whether to store the entered or modified data.

Table 2-2 lists the secondary keywords in the STAP BDD language.

Table 2-2 Secondary Keywords

Secondary Keywords Description
Given Sets up the initial context or state.
When Describes the action or event that triggers the behavior.
Then Specifies the expected outcome or result.
And Adds additional context or actions within Given, When, or Then steps.
| Used as a separator.
# When placed as the first character in a line, used anywhere in the file to denote a comment. Block comments are currently not supported.
' ' Used to indicate the bounds of a string value.
. (dot) , (comma) and ; (semi-colon) - Step description separators.

The BDD language treats white space in the following ways::

  • Indentation: Spaces can be used for indentation and they do not affect the contents.
  • Blank Lines: There are no restrictions on using blank lines to separate contents in a BDD document.

BDD Use Case

This example details the process for verifying that discounted rates are applied to Friends and Family accounts through the Diameter Gateway. In the integrated ECE, BRM, and PDC environment, the objective is to ensure that calls between Friends and Family members are charged at a special discounted rate, while calls involving non-Friends and Family members are charged at standard rates.

Pricing Structure

  • Calls between non-Friends and Family members: $0.05 per minute
  • Calls between Friends and Family members: $0.01 per minute

Products Involved

  • BRM (Billing and Revenue Management)
  • ECE (Elastic Charging Engine)
  • PDC (Pricing Design Center)

Use-Case Steps

  1. Load Pricing Configurations: Set up pricing configurations, including discounts for Friends and Family groups.
  2. Create Non-Friends and Family Accounts: Create accounts that are not associated with the Friends and Family group.
  3. Generate Usage and Validate Charges: Generate 20 minutes (1200 seconds) of usage through the Diameter gateway for the standard accounts.

    Note:

    Ensure that the standard (non-discounted) charge of $0.05 per minute is applied, resulting in total charges of $1.00.
  4. Add Accounts to Friends and Family Group: Add the previously created accounts to the Friends and Family group.
  5. Generate Usage and Validate Discounts: Generate another 20 minutes (1200 seconds) of usage for these accounts.

    Note:

    Ensure the Friends and Family discounted rate of $0.01 per minute is applied, resulting in total charges of $0.20.

JSON Data Processing (Release 1.25.1.1.0 or later)

JSON Data Processing refers to manipulating and transforming JSON data using predefined actions. These functions help automate the creation, modification, extraction, and saving of JSON objects to streamline data handling.

The different JSON data processing functions are:

  1. Creation and Modification
    • CREATE_FROM_JSON: Generates a new entity from JSON data.
    • findAndReplace: Replaces specific values within a JSON object.
  2. Extraction and Transformation
    • addFromJsonArray: Extracts data from an array and creates a new JSON object.
    • addFromJson: Extracts specified values from JSON and creates a new JSON object.
    • appendFromJsonArray: Adds new data to an existing JSON structure.
  3. Saving the Result
    • newJson: Stores the final processed JSON object for further use.

These functions provide structured ways to interact with JSON data dynamically, ensuring efficient data processing without manual intervention.

CREATE_FROM_JSON

The CREATE_FROM_JSON function creates a new entity based on the provided JSON data. It takes a JSON string as input, uses the JSON data to create a new entity, and performs necessary validation and processing to ensure successful creation. Use the $json action to pass the actual JSON string.

The following sample depicts the input syntax:

Data:
| $action | CREATE_FROM_JSON |
| $json | {"data":[{"name":"James Brown","id":"1"},{"name":"Rowan Blake","id":"2"},{"name":"Nora Miller","id":"3"},{"name":"Lily John","id":"4"}]} |

The following sample depicts the output from the data provided above:


| myjson | $JSON{todoJson} | {"data":[{"name":"James Brown","id":"1"},{"name":"Rowan Blake","id":"2"},{"name":"Nora Miller","id":"3"},{"name":"Lily John","id":"4"}]} |

findAndReplace

Replaces a specified value in the JSON data with a new value.

Syntax: | $findAndReplace | find_value | replace_value |

Description: Searches for occurrences of find_value in the JSON data and replaces them with replace_value

For example,

| $json | {"id":"2","name":"Emily Brown","description":"Residential customer","status":"TODO", "Due Date":"INITIAL DATE", "str":{ "Due Date":"INITIAL DATE2", "str2":{ "str3":{ "Due Date":"INITIAL DATE3", "str4":{ "Due Date":"INITIAL DATE4" } } } } } |
| $findAndReplace | Due Date, New Date Value|

After update:

$json: {"id":"2","name":"Emily Brown","description":"Residential customer","status":"TODO", "Due Date":"New Date Value", "str":{ "Due Date":"New Date Value", "str2":{ "str3":{ "Due Date":"New Date Value", "str4":{ "Due Date":"New Date Value", } } } } }

addFromJsonArray

Adds data from a JSON array to a new JSON object.

Syntax: | array | $addFromJsonArray($json,selector, key1,key2,...) |

Description: Extracts data from the specified source_array_path in the JSON data and adds it to a new JSON object. The extracted data is mapped to the corresponding keys (key1, key2, and so on.) in the new object.

For example,

This JSON array:

{"data":[{"name":"John","age":25},{"name":"Alice","age":30}]} 
| array | $addFromJsonArray($json,[*],name) |

You will have the following result:

{"array":[{"name":"John"},{"name":"Alice"}]}

addFromJson

Adds data from a JSON object to a new JSON object.

Syntax: $addFromJson($json,key1,key2,...)

Description: Extracts data from the specified keys (key1, key2, and so on.) in the JSON data and adds it to a new JSON object. The extracted data is assigned to the corresponding keys in the new object.

For example,

 
JSON Object - {"name":"John","age":30,"occupation":"Developer"}
 
| data | $addFromJson($json,name,name,value,value) |
 
data Runtime Value - {"data":{"name":"John","value":"Developer"}}

appendFromJsonArray

Appends data from a JSON array to an existing JSON object.

Syntax: $appendFromJsonArray($json,source_array_path,key1,key2,...)

Description: Extracts data from the specified source_array_path in the JSON data and appends it to an existing JSON object. The extracted data is mapped to the corresponding keys (key1, key2, and so on.) in the existing object.

For example,


 
Step:
| array | $addFromJsonArray($json,[*],name,value) |
 
Runtime Value:
 
|  JsonArray  |  $newJson  | {"array":[{"description":"Purchase Fees (srvc) (srvc): Supremo Broadband Installation Service","remainingAmount.value":19.99}]} |
 
Step:
| array | $appendFromJsonArray($json,[*],description,remainingAmount.value) |
 
Runtime Value:
 
|  JsonArray  |  $newJson  |  {"array":[{"description":"Purchase Fees (srvc) (srvc): Supremo Broadband Installation Service","remainingAmount.value":19.99},{"description":"Cycle Forward Fees (srvc): Supremo Basic Internet Service","remainingAmount.value":12.34}]}  |

newJson

Saves the newly created or updated JSON object.

Syntax: $newJson

Description: Saves the resulting JSON object to a variable named newJson.

Save:
| newJson | $newJson |