@isTest private class NFM205RestTest { @isTest static void test_method_one() { ControllerUtil.EscapeNFM001Trigger = true; StaticParameter.EscapeNFM001AgencyContractTrigger = true; List rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店']; if (rectCo.size() == 0) { return; } List rectContract = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '契約']; if (rectCo.size() == 0) { return; } //经销商 Account myAccount1 = new Account(name='Testaccount001', Dealer_discount__c =20, RecordTypeId = rectCo[0].Id); insert myAccount1; Date dtafs = Date.today()-1; Date dtaadc = Date.today()-1; Date dtbdc = Date.today()+1; Date dtlast = Date.today()+10; Opportunity opp = new Opportunity(Authorized_Finish_Sales__c='11', Authorized_DB_No__c='1008', Autholization_Activated_Date__c = dtaadc ,Bidding_Content__c='qwer', Bid_Date__c = dtbdc, Bidding_No__c='4035',Agency1__c = myAccount1.Id, Agency2__c = myAccount1.Id, Bidding_Project_Name__c='efg',StageName='目標', Name='xunjia',CloseDate=dtlast ); insert opp; List opplist = [select Id,Name,Opportunity_No__c from Opportunity where Opportunity_No__c != '' ]; NFM205Rest.GeDatas GeDatas = new NFM205Rest.GeDatas(); NFM205Rest.GeData GeData = new NFM205Rest.GeData(); GeDatas.GeData = new NFM205Rest.GeData[]{GeData}; Datetime nowDT = Datetime.now(); String nowStr = nowDT.format('yyyyMMddHHmm'); GeDatas.Monitoring = new NFMUtil.Monitoring(); GeDatas.Monitoring.MessageGroupNumber = nowStr + '01'; GeData.Opportunity_Code = opplist.get(0).Opportunity_No__c; GeData.Authorized_DB_No = '123456'; GeData.Authorized_Finish_Sales = '8163584'; GeData.Authorized_Date = '2018-12-01'; GeData.Autholization_Activated_Date = '2018-12-03'; GeData.Bid_Project_Name = 'abcd11111abcd1111111111111111111111111111111abcd111111' + '111111111111111111111111111111111111111111111111111111' + '111111111111111111111111111111111111111111111111111111' + '111111111111111111111111111111111111111111111111111111' + '111111111111111111111111111111111111111111111111111111' + '111111111111111111111111111111111111111111111111111111' + '111111111111111111111111111111111111111111111111111111' + '111111111111111111111111111111111111111111111111111111' + '111111111111111111111111111111111111111111111111111111' + '111111111111111111111111111111111111111111111111111111' + '111111111111111111111111111111111111111111111111111111' + '111111111111111111111111111111111111111111111111111111' + '111111111111111111111111111111111111111111111111111111' + '111111111111111111111111111111111111111111111111111111'; GeData.Bidding_Content = 'qwer'; GeData.Bid_Date = '2018-12-01'; GeData.Bidding_No = '151410'; GeData.Authorized_Status = '1'; System.Test.startTest(); NFMUtil.Monitoring Monitoring = GeDatas.Monitoring; BatchIF_Log__c rowData = NFMUtil.saveRowData(Monitoring, 'NFM205', GeDatas.GeData); NFM205Rest.executefuture(rowData.Id); GeData.Opportunity_Code = 'opp1111'; rowData = NFMUtil.saveRowData(Monitoring, 'NFM205', GeDatas.GeData); NFM205Rest.executefuture(rowData.Id); GeData.Opportunity_Code = ''; rowData = NFMUtil.saveRowData(Monitoring, 'NFM205', GeDatas.GeData); NFM205Rest.executefuture(rowData.Id); System.Test.stopTest(); } @isTest static void test_method_two() { Test.startTest(); RestRequest req = new RestRequest(); RestResponse res = new RestResponse(); String JsonMsg = '{"Monitoring":{"TransmissionDateTime":"201812201320","Text":"","Tag":"MSGH","Sender":"SFDC","Receiver":"SPO","NumberOfRecord":"1","MessageType":"NFM205","MessageGroupNumber":"20180001722190"},"GeData":[{"Opportunity_Code":"HKBJ-GI-BJ0588881","Bidding_No":"as123121","Bidding_Content":"招标内容","Bid_Project_Name":"招标项目名","Bid_Date":"20181203","Authorized_Status":"1","Authorized_Finish_Sales":"30033","Authorized_DB_No":"MGZWESQHN201812001","Authorized_Date":"20190316","Autholization_Activated_Date":"20190415"}]}'; req.requestURI = 'services/apexrest/NFM205/execute'; req.httpMethod = 'POST'; req.requestBody = Blob.valueof(JsonMsg); RestContext.request = req; RestContext.response= res; NFM205Rest.execute(); Test.stopTest(); } }