Testing Data Transformations
After you compile a data transformation class, you can (and should) test it. This chapter describes how to do so. It contains the following sections:
This chapter applies to both DTL transformations and custom transformations.
Using the Transformation Testing Page
The Management Portal provides the Test Transform wizard. You can access this from the following locations in the Management Portal:
-
Click Test from the Tools tab in the Data Transformation Builder
-
Select the transformation and click Test on the Data Transformation List page.
Initially the Output Message window is blank and the Input Message window contains a text skeleton in a format appropriate to the source message. To test:
-
Edit the Input Message so that it contains appropriate data. What displays and what you enter in the input box depends on your source type and class:
-
For HL7 or other EDI messages, the window displays raw text; have some saved text files ready so that you can copy and paste text from these files into the Input Message box.
-
For regular Ensemble messages, the window displays an XML skeleton with an entry for each of the properties in the message object; type in a value for each property.
-
-
Click Test.
-
Review the results in the Output Message box.
The following shows an example:
Testing a Transformation Programmatically
To test a transformation programmatically, do the following in the Terminal (or write a routine or class method that contains these steps):
-
Create an instance of the source message class.
-
Set properties of that instance.
-
Invoke the Transform() class method of your transformation class. This method has the following signature:
classmethod Transform(source As %RegisteredObject, ByRef target As %RegisteredObject) as %Status
Where:
-
source is the source message.
-
target is the target message created by the transformation.
-
-
Examine the target message and see if it has been transformed as wanted. For an easy way to examine both messages in XML format, do the following:
-
Create an instance of %XML.WriterOpens in a new tab.
-
Optionally set the Indent property of that instance equal to 1.
This adds line breaks to the output.
-
Call the RootObject() method of the writer instance, passing the source message as the argument.
-
Kill the writer instance.
-
Repeat with the target message.
-
For example:
//create an instance of the source message
set source=##class(DTLTest.Message).CreateOne()
set writer=##class(%XML.Writer).%New()
set writer.Indent=1
do writer.RootObject(source)
w !!
set sc=##class(DTLTest.Xform1).Transform(source,.target)
if $$$ISERR(sc) {do $system.Status.DisplayError(sc)}
set writer=##class(%XML.Writer).%New()
set writer.Indent=1
do writer.RootObject(target)