Back Forward How to unit test a Parse Structured rule

About Parse Structured rules

You can test a Parse Structured rule directly, separate from the activity or other context in your application in which it will ultimately operate. C-2434

Preparation

For a simple test, obtain an XML document that contains test data. You can choose to type or paste the document into a form, store it in a local Windows file, or upload it into a Text File rule.

Conducting the test

For basics of unit testing, see Unit testing a rule with the Run toolbar button.

  1. Save the Parse Structured form.C-2434
  2. Click the Run toolbar button (Run) or the equivalent keyboard shortcut CTRL + R. A test window opens.
  3. Select a radio button to indicate whether a new empty page or an existing page is to provide input property values for the test.
  4. Select a radio button to indicate the source of test data.
  5. If the data is to be entered directly, type or paste the data into the text area. If the data is in a local file, click  Browse   and navigate to the file. Click  OK  . If the test data is in a text file rule, enter all three key parts of the rule separated by periods.
  6. Click  Execute  . The resulting parsed XML document appears in a new window. The clipboard is not altered.

The parseState object and debugging

Advanced featureAs it executes, a Parse Structured rule creates and maintains a Java object in memory named parseState. This corresponds to a method variable in the generated Java.

This object is not visible through the Tracer or the Clipboard tool, but you can use Public API functions to examine it. To do this, include a Java step containing the Public API call:

myStepPage.putString("debug3", Long.toString(parseState.getStreamOffset()) );

where debug3 is a Single Value property. This function places the byte offset position of the Java object into a clipboard value. You can review the clipboard value with the Tracer or Clipboard tool.

Four PRPC methods operate on the parseState object:

The result of each method is stored in parseState.lastToken (which can be accessed in a Java step) and optionally is stored as a property value.

Advanced featureThe parseState object is defined in the PublicAPI Interface

com.pega.pegarules.pub.runtime

This facility is based on java.io.* capabilities (not the newer java.nio.* capabilities). The PublicAPI includes methods to query or operate on the object. BURND 2/23/06

Using the Tracer

To trace the start and end of Parse Structured rule executions, select the Parse Rules checkbox in the Rule Types to Trace area of the Trace Options panel. See Tracer — Setting Options.

Up About Parse Structured rules