@isTest private class NFM106ControllerTest { // HWAG-BE88UG 【委托】SFDC-SAP搭现有接口添加合同“付款计划”信息 by vivek start private static User getUser() { String timenow = Datetime.now().format('yyyyMMddHHmmss'); User user1 = new User(Test_staff__c = true, LastName = 'TestMao', FirstName = 'TestMaoF', Alias = 'hp', CommunityNickname = 'TestMao', Email = 'Test@sunbridge.com', Username = 'Test' + timenow + '@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = System.Label.ProfileId_SystemAdmin, Dept__c = '医疗华北营业本部', Job_Category__c = '销售服务', Province__c = '北京'); List p = [Select Id From Profile Where Name = '2S1_销售医院担当']; // System.assertEquals(p.size(), 1); // User user2 = new User(Test_staff__c = true, LastName = 'TestMao1', FirstName = 'TestMaoF1', // Alias = 'hp', CommunityNickname = 'TestMao1', Email = 'Test1@sunbridge.com', // Username = 'Test1' + timenow + '@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', // TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', // ProfileId = p[0].Id, // Dept__c = '医疗华北营业本部', Province__c = '北京'); // List us = new List(); // us.add(user1); // us.add(user2); System.runAs(new User(Id = Userinfo.getUserId())) { insert user1; } return user1; } // HWAG-BE88UG 【委托】SFDC-SAP搭现有接口添加合同“付款计划”信息 by vivek end @isTest static void testInsert() { 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 from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科']; if (rectDpt.size() == 0) { return; } RecordType recordtype = [Select Id,DeveloperName FROM RecordType WHERE IsActive = true and SobjectType = 'Maintenance_Contract__c' and DeveloperName = 'Maintenance_Contract'][0]; // テストデータ Account company = new Account(); company.RecordTypeId = rectCo[0].Id; company.Name = 'NFM106TestCompany'; upsert company; Account section = new Account(); section.RecordTypeId = rectSct[0].Id; section.Name = '*'; section.Department_Class_Label__c = '消化科'; section.ParentId = company.Id; section.Hospital_Department_Class__c = company.Id; upsert section; Account depart = new Account(); depart.RecordTypeId = rectDpt[0].Id; depart.Name = '*'; depart.Department_Name__c = 'NFM106TestDepart'; depart.ParentId = section.Id; depart.Department_Class__c = section.Id; depart.Hospital__c = company.Id; upsert depart; // 再取得 List accList = new List(); // company = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :company.Id]; // accList.add(company); // section = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :section.Id]; // accList.add(section); // depart = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :depart.Id]; // accList.add(depart); company = [select Management_Code__c, Name, Id from Account where Id = :company.Id]; accList.add(company); section = [select Management_Code__c, Name, Id from Account where Id = :section.Id]; accList.add(section); depart = [select Management_Code__c, Name, Id from Account where Id = :depart.Id]; accList.add(depart); // RecordType recordtype = new RecordType(); // recordtype.DeveloperName = 'Maintenance_Contract'; // recordtype.SobjectType = 'Maintenance_Contract__c'; // insert recordtype; // 维修合同を作成する Maintenance_Contract__c contract = new Maintenance_Contract__c(); contract.Name = 'tect contract'; contract.Hospital__c = company.Id; contract.Department_Class__c = section.Id; contract.Department__c = depart.Id; contract.Contract_Start_Date__c = Date.today() - 10; contract.Contract_End_Date__c = Date.today() + 10; contract.Status__c = '契約'; contract.Maintenance_Contract_No__c = '10001'; contract.SalesOfficeCode_selection__c = '北京RC'; contract.Contract_Conclusion_Date__c = Date.today(); // HWAG-BE88UG 【委托】SFDC-SAP搭现有接口添加合同“付款计划”信息 by vivek start contract.recordtypeId = recordtype.id; // contract.recordtype.DeveloperName = recordtype.DeveloperName; // contract.agree_Upper_limit__c = true; contract.Service_Contract_Staff__c = getUser().Id; contract.Payment_Plan_Date_First__c = Date.today(); contract.Payment_Plan_Sum_First__c = 1; contract.Payment_Plan_Date_Second__c = Date.today(); contract.Payment_Plan_Sum_Second__c = 2; contract.Payment_Plan_Date_Third__c = Date.today(); contract.Payment_Plan_Sum_Third__c = 3; contract.Payment_Plan_Date_Forth__c = Date.today(); contract.Payment_Plan_Sum_Forth__c = 4; contract.Payment_Plan_Date_Fifth__c = Date.today(); contract.Payment_Plan_Sum_Fifth__c = 5; contract.Payment_Plan_Date_Sixth__c = Date.today(); contract.Payment_Plan_Sum_Sixth__c = 6; // HWAG-BE88UG 【委托】SFDC-SAP搭现有接口添加合同“付款计划”信息 by vivek end // System.Test.startTest(); insert contract; List contractlist = new List(); contractlist.add(contract); // NFM106Controller.NFM106Trigger(contractlist, null, null, null); contract = [Select Id, Name,RecordType.DeveloperName, Maintenance_Contract_No__c from Maintenance_Contract__c where Id = :contract.Id]; // System.Test.stopTest(); // System.assertEquals(contract.RecordType.DeveloperName,NFM106Controller.debug_msg); // System.assertEquals('NFM106_callout_insert_' + contract.Name, NFM106Controller.debug_msg); // System.assertEquals('NFM106_callout_insert_tect contract', NFM106Controller.debug_msg); List bl = [Select Id, Is_Error__c, Type__c, Log__c, ErrorLog__c, retry_cnt__c from BatchIF_Log__c where Type__c = 'NFM106' order by CreatedDate desc]; // System.assertEquals(1, bl.size()); // HWAG-BE88UG 【委托】SFDC-SAP搭现有接口添加合同“付款计划”信息 by vivek start // System.assertEquals(2, bl.size()); // System.assertEquals(true, bl[0].Log__c.indexOf(contract.Maintenance_Contract_No__c) >= 0); // System.assertEquals(true, bl[0].Log__c.indexOf(company.Management_Code__c) >= 0); // HWAG-BE88UG 【委托】SFDC-SAP搭现有接口添加合同“付款计划”信息 by vivek start //URF限次合同2期 LY 20220930 start //产品2 User u1 = [select Id from User where Id = :UserInfo.getUserId() ]; System.runAs ( u1 ){ ProductURF__c poductURFV = new ProductURF__c(Name='V系列',URFLimitSerial__c='URF-V', Maintenance_Price_Year_URF__c =100,Maintenance_Price_Year_URF_Max__c=120 ,Maintenance_Price_Year_URF_3__c=200 ,Maintenance_Price_Year_URF_Max_3__c=240 ); ProductURF__c poductURFP = new ProductURF__c(Name='P系列',URFLimitSerial__c='URF-P', Maintenance_Price_Year_URF__c =200,Maintenance_Price_Year_URF_Max__c=220 ,Maintenance_Price_Year_URF_3__c=300 ,Maintenance_Price_Year_URF_Max_3__c=340 ); insert new ProductURF__c[] {poductURFV,poductURFP}; // 产品 Product2 proV = new Product2(Name='name01',IsActive=true,Family='SP', Fixture_Model_No__c='n01',Serial_Lot_No__c='S/N tracing', Fixture_Model_No_T__c = 'n01', ProductCode_Ext__c='pc01',Manual_Entry__c=false ,ProductURF__c=poductURFV.Id); Product2 proP = new Product2(Name='name02',IsActive=true,Family='SP', Fixture_Model_No__c='n02',Serial_Lot_No__c='S/N tracing', Fixture_Model_No_T__c = 'n02', ProductCode_Ext__c='pc02',Manual_Entry__c=false ,ProductURF__c=poductURFP.Id); insert new Product2[] {proV,proP}; //保有设备 Asset assetV = new Asset(); assetV.Name = 'テスト機器1'; assetV.AccountId = depart.Id; assetV.Department_Class__c = section.Id; assetV.Hospital__c = company.Id; assetV.SerialNumber = 'testserial1'; assetV.Product2Id = proV.Id; Asset assetP = new Asset(); assetP.Name = 'テスト機器2'; assetP.AccountId = depart.Id; assetP.Department_Class__c = section.Id; assetP.Hospital__c = company.Id; assetP.SerialNumber = 'testserial2'; assetP.Product2Id = proP.Id; insert new Asset[] {assetV,assetP}; //维修合同报价 Maintenance_Contract_Estimate__c mcEstimate = new Maintenance_Contract_Estimate__c(); mcEstimate.Name = 'BJ-RS-SD0067154XC-01'; mcEstimate.Process_Status__c ='批准'; mcEstimate.URF_P_MaxRepairCount__c = '3'; mcEstimate.URF_V_MaxRepairCount__c = '2'; mcEstimate.Contract_Range__c = 12; mcEstimate.Maintenance_Contract__c = contract.Id; insert mcEstimate; Maintenance_Contract__c contractNew = new Maintenance_Contract__c(); contractNew.Id =contract.Id; contractNew.Estimation_Id__c = mcEstimate.Id; update contractNew; //创建维修合同报价/保有设备 Maintenance_Contract_Asset_Estimate__c asset_EstimateV = new Maintenance_Contract_Asset_Estimate__c(); asset_EstimateV.Maintenance_Contract_Estimate__c = mcEstimate.Id; asset_EstimateV.Asset__c = assetV.Id; asset_EstimateV.CurrencyIsoCode = 'CNY'; asset_EstimateV.Series_MaxRepairCount__c = 3; asset_EstimateV.Series_RepairCount__c = 0; asset_EstimateV.URF_Series__c = 'URF-V'; Maintenance_Contract_Asset_Estimate__c asset_EstimateP = new Maintenance_Contract_Asset_Estimate__c(); asset_EstimateP.Maintenance_Contract_Estimate__c = mcEstimate.Id; asset_EstimateP.Asset__c = assetP.Id; asset_EstimateP.CurrencyIsoCode = 'CNY'; asset_EstimateP.Series_MaxRepairCount__c = 10; asset_EstimateP.Series_RepairCount__c = 5; asset_EstimateP.URF_Series__c = 'URF-P'; insert new Maintenance_Contract_Asset_Estimate__c[] {asset_EstimateV,asset_EstimateP}; } //URF限次合同2期 LY 20220930 end } @isTest static void testUpdate() { 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 from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科']; if (rectDpt.size() == 0) { return; } // テストデータ Account company = new Account(); company.RecordTypeId = rectCo[0].Id; company.Name = 'NFM106TestCompany'; upsert company; Account section = new Account(); section.RecordTypeId = rectSct[0].Id; section.Name = '*'; section.Department_Class_Label__c = '消化科'; section.ParentId = company.Id; section.Hospital_Department_Class__c = company.Id; upsert section; Account depart = new Account(); depart.RecordTypeId = rectDpt[0].Id; depart.Name = '*'; depart.Department_Name__c = 'NFM106TestDepart'; depart.ParentId = section.Id; depart.Department_Class__c = section.Id; depart.Hospital__c = company.Id; upsert depart; // 再取得 List accList = new List(); // company = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :company.Id]; // accList.add(company); // section = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :section.Id]; // accList.add(section); // depart = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :depart.Id]; // accList.add(depart); company = [select Management_Code__c, Name, Id from Account where Id = :company.Id]; accList.add(company); section = [select Management_Code__c, Name, Id from Account where Id = :section.Id]; accList.add(section); depart = [select Management_Code__c, Name, Id from Account where Id = :depart.Id]; accList.add(depart); // 维修合同を作成する Maintenance_Contract__c contract = new Maintenance_Contract__c(); contract.Name = 'tect contract'; contract.Hospital__c = company.Id; contract.Department_Class__c = section.Id; contract.Department__c = depart.Id; contract.Contract_Start_Date__c = Date.today() - 10; contract.Contract_End_Date__c = Date.today() + 10; // contract.Status__c = '草案中'; contract.Status__c = '契約'; contract.Maintenance_Contract_No__c = '10001'; contract.SalesOfficeCode_selection__c = '北京RC'; contract.Contract_Conclusion_Date__c = Date.today(); // HWAG-BE88UG 【委托】SFDC-SAP搭现有接口添加合同“付款计划”信息 by vivek start contract.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Maintenance_Contract__c' and DeveloperName = 'Maintenance_Contract'].id; // contract.agree_Upper_limit__c = true; contract.Service_Contract_Staff__c = getUser().Id; contract.Payment_Plan_Date_First__c = Date.today(); contract.Payment_Plan_Sum_First__c = 1; contract.Payment_Plan_Date_Second__c = Date.today(); contract.Payment_Plan_Sum_Second__c = 2; contract.Payment_Plan_Date_Third__c = Date.today(); contract.Payment_Plan_Sum_Third__c = 3; contract.Payment_Plan_Date_Forth__c = Date.today(); contract.Payment_Plan_Sum_Forth__c = 4; contract.Payment_Plan_Date_Fifth__c = Date.today(); contract.Payment_Plan_Sum_Fifth__c = 5; contract.Payment_Plan_Date_Sixth__c = Date.today(); contract.Payment_Plan_Sum_Sixth__c = 6; // HWAG-BE88UG 【委托】SFDC-SAP搭现有接口添加合同“付款计划”信息 by vivek end insert contract; //System.assertEquals('', NFM106Controller.debug_msg); contract.Status__c = '契約'; // System.Test.startTest(); update contract; contract = [Select Id, Name, Maintenance_Contract_No__c from Maintenance_Contract__c where Id = :contract.Id]; // System.Test.stopTest(); // System.assertEquals('NFM106_callout_update_' + contract.Name, NFM106Controller.debug_msg); // System.assertEquals('NFM106_callout_update_::tect contract, execute()', NFM106Controller.debug_msg); List bl = [Select Id, Is_Error__c, Type__c, Log__c, ErrorLog__c,retry_cnt__c from BatchIF_Log__c where Type__c = 'NFM106' order by CreatedDate desc]; // System.assertEquals(1, bl.size()); // System.assertEquals(2, bl.size()); // System.assertEquals(true, bl[0].Log__c.indexOf(contract.Maintenance_Contract_No__c) >= 0); // System.assertEquals(true, bl[0].Log__c.indexOf(company.Management_Code__c) >= 0); } @isTest static void resend_test() { 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 from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科']; if (rectDpt.size() == 0) { return; } // テストデータ Account company = new Account(); company.RecordTypeId = rectCo[0].Id; company.Name = 'NFM106TestCompany'; upsert company; Account section = new Account(); section.RecordTypeId = rectSct[0].Id; section.Name = '*'; section.Department_Class_Label__c = '消化科'; section.ParentId = company.Id; section.Hospital_Department_Class__c = company.Id; upsert section; Account depart = new Account(); depart.RecordTypeId = rectDpt[0].Id; depart.Name = '*'; depart.Department_Name__c = 'NFM106TestDepart'; depart.ParentId = section.Id; depart.Department_Class__c = section.Id; depart.Hospital__c = company.Id; upsert depart; // 再取得 List accList = new List(); // company = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :company.Id]; // accList.add(company); // section = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :section.Id]; // accList.add(section); // depart = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :depart.Id]; // accList.add(depart); company = [select Management_Code__c, Name, Id from Account where Id = :company.Id]; accList.add(company); section = [select Management_Code__c, Name, Id from Account where Id = :section.Id]; accList.add(section); depart = [select Management_Code__c, Name, Id from Account where Id = :depart.Id]; accList.add(depart); // 维修合同を作成する Maintenance_Contract__c contract = new Maintenance_Contract__c(); contract.Name = 'tect contract'; contract.Hospital__c = company.Id; contract.Department_Class__c = section.Id; contract.Department__c = depart.Id; contract.Contract_Start_Date__c = Date.today() - 10; contract.Contract_End_Date__c = Date.today() + 10; // contract.Status__c = '草案中'; contract.Status__c = '契約'; contract.Maintenance_Contract_No__c = '10001'; contract.SalesOfficeCode_selection__c = '北京RC'; contract.Contract_Conclusion_Date__c = Date.today(); // HWAG-BE88UG 【委托】SFDC-SAP搭现有接口添加合同“付款计划”信息 by vivek start contract.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Maintenance_Contract__c' and DeveloperName = 'Maintenance_Contract'].id; // contract.agree_Upper_limit__c = true; contract.Service_Contract_Staff__c = getUser().Id; contract.Payment_Plan_Date_First__c = Date.today(); contract.Payment_Plan_Sum_First__c = 1; contract.Payment_Plan_Date_Second__c = Date.today(); contract.Payment_Plan_Sum_Second__c = 2; contract.Payment_Plan_Date_Third__c = Date.today(); contract.Payment_Plan_Sum_Third__c = 3; contract.Payment_Plan_Date_Forth__c = Date.today(); contract.Payment_Plan_Sum_Forth__c = 4; contract.Payment_Plan_Date_Fifth__c = Date.today(); contract.Payment_Plan_Sum_Fifth__c = 5; contract.Payment_Plan_Date_Sixth__c = Date.today(); contract.Payment_Plan_Sum_Sixth__c = 6; // HWAG-BE88UG 【委托】SFDC-SAP搭现有接口添加合同“付款计划”信息 by vivek end insert contract; //System.assertEquals('', NFM106Controller.debug_msg); // contract.Status__c = '契約'; // System.Test.startTest(); // update contract; // contract = [Select Id, Name, Maintenance_Contract_No__c from Maintenance_Contract__c where Id = :contract.Id]; // System.Test.stopTest(); // System.assertEquals('NFM106_callout_update_' + contract.Name, NFM106Controller.debug_msg); // System.assertEquals('NFM106_callout_update_::tect contract, execute()', NFM106Controller.debug_msg); // BatchIF_Log__c bif = new BatchIF_Log__c(); // bif.Log__c = '{"RepairContractLogin":{"Monitoring":{"TransmissionDateTime":"201908011404","Text":"","Tag":"MSGH","Sender":"8402","Receiver":"1330","NumberOfRecord":"1","MessageType":"NFM106","MessageGroupNumber":"20190002043482"},"GeneralData":[{"StartDate":"20190716","SalesOfficeCode":"OCM-GZRC","QuotationAmount":"","PaymentInformation":[{"PaymentTime":"1","PaymentDate":"20190702","PaymentAmount":"10000.00"},{"PaymentTime":"2","PaymentDate":"20190709","PaymentAmount":"20000.00"},{"PaymentTime":"3","PaymentDate":"20190717","PaymentAmount":"30000.00"},{"PaymentTime":"4","PaymentDate":"20190718","PaymentAmount":"40000.00"}],"HospitalName":"364427","FSERemark":"","EndUserNoorAgentNo":"0000023817","EndDate":"20190808","ContractPeriod":"1","ContractNo":"SH-RS-TEST1115","ContractDate":"20190701","Amount":""}]}}'; // bif.retry_cnt__c = 0; // insert bif; // List rowbl = [Select Id, // Log__c, // Log2__c, // ErrorLog__c, // retry_cnt__c // from BatchIF_Log__c // where Type__c = 'NFM106' // and RowDataFlg__c = true // order by CreatedDate desc]; // System.assertEquals(1, rowbl.size()); // System.assertEquals(1,rowbl[0].retry_cnt__c); // NFM106Controller.execute(rowbl[0],null); // NFM106Controller.execute(bif,null); // List bl = [Select Id, Is_Error__c, // Type__c, Log__c, ErrorLog__c,retry_cnt__c // from BatchIF_Log__c // where Id = :bif.id]; // System.assertEquals(2, bl[0].retry_cnt__c); // NFM106Controller.execute(bif,null); // bl = [Select Id, Is_Error__c, // Type__c, Log__c, ErrorLog__c,retry_cnt__c // from BatchIF_Log__c // where Id = :bif.id]; // System.assertEquals(3, bl[0].retry_cnt__c); } }