高章伟
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
@isTest
private class Opportunity_Shipments_ForecastBatchTest {
    
    static testMethod void test_method_OSF() {
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科'];
        if (rectSct.size() == 0) {
            return;
        }
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
        if (rectDpt.size() == 0) {
            return;
        }
        // テストデータ
        Account company = new Account();
        company.RecordTypeId = rectCo[0].Id;
        company.Name         = 'NFM206TestCompany';
        upsert company;
        Account section = new Account();
        section.RecordTypeId = rectSct[0].Id;
        section.Name         = '*';
        section.Department_Class_Label__c = '消化科';
        section.ParentId                  = company.Id;
        section.Hospital_Department_Class__c = company.Id;
        upsert section;
        Account depart = new Account();
        depart.RecordTypeId = rectDpt[0].Id;
        depart.Name         = '*';
        depart.Department_Name__c  = 'NFM206TestDepart';
        depart.ParentId            = section.Id;
        depart.Department_Class__c = section.Id;
        depart.Hospital__c         = company.Id;
        upsert depart;
        Date today = Date.today();
        Date lastDate1 = Date.today().addMonths(1);
        Date lastDate2 = Date.today().addMonths(2);
        Date lastDate3 = Date.today().addMonths(3);
 
        Opportunity opp = new Opportunity();
        opp.AccountId           = depart.Id;
        opp.Department_Class__c = section.Id;
        opp.Hospital__c         = company.Id;
        opp.SAP_Send_OK__c      = false;
        opp.Name                = 'GZ-SP-NFM009_0';
        opp.Trade__c            = '内貿';
        opp.StageName           = '引合';
        opp.CloseDate           = lastDate1;
        opp.Close_Forecasted_Date__c = lastDate1;
        opp.Stock_apply_status__c = '申请中';
        insert opp;
        //List<Opportunity> oopList = [select Id,Opportunity_No__c from Opportunity where Id = opp.Id]
 
        List<String> oppIds = new List<String>();
        //oppIds.add(oopList[0].);
        List<Opportunity> opps = [select Opportunity_No__c from Opportunity where Close_Forecasted_Date__c >= :Date.today() and Close_Forecasted_Date__c <= :Date.today().addMonths(2)];
        System.assertEquals(1, opps.size());
        oppIds.add(opps[0].Opportunity_No__c);
        Id execBTId = null;
        System.Test.StartTest();
        execBTId = Database.executeBatch(new Opportunity_Shipments_ForecastBatch(oppIds));
        
        execBTId = Database.executeBatch(new Opportunity_Shipments_ForecastBatch('20190101'));
        execBTId = Database.executeBatch(new Opportunity_Shipments_ForecastBatch());
        System.Test.StopTest();
    }
    
}