Creating test scenarios
You can check that you solution works as expected by running tests on the entities and events. In test scenarios, you load entities and submit events from a single file, and then you can write tests that check the values of the entities, the entity attributes, and the events on your server.
Before you begin
About this task
You create your scenario and end each construct with a semi-colon (;). The results of your test display in the Console tab so that you can compare these results with what you expect.
Procedure
Example
In the following example, entities from two entity loaders (customer_ids and items) are loaded and events from two event sequences (purchases and returns) are submitted to the server. Next, a test checks the attributes for the entity Betty. The test checks Betty's name, occupation, and address.
load entities from:
- "customer_ids"
- "items" ;
submit events from :
- "purchases"
- "returns" ;
check that for the customer "Betty" :
- the name of this customer is "Betty"
- the occupation of this customer is not "Software Architect"
- the address of this customer is not null
- the occupation of this customer is not null ;
The following example uses number operators to check that the age of the customer falls within a range.
check that for the customer "Betty" :
- the age of this customer is between 18 and 65
- the age of this customer is more than 21
- the age of this customer is at most 50 ;
In the following example, a customer has a status of GOLD after a set of transactions is made. To check what happens when times passes, three tests check David's status after intermittent periods of time. The continue processing until <date> construct simulates the passing of time from the last timestamp in the event sequence to the <date> specified, during which events can be scheduled. In this example, no other transaction events are scheduled for David. A test checks that his status is SILVER on 08/24/15, another test checks that a status change was emitted, and a third test checks that his status is BRONZE on 02/24/16. As time passes from the last timestamp in the event sequence event to 08/24/15 and then to 02/24/16, David's status goes from GOLD to SILVER and then to BRONZE as a result. The customer status is lowered because, as time passes, David makes no new transactions.
submit events from "transactions until gold" ;
check that for the customer "David":
- the status of this customer is GOLD ;
continue processing until 08/24/16 ;
check that for the customer "David" :
- the status of this customer is SILVER ;
check that for the status change in the events emitted
by "CustomerLoyaltyAgent" :
- the customer id of the customer of this status change is "David"
- the new status of this status change is SILVER ;
continue processing until 02/24/17 ;
check that for the customer "David" :
- the status of this customer is BRONZE ;