How to unit test a Parse Structured rule |
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
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.
For basics of unit testing, see Unit testing a rule with the Run toolbar button.
CTRL
+ R
. A
test window opens.
As 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 Process Commander 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.
The 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
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.