API tests

The API tests show you how to use the Business Rules Embedded classes.

Under the directory <InstallDir>/rules-sdk/test, three separate API tests are provided. The source code files that contain the API tests are found in <InstallDir>/rules-sdk/test/src/com/ibm/rules/sdk/tests. Each test file demonstrates specific aspects of the Business Rules Embedded API. The code in each file is commented to direct your attention.

Table 1. API test files

Test file name

Test description

ApiTest.java

Demonstrates the end to end lifecycle of a ruleset that is based on an XML schema. Includes creating an object model from an XML schema, creating a vocabulary for a locale, defining a ruleset parameter, adding a rule and a decision table. Also demonstrates building, deploying, and executing the ruleset, and how to use the API to export a rule project that is based on an XML schema.

Restriction: When the project is imported into Rule Designer the rules that are not in the current locale of Rule Designer are in error. This error is due to a Rule Designer limitation on parameters.

JavaApiTest.java

Demonstrates the end to end lifecycle of a ruleset that is based on a Java XOM. Includes creating an object model from a Java XOM, creating a vocabulary for a locale, defining a ruleset parameter, adding rules to demonstrate the rule syntax for Java invocation. Also demonstrates building, deploying, and executing the ruleset, and how to use the API to export a rule project with a Java XOM.

ManagementApiTest.java

Demonstrates the use of the management session APIs to retrieve the management session and repository and to query all deployed rulesets in the environment.

How to run the API tests with Ant

To run the API tests by using the build.xml script that is provided, you must have Ant 1.7.1 or later set up on your system. If you do not have Ant, you can download it from the following website: The Apache Ant Project.

To run the API tests:

  1. Add the directory <InstallDir>/rules-sdk/test to your PATH environment variable.
  2. Enter the following commands in Command Prompt:
    >cd <InstallDir>/rules-sdk/test
    >ant 

By default, the ant command runs the build.xml file in the test folder.

How to run the API tests with Eclipse

To run the API tests as a Java project from Eclipse, you must have Eclipse.

  1. Create a Java project:
    1. Create a workspace for your project.
    2. In Eclipse, select File > New > Java Project.
    3. Type a name for your project and check that JRE uses the Java-1.6 execution environment.
    4. Click Finish.
  2. Copy the src directory from <InstallDir>/rules-sdk/test and paste it into your project.
  3. In Eclipse, click File > Refresh.
  4. Add the JAR files onto the classpath:
    1. Right-click your project and select Properties.
    2. In Java Build Path, select the Libraries tab and click Add External JARs….
    3. Select the junit.jar file from <InstallDir>/rules-sdk/test/lib and click Open to add the JAR file.
    4. Click Add External JARs... again, and add all the JAR files found in the <InstallDir>/rules-sdk/lib directory.
    5. Click OK to close the Properties window.
  5. Right-click your project and select Run as > JUnit Test.

The JUnit view opens and the project runs without errors.