Let’s test the Rulesheet. Create a Ruletest named CheckFlightPlanWeight.ert that uses CheckFlightPlanWeight.ers as its test subject running in Studio.

media/image34.png

By default, a Ruletest is not configured to read or update a database. You need to change its Database Access setting before you run the Ruletest. Select Ruletest > Testsheet > Database Access > Read Only. As you can see below, there is also a Read/Update setting that enables you to configure the Ruletest to update the database.

media/image35.png

Next, let’s define the input. Drag and drop the FlightPlan entity from the Rule Vocabulary view to the Input pane and specify 111 as the value for flightNumber.

media/image36.png

Run the Ruletest. You get the following output:

media/image37.png

As you can see, based on the flightNumber (111), Corticon:

  1. Retrieved data about the aircraft and cargo associated with the flight plan from the database tables.
  2. Calculated the total of the cargo weights.
  3. Compared the value of the total of the cargo weights with the maxCargoWeight of the aircraft.
  4. Generated a message—in this case, a Violation message, which is displayed in the Ruletest.

Associations play an important role in how a rule reads from a database. As you have seen in this example, if a rule uses a primary key to retrieve records, it retrieves records of not only the entity table to which the primary key belongs, but also records of associated entities.

You have now modeled and tested rules that read a record from a database using a primary key.