Samples > Rule Scenario Manager Demonstration > How to Test Rules in Rule Scenario Manager Using Java Binding

This sample shows how to test rules in Rule Scenario Manager using Java data binding.

A scenario is a defined collection of components including the path to a deployed ruleset, input data, and performance tests, which is executed as a test case on a set of business rules. See Scenarios for a more detailed description.

Scenarios can be grouped together into scenario suites, which are lists of scenarios with a KPI that is calculated over the scenario results. See Scenario Suites for a more detailed description.

A simulation is a list of scenario suites together with a KPI, which provides global feedback on the executed scenarios. See Simulations for a more detailed description.

Scenario, scenario suite and simulation executions produce reports in different formats that you can view and store.

Note that most Rule Scenario Manager artifacts can be generated using a wizard. For more details, see Defining Rule Scenario Manager Artifacts.

Key Features

Key features include:

Installing this Sample

To install the sample:

  1. In the Samples Console locate the scenariomanager > basics-javabinding sample.
  2. Check that the Samples Server is started.
  3. For information on how to start and stop the Samples Server, see Stopping and Restarting the Samples Server from the Samples Console.
  4. Execute the deploy.ruleapp command to deploy the loanvalidationruleapp Replay used in this sample to the Rule Execution Server.
  5. This operation has completed successfully when the Samples Trace returns the message Deploy succeeded.
  6. Execute the build command to compile the source code.
  7. Execute the deploy command to package the XOM JAR file into the SSP WAR file and deploy the new SSP.
  8. Wait for the Java EE application to start before continuing.
  9. When the Java EE application is ready, the server trace displays the message: Application ready. You can now execute the "run.*" targets.

Running this Sample

This sample can only be opened and run in the Samples Console.

Simple Scenario

When executing a simple scenario, you can view the results in XML and HTML format.

To run a simple scenario:

  1. Double-click the run.scenario target.
  2. The results on the Samples Trace show that 16 tests ran and four of them failed.
  3. To view the results in XML format, go to the directory: <InstallDir>/scenariomanager/samples/basics-javabinding/data/scenario/reports/xml.
  4. Open the loanValidationReport0.xml file with any text editor.
  5. This report file contains all data related to the execution. For information about the XML format, see the file: <InstallDir>/doc/schemas/rsmExecutiontrace.xsd
  6. To generate a report of the output in HTML format, return to the Samples Console and double-click the run.report target.
  7. To view the HTML report, go to the directory: <InstallDir>/scenariomanager/samples/basics-javabinding/data/scenario/reports/junit.
  8. Open the index.html file in your browser.
  9. Click the MyScenarioJUnit link in the left pane. The results of the execution are displayed in the right pane:
  10. images/rsm-report-junit.png
Scenario Suite

This sample provides a number of scenario suites for you to run. When executing a simple scenario suite, you can view the results in Excel and HTML format. When executing a scenario suite with generated scenarios, or a custom scenario suite, you can view them in XML and HTML format.

To run a simple scenario suite:

  1. Double-click the run.scenariosuite target.
  2. The results on the Samples Trace show that 13 tests ran and two of them failed.
  3. To view the output as an Excel report, go to the directory: <InstallDir>/scenariomanager/samples/basics-javabinding/data/scenario/reports/excel.
  4. Open the loanValidationSuiteReport1.xls Excel file. This report file contains all data related to the execution:
  5. images/rsm-report-excel.png
  6. In the samples console, double-click the run.report target.
  7. To view the HTML report, go to the directory: <InstallDir>/scenariomanager/samples/basics-javabinding/data/scenario/reports/junit.
  8. Open the index.html file in your browser.
  9. Click the MyScenarioSuiteJUnit link in the left pane. The results of the execution are displayed in the right pane.

To run a scenario suite with generated scenarios:

  1. Double-click the run.scenariosuitetemplate target.
  2. The result on the samples trace shows that five tests ran and three of them failed.
  3. To view the output in XML format, go to the directory: <InstallDir>/scenariomanager/samples/basics-javabinding/data/scenario/template/reports.
  4. You will find five files. The LoanValidationSuiteXMLReport.xml file is the report for the scenario suite execution. The other files correspond to each scenario generated.
  5. To generate a report of the output in HTML format, in the Samples Console double-click the run.report target.
  6. To view the HTML report, go to the directory: <InstallDir>/scenariomanager/samples/basics-javabinding/data/scenario/reports/junit.
  7. Open the index.html file in your browser.
  8. Click the MyScenarioSuiteTemplateJUnit link in the left pane. The results of the execution are displayed in the right pane.
  9. You will notice tests with names like Scenario XML Inputx. These are not real tests; they are the titles for the tests that are just below them.

To run a custom scenario suite:

  1. Double-click the run.customsuite target.
  2. The results on the Samples Trace show that seven tests ran and two of them failed.
  3. Go to the directory: <InstallDir>/scenariomanager/samples/basics-javabinding/data/scenario/reports/excel.
  4. You will find two new files: resultReport.xls and resultReport.xml. These are both reports for the scenario suite executed, but in a different formats.
  5. To generate a report of the output in HTML format, in the Samples Console double-click the run.report target.
  6. Go to the directory: <InstallDir>/scenariomanager/samples/basics-javabinding/data/scenario/reports/junit.
  7. Open the index.html file in your browser.
  8. Click the MyCustomSuiteJUnit link in the left pane. The results of the execution are displayed in the right pane.
  9. You will notice tests with names like Sx. These are not real tests; they are the titles for the tests that are just below them.
Simulation

When executing a simulation, you can view the results in Excel, XML and HTML format.

To run a simulation:

  1. Double-click the run.simulation target.
  2. The result on the samples trace shows that 19 tests ran and three of them failed.
  3. To view a report of the simulation execution in Excel format, go to the directory: <InstallDir>/scenariomanager/samples/basics-javabinding/data/scenario/reports/excel and open the fileloanValidationSuiteReport1.xls.
  4. Go to the directory: <InstallDir>/scenariomanager/samples/basics-javabinding/data/scenario/reports/xml. You will find the following files:
  5. - loanValidationReport1.xml A report of the first of two scenario executions.
    - loanValidationReport2.xml A report of the second scenario execution.
    - loanValidationSuiteReport1.xml This is the report of the scenario suite execution.
    - loanValidationSimulation1Report.xml This is the report of the simulation execution.
  6. To generate a report of the output in HTML format, in the Samples Console double-click the run.report target.
  7. To view the HTML report, go to the directory: <InstallDir>/scenariomanager/samples/basics-javabinding/data/scenario/reports/junit.
  8. Open the index.html file in your browser.
  9. Click the MySimulationJUnit link in the left pane.
  10. The results of the execution are displayed in the right pane.

To run scenarios from an RSM archive:

  1. Double-click the run.archive target.
    Note
    The run.archive target fails if Excel is still open on the previous resulting files. All files previously loaded in Excel should be closed before running the target.
  2. The result on the samples trace shows that 19 tests ran and four of them failed.
  3. Go to the directory: <InstallDir>/scenariomanager/samples/basics-javabinding/data/scenario/reports/excel. You will find a file named loanValidationSuiteReport1.xls. This is a report on the archive execution.
  4. Go to the directory: <InstallDir>/scenariomanager/samples/basics-javabinding/data/scenario/reports/xml. You will find four files:
  5. - loanValidationReportx.xml are the reports of the scenario executions.
    - loanValidationSuiteReport1.xml is the report of the scenario suite execution.
    - loanValidationSimulation1Report.xml is the report of the simulation execution.
  6. To generate a report of the output in HTML format, in the Samples Console, double-click the run.report target.
  7. Go to the directory: <InstallDir>/scenariomanager/samples/basics-javabinding/data/scenario/reports/junit.
  8. Open the index.html file in your browser.
  9. Click the MyArchiveJUnit link in the left pane. The results of the execution are displayed in the right pane.

To run a simulation with the JUnit User Interface (TestRunner):

  1. Double-click the run.uimode target. A JUnit window is displayed.
    Note
    The run.uimode target fails if Excel is still open on the previous resulting files. All files previously loaded in Excel should be closed before running the target.
  2. images/rsm-report-junit-swing.png
    After a few seconds, the tests are started automatically. When they are complete, the results are displayed in the window.
  3. Click the Exit button at the bottom of the JUnit window to close it.
Generate Rule Scenario Manager input data files (XML or Excel) from Java objects

This sample helps you to generate the input data files from your Java object.

To generate the input files:

  1. Double-click the run.inoutparameters target.
  2. The result on the samples trace shows that two tests ran and none of them failed.
  3. Go to the directory: <InstallDir>/scenariomanager/samples/basics-javabinding/data/scenario/inputs/excel. An input Excel file has been generated.
  4. Go to the directory: <InstallDir>/scenariomanager/samples/basics-javabinding/data/scenario/inputs/xml. An input XML file has been generated.

Source Files

This sample is located in <InstallDir>/scenariomanager/samples/basics-javabinding.Only the files used in the samples are listed here.

Highlights

Highlights for this sample are described in the following sections.

Deployment

As the rules are executed against a Java XOM (loanvalidation-xom.jar), the XOM needs to be deployed within the web-inf\lib directory of the SSP WAR file. You can see how this is done by looking at the deploy target in the build.xml file.

Configuration

Environment configuration data, which can be applied to scenarios, scenario suites, and simulations, are contained in XML files. See Configurations for an explanation of how scenarios are controlled by their configuration.

You use this XML data configuration to define the following:

In this sample, the configuration is specified by the loanValidationConfigurationXML.xml file or the loanValidationConfigurationExcel.xml file. These files specify the properties required to execute the scenarios, such as the executor class and the input and output databinding classes.

Note that all requests for executions are sent to a remote Scenario Service Provider through the IlrHTTPExecutorImpl executor. This class allows you to execute rulesets remotely using the HTTP protocol.

The configuration also defines the method by which the input data is read. To read XML data, the configuration specifies IlrXMLInOutParametersImpl as the input binding class. To read Excel data, the configuration specifies IlrExcelInOutParametersImpl as the input binding class.

Definitions

The Rule Scenario Manager testing artifacts, scenarios, suites and simulations, are defined in XML files.

Scenario definition

You use this XML file to define scenarios using the following data:

Input data is the source data on which a ruleset (defined by the ruleset path) is executed.

After the ruleset is executed, an execution response is generated. The response includes such information as the time taken to complete the ruleset execution, the rules fired, the tasks executed, the number of rules fired, the number of tasks executed, and so on. You can use filters to determine how much information you retrieve from the ruleset execution; see Filters for further information.

A scenario report represents the results of a scenario execution. It contains the name and description of the scenario, the tests that were performed over the ruleset execution results, and the test results. Output data is the data returned by the rule engine on the execution of the ruleset - the results of firing the rules.

Scenario suite definition

You use this XML file to define scenario suites using the following data:

This sample uses the scenario suite KPI class myPackage.MyCoverageKpi, which calculates the rules coverage percentage (the number of rules fired over the total number of rules).

Simulation definition

You use this XML file to define simulations using the following data:

This sample uses the simulation KPI class myPackage.MyBestCoverageKpi, which calculates the best rules coverage percentage from the member scenario suites. This class works with the myPackage.MyCoverageKpi class, which calculates the rules coverage percentage (the number of rules fired over the total number of rules).

Summary

Rebuilding this Sample

To rebuild the sample:

  1. In the Samples Console, double-click the build target to compile the code.
  2. To deploy it, double-click the deploy target.
  3. To run all samples, simply double-click the run target.
  4. To run the JUnit report, double-click the run.report target.
  5. To deploy the RuleApp, double-click the deploy.ruleapp target.

Related Concepts

Scenarios
Scenario Suites
Simulations
Configurations
Scenario Service Provider
Scenario Report
Scenario Suite Report
Simulation Report
Data and Datasets
Execution Trace
Databinding
Executor
Tests
Extractor
Scenario Suite KPI
Simulation KPI
RSM Archives

Related Tasks

Rule Scenario Manager XML and Java Artifacts
Executing Scenarios, Scenario Suites, Simulations, and RSM Archives

Related Reference

Test Extractors and Operators

Related Samples and Tutorials

How to Test Rules in Rule Scenario Manager using XML Binding