@isTest
|
public class SyncAccountContactToAWSTest {
|
class HttpMock implements HttpCalloutMock{
|
|
public HTTPResponse respond(HTTPRequest request) {
|
// 创建一个假的回应
|
System.debug('------------------------------------------------------');
|
HttpResponse response = new HttpResponse();
|
string body = '';
|
system.debug(request.getEndpoint());
|
if(request.getEndpoint().contains('token')){
|
system.debug('url=token');
|
response.setHeader('Content-Type', 'application/json');
|
body='{ "message": "", "object": "freqfewqfewewfewfew", "status": "", "success": true, "timestamp": 0, "txId": "" }';
|
} else if(request.getEndpoint().contains('insert')){
|
system.debug('url=Insert');
|
response.setHeader('Content-Type', 'application/json');
|
body='{ "message": "", "object": [ { "dataId": "123456", "directShippmentAddress": "", "directShippmentAddressEncrypt": "", "isDelete": 0, "phoneNumber": "", "phoneNumberEncrypt": "", "sfRecordId": "a2R1m0000007BPD" } ], "status": "", "success": true, "timestamp": 0, "txId": "" }';
|
} else if(request.getEndpoint().contains('update')){
|
system.debug('url=update');
|
response.setHeader('Content-Type', 'application/json');
|
body='{ "message": "", "object": [ { "dataId": "123456", "directShippmentAddress": "", "directShippmentAddressEncrypt": "", "isDelete": 0, "phoneNumber": "", "phoneNumberEncrypt": "", "sfRecordId": "a2R1m0000007BPD" } ], "status": "", "success": true, "timestamp": 0, "txId": "" }';
|
} else{}
|
|
response.setBody(body);
|
response.setStatus('OK');
|
response.setStatusCode(200);
|
return response;
|
// }
|
}
|
}
|
@isTest
|
static void startTest() {
|
TestDataUtility.CreatePIPolicyConfigurations(new string[]{'Agency_Contact__c','Contact'});
|
Test.setMock(HttpCalloutMock.class, new HttpMock());
|
List<Agency_Contact__c> lra = new List<Agency_Contact__c>();
|
lra.add(new Agency_Contact__c(AWS_Data_Id__c='Test AWS'));
|
insert lra;
|
System.Test.startTest();
|
try{
|
//String soql = 'SELECT id,Doctor_Division1__c,Doctor_Division1_Encrypted__c,Name,Name_Encrypted__c,Type__c,Type_Encrypted__c,AWS_Data_Id__c,Contact__c, Contact__r.Doctor_Division1_Encrypted__c,Contact__r.LastName_Encrypted__c, Contact__r.Type_Encrypted__c FROM Agency_Contact__c WHERE id=\'a2R10000001cfatEAA\' And AWS_Data_Id__c =\'\' And Contact__c != null';
|
String soql = 'SELECT id,Doctor_Division1__c,Doctor_Division1_Encrypted__c,Name,Name_Encrypted__c,Type__c,Type_Encrypted__c,AWS_Data_Id__c,Contact__c, Contact__r.Doctor_Division1_Encrypted__c,Contact__r.LastName_Encrypted__c, Contact__r.Type_Encrypted__c FROM Agency_Contact__c WHERE AWS_Data_Id__c =\'Test AWS\'';
|
SyncAccountContactToAWS contactBatch = new SyncAccountContactToAWS(soql);
|
Id execBTId = Database.executeBatch(contactBatch,1);
|
}catch(Exception e){
|
system.debug('Exception from sync aws batch:'+ e.getMessage());
|
}
|
try{
|
SyncAccountContactToAWS.assignOnceOneMinuteLater();
|
}catch(Exception e){
|
system.debug('Exception from sync aws scheduler:'+ e.getMessage());
|
}
|
System.Test.stopTest();
|
}
|
|
// static testMethod void testExecute() {
|
// // This test runs a scheduled job at midnight Sept. 3rd. 2022
|
// String CRON_EXP = '0 0 0 3 9 ? 2022';
|
// String soql = 'SELECT id,Doctor_Division1__c,Doctor_Division1_Encrypted__c,Name,Name_Encrypted__c,Type__c,Type_Encrypted__c,AWS_Data_Id__c,Contact__c, Contact__r.Doctor_Division1_Encrypted__c,Contact__r.LastName_Encrypted__c, Contact__r.Type_Encrypted__c FROM Agency_Contact__c WHERE id=\'a2R10000001cfatEAA\' And AWS_Data_Id__c =\'\' And Contact__c != null';
|
|
// System.Test.startTest();
|
// // Schedule the test job
|
// String jobId = system.schedule('SyncAccountContactToAWSTest', CRON_EXP, new SyncAccountContactToAWS(soql));
|
// // Get the information from the CronTrigger API object
|
// CronTrigger ct = [SELECT Id, CronExpression, TimesTriggered, NextFireTime FROM CronTrigger WHERE id = :jobId];
|
// // Verify the expressions are the same
|
// System.assertEquals(CRON_EXP, ct.CronExpression);
|
// // Verify the job has not run
|
// System.assertEquals(0, ct.TimesTriggered);
|
// // Verify the next time the job will run
|
// System.assertEquals('2022-09-03 00:00:00', String.valueOf(ct.NextFireTime));
|
// System.Test.StopTest();
|
// }
|
|
}
|