/* * Author: Zhang,Heyang * Created Date: 2023/08/07 * Purpose: testClass * * */ @isTest private class LexNewAndEditASEActivityPIPLTest { public static String rectAg = Schema.SObjectType.Contact.getRecordTypeInfosByDeveloperName().get('Agency').getRecordTypeId(); @testSetup static void setupTestData() { List rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院']; Account myAccount1 = new Account(name='Testaccount001',Dealer_discount__c =10,RecordTypeId = rectCo[0].Id,AgentCode_Ext__c = '8888888'); insert myAccount1; ASEActivity__c ase = new ASEActivity__c(); ase.VisitStaff__c = 'Test'; insert ase; Contact testContacts = new Contact(email='jplumber@salesforce.com', firstname='Joe', RecordTypeId = rectAg, lastname='Plumber', AWS_Data_Id__c = 'TestContact', accountId = myAccount1.id); insert testContacts; PI_Policy_Configuration__c config1 = new PI_Policy_Configuration__c(Sobject_Type__c = 'ASEActivity__c'); insert config1; PI_Policy_Configuration__c config2 = new PI_Policy_Configuration__c(Sobject_Type__c = 'ASEActivity__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 = 'phone2', SF_Field_API_Name__c = 'Phone2',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(){ ASEActivity__c ase = [SELECT Id FROM ASEActivity__c WHERE VisitStaff__c = 'Test' LIMIT 1]; String body='{"size":1,"totalSize":1,"done":true,"queryLocator":null,"entityTypeName":"Layout","records":[{"attributes":{"type":"Layout","url":"/services/data/v41.0/tooling/sobjects/Layout/00h10000009lGOKAA2"},"Id":"00h10000009lGOKAA2","Name":"ASE工作活动 布局","TableEnumOrId":"01I10000001Yr0XEAS","LayoutType":"Standard"}]}'; Test.setMock(HttpCalloutMock.class, new BaseHttpMock(body,'1','200')); System.Test.startTest(); String objectType = 'ASEActivity__c'; List layout = MetaDataUtility.GetRecordTypePageLayout('',objectType); LexNewAndEditBasePIPLController.initData(ase.Id,'',objectType); LexNewAndEditASEActivityPIPLController.initData(ase.Id,'',objectType); Contact con = [SELECT Id,AWS_Data_Id__c FROM Contact WHERE AWS_Data_Id__c = 'TestContact']; LexNewAndEditASEActivityPIPLController.getContactByAWSId(con.AWS_Data_Id__c); System.Test.stopTest(); } 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; } } }