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
- Stop the sample server and then restart it. By restarting it, you clear the events that were
used in the previous lesson.
- Open the Java perspective.
- Import the Java test client:
- In Decision Server
Insights Designer, click , expand General, select Existing Projects into
Workspace, and click Next.
- For the root directory, navigate to and select the
<InstallDir>/gettingstarted/answer/CreditCardClient
folder, and click OK.
- Select Copy projects into workspace and click
Finish.
- Optional: View the libraries that the test driver API uses:
- Right-click the CreditCardClient project and click Properties.
- Click Java Build Path.
- Click the Libraries tab. You can see that the build path uses the predefined test driver libraries.
- Click Cancel.
- Inspect and edit the testdriver.properties file. This file, which is in the CreditCardClient folder, is used to initialize
the TestDriver instance.
- 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.
- 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
- Click Save and close the testdriver.properties
file.
- Explore the test client:
- Open the CreditCardClient/src/test/CreditCardTest.java file.
- 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.
- Review the emitTransactionAndCheck and
emitInitializeAccountAndCheck methods. These methods create and emit events, and get entities. They also start and stop the recording
of events.
- Review the definition of the MyReceiver class. This class defines an addDebugInfo method that writes comments when an
event is emitted.
- Run the test client:
- Right-click the test client and select .
- Expand JUnit and select CreditCard
Test.
- 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]
- Open the JUnit view. This
view shows that the tests ran without error.
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 , 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.