@isTest private class LexNewAndEditOnCallPIPLControllerTest { public static String rectAg = Schema.SObjectType.Contact.getRecordTypeInfosByDeveloperName().get('Agency').getRecordTypeId(); @testSetup static void setupTestData() { User thisUser = [ select Id from User where Id = :UserInfo.getUserId()]; System.runAs(thisUser){ // Profile prof1 = [select Id from Profile where Name ='901_经销商社区普通权限_2重验证(ET Email)']; List rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院']; List rectCo1 = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 普外科']; List rectCo2 = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 普外科']; if (rectCo.size() == 0) { return; } Account account0 = new Account(RecordTypeId = rectCo[0].Id, AgentCode_Ext__c = '9999909', Name = 'olympus0',Is_Active__c = '有効'); insert account0; Account account1 = new Account(RecordTypeId = rectCo1[0].Id, AgentCode_Ext__c = '9999900', Name = 'olympus1',ParentId = account0.Id,Hospital__c = account0.Id,Department_Class_Label__c = '普外科'); insert account1; Account account2 = new Account(RecordTypeId = rectCo2[0].Id, AgentCode_Ext__c = '66666', Name = 'olympus2',ParentId = account1.Id,Department_Class__c = account1.Id,Hospital__c = account0.Id,Is_Active__c = '有効'); insert account2; Product2 prod07 = new Product2(Name='Test07',ProductCode='Test07',Asset_Model_No__c = 'Test07',SFDA_Status__c = '有効',Dealer_special_Object__c = true,Packing_list_manual__c = 1,Manual_Entry__c = false); insert prod07; Product2__c proG = new Product2__c(Name='MH-155:白平衡帽',OT_CODE_Text__c='Test001',Product2__c = prod07.Id); insert proG; String RecordTypeId = Schema.SObjectType.Asset.getRecordTypeInfosByDeveloperName().get('HPAsset').getRecordTypeId(); System.debug(RecordTypeId); Asset ass = new Asset(); ass.Hospital__c = account0.Id; ass.RecordTypeId = RecordTypeId; ass.Product_Old__c = prod07.Id; ass.Product2Id = prod07.Id; ass.AccountId = account0.Id; ass.Asset_Owner__c = '医院资产'; ass.Name = 'Test'; ass.SerialNumber = '1234567'; insert ass; On_Call__c onc = new On_Call__c(); onc.segment__c = account2.Id; onc.Responsible_Person_HP__c = 'Test'; onc.Caller_phone__c = '18922764516'; onc.Oncall_report_number_c__c = '124312'; onc.Trable_occur_day_c__c = System.now(); onc.Taking_call_Time_c__c = System.now(); onc.Hospital__c = account0.Id; onc.Oncall_Equipment__c = ass.Id; insert onc; System.debug('onc===>'+onc); PI_Policy_Configuration__c config1 = new PI_Policy_Configuration__c(Sobject_Type__c = 'On_Call__c'); insert config1; PI_Policy_Configuration__c config2 = new PI_Policy_Configuration__c(Sobject_Type__c = 'On_Call__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(){ On_Call__c onc = [SELECT Id FROM On_Call__c WHERE Responsible_Person_HP__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/00h10000005qQHtAAM"},"Id":"00h10000005qQHtAAM","Name":"On-Call 布局","TableEnumOrId":"01I10000000T5ahEAC","LayoutType":"Standard"}]}'; Test.setMock(HttpCalloutMock.class, new BaseHttpMock(body,'1','200')); System.Test.startTest(); String objectType = 'On_Call__c'; List layout = MetaDataUtility.GetRecordTypePageLayout('',objectType); LexNewAndEditBasePIPLController.initData(onc.Id,'',objectType); LexNewAndEditOnCallPIPLController.initData(onc.Id, '',objectType); 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; } } }