@isTest private class NFM206RestTest { @isTest static void test_method_one() { // Implement test code 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 authorized_Date = Date.today()-1; Date autholization_Activated = Date.today()-1; Date bid_Date = Date.today()-1; Date dtlast = Date.today()+1; Opportunity opp = new Opportunity(Authorized_Finish_Sales__c='11', Authorized_DB_No__c='1008', Authorized_Date__c = authorized_Date, Autholization_Activated_Date__c = autholization_Activated ,Bidding_Content__c='qwer', Bid_Date__c = bid_Date, Bidding_No__c='4035',Agency1__c = myAccount1.Id, Agency2__c = myAccount1.Id, Bidding_Project_Name__c='efg',StageName='目標', Name='xunjia',CloseDate=dtlast, Contract_DB_complite_day__c = bid_Date, SAP_Send_OK__c = true ); insert opp; List opplist = [select Id,Name,Opportunity_No__c from Opportunity where Opportunity_No__c != '' ]; NFM206Rest.GeDatas GeDatas = new NFM206Rest.GeDatas(); NFM206Rest.GeData GeData = new NFM206Rest.GeData(); GeDatas.GeData = new NFM206Rest.GeData[]{GeData}; Datetime nowDT = Datetime.now(); String nowStr = nowDT.format('yyyyMMddHHmm'); GeDatas.Monitoring = new NFMUtil.Monitoring(); GeDatas.Monitoring.MessageGroupNumber = nowStr + '01'; GeData.Opportunity_No = opplist.get(0).Opportunity_No__c; GeData.OCM_Agent1_Price_DB = '1130000'; GeData.NotesApprovedNo = 'MSHHTSQHD201812057' + 'MSHHTSQHD201812057' + 'MSHHTSQHD201812057' + 'MSHHTSQHD201812057' + 'MSHHTSQHD201812057' + 'MSHHTSQHD201812057'; GeData.Contract_DB_SalesDept_complite_day = null; GeData.Contract_DB_request_reason = ''; GeData.Contract_DB_complite_day = String.valueOf(Date.today()-1); GeData.Closing_Bid_Date = String.valueOf(Date.today()-1); GeData.Assistant_Applied_Date = String.valueOf(Date.today()-1); GeData.ApprovedType = '1'; GeData.SPOApprovedQuote = 'test';//20200430 add System.Test.startTest(); NFMUtil.Monitoring Monitoring = GeDatas.Monitoring; BatchIF_Log__c rowData = NFMUtil.saveRowData(Monitoring, 'NFM206', GeDatas.GeData); NFM206Rest.executefuture(rowData.Id); GeData.ApprovedType = '3'; rowData = NFMUtil.saveRowData(Monitoring, 'NFM206', GeDatas.GeData); NFM206Rest.executefuture(rowData.Id); GeData.ApprovedType = ''; rowData = NFMUtil.saveRowData(Monitoring, 'NFM206', GeDatas.GeData); NFM206Rest.executefuture(rowData.Id); GeData.Opportunity_No = ''; rowData = NFMUtil.saveRowData(Monitoring, 'NFM206', GeDatas.GeData); NFM206Rest.executefuture(rowData.Id); GeData.ApprovedType = '1'; GeData.Opportunity_No = 'opp0522'; rowData = NFMUtil.saveRowData(Monitoring, 'NFM206', GeDatas.GeData); NFM206Rest.executefuture(rowData.Id); System.Test.stopTest(); } @isTest static void test_method_two() { // Implement test code 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; } StaticParameter.EscapeNFM007Trigger = true; StaticParameter.EscapeOpportunityBefUpdTrigger = true; StaticParameter.EscapeOpportunityHpDeptUpdTrigger = true; StaticParameter.EscapeSyncOpportunityTrigger = true; StaticParameter.EscapeAccountTrigger = true; //经销商 Account myAccount1 = new Account(name='Testaccount001', Dealer_discount__c =20, RecordTypeId = rectCo[0].Id); insert myAccount1; Date authorized_Date = Date.today()-1; Date autholization_Activated = Date.today()-1; Date bid_Date = Date.today()-1; Date dtlast = Date.today()+1; Opportunity opp = new Opportunity(Authorized_Finish_Sales__c='11', Authorized_DB_No__c='1008', Authorized_Date__c = authorized_Date, Autholization_Activated_Date__c = autholization_Activated ,Bidding_Content__c='qwer', Bid_Date__c = bid_Date, Bidding_No__c='4035',Agency1__c = myAccount1.Id, Agency2__c = myAccount1.Id, Bidding_Project_Name__c='efg',StageName='目標', Name='xunjia',CloseDate=dtlast, Contract_DB_complite_day__c = bid_Date //SAP_Send_OK__c = true ); insert opp; List opplist = [select Id,Name,Opportunity_No__c from Opportunity where Opportunity_No__c != '' ]; NFM206Rest.GeDatas GeDatas = new NFM206Rest.GeDatas(); NFM206Rest.GeData GeData = new NFM206Rest.GeData(); GeDatas.GeData = new NFM206Rest.GeData[]{GeData}; Datetime nowDT = Datetime.now(); String nowStr = nowDT.format('yyyyMMddHHmm'); GeDatas.Monitoring = new NFMUtil.Monitoring(); GeDatas.Monitoring.MessageGroupNumber = nowStr + '01'; GeData.Opportunity_No = opplist.get(0).Opportunity_No__c; GeData.OCM_Agent1_Price_DB = '1130000'; GeData.NotesApprovedNo = ''; GeData.SPOApprovedQuote = 'test';//20200430 add GeData.Contract_DB_SalesDept_complite_day = null; GeData.Contract_DB_request_reason = ''; GeData.Contract_DB_complite_day = null; GeData.Closing_Bid_Date = null; GeData.Assistant_Applied_Date = null; GeData.ContractType = '1'; GeData.ApprovedType = '1'; System.Test.startTest(); NFMUtil.Monitoring Monitoring = GeDatas.Monitoring; BatchIF_Log__c rowData = NFMUtil.saveRowData(Monitoring, 'NFM206', GeDatas.GeData); NFM206Rest.main(rowData.Id); System.Test.stopTest(); } @isTest static void test_method_three() { // Implement test code 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; } StaticParameter.EscapeNFM007Trigger = true; StaticParameter.EscapeOpportunityBefUpdTrigger = true; StaticParameter.EscapeOpportunityHpDeptUpdTrigger = true; StaticParameter.EscapeSyncOpportunityTrigger = true; StaticParameter.EscapeAccountTrigger = true; //经销商 Account myAccount1 = new Account(name='Testaccount001', Dealer_discount__c =20, RecordTypeId = rectCo[0].Id); insert myAccount1; Date authorized_Date = Date.today()-1; Date autholization_Activated = Date.today()-1; Date bid_Date = Date.today()-1; Date dtlast = Date.today()+1; Opportunity opp = new Opportunity(Authorized_Finish_Sales__c='11', Authorized_DB_No__c='1008', Authorized_Date__c = authorized_Date, Autholization_Activated_Date__c = autholization_Activated ,Bidding_Content__c='qwer', Bid_Date__c = bid_Date, Bidding_No__c='4035',Agency1__c = myAccount1.Id, Agency2__c = myAccount1.Id, Bidding_Project_Name__c='efg',StageName='目標', Name='xunjia',CloseDate=dtlast, Contract_DB_complite_day__c = bid_Date, //songxiaoqi-------start Estimation_Decision__c = true, Estimation_No__c = 'test', Estimation_Id__c='002' //StageName='引合' //songxiaoqi--------end //SAP_Send_OK__c = true ); insert opp; //2020/11/4 songxiaoqi update opp.Estimation_Decision__c=true; opp.StageName= '引合'; //2020/11/4 songxiaoqi end update opp; Opportunity opplist = [select Id,Name,Opportunity_No__c ,Estimation_Decision__c from Opportunity where Id = :opp.Id ]; System.assertEquals(true, opplist.Estimation_Decision__c); NFM206Rest.GeDatas GeDatas = new NFM206Rest.GeDatas(); NFM206Rest.GeData GeData = new NFM206Rest.GeData(); GeDatas.GeData = new NFM206Rest.GeData[]{GeData}; Datetime nowDT = Datetime.now(); String nowStr = nowDT.format('yyyyMMddHHmm'); GeDatas.Monitoring = new NFMUtil.Monitoring(); GeDatas.Monitoring.MessageGroupNumber = nowStr + '01'; // GeData.Opportunity_No = opplist.get(0).Opportunity_No__c; GeData.Opportunity_No = opplist.Opportunity_No__c; GeData.OCM_Agent1_Price_DB = '1130000'; GeData.NotesApprovedNo = ''; GeData.SPOApprovedQuote = 'test';//20200430 add GeData.Contract_DB_SalesDept_complite_day = null; GeData.Contract_DB_request_reason = ''; GeData.Contract_DB_complite_day = null; GeData.Closing_Bid_Date = null; GeData.Assistant_Applied_Date = null; GeData.ContractType = '2'; GeData.ApprovedType = '1'; //songxiaoqi--------start //测试合同终止 GeData.IsTermination ='true'; //songxiaoqi--------结束 System.Test.startTest(); NFMUtil.Monitoring Monitoring = GeDatas.Monitoring; BatchIF_Log__c rowData = NFMUtil.saveRowData(Monitoring, 'NFM206', GeDatas.GeData); NFM206Rest.main(rowData.Id); System.Test.stopTest(); } @isTest static void test_method_four() { 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":"NFM206","MessageGroupNumber":"20180001722190"},"GeData":[{"Opportunity_No":"BJ-SP-BJ0577783","OCM_Agent1_Price_DB":"950000","NotesApprovedNo":"MGZHTSQHN201812009","Contract_DB_SalesDept_complite_day":null,"Contract_DB_request_reason":"","Contract_DB_complite_day":"20181218","Closing_Bid_Date":"20181206","Assistant_Applied_Date":"20181218","ApprovedType":"3","SPOApprovedQuote":"test"}]}'; req.requestURI = 'services/apexrest/NFM206/execute'; req.httpMethod = 'POST'; req.requestBody = Blob.valueof(JsonMsg); RestContext.request = req; RestContext.response= res; NFM206Rest.execute(); Test.stopTest(); //Test.setMock(HttpCalloutMock.class, new NFM205RestCalloutMock()); //NFM205Rest.execute1('{"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"}]}'); } }