@isTest private class AssetUseInfoBatchTest { private static void init() { List rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP']; if (rectHp.size() == 0) { return; } List rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI']; if (rectDpt.size() == 0) { return; } Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin]; User hpOwner = new User(Test_staff__c = true, LastName = 'hp', FirstName = 'owner', Alias = 'hp', Work_Location__c = '北京', 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; User hpOwner2 = new User(Test_staff__c = true, LastName = 'hp2', FirstName = 'owner', Alias = 'hp2', Work_Location__c = '重庆', CommunityNickname = 'hpOwner2', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner2@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id); insert hpOwner2; // 病院作成 Account hp = new Account(RecordTypeId = rectHp[0].Id, Name = 'hp', OwnerId = hpOwner.Id); hp.FSE_GI_Main_Leader__c = hpOwner.Id; hp.FSE_SP_Main_Leader__c = hpOwner2.Id; insert hp; Account dc = [select Id, Name, RecordType_DeveloperName__c, Account2__c from Account where ParentId = :hp.Id and RecordType_DeveloperName__c = 'Department_Class_GI']; // 診療科を作る Account dpt = new Account(RecordTypeId = rectDpt[0].Id); dpt.Name = '*'; dpt.Department_Name__c = 'TestDepart'; dpt.ParentId = dc.Id; dpt.Department_Class__c = dc.Id; dpt.Hospital__c = hp.Id; insert dpt; RecordType rectOpp = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity' and DeveloperName = 'Opportunity' ]; Opportunity opp = new Opportunity( Name='testOpp1', StageName='引合', CloseDate=Date.today(), AccountId=dpt.Id, Sales_Root__c = 'OCM直接販売', Competitor__c ='A', Click_Close_Date__c = null, RecordType = rectOpp ); insert opp; Statu_Achievements__c Sac = new Statu_Achievements__c( name = 'zhucan_one', Opportunity__c = opp.id, DeliveryDate__c = Date.today(), FirstApproveDate__c = Date.valueOf('2016-08-10') ); insert Sac; Product2 pro1 = new Product2(Name='name01',IsActive=true,Family='GI',Asset_Model_No__c='n01',Serial_Lot_No__c='S/N tracing',ProductCode_Ext__c='pc01',Manual_Entry__c=false); pro1.Extend_new_product_gurantee__c = true; pro1.Entend_gurantee_period__c = '两年'; pro1.Extend_Gurantee_Start__c = Date.valueOf('2015-01-01'); pro1.Extend_Gurantee_End__c = Date.valueOf('2017-01-04'); insert pro1; // 納入機器を作成する Asset asset = new Asset(); asset.Name = 'テスト機器'; asset.AccountId = dpt.Id; asset.Department_Class__c = dc.Id; asset.Hospital__c = hp.Id; asset.SerialNumber = 'testserial'; asset.Product2Id = pro1.Id; asset.Backorder__c = Sac.Id; asset.InstallDate = Date.valueOf('2017-05-10'); asset.Guarantee_period_for_products__c = Date.valueOf('2018-05-10'); insert asset; } @isTest static void test_today() { init(); Id execBTId = Database.executeBatch(new AssetUseInfoBatch(), 5); } @isTest static void test_2018() { init(); Id execBTId = Database.executeBatch(new AssetUseInfoBatch(2018), 5); } @isTest static void test_2019() { init(); Id execBTId = Database.executeBatch(new AssetUseInfoBatch(2019), 5); } @isTest static void test_2020() { init(); Id execBTId = Database.executeBatch(new AssetUseInfoBatch(2020), 5); } @isTest static void test_2021() { init(); Id execBTId = Database.executeBatch(new AssetUseInfoBatch(2021), 5); } @isTest static void test_2022() { init(); Id execBTId = Database.executeBatch(new AssetUseInfoBatch(2022), 5); } @isTest static void test_2023() { init(); Id execBTId = Database.executeBatch(new AssetUseInfoBatch(2023), 5); } @isTest static void test_2024() { init(); Id execBTId = Database.executeBatch(new AssetUseInfoBatch(2024), 5); } @isTest static void test_2025() { init(); Id execBTId = Database.executeBatch(new AssetUseInfoBatch(2025), 5); } @isTest static void test_2026() { init(); Id execBTId = Database.executeBatch(new AssetUseInfoBatch(2026), 5); } }