@IsTest public with sharing class NFM502ControllerTest { public NFM502ControllerTest() { } @testSetup static void makeTestQLM502() { TestDataUtility.CreatePIPolicyConfiguration('NFM502'); BatchIF_Transfer__c transfer1 = new BatchIF_Transfer__c(); transfer1.Table__c = 'QLMoldMark'; transfer1.Internal_Value__c = '*'; insert transfer1; List NFM501GainEndTimeTransfers = new List(); BatchIF_Transfer__c transfer2 = new BatchIF_Transfer__c(); transfer2.Table__c = 'NFM501GainEndTime'; transfer2.NFM501_Gain_End_Time__c = Datetime.now(); NFM501GainEndTimeTransfers.add(transfer2); insert NFM501GainEndTimeTransfers; List NFM501TokenTransfers = new List(); BatchIF_Transfer__c transfer3 = new BatchIF_Transfer__c(); transfer3.Table__c = 'NFM501Token'; transfer3.NFM501_Token__c = null;//'eyJhbGciOiJIUzUxMiJ9.eyJhcHBLZXkiOiIwNzBmMDBiZi02NGYxLTQ3MjAtYThkOC1iYmUxYWE5NzZkMjIiLCJhcHBTZWNyZXQiOiI2N0JCMkJBRkM4QUEwQkEwQ0FCQjM3Q0JGNTBFQzI5MiIsImV4cCI6MTYyNDI2MTc1OX0.s55zh9SSpwqRdp1wXH43_wEGpwlZtMfRgl1x8t69A-N0H7QrzRNmK5MNqNGGLhQ2LL_AbMSJmDfwO5chgwndoA'; NFM501TokenTransfers.add(transfer3); insert NFM501TokenTransfers; Tender_information__c Ten = new Tender_information__c(); Ten.Name = '123456'; Ten.InfoTitle__c = '123456'; Ten.ProjectId__c = '38_99df2844cf784982acdc61d00d7a7dbb'; insert Ten; BatchIF_Log__c rowData = new BatchIF_Log__c(); rowData.Type__c = 'NFM501'; rowData.RowDataFlg__c = true; // rowData.Log__c = '{"code":"0","data":{"cursorMark":"60d01dde42ec7ed48d3730d6","list1":[{"agentRelationName":[],"agentRelationWay":[],"agentUnit":[],"areaCity":"惠州市","areaCountry":"","areaProvince":"广东省","biddingType":"0","bidingAcquireTime":"","bidingEndTime":"","budget":[{"amount":"250000.00","unit":"元"}],"infoFile":["http://cusdata.qianlima.com/vip/info/download/V2/eyJhbGciOiJIUzI1NiJ9.eyJpbmZvSWQiOiIyMjczMjgxOTAiLCJhcHBLZXkiOiIwNzBmMDBiZi02NGYxLTQ3MjAtYThkOC1iYmUxYWE5NzZkMjIiLCJhcHBTZWNyZXQiOiI2N0JCMkJBRkM4QUEwQkEwQ0FCQjM3Q0JGNTBFQzI5MiIsImZpbGVVcmwiOiI0QjY2Mzg2MzY4MzI0MTQyNzY2MjU5NEI0QTc0NEM1NzcxNkI2RjcyNkI1MTNEM0QifQ.3UTAGOde4plSKFKf_DV1sBWXJbdsz7zN8a1KZZys6bo"],"infoId":"227328190","infoPublishTime":"2021-06-21 09:41:26","infoQianlimaUrl":"http://www.qianlima.com/zb/detail/20210621_227328190.html","infoTitle":"皮肤镜图像处理工作站调研公告","infoType":"0","infoTypeSegment":"3","isElectronic":"0","keywords":"图像处理","openBidingTime":"","projectId":"38_99df2844cf784982acdc61d00d7a7dbb","target":null,"tenderBeginTime":"","tenderEndTime":"","winnerAmount":[],"xmNumber":"CD-1624266167710","zhaoBiaoUnit":["惠州市第一人民医院"],"zhaoRelationName":["范梅红"],"zhaoRelationWay":["0752-2883625"],"zhongBiaoUnit":[],"zhongRelationName":[],"zhongRelationWay":[]}]},"msg":"正确返回数据"}'; rowData.Log__c ='{"data":{"list1":[{"DataId":"958850380886708224","agentRelationWayEncrypted":["ca93b1d0d9e14d81119d429b03faa17c"],"agentRelationNameEncrypted":["9e8e6aa24a7bf37db834622fd302b7b4"],"zhongRelationWayEncrypted":[],"zhongRelationNameEncrypted":[],"zhaoRelationWayEncrypted":["9e4d791610abcc65d501f3d96f11bf50"],"zhaoRelationNameEncrypted":["c41f9f806b7de8fffae5cb668dbb09e4"],"allKeywords":"进口","moreZhongBiaoUnit":[],"zhongRelationWay":[],"zhongRelationName":[],"zhongBiaoUnit":[],"zhaoRelationWay":["***********"],"zhaoRelationName":["***"],"zhaoBiaoUnit":["无极县医院"],"xmNumber":"HBZJ-2022N0253","winnerAmount":[],"tenderEndTime":"2022-04-20 09:30:00","tenderBeginTime":"","target":null,"projectId":"14e9fe7920df42d697830ce12abf31f3","openBidingTime":"","keywords":"电切镜,硬性镜,超声刀,内窥镜,窥镜,内镜,输尿管软镜,支气管镜,气管镜","isElectronic":"0","infoTypeSegment":"3","infoType":"0","infoTitle":"无极县医院迁建项目部分医疗设备购置(三)公开招标公告","infoQianlimaUrl":"http://www.qianlima.com/zb/detail/20220330_265423120.html","infoPublishTime":"2022-03-30 17:07:25","infoId":"265423120","infoFile":["http://cusdata.qianlima.com/vip/info/download/V2/eyJhbGciOiJIUzI1NiJ9.eyJpbmZvSWQiOiIyNjU0MjMxMjAiLCJhcHBLZXkiOiIwNzBmMDBiZi02NGYxLTQ3MjAtYThkOC1iYmUxYWE5NzZkMjIiLCJhcHBTZWNyZXQiOiI2N0JCMkJBRkM4QUEwQkEwQ0FCQjM3Q0JGNTBFQzI5MiIsImZpbGVVcmwiOiI1NTcyNTk3NTU1NTQ2QzY5NEY1OTZCNTE0MzUzNjc3MDVBNzUzNDU3NzQ0MTNEM0QifQ.9ZMaqZVUxWgc9xAlHvfNEjUnPKztSokDqqZU-tGqpLw"],"budget":[{"unit":"元","amount":"38706500.00"}],"bidingEndTime":"2022-04-20 09:30:00","bidingAcquireTime":"2022-03-31 09:00:00","biddingType":"0","areaProvince":"河北省","areaCountry":"无极县","areaCity":"石家庄市","agentUnit":["河北中机咨询有限公司"],"agentRelationWay":["***********"],"agentRelationName":["***"]}],"cursorMark":"62444cc820386292a07cf3a1"},"code":"0","msg":"正确返回数据"}'; rowData.MessageGroupNumber__c = transfer1.Internal_Value__c; insert rowData; BatchIF_Log__c iflog = new BatchIF_Log__c(); iflog.Type__c = 'NFM501'; iflog.RowDataFlg__c = false; iflog.Log__c = ' '; iflog.ErrorLog__c = ' '; iflog.MessageGroupNumber__c = rowData.MessageGroupNumber__c; insert iflog; List WebAttList = new List(); Attachment WebAtt = new Attachment(); WebAtt.ParentId = Ten.Id; WebAtt.Body = Blob.valueOf('123456789'); WebAtt.Name = '1234567.html'; WebAttList.add(WebAtt); insert WebAttList; } @IsTest static void Test502() { BatchIF_Log__c rowData = [Select Id, Name, Log__c, ErrorLog__c, Log2__c, Log3__c, Log4__c, Log5__c, Log6__c, Log7__c, Log8__c, Log9__c, Log10__c, Log11__c, Log12__c, MessageGroupNumber__c, retry_cnt__c, NFM501Future_Count__c, NFM501_Web_Annex_Count__c from BatchIF_Log__c where RowDataFlg__c = true]; BatchIF_Log__c iflog = [Select Id, Name, Log__c, ErrorLog__c, Log2__c, Log3__c, Log4__c, Log5__c, Log6__c, Log7__c, Log8__c, Log9__c, Log10__c, Log11__c, Log12__c, MessageGroupNumber__c, retry_cnt__c, NFM501Future_Count__c, NFM501_Web_Annex_Count__c from BatchIF_Log__c Limit 1]; Test.startTest(); Test.setMock(HttpCalloutMock.class, new NFM501HttpCallMock()); NFM502Controller.WebAnnexGain(rowData.Id, iflog.Id, false); Test.stopTest(); } // 报错 @IsTest static void myTest1() { BatchIF_Log__c rowData = [Select Id, Name, Log__c, ErrorLog__c, Log2__c, Log3__c, Log4__c, Log5__c, Log6__c, Log7__c, Log8__c, Log9__c, Log10__c, Log11__c, Log12__c, MessageGroupNumber__c, retry_cnt__c, NFM501Future_Count__c, NFM501_Web_Annex_Count__c from BatchIF_Log__c where RowDataFlg__c = true]; BatchIF_Log__c iflog = [Select Id, Name, Log__c, ErrorLog__c, Log2__c, Log3__c, Log4__c, Log5__c, Log6__c, Log7__c, Log8__c, Log9__c, Log10__c, Log11__c, Log12__c, MessageGroupNumber__c, retry_cnt__c, NFM501Future_Count__c, NFM501_Web_Annex_Count__c from BatchIF_Log__c Limit 1]; // List TIList = // [Select Id, ProjectId__c, InfoType__c // FROM Tender_information__c]; Test.startTest(); try{ Test.setMock(HttpCalloutMock.class, new NFM501HttpCallMockEx()); NFM502Controller.WebAnnexGain(rowData.Id, iflog.Id, false); NFM502Controller.test(); }catch(Exception e){ system.debug('Exception from insert NFM502'); } Test.stopTest(); } }