/*  * Author: Wang,Xueqin  * Created Date: 08/07/2023  * Purpose:Test Class  * */ @isTest private class LexTenderinformationPIPLControllerTest{ public static String raRecordTypeId = Schema.SObjectType.Tender_information__c.getRecordTypeInfosByDeveloperName().get('QLM').getRecordTypeId(); @testSetup static void setupTestData() { Tender_information__c te = new Tender_information__c(); te.InfoQianlimaUrl__c = 'www.test.com'; te.Name = 'Test'; insert te; PI_Policy_Configuration__c config1 = new PI_Policy_Configuration__c(Sobject_Type__c = 'Tender_information__c'); insert config1; PI_Policy_Configuration__c config2 = new PI_Policy_Configuration__c(Sobject_Type__c = 'Tender_information__cV2'); insert config2; PI_Policy_Configuration__c config3 = new PI_Policy_Configuration__c(Sobject_Type__c = 'Contact'); insert config3; PI_Field_Policy_Detail__c pfpd1 = new PI_Field_Policy_Detail__c(AWS_Field_API__c = 'phone1', SF_Field_API_Name__c = 'Phone1',PI_Policy_Configuration__c = config1.Id, Enable_Encrypt__c=true); insert pfpd1; PI_Field_Policy_Detail__c pfpd2 = new PI_Field_Policy_Detail__c(AWS_Field_API__c = 'phone2', SF_Field_API_Name__c = 'Phone2',PI_Policy_Configuration__c = config2.Id, Enable_Encrypt__c=true); insert pfpd2; PI_Field_Policy_Detail__c pfpd3 = new PI_Field_Policy_Detail__c(AWS_Field_API__c = 'phone2', SF_Field_API_Name__c = 'Phone2',PI_Policy_Configuration__c = config3.Id, Enable_Encrypt__c=true); insert pfpd3; } @isTest static void tesMethod1(){ Tender_information__c te = [SELECT Id,Name FROM Tender_information__c where RecordTypeId =:raRecordTypeId LIMIT 1]; List p = [SELECT Id FROM Profile WHERE Name = '系统管理员']; if(p.size() == 0) { p = [SELECT Id FROM Profile WHERE Name = 'System Administrator']; } Id systemAdminProfileId = p[0].Id; String body='{"size":1,"totalSize":1,"done":true,"queryLocator":null,"entityTypeName":"ProfileLayout","records":[{"attributes":{"type":"ProfileLayout","url":"/services/data/v41.0/tooling/sobjects/ProfileLayout/01G1000000zCVFjEAO"},"Layout":{"attributes":{"type":"Layout","url":"/services/data/v41.0/tooling/sobjects/Layout/00h10000009eMblAAE"},"Name":"招投标项目 布局","TableEnumOrId":"01I10000001Ilp1EAC"},"ProfileId":"'+systemAdminProfileId+'","Profile":{"attributes":{"type":"Profile","url":"/services/data/v41.0/tooling/sobjects/Profile/'+systemAdminProfileId+'"},"Name":"系统管理员"},"RecordTypeId":"'+raRecordTypeId+'"}]}'; Test.setMock(HttpCalloutMock.class, new BaseHttpMock(body,'1','200')); System.Test.startTest(); String record_type_id = raRecordTypeId; String objectType = 'Tender_information__c'; List layout = MetaDataUtility.GetRecordTypePageLayout(record_type_id,objectType); LexTenderinformationPIPLController.initData(te.Id,raRecordTypeId,objectType); LexTenderinformationPIPLController.initData(te.Id,'',objectType); LexTenderinformationPIPLController.queryAccount('Department_Class__c','000000000000000'); LexTenderinformationPIPLController.searchContactInit('000000000000000','天津医院'); } public class BaseHttpMock implements HttpCalloutMock { String body =''; String status = ''; String statusCode = ''; public BaseHttpMock(String body,String status,String statusCode){ this.body = body; this.status = status; this.statusCode = statusCode; } public HTTPResponse respond(HTTPRequest req) { HttpResponse res = new HttpResponse(); res.setHeader('Content-Type', 'application/json'); res.setBody(body); res.setStatus('OK'); res.setStatusCode(200); return res; } } }