/* * @author 陳 * @date 2018.8.28 * @description ET_Product_ScoreTable_Batch test method */ @isTest private class ET_Product_ScoreTable_BatchTest { //省 private static Address_Level__c al = new Address_Level__c(); //市 private static Address_Level2__c al2 = new Address_Level2__c(); //Account HP private static Account AccountHP = new Account(); //Account Agent1 private static Account AccountAgent1 = new Account(); //User //private static user myUser_test = new user(); //Product2 private static Product2 prod01 = new Product2(); private static Product2 prod08 = new Product2(); private static Product2 prod03 = new Product2(); private static Product2 prod04 = new Product2(); private static Product2 prod05 = new Product2(); private static Product2 prod06 = new Product2(); private static Product2 prod07 = new Product2(); /******************************************************************************************************* *@description testデータ作成 */ private static void setdata(){ //Profile prof = [select Id from Profile where Name ='系统管理员']; //myUser_test = New User(Alias = 'newUserA',Email='newuserA@testorg.com',EmailEncodingKey='UTF-8', LastName='testUserA', LanguageLocaleKey='zh_CN',LocaleSidKey='zh_CN', ProfileId = prof.Id,TimeZoneSidKey='Asia/Shanghai', UserName='testUserA@testorg.com',Work_Location__c = '北京'); //insert myUser_test; // OLY_OCM-644 StaticParameter.EscapeConsumableOrderDetail2Trigger = true; //Account 经销商 recordtypeID Id AgencyRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Agency').getRecordTypeId(); //Account 医院 recordtypeID Id HPRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('HP').getRecordTypeId(); // 省 al = new Address_Level__c(Name = '東京', Level1_Code__c = 'CN-99', Level1_Sys_No__c = '999999'); insert al; // 市 al2 = new Address_Level2__c(Level1_Code__c = 'CN-99', Level1_Sys_No__c = '999999', Level1_Name__c = '東京', Name = '渋谷区', Level2_Code__c = 'CN-9999', Level2_Sys_No__c = '9999999', Address_Level__c = al.id); insert al2; AccountHP = new Account(name='testHP001',RecordTypeId = HPRecordTypeId, Is_Active__c = '有効', Attribute_Type__c = '卫生部', Speciality_Type__c = '综合医院', Grade__c = '一级', OCM_Category__c = 'SLTV', Is_Medical__c = '医疗机构', State_Master__c = al.id, City_Master__c = al2.id, Town__c = '东京'); insert AccountHP; AccountAgent1 = new Account(name='testAgent001',RecordTypeId = AgencyRecordTypeId ); insert AccountAgent1; prod01 = new Product2(Name='Test01', ProductCode='Test01', Asset_Model_No__c = 'Test01', SFDA_Status__c = '有効', Dealer_special_Object__c = true, Family = 'ET', Category2__c = '耗材', Category3__c = 'ERCP', Category4__c = '导丝', Category5__c = 'Visiglide35'); insert prod01; prod08 = new Product2(Name='Test08', ProductCode='Test08', Asset_Model_No__c = 'Test08', SFDA_Status__c = '有効', Dealer_special_Object__c = true, Family = 'ET', Category2__c = '耗材', Category3__c = 'EUS', Category4__c = '吸引活检针', Category5__c = 'Visiglide35'); insert prod08; prod03 = new Product2(Name='Test03', ProductCode='Test03', Asset_Model_No__c = 'Test03', SFDA_Status__c = '有効', Dealer_special_Object__c = true, Family = 'ET', Category2__c = '耗材', Category3__c = 'ESD', Category4__c = '先端系粘膜切开刀', Category5__c = 'Visiglide35'); insert prod03; prod04 = new Product2(Name='Test04', ProductCode='Test04', Asset_Model_No__c = 'Test04', SFDA_Status__c = '有効', Dealer_special_Object__c = true, Family = 'ET', Category2__c = '耗材', Category3__c = 'ERCP', Category4__c = '乳头切开刀', Category5__c = 'Visiglide35'); insert prod04; prod05 = new Product2(Name='Test05', ProductCode='Test05', Asset_Model_No__c = 'Test05', SFDA_Status__c = '有効', Dealer_special_Object__c = true, Family = 'ET', Category2__c = '耗材', Category3__c = 'ERCP', Category4__c = '注射针(胃镜)', Category5__c = 'Visiglide35'); insert prod05; prod06 = new Product2(Name='Test06', ProductCode='Test06', Asset_Model_No__c = 'Test06', SFDA_Status__c = '有効', Dealer_special_Object__c = true, Family = 'ET', Category2__c = '耗材', Category3__c = 'ERCP', Category4__c = '注射针(肠镜)', Category5__c = 'Visiglide35'); insert prod06; prod07 = new Product2(Name='Test07', ProductCode='Test07', Asset_Model_No__c = 'Test07', SFDA_Status__c = '有効', Dealer_special_Object__c = true, Family = 'ET', Category2__c = '耗材', Category3__c = '呼吸科ET', Category4__c = '吸引活检针', Category5__c = 'Visiglide35'); insert prod07; } /******************************************************************************************************* *@description //call ET_Product_ScoreTable_Batch */ private static testMethod void ET_Product_ScoreTable_BatchTest01() { system.test.startTest(); setdata(); ET_Product_ScoreTable_Batch bat = new ET_Product_ScoreTable_Batch (); Database.executeBatch(bat); system.test.stopTest(); } /******************************************************************************************************* *@description //Error Mail Sending Test */ private static testMethod void ET_Product_ScoreTable_BatchTest02() { system.test.startTest(); setdata(); //让组成Unikey时超过长度报错 prod01.Category3__c = 'ERCPABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEF' + 'ABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJ' + 'ABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDE'; update prod01; Product2 prod02 = new Product2(Name='Test02', ProductCode='Test02', Asset_Model_No__c = 'Test02', SFDA_Status__c = '有効', Dealer_special_Object__c = true, Family = 'ET', Category2__c = '耗材', Category3__c = 'ERCP', Category4__c = '导丝A', Category5__c = 'Visiglide35'); insert prod02; ET_Product_ScoreTable_Batch bat = new ET_Product_ScoreTable_Batch (); Database.executeBatch(bat); system.test.stopTest(); } }