Example: OnAfterProductionStart
The Tutorial.ProductionTest OnAfterProductionStart method runs after the production has successfully started. Override the method to do the following:
-
Create and send two request messages to the Testing Service using SendRequest. In each case the Testing Service forwards the request message to the Tutorial.ExampleProduction Business Operation, which is named Tutorial.ExampleOperation.
-
Verify the contents of the first response using $$$AssertEquals. Note that a variable named response is passed by reference to SendRequest. When the method returns, this variable points to the response message from the Business Operation.
-
The second request message contains a null value for its StringValue property. This causes the Business Operation to generate and return an error.
Here is the method:
Method OnAfterProductionStart() As %Status
{
Set request = ##class(Ens.StringRequest).%New()
set request.StringValue="Hello Productions"
Set tSC = ..SendRequest( "Tutorial.ExampleOperation" ,request,
.response,1,40)
Do $$$AssertEquals(response.StringValue,"OK","Response should contain OK.")
Set request.StringValue=""
Set tSC = ..SendRequest( "Tutorial.ExampleOperation" ,request,
.response,1,40)
Return $$$OK
}
For a list of the macros and AssertX methods supported by %UnitTest.TestCaseOpens in a new tab see The %UnitTest Framework for InterSystems IRIS.
For a discussion of passing method arguments by reference, see Calling by Reference in the Methods section of Defining and Using Classes.