afv-library/skills/omnistudio-callable-apex-generate/assets/pattern_test_class.cls

66 lines
2.4 KiB
OpenEdge ABL

/**
* Test class skeleton for System.Callable implementations.
* Covers: positive, negative (missing input), unsupported action, and null-args cases.
*
* Replace Industries_XxxCallable, Industries_XxxCallableTest, and actionOne
* with the actual class/action names. Add @TestSetup data for your specific SObjects.
*/
@IsTest
private class Industries_XxxCallableTest {
@TestSetup
static void setup() {
// Insert test SObject records needed by the callable here.
// Example:
// Account acc = new Account(Name = 'Test Account');
// insert acc;
}
@IsTest
static void testActionOne_success() {
System.Callable svc = new Industries_XxxCallable();
Map<String, Object> args = new Map<String, Object>{
'inputMap' => new Map<String, Object>{ 'requiredKey' => 'requiredValue' },
'options' => new Map<String, Object>()
};
Map<String, Object> result = (Map<String, Object>) svc.call('actionOne', args);
Assert.isTrue((Boolean) result.get('success'), 'Expected success=true');
Assert.isNotNull(result.get('data'), 'Expected data to be present');
}
@IsTest
static void testActionOne_missingInput() {
System.Callable svc = new Industries_XxxCallable();
Map<String, Object> args = new Map<String, Object>{
'inputMap' => new Map<String, Object>(),
'options' => new Map<String, Object>()
};
Map<String, Object> result = (Map<String, Object>) svc.call('actionOne', args);
Assert.isFalse((Boolean) result.get('success'), 'Expected success=false for missing input');
}
@IsTest
static void testUnsupportedAction() {
try {
System.Callable svc = new Industries_XxxCallable();
svc.call('unknownAction', new Map<String, Object>());
Assert.fail('Expected IndustriesCallableException');
} catch (IndustriesCallableException e) {
Assert.isTrue(e.getMessage().contains('Unsupported action'),
'Expected unsupported action message');
}
}
@IsTest
static void testNullArgs() {
System.Callable svc = new Industries_XxxCallable();
// Null args must be handled defensively; must not throw NullPointerException
Map<String, Object> result = (Map<String, Object>) svc.call('actionOne', null);
Assert.isNotNull(result, 'Result must not be null even with null args');
}
}