Question
· Aug 23, 2019

Testing interoperability productions without connecting to external systems

Hello all,
I'm trying to write tests for an interoperability production using %UnitTest.TestProduction. I'd like to control the behavior of the SOAP operations so they don't actually connect to external systems when I'm testing. My first thought for this is to create a mock outbound adapter class that answers with some configured class method:

Class UnitTest.Helper.Integration.MockSoapAdapter Extends EnsLib.SOAP.OutboundAdapter
{

Property MockAdapterAnswerClass As %String;

Property MockAdapterAnswerMethod As %String;

Parameter SETTINGS = "MockAdapterAnswerClass,MockAdapterAnswerMethod";

Method InvokeMethod(pMethodName As %String, Output pResult As %RegisteredObject, pArgs...) As %Status
{
    return $classmethod(..MockAdapterAnswerClass, ..MockAdapterAnswerMethod, pMethodName, .pResult, pArgs...)
}

}

And then in my test I could inject the mock adapter and the answer method through the settings:

ClassMethod SomeAnswer(pMethodName As %String, Output pResult As %RegisteredObject, pArgs...) As %Status
{
    // define some test behavior here
}

Method OnAfterProductionStart() As %Status
{
    $$$QuitOnError(..ChangeSetting(,"Some Operation", "Adapter", "UnitTest.Helper.Integration.MockSoapAdapter"))
    $$$QuitOnError(..ChangeSetting(,"Some Operation", "MockAdapterAnswerClass", ..%ClassName(1)))
    $$$QuitOnError(..ChangeSetting(,"Some Operation", "MockAdapterAnswerMethod", "SomeAnswer"))
    // create request, send request, verify response
}

But I'm finding I can't actually change the outbound adapter class as a setting on the operation. Does anybody have ideas on how to connect an operation to a mock outbound adapter class in a test context? Or is there something simpler I should be doing? Thanks.

Discussion (4)2
Log in or sign up to continue