JUnit test sample details

After you run the sample, you can study the source files to learn how the sample works.

Running the sample

  1. In the Java perspective, right-click the test client JUnitClient and select Run As > Run Configurations.
  2. Expand JUnit and select JUnit Test.
  3. Click Run. The Console view opens and displays several messages about the test driver connection.

    In each of the tests, an assertion is done on the final status of the customer. When the tests finish, each test is shown as green.

Source files

The sample source files are in <InstallDir>/samples/junit. They are imported into Decision Server Insights during the setup procedure for the sample, and include the following items:
  • JUnitSolution, the solution project
  • JUnitRuleAgent, the rule agent that is used by the solution
  • JUnitSolution - Java Model, which contains the Java™ interfaces of the solution
  • JUnitSolutionBOM, the BOM of the solution
  • JUnitClient, which contains the JUnit test that submits the event and tests the different steps of the test

How this sample works

The solution is exported to a solution archive, which is deployed to the cisDev server by the solutionManager command. The Ant tasks that are used to deploy the sample are defined in build.xml.

The JUnitClient project contains Java code to initialize a Customer entity, submit the events, and check that the entity is updated. Public methods are annotated with @Before keywords to set up the test driver service, delete all entity instances, and clear the history of the current solution. These methods run before the three @Test methods. Each of the three rules in JUnitRuleAgent has a test.

For each test, the customer entity is created and one or more purchase events are sent. Depending on these events, the customer status is updated. In both the gold() and goldToSilver() tests, a ZonedDateTime object sends a randomly generated purchase event each day over a simulated period of 10 days.

Rebuilding the sample

After you use or modify the sample, you can rebuild it to its original state so that you can run the tests again.

  1. In the Samples Commands view, open Samples Commands > Samples > JUnit service usage.
  2. Double-click redeploy and wait for the BUILD SUCCESSFUL message. This command undeploys and redeploys the solution.