高章伟
2022-02-18 8b5f4c6c281cfa548f92de52c8021e37aa81901e
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
/**
 * Created by shentianyi on 2019/08/07.
 */
 
@isTest
private class ET_Batch3_SchedulerTest {
    public static String CRON_EXP = '0 0 0 3 9 ? 2032';
 
    //省
    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;
 
        //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;
    }
 
    private static testMethod void test_method_one() {
        setdata();
 
        Test.startTest();
        // Schedule the test job
        String jobId = System.schedule('ET_Batch3_SchedulerTest', CRON_EXP, new ET_Batch3_Scheduler());
        // Get the information from the CronTrigger API object
        CronTrigger ct = [SELECT Id, CronExpression, TimesTriggered, NextFireTime FROM CronTrigger WHERE Id = :jobId];
        // Verify the expressions are the same
        System.assertEquals(CRON_EXP, ct.CronExpression);
        // Verify the job has not run
        System.assertEquals(0, ct.TimesTriggered);
        // Verify the next time the job will run
        System.assertEquals('2032-09-03 00:00:00', String.valueOf(ct.NextFireTime));
        Test.stopTest();
        
    }
}