119 lines
4.2 KiB
OpenEdge ABL
119 lines
4.2 KiB
OpenEdge ABL
@IsTest
|
|
public with sharing class CreateFolderInvocableHandlerTest {
|
|
|
|
@IsTest
|
|
static void testDriveAutomateRequestInitialization() {
|
|
|
|
System.debug('===== START Test DriveAutomateRequest =====');
|
|
|
|
// Initialize static map
|
|
CreateFolderInvocableHandler.staticMapForUseInNextTxn =
|
|
new Map<String,String>();
|
|
CreateFolderInvocableHandler.staticMapForUseInNextTxn.put('accesstoken', 'dummyToken');
|
|
|
|
System.debug('Static Map: ' + CreateFolderInvocableHandler.staticMapForUseInNextTxn);
|
|
|
|
CreateFolderInvocableHandler.DriveAutomateRequest req =
|
|
new CreateFolderInvocableHandler.DriveAutomateRequest();
|
|
|
|
req.folderName = 'Test Folder';
|
|
req.parentFolderId = 'Parent001';
|
|
req.storageType = 'Google Drive';
|
|
req.driveId = 'Drive123';
|
|
req.recordId = UserInfo.getUserId();
|
|
|
|
System.debug(JSON.serializePretty(req));
|
|
|
|
System.assertEquals('Test Folder', req.folderName);
|
|
System.assertEquals('Google Drive', req.storageType);
|
|
}
|
|
|
|
|
|
/*
|
|
* Mock response for createFolderFromAction callout
|
|
*/
|
|
class FolderCalloutMock implements HttpCalloutMock {
|
|
public HTTPResponse respond(HTTPRequest req) {
|
|
|
|
System.debug('Mock Endpoint: ' + req.getEndpoint());
|
|
System.debug('Mock Body: ' + req.getBody());
|
|
|
|
HttpResponse res = new HttpResponse();
|
|
res.setStatusCode(200);
|
|
|
|
// Simulate response map structure expected
|
|
res.setBody('{"parentFolderId":"Folder123","folderName":"UnitTest Folder","isnewAccesstoken":"true","newAccessToken":"newDummyToken"}');
|
|
return res;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@IsTest
|
|
static void testHandleOperation_Success() {
|
|
|
|
System.debug('===== START SUCCESS TEST =====');
|
|
|
|
Test.setMock(HttpCalloutMock.class, new FolderCalloutMock());
|
|
|
|
// Initialize static access token
|
|
CreateFolderInvocableHandler.staticMapForUseInNextTxn =
|
|
new Map<String,String>();
|
|
CreateFolderInvocableHandler.staticMapForUseInNextTxn.put('accesstoken', 'oldDummyToken');
|
|
|
|
// Prepare request
|
|
CreateFolderInvocableHandler.DriveAutomateRequest req =
|
|
new CreateFolderInvocableHandler.DriveAutomateRequest();
|
|
|
|
req.folderName = 'UnitTest Folder';
|
|
|
|
req.parentFolderId = 'Parent001';
|
|
req.storageType = 'Google Drive';
|
|
req.driveId = 'Drive123';
|
|
req.recordId = UserInfo.getUserId();
|
|
|
|
List<CreateFolderInvocableHandler.DriveAutomateRequest> requestList =
|
|
new List<CreateFolderInvocableHandler.DriveAutomateRequest>{ req };
|
|
|
|
Test.startTest();
|
|
List<CreateFolderInvocableHandler.DriveAutomateResult> results =
|
|
CreateFolderInvocableHandler.handleOperation(requestList);
|
|
Test.stopTest();
|
|
|
|
System.debug('Results: ' + JSON.serializePretty(results));
|
|
System.debug('Updated Static Map: ' + CreateFolderInvocableHandler.staticMapForUseInNextTxn);
|
|
// Assertions
|
|
// System.assertEquals(1, results.size());
|
|
// System.assertEquals(req.recordId, results[0].recordId);
|
|
// System.assertEquals('Folder123', results[0].folderId);
|
|
// System.assertEquals('UnitTest Folder', results[0].folderName);
|
|
|
|
// Verify token updated
|
|
// System.assertEquals('newDummyToken',
|
|
CreateFolderInvocableHandler.staticMapForUseInNextTxn.get('accesstoken');
|
|
|
|
System.debug('===== END SUCCESS TEST =====');
|
|
}
|
|
|
|
@IsTest
|
|
static void testHandleOperation_Exception() {
|
|
|
|
System.debug('===== START EXCEPTION TEST =====');
|
|
|
|
// Force exception by sending null list
|
|
List<CreateFolderInvocableHandler.DriveAutomateRequest> requestList = null;
|
|
|
|
Test.startTest();
|
|
List<CreateFolderInvocableHandler.DriveAutomateResult> results =
|
|
CreateFolderInvocableHandler.handleOperation(requestList);
|
|
Test.stopTest();
|
|
|
|
System.debug('Exception Results: ' + JSON.serializePretty(results));
|
|
|
|
// System.assertEquals(1, results.size());
|
|
// System.assert(results[0].folderName.contains('Error'));
|
|
|
|
System.debug('===== END EXCEPTION TEST =====');
|
|
}
|
|
|
|
} |