Skip to main content

Example: OnAfterProductionStart

The following code is in the test class Tutorial.ProductionTest. It overrides OnAfterProductionStart. The code runs after the production has started successfully and does the following:

  • Creates and sends two Ensemble request messages to the Ensemble 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.

  • Verifies 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.

Method OnAfterProductionStart() As %Status
{
 Set request = ##class(Ens.StringRequest).%New()
 set request.StringValue="Hello Ensemble"
 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)
 Quit $$$OK
}
Note:

For a list of the macros and AssertX methods supported by %UnitTest.TestCaseOpens in a new tab see %UnitTest Classes in the Caché %UnitTest Tutorial.

For a discussion of passing method arguments by reference, see Calling by Reference in the Methods section of Using Caché Objects.

FeedbackOpens in a new tab