< Previous | Next >

Task 3-3 (Optional): Testing the solution with a Java test client

You can create a Java™ test client for the solution to ensure that it is operating as expected. A Java test client offers flexibility, but requires Java coding skills.

About this task

The TestDriver API can be used to capture events for debugging and problem determination. You can use the methods in the TestDriver API to create a test driver instance, which connects to an Insight Server over a port and sends the server a solution identifier and a list of solution agents. The server sends events to the test driver instance, which collects the events in memory or writes them to a file.

The TestDriver class provides model factory methods to create events and entities.

In this tutorial, you import and use a predefined Java project that includes the Java code to call the TestDriver API.

Procedure

  1. Stop the sample server and then restart it. By restarting it, you clear the events that were used in the previous lesson.
  2. Open the Java perspective.
  3. Import the Java test client:
    1. In Decision Server Insights Designer, click File > Import, expand General, select Existing Projects into Workspace, and click Next.
    2. For the root directory, navigate to and select the <InstallDir>/gettingstarted/answer/CreditCardClient folder, and click OK.
    3. Select Copy projects into workspace and click Finish.
  4. Optional: View the libraries that the test driver API uses:
    1. Right-click the CreditCardClient project and click Properties.
    2. Click Java Build Path.
    3. Click the Libraries tab. You can see that the build path uses the predefined test driver libraries.
    4. Click Cancel.
  5. Inspect and edit the testdriver.properties file. This file, which is in the CreditCardClient folder, is used to initialize the TestDriver instance.
    1. Review the properties. For example, the solutionname property points to the name of the solution project, and the host property points to the default server name.
    2. For the trustStoreLocation property, edit the path if necessary to ensure that it specifies the location in which you installed the product:
      <InstallDir>/runtime/wlp/usr/servers/cisDev/resources/security/key.jks
    3. Click Save and close the testdriver.properties file.
  6. Explore the test client:
    1. Open the CreditCardClient/src/test/CreditCardTest.java file.
    2. Review the setUpBeforeClass function. This function creates a TestDriver instance and connects to the Insight Server by using the values that are specified in the testdriver.properties file. It also creates a receiver to capture the events that are emitted when rules are run.
    3. Review the emitTransactionAndCheck and emitInitializeAccountAndCheck methods. These methods create and emit events, and get entities. They also start and stop the recording of events.
    4. Review the definition of the MyReceiver class. This class defines an addDebugInfo method that writes comments when an event is emitted.
  7. Run the test client:
    1. Right-click the test client and select Run As > Run Configurations.
    2. Expand JUnit and select CreditCard Test.
    3. Click Run. The Console view opens and displays several messages. For each of the three tests, the messages indicate that the test driver is connected and that AuthorizationResponse events are emitted and processed. One of the last messages is similar to the following output:
      [3/4/15 14:42:03:649 EST] 00000001 ObjectGridImp I   CWOBJ4700I: The map name EventQueue@MyCreditCardSolution matched the regular expression of template map EventQueue.*.  The EventQueue@MyCreditCardSolution map was created for ObjectGrid com.ibm.ia:0.
      Debug info received: CreditCardRules, CreditCardRules, *, E8EA5E88AEE340C2A611E45637F151E6, MyCreditCardSolution
      Event: event 2015-03-04T14:42:03.430-05:00[America/New_York] $Id=E8EA5E88AEE340C2A611E45637F151E6 $Timestamp=2015-03-04T14:42:03.430-05:00[America/New_York]
    4. Open the JUnit view. This view shows that the tests ran without error.
      JUnit view shows that the tests ran and completed

What to do next

After you run the tests and analyze the results, you can redeploy the solution so that it is in its original state and so that you can run the tests again.

To redeploy the solution, right-click the MyCreditCardSolution project, select Deploy > Redeploy MyCreditCardSolution, and wait for the message Server configuration file successfully updated for server: cisDev. You can then rerun the tests.

When you are done with the tutorial, stop the sample server by clicking the Stop icon in the Sample Server view of the Samples Console perspective.

< Previous | Next >