高章伟
2022-02-24 2aa8da8af66aa8ae00f25831aed6bb0364176e7b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
* @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();
    
    /*******************************************************************************************************
    *@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;
    }
 
    /*******************************************************************************************************
    *@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();
    }
}