Task 3: Customizing the Expected Results sheet

You add a new test in the Expected Results sheet.

About this task

Now that you have configured your BOM so that it generates the correct columns with meaningful names, you want to add some tests to the Expected Results sheet of the Excel scenario file.

You want to test:

  • If the loan is approved.
  • The first message that is displayed when you run the rules.

The Report class contains a method that returns a collection of messages (java.util.List). When using an Excel scenario file, you can only define tests that verify what is contained in the collection, that is, regardless of the position of the contained element in the collection. To be able to test exactly what the first message in the collection is, you must define a new method in the BOM.

In this task, you create a new column for the Expected Results sheet to test the first message.

You must create a virtual attribute and define a getter that returns only the first message.

Step 1: Creating an attribute for the first message

You create an attribute for the first message.

Procedure

  1. In the Rule Explorer, navigate to loanvalidation-rules > bom > model > loan.
  2. Double-click the Report class to open it in the BOM editor.
  3. In the Members area, click New.
  4. In the New Member window, make sure the Attribute type is selected.
  5. In the Name field, enter firstMessage.
  6. In the Type field, enter java.lang.String, and then click Finish.

Step 2: Defining a getter for an attribute

You define a getter for the firstMessage attribute.

Procedure

  1. In the Members area, double-click the new firstMessage attribute.
  2. In the General Information area, select Read Only.
  3. In the Member Verbalization area, click Create a default verbalization.
  4. In the Template field, make sure the verbalization is as follows:

    {first message} of {this}

  5. In the BOM to XOM Mapping area, click Edit the imports.
  6. In the Imports field, make sure the following is displayed:
    import java.util.Iterator;
    import java.lang.StringBuffer;
  7. In the Members area, double-click the firstMessage attribute to open it.
  8. In the Getter field of the BOM to XOM Mapping section, type the following code:
    Iterator it = this.getMessages().iterator();
    StringBuffer buf = new StringBuffer();
    if (it.hasNext()) {
    buf.append(it.next()).append('\n');
    }
    return buf.toString();
    
  9. Save the changes.

Step 3: Checking the Expected Results sheet

You check that the first message column that is shown in the Expected Results sheet by generating the Excel scenario file template.

Procedure

  1. In the Rule Explorer, right-click the loanvalidation-rules project, and then click Testing and simulation > Generate Excel Scenario File Template.
  2. Keep the default options as you did in the previous tasks.
  3. On the Expected Results page, expand the loan report, select approved and first message, and click Next.
  4. Click Finish.
  5. In the Rule Explorer, double-click testsuite.xlsx to open it.

    In the Expected Results sheet, you can see the new tests.

    Expected Results sheet
  6. Close testsuite.xlsx.

What to do next

In the next task, you add a domain to the properties of the borrower and see how to maintain it in the scenario file.