@isTest public with sharing class AWSServiceTool2V2Test { @TestSetup static void setup(){ TestDataUtility.CreatePIPolicyConfigurations(new string[]{'Repair__c','Agency_Contact__c','Contact','Address__c','Repair__cV2'}); } @isTest static void Test1(){ Test.setMock(HttpCalloutMock.class, new HttpMock()); Repair__c rs = TestDataUtility.CreateRepairs(1)[0]; Contact contact2 = new Contact(); contact2.AccountId = rs.Account__c; contact2.FirstName = '小明'; contact2.LastName = 'test1经销商'; insert contact2; Address_Level__c alc1 = new Address_Level__c( Name = '山东' ); Address_Level2__c alc11 = new Address_Level2__c( Name = '青岛市',Address_Level__c = alc1.Id,Level1_Name__c='山东' ); Address__c add = new Address__c(); add.Address_Classification__c = '办事处'; add.Customer__c = rs.Account__c; add.Contacts__c = contact2.id; add.Telephone__c = '123123'; add.Province__c = alc1.Id; add.City__c = alc11.Id; add.Detailed_Address__c = '北京市顺义区西海洪村'; insert add; Test.startTest(); AWSServiceTool2V2.EncryptPushDataRepair(rs.Id); Test.stopTest(); } 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":"RT_SUCCESS","object":{"a0J9D000003pVS3UAM":"1058028677385682945"},"status":"0","success":true,"timestamp":1672295303119}'; } else if(request.getEndpoint().contains('update')){ system.debug('url=update'); response.setHeader('Content-Type', 'application/json'); body='{"message":"RT_SUCCESS","object":{"a0J9D000003pVS3UAM":"1058028677385682945"},"status":"0","success":true,"timestamp":1672295303119}'; } else{ } response.setBody(body); response.setStatus('OK'); response.setStatusCode(200); return response; } } }