@isTest private class UpdateInspectionReportAssetBatchTest { static testMethod void testMethod1() { ControllerUtil.EscapeNFM001Trigger = true; StaticParameter.EscapeNFM001Trigger = true; StaticParameter.EscapeNFM001AgencyContractTrigger = true; StaticParameter.EscapeNFM001AgencyContractTrigger2 = true; Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin]; // ユーザー作成 User hpOwner = new User(Test_staff__c = true, Job_Category__c='销售服务' ,LastName = 'hp', FirstName = 'owner', Alias = 'hp', CommunityNickname = 'hpOwner', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id); insert hpOwner; // 取引先作成 RecordType rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院']; RecordType rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科']; Account hp = new Account(RecordTypeId = rectHp.Id, Name = 'InsReportPDFControllerTestHp1', OwnerId = hpOwner.Id); insert hp; Account section = [Select Id from Account where RecordType.Name = '戦略科室分類 消化科' and ParentId =: hp.Id]; Account depart = new Account(); depart.RecordTypeId = rectDpt.Id; depart.Name = '*'; depart.Department_Name__c = 'HistoryTestDepart'; depart.ParentId = section.Id; depart.Department_Class__c = section.Id; depart.Hospital__c = hp.Id; insert depart; Asset ass1 = new Asset( AccountId = depart.Id, Hospital__c = hp.Id, SerialNumber = 'lw0001', Name = '测试设备0001:aaaaa' ); Asset ass2 = new Asset( AccountId = depart.Id, Hospital__c = hp.Id, SerialNumber = 'lw0002', Name = '测试设备0002:aaaaa' ); insert new Asset[] {ass1, ass2}; Inspection_Report__c ir0 = new Inspection_Report__c(Name = '*', Hospital__c = hp.Id, Reporter__c = hpOwner.id, Approved_date__c = Date.today().addDays(-1) ); insert ir0; Inspection_Report__c ir1 = new Inspection_Report__c(Id = ir0.Id, Status__c = '批准' ); update ir1; Inspection_Item__c ii0 = new Inspection_Item__c( Inspection_ReportId__c = ir0.Id, AssetId__c = ass1.Id ); insert ii0; List templist = [select id ,if_UpdateAsset__c from Inspection_Report__c where if_UpdateAsset__c = true]; System.assertEquals(1,templist.size()); System.Test.StartTest(); Database.executeBatch(new UpdateInspectionReportAssetBatch(),1); System.Test.StopTest(); } //2021-09-01 mzy LJPH-C5Y5YD 【委托】合同前点检结果的实时带入 改为调用Batch来实现更新到保有设备 start static testMethod void testMethod2() { ControllerUtil.EscapeNFM001Trigger = true; StaticParameter.EscapeNFM001Trigger = true; StaticParameter.EscapeNFM001AgencyContractTrigger = true; StaticParameter.EscapeNFM001AgencyContractTrigger2 = true; Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin]; // ユーザー作成 User hpOwner = new User(Test_staff__c = true, Job_Category__c='销售服务' ,LastName = 'hp', FirstName = 'owner', Alias = 'hp', CommunityNickname = 'hpOwner', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id); insert hpOwner; // 取引先作成 RecordType rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院']; RecordType rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科']; Account hp = new Account(RecordTypeId = rectHp.Id, Name = 'InsReportPDFControllerTestHp1', OwnerId = hpOwner.Id); insert hp; Account section = [Select Id from Account where RecordType.Name = '戦略科室分類 消化科' and ParentId =: hp.Id]; Account depart = new Account(); depart.RecordTypeId = rectDpt.Id; depart.Name = '*'; depart.Department_Name__c = 'HistoryTestDepart'; depart.ParentId = section.Id; depart.Department_Class__c = section.Id; depart.Hospital__c = hp.Id; insert depart; Asset ass1 = new Asset( AccountId = depart.Id, Hospital__c = hp.Id, SerialNumber = 'lw0001', Name = '测试设备0001:aaaaa' ); Asset ass2 = new Asset( AccountId = depart.Id, Hospital__c = hp.Id, SerialNumber = 'lw0002', Name = '测试设备0002:aaaaa' ); insert new Asset[] {ass1, ass2}; Inspection_Report__c ir0 = new Inspection_Report__c(Name = '*', Hospital__c = hp.Id, Reporter__c = hpOwner.id, Approved_date__c = Date.today().addDays(-1) ); insert ir0; Inspection_Item__c ii0 = new Inspection_Item__c( Inspection_ReportId__c = ir0.Id, AssetId__c = ass1.Id ); insert ii0; Inspection_Report__c ir1 = new Inspection_Report__c(Id = ir0.Id, Status__c = '申请中' ); update ir1; List templist = [select id ,if_UpdateAsset__c from Inspection_Report__c ]; System.assertEquals(1,templist.size()); List ids = new List(); ids.add(templist[0].Id); //System.assertEquals(null,ids); System.Test.StartTest(); UpdateInspectionReportAssetBatch.updateAssetFun(ids); System.Test.StopTest(); } static testMethod void testMethod2_2() { ControllerUtil.EscapeNFM001Trigger = true; StaticParameter.EscapeNFM001Trigger = true; StaticParameter.EscapeNFM001AgencyContractTrigger = true; StaticParameter.EscapeNFM001AgencyContractTrigger2 = true; Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin]; // ユーザー作成 User hpOwner = new User(Test_staff__c = true, Job_Category__c='销售服务' ,LastName = 'hp', FirstName = 'owner', Alias = 'hp', CommunityNickname = 'hpOwner', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id); insert hpOwner; // 取引先作成 RecordType rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院']; RecordType rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科']; Account hp = new Account(RecordTypeId = rectHp.Id, Name = 'InsReportPDFControllerTestHp1', OwnerId = hpOwner.Id); insert hp; Account section = [Select Id from Account where RecordType.Name = '戦略科室分類 消化科' and ParentId =: hp.Id]; Account depart = new Account(); depart.RecordTypeId = rectDpt.Id; depart.Name = '*'; depart.Department_Name__c = 'HistoryTestDepart'; depart.ParentId = section.Id; depart.Department_Class__c = section.Id; depart.Hospital__c = hp.Id; insert depart; Asset ass1 = new Asset( AccountId = depart.Id, Hospital__c = hp.Id, SerialNumber = 'lw0001', Name = '测试设备0001:aaaaa' ); Asset ass2 = new Asset( AccountId = depart.Id, Hospital__c = hp.Id, SerialNumber = 'lw0002', Name = '测试设备0002:aaaaa' ); insert new Asset[] {ass1, ass2}; Inspection_Report__c ir0 = new Inspection_Report__c(Name = '*', Hospital__c = hp.Id, Reporter__c = hpOwner.id, Approved_date__c = Date.today().addDays(-1) ); insert ir0; Inspection_Item__c ii0 = new Inspection_Item__c( Inspection_ReportId__c = ir0.Id, AssetId__c = ass1.Id ); insert ii0; Inspection_Report__c ir1 = new Inspection_Report__c(Id = ir0.Id, Status__c = '批准' ); update ir1; List templist = [select id ,if_UpdateAsset__c from Inspection_Report__c where if_UpdateAsset__c = true]; System.assertEquals(1,templist.size()); List ids = new List(); ids.add(templist[0].Id); //System.assertEquals(null,ids); System.Test.StartTest(); UpdateInspectionReportAssetBatch.updateAssetFun(ids); System.Test.StopTest(); } //2021-09-01 mzy LJPH-C5Y5YD 【委托】合同前点检结果的实时带入 改为调用Batch来实现更新到保有设备 end }