Rule Designer API

Package ilog.rules.dvs.client

Provides the entry point for running test suites and simulations.

See:
          Description

Class Summary
IlrSSPClient Used to invoke a remote SSP server using HTTP.
IlrSSPServiceFactory Factory that creates instances of an SSP service.
 

Package ilog.rules.dvs.client Description

Provides the entry point for running test suites and simulations.

Overview

You can use the DVS API to connect your application to an SSP server to launch the execution of your scenario suite and retrieve an execution report.

The main steps are:

  1. Prepare the input data
  2. Connect to a running SSP server
  3. Run the scenario suite, synchronously or asynchronously
  4. Parse the result to build a report

More explanations including code examples are provided in the sections below.

Prepare the input data

To prepare the input data:

  1. Define the scenario suite format using a format descriptor (an implementation of the IlrScenarioFormatDescriptor interface)
  2. Create a scenario suite descriptor based on this format and set all input data on it

The following code shows how to do this:

  // Define the scenario suite format to use
  IlrScenarioFormatDescriptor formatDescriptor = IlrScenarioFormatDescriptorFactory.getInstance().createScenarioFormatDescriptor();
  formatDescriptor.setScenarioFormatName("my excel format");
  formatDescriptor.setScenarioProviderClassName("ilog.rules.dvs.core.scenarioproviders.IlrExcel2003ScenarioProvider");
  IlrComparisonPrecisionDescriptor comparisonPrecision = new IlrComparisonPrecisionDescriptor();
  comparisonPrecision.setDecimalPrecision(2); // To compare numbers up to two digits to the right of the decimal point
  formatDescriptor.setComparisonPrecisionDescriptor(comparisonPrecision);
  
  // Create a scenario suite descriptor
  IlrScenarioSuiteDescriptor scenarioSuiteDescriptor = new IlrScenarioSuiteDescriptorFactory().createScenarioSuiteDescriptor(formatDescriptor);

  // Load the ruleset to test and store it in the scenario suite descriptor
  InputStream miniloanInputStream = SynchronousRunner.class.getResourceAsStream("/loanvalidation-rules.jar");
  IlrRulesetArchive rulesetToTest = IlrRulesetArchive.extractArchive(new IlrJarArchiveLoader(new JarInputStream(miniloanInputStream)));
  scenarioSuiteDescriptor.setProductionRulesetArchive(rulesetToTest);

  // The RES server to use to run the tests
  scenarioSuiteDescriptor.setResURL(new URL("http://localhost:9080/res"));
  scenarioSuiteDescriptor.setResUser("resAdmin");
  scenarioSuiteDescriptor.setResPassword("resAdmin");

  // Add the scenario data to the scenario suite descriptor.
  // The excel scenario provider expects the excel file as a byte array, in a property named excel2003BinaryData
  ByteArrayOutputStream os = new ByteArrayOutputStream();
  InputStream inputStream = null;
  try {
      inputStream = SynchronousRunner.class.getClassLoader().getResourceAsStream("loanvalidation-scenarios.xls");
      byte[] buffer = new byte[4096];
      int readen = 0;
      while ((readen = inputStream.read(buffer)) > 0) {
             os.write(buffer, 0, readen);
             }
      } finally {
             if (inputStream != null) {
                 inputStream.close();
             }
      }
  byte[] scenarioData = os.toByteArray();
  scenarioSuiteDescriptor.add("excel2003BinaryData", scenarioData);

Connect to a running SSP server

The following code shows how to connect to the SSP running on localhost, port 9080:

  ssp = IlrSSPServiceFactory.getInstance().createHTTPClient(new URL("http://localhost:9080/testing"), "resAdmin", "resAdmin");

Run the scenario suite, synchronously ou asynchronously

Running the scenario suite can by done synchronously ou asynchronously. The following example shows an asynchronous run:

  // Start the execution of the scenario suite on the remote server
  String jobID = ssp.createJob(scenarioSuiteDescriptor);
  IlrSSPJobResult jobResult = null;

  boolean jobHasNotYetCompleted = true;
  System.out.print("Waiting for job completion");
  while (jobHasNotYetCompleted) {
     try {
         jobResult = ssp.getJobResult(jobID);
         jobHasNotYetCompleted = false;
         System.out.println("\nJob has completed");
     } catch (IlrRunnerException e) {
      // The job has not yet completed
         System.out.print(".");
         Thread.sleep(20);
         }
  }
  IlrScenarioSuiteTestResult globalResult = jobResult.getResult();

The following code shows how to run the scenario suite synchronously:

  IlrScenarioSuiteTestResult globalResult = ssp.run(scenarioSuiteDescriptor);

Parse the result to build a report

The following example shows how to display the test result on system out:

  List scenarioResults = globalResult.getScenarioTestResults();
  for (IlrScenarioTestResult scenarioResult: scenarioResults) {
     System.out.println(scenarioResult.getName() + ": " + scenarioResult.getStatus());
     List testResults = scenarioResult.getTestResults();
     for (IlrTestResult testResult: testResults) {
         System.out.println("\t" + testResult.getName() + ": " + testResult.getStatus() + " (" + testResult.getMessage() + ")");
     }
  }


Rule Designer API

© Copyright IBM Corp. 1987, 2013