Written by

Developer - Internal Applications at InterSystems
Question Pravin Barton · 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.

Comments

Eduard Lebedyuk · Aug 23, 2019

I'd add another Operation called MockSOAPOperation which accepts SOAP requests and calls your method.

After that change Business Host setting(s) to point to this mock operation.

0
Pravin Barton  Aug 23, 2019 to Eduard Lebedyuk

Thanks for the reply. How can my unit test configure a BPL process to call my mock operation instead of the real operation? Do I have to rewrite the business process to use indirection in the target of each <call> element and make the target a custom setting on the business host?

0
Eduard Lebedyuk  Aug 23, 2019 to Pravin Barton

Well, I always specify BH calls with indirection, so I guess my answer would be yes.

0
Heloisa Ramalho · Aug 26, 2019

You might consider using OnBeforeProductionStart() instead of OnAfterProductionStart() when you want to change settings.

0