@isTest public class NFM118ControllerTest { static testMethod void testMethod1(){ List rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院']; if (rectCo.size() == 0) { return; } List rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科']; if (rectSct.size() == 0) { return; } List rectDpt = [select Id, Name from RecordType where IsActive = true and SobjectType = 'Account' and Name IN ('診療科 消化科', '診療科 呼吸科') order by Name desc]; if (rectDpt.size() == 0) { return; } List rectAs = [select Id, Name from RecordType where IsActive = true and SobjectType = 'Asset' and Name = '备品']; if (rectAs.size() == 0) { return; } // insert hospital Account company1 = new Account(); company1.RecordTypeId = rectCo[0].Id; company1.Name = '病院テスト1'; company1.OCM_man_province_txt__c = '江西'; List hps = new Account[]{company1}; insert hps; List dc1s = [Select Id, Name, Department_Class_Label__c, Sys_Dept_Name_Change_Chk__c from Account where Parent.Id = :company1.Id order by Department_Class_Label__c]; Account depart1 = new Account(); depart1.RecordTypeId = rectDpt[0].Id; depart1.Name = '*'; depart1.Department_Name__c = '診療科1'; depart1.ParentId = dc1s[0].Id; depart1.Department_Class__c = dc1s[0].Id; depart1.Hospital__c = company1.Id; depart1.OCM_man_province_txt__c = '江西'; insert new Account[] {depart1}; List prdList = new List(); Product2 prd1 = new Product2(); prd1.ProductCode_Ext__c = 'HistoryPrd1'; prd1.ProductCode = 'HistoryPrd1'; prd1.Repair_Product_Code__c = 'HistoryPrd1_RP'; prd1.Name = 'HistoryPrd1'; prd1.Manual_Entry__c = false; prd1.Extend_new_product_gurantee__c = true; prd1.Extend_Gurantee_Start__c = Date.today().addDays(-60); prd1.Extend_Gurantee_End__c = Date.today().addDays(60); prdList.add(prd1); insert prdList; Asset ast = new Asset(); ast.RecordTypeId = rectAs[0].Id; ast.SerialNumber = 'abcdefg'; ast.Name = '测试资产1'; ast.AccountId = depart1.Id; ast.Department_Class__c = dc1s[0].Id; ast.Hospital__c = company1.Id; ast.Product2Id = prd1.Id; ast.Guarantee_period_for_products__c = Date.today(); ast.InstallDate = Date.today(); ast.Manage_type__c = '个体管理'; ast.FirstApproveDate_old__c = Date.today().addDays(-30); Oly_TriggerHandler.bypass('AssetHandler'); insert ast; Asset ast1 = [select RecordTypeID__c from Asset where Id =: ast.Id]; String RecordTypeID = ast1.RecordTypeID__c; System.assertEquals(RecordTypeID , ast.RecordTypeId); RecordType rectOpp = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity' and DeveloperName = 'Opportunity' ]; Opportunity opp = new Opportunity( Name='testOpp1', StageName='引合', CloseDate=Date.today(), AccountId=depart1.Id, Sales_Root__c = '販売店', Competitor__c ='A', Click_Close_Date__c = null, RecordType = rectOpp ); insert opp; //注残 Statu_Achievements__c Sac = new Statu_Achievements__c( name = 'zhucan_one', Opportunity__c = opp.id, DeliveryDate__c = Date.today(), ContractNO__c = 'ContractNO1', ContractAmount__c = 1000 ); insert Sac; //新建电子签收单 eSignForm__c eSignForm = new eSignForm__c(); eSignForm.Statu_Achievements__c = Sac.Id; eSignForm.Name = '::测试电子签收单'; eSignForm.DNName__c = '65330898'; eSignForm.AccessoriesQualified__c = true; eSignForm.handleOpinionAgency__c = '哇哈哈哈哈哈哈哈哈'; eSignForm.agencyScanDay__c = Date.today(); eSignForm.agencySignUpDate__c =Date.today(); eSignForm.agencyConfirmDate__c = Date.today(); insert eSignForm; waybill__c w = new waybill__c(); w.waybill_number__c = '6501621931'; insert w; } static testMethod void testSendPostRequest() { Test.startTest(); // // 设置测试环境 Test.setMock(HttpCalloutMock.class, new MockHttpResponseGenerator()); // 执行测试 NFM118Controller.callout('','65330898'); NFM118Controller.Obtainlogistics2('65330898'); NFM118Controller.executefuture('','65330898'); Test.stopTest(); } // 创建一个模拟的 HTTP 请求和响应类 private class MockHttpResponseGenerator implements HttpCalloutMock { public HttpResponse respond(HttpRequest req) { HttpResponse res = new HttpResponse(); res.setHeader('Content-Type', 'application/json'); res.setStatus('{"success": true}'); // 测试1 res.setBody('{"resinfo": {"Status": 200,"Erro_code": "00","Erro_val": ""},"order": {"order_number": "D20211012099","so_dn": 65330898,"order_info": "BJ-GS-210656","cre_dat": "2023/10/12 14:01:18","shipping_company": "奥林巴斯贸易(上海)有限公司","shipping_man": "朱新德","shipping_address": "上海市浦东新区泰谷路185号3层E-F部位","shipping_tel": "021-58667171-8437","receiving_company": "西安好克光电仪器有限公司","receiving_man": "吴明明","receiving_address": "西安曲江新区雁展路1111号莱安中心2幢1单元11层11108号","receiving_tel": 15339092148,"shipping_province": "上海","shipping_city": "上海市","receiving_province": "陕西省","receiving_city": "西安市"},"waybill": {"waybill_number": 6501621931,"carrier_name": "上海大田运输服务有限公司","transport_way": "公路","shipping_time": "2023/09/17 13:00:00","request_time": "2023/09/18 16:00:00","receive_time": "","signer": "吴明明","transportion_time": "","is_ontime": "是","delay_type1": "","delay_type2": "","delay_reason": "","waybill_status": "已创建","transinfo": [{"op_time": "2023/09/17 14:13:38","op_place": "","op_way": "0001","cmemo": "货物已由 [上海站] 揽收 操作员:[]","op_man": ""}]}}'); res.setStatusCode(200); return res; } } }