%UnitTest.TestProduction
class %UnitTest.TestProduction extends %UnitTest.TestCase
Unit test base class specialized for testing productions.
Unit tests created based on this class are associated with one production.
When the unit test is run, it automatically starts the production, allows it to run for a parameterized time,
puts new event log entries in an array and passes control to a method for custom verifications, then
stops the production and checks for errors.
The programmer can adjust some parameters, add code to verify results, and use callback methods to handle events
before/after start/stop production.
How to use this class:
- Create a subclass of this base class, one per production. Typically there will be one directory per production, and one unit test class per directory/production, called for example Test.xml. In case one wants to run the same production with various settings there may be additional unit test classes such as Test2.xml, Test3.xml, etc.
- Override parameter PRODUCTION to contain the production class name.
- Override parameters MAXWAIT, MINRUN and IGNOREPRODUCTIONERRORS if the defaults are not adequate to the production case.
- Override method CheckResults() to include your code with custom verification of the intended production results.
- Override method CheckErrors() if you set IGNOREPRODUCTIONERRORS = 1 and want to check the errors yourself.
- Override methods OnBeforeProductionStart() and OnAfterProductionStart() with code to run before or after the production is started, for example to put files in place (before start), or to call a method that fires the test by instantiating a business service and sending a message (after start).
- Override methods OnBeforeProductionStop() and OnAfterProductionStop() with
code to run right before or after the production is stopped, if needed.
Note: Initialization and cleanup code may go as usual into OnBeforeOneTest(), OnAfterOneTest(), etc., inherited from %UnitTest.TestCase.
There are methods to facilitate usage, such as change settings, retrieve additional records from the
Interoperability event log, compare files, etc. More details are given below and in the description for each method.
General utility/helper methods available to be used in the test code:
- GetSetting(): Get the current value of a setting for a production item.
- ChangeSetting(): Change the value of settings for production items.
- CreateCredentials(): Define credentials.
- SendRequest(): Call Interoperability testing service to send a request.
- CopyFile(): Copy a file from a directory to another directory.
- CompareFiles(): Compare the contents of two files.
- Error(): Compose a general error message as %Status with the text message provided.
- LogErrors(): Generate log messages with all errors contained in a status variable.
- GetEventLog(): Retrieve records from the Interoperability event log.
- SelectToString(): Return a string containing select information from the Event Log.
File management utility/helper methods available to be used in the test code (all with normalized names):
- CreateMainDirTree(): Initialize test directories, with subdirectories for HL7 use.
- CopyFile(): Copy a file from a directory to another directory.
- CompareFiles(): Compare the contents of two files.
- CleanUpDirectory(): Remove all files from a directory or tree.
The following properties are available:
- MainDir
- HL7InputDir
- HL7OutputDir
- HL7ArchiveDir
- HL7WorkDir
- MachineName
- InstanceName
- DSNToSamples
- DSNToUser
Utility/helper methods to be used during test development or debugging:
- Run(): Run without loading/deleting any classes.
- Debug(): Run in debug mode, without loading/deleting any classes.
- Export(): Export all classes in a package to a directory.
- ListSettings(): List to the terminal all current settings for a given production and config item.
Property Inventory
- BaseLogId
- DSNToSamples
- DSNToUser
- HL7ArchiveDir
- HL7InputDir
- HL7OutputDir
- HL7WorkDir
- InstanceName
- LastLogId
- MachineName
- MainDir
Method Inventory
- ChangeSetting()
- CheckErrors()
- CheckNamespace()
- CheckResults()
- CompareFiles()
- CopyFile()
- CreateCredentials()
- CreateMainDirTree()
- Debug()
- Error()
- Export()
- GetEventLog()
- GetFullName()
- GetSetting()
- ListSettings()
- LogErrors()
- OnAfterProductionStart()
- OnAfterProductionStop()
- OnBeforeProductionStart()
- OnBeforeProductionStop()
- Run()
- SelectToString()
- SendRequest()
- SubMainDir()
Parameters
Properties
Methods
Set s = ..ChangeSetting([Production], ConfigName, Setting, Value)
Set s = ##class(%UnitTest.TestProduction).ChangeSetting(Production, ConfigName, Setting, Value, 1)
The values are validated. Check the return for errors.
This method is initialized with a local array containing user created entries of type "Info" from the Event Log, not including the start production/components entries, with the following contents:
Log = last existing seq for array Log()
Log(seq, fieldname) = fieldvalue
To get other entries from the Event Log, or for more information about the array contents, see method GetEventLog().
Return $$$OK in most cases, or an error status if you want to indicate that there was a failure. Remember that failures are automatic when unit test macros are used.
The default for FileName2 is the same name as FileName1 concatenated with _reference before the last file extension.
Examples:
FileName1 = MyFile.txt, default FileName2 = MyFile_Reference.txt
FileName1 = HL7Message_ADTA01, default FileName2 = HL7Message_ADTA01_Reference
The default for Dir1 is the directory name specified by HL7OutputDir.
The default for Dir2 is the unit test directory.
Set s = ..CreateCredentials(Id, UserName, Password)
Set s = ##class(%UnitTest.TestProduction).CreateCredentials(Id, UserName, Password)
This method does not erase any files or directories if they are already present. To do a cleanup, see method CleanUpDirectory().
This method may be invoked in OnBeforeAllTests() or OnBeforeProductionStart() to initialize the test directory tree.
Do ##class(MyTestClass).Debug()
See also method Run().
To append text to an existing error text, pass the status as a second argument.
Examples:
Set status=..Error(message, [oldstatus])
Set status=##class(%UnitTest.TestProduction).Error(message, [oldstatus])
If the directory is not specified, then ^UnitTestRoot will be used as a base and the last piece of the package name will be used as the subdirectory name.
If the suite name is not specified, then the last piece of the package name of the current class will be used.
Note that parameter suite is ignored when a directory is specified.
Examples:
Do ##class(MyTestClass).Export()
Do ##class(MyTestClass).Export("D:\Test\MyProductionTests\TempDir")
Do ##class(MyTestClass).Export(,"MySuite")
To do: In production-enabled namespaces, all rules and VDoc schemas whose names start with the package should also be exported.
To do: Think about other kinds of files such as CSP pages.
type = "info" or "error" or "trace" or "warning" or "alert" or "assert" or "infouser" or "startstop" or "other" name = config name to filter entries (only fetch entries associated with this config name)
Examples:
To get new user entries of type "Info":
Set s = ..GetEventLog("infouser", "", "", .Log, .New)
To get new entries of type "Trace":
Set s = ..GetEventLog("trace", "MyBP", "", .Log, .New)
where New indicates how many new entries were found.
Sample format for the returned array:
Log(1,"ConfigName")="Ens.ScheduleHandler"
Log(1,"ID")="114"
Log(1,"Job")="4768"
Log(1,"SessionId")="8"
Log(1,"SourceClass")="Ens.Director"
Log(1,"SourceMethod")="UpdateProduction"
Log(1,"Stack")=""
Log(1,"Text")="Production 'QDENS.HL7.HL7Routing.Production' is up-to-date."
Log(1,"TimeLogged")="2006-12-05 17:41:06.421"
Log(1,"Type")="Info"
Set s = ..GetSetting([Production], ConfigName, Setting, .Value)
Set s = ##class(%UnitTest.TestProduction).GetSetting(Production, ConfigName, Setting, .Value)
Do ##class(MyTestClass).ListSettings(, [configname])
Do ##class(%UnitTest.TestProduction).ListSettings(production, [configname])
- Adjust settings - see method ChangeSetting().
- Create directories - see method CreateMainDirTree().
- Copy files - see method CopyFile().
- Create credentials required by the production - see method CreateCredentials().
- etc.
Do ##class(MyTestClass).Run()
See also method Debug().
If no request object type is passed, then type Ens.Request is assumed.
Example:
Set s = ..SendRequest("MyBPName", MyRequestObject, .Response, [GetReply], [Time])
GetReply=1 indicates a response is expected (default is 0).
Time indicates how long to wait for a response in case GetReply=1. Default is 30 secs.
Inherited Members
Inherited Properties
Inherited Methods
- %AddToSaveSet()
- %ClassIsLatestVersion()
- %ClassName()
- %ConstructClone()
- %DispatchClassMethod()
- %DispatchGetModified()
- %DispatchGetProperty()
- %DispatchMethod()
- %DispatchSetModified()
- %DispatchSetMultidimProperty()
- %DispatchSetProperty()
- %Extends()
- %GetParameter()
- %IsA()
- %IsModified()
- %New()
- %NormalizeObject()
- %ObjectModified()
- %OriginalNamespace()
- %PackageName()
- %RemoveFromSaveSet()
- %SerializeObject()
- %SetModified()
- %ValidateObject()
- AssertEqualsViaMacro()
- AssertFailureViaMacro()
- AssertFilesSQLUnorderedSameViaMacro()
- AssertFilesSameViaMacro()
- AssertNotEqualsViaMacro()
- AssertNotTrueViaMacro()
- AssertSkippedViaMacro()
- AssertStatusEqualsViaMacro()
- AssertStatusNotOKViaMacro()
- AssertStatusOKViaMacro()
- AssertSuccessViaMacro()
- AssertTrueViaMacro()
- Checkout()
- LogMessage()
- OnAfterAllTests()
- OnAfterOneTest()
- OnBeforeAllTests()
- OnBeforeOneTest()