高章伟
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
@isTest
private class NFM205RestTest {
    @isTest static void test_method_one() {
        ControllerUtil.EscapeNFM001Trigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
       List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
        if (rectCo.size() == 0) {
            return;
        }
 
        List<RecordType> rectContract = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '契約'];
        if (rectCo.size() == 0) {
            return;
        }
        //经销商
        Account myAccount1 = new Account(name='Testaccount001',
                                        Dealer_discount__c =20,
                                        RecordTypeId = rectCo[0].Id);
        insert myAccount1;
 
        Date dtafs = Date.today()-1;
        Date dtaadc = Date.today()-1;
        Date dtbdc = Date.today()+1;
        Date dtlast = Date.today()+10;
 
        Opportunity  opp = new Opportunity(Authorized_Finish_Sales__c='11',
                                           Authorized_DB_No__c='1008',  
                                           Autholization_Activated_Date__c = dtaadc ,Bidding_Content__c='qwer',
                                           Bid_Date__c = dtbdc, Bidding_No__c='4035',Agency1__c = myAccount1.Id,
                                           Agency2__c = myAccount1.Id, Bidding_Project_Name__c='efg',StageName='目標',
                                           Name='xunjia',CloseDate=dtlast
                                           );
        insert opp;
        List<Opportunity> opplist = [select Id,Name,Opportunity_No__c from Opportunity where Opportunity_No__c != '' ];
        NFM205Rest.GeDatas GeDatas = new NFM205Rest.GeDatas();
        NFM205Rest.GeData GeData = new NFM205Rest.GeData();
        GeDatas.GeData = new NFM205Rest.GeData[]{GeData};
 
        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        GeDatas.Monitoring = new NFMUtil.Monitoring();
        GeDatas.Monitoring.MessageGroupNumber = nowStr + '01';
        
        GeData.Opportunity_Code = opplist.get(0).Opportunity_No__c;
        GeData.Authorized_DB_No = '123456';
        GeData.Authorized_Finish_Sales = '8163584';
        GeData.Authorized_Date = '2018-12-01';
        GeData.Autholization_Activated_Date = '2018-12-03';
        GeData.Bid_Project_Name = 'abcd11111abcd1111111111111111111111111111111abcd111111'
                                    + '111111111111111111111111111111111111111111111111111111'
                                    + '111111111111111111111111111111111111111111111111111111'
                                    + '111111111111111111111111111111111111111111111111111111'
                                    + '111111111111111111111111111111111111111111111111111111'
                                    + '111111111111111111111111111111111111111111111111111111'
                                    + '111111111111111111111111111111111111111111111111111111'
                                    + '111111111111111111111111111111111111111111111111111111'
                                    + '111111111111111111111111111111111111111111111111111111'
                                    + '111111111111111111111111111111111111111111111111111111'
                                    + '111111111111111111111111111111111111111111111111111111'
                                    + '111111111111111111111111111111111111111111111111111111'
                                    + '111111111111111111111111111111111111111111111111111111'
                                    + '111111111111111111111111111111111111111111111111111111';
        GeData.Bidding_Content = 'qwer';
        GeData.Bid_Date = '2018-12-01';
        GeData.Bidding_No = '151410';
        GeData.Authorized_Status = '1';
        
        System.Test.startTest();
        NFMUtil.Monitoring Monitoring = GeDatas.Monitoring;
        BatchIF_Log__c rowData = NFMUtil.saveRowData(Monitoring, 'NFM205', GeDatas.GeData);
        NFM205Rest.executefuture(rowData.Id);
        
        GeData.Opportunity_Code = 'opp1111';
        rowData = NFMUtil.saveRowData(Monitoring, 'NFM205', GeDatas.GeData);
        NFM205Rest.executefuture(rowData.Id);
 
        GeData.Opportunity_Code = '';
        rowData = NFMUtil.saveRowData(Monitoring, 'NFM205', GeDatas.GeData);
        NFM205Rest.executefuture(rowData.Id);
        System.Test.stopTest();
    }
 
    @isTest static void test_method_two() {
 
        Test.startTest();
        
        RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();
 
        String JsonMsg = '{"Monitoring":{"TransmissionDateTime":"201812201320","Text":"","Tag":"MSGH","Sender":"SFDC","Receiver":"SPO","NumberOfRecord":"1","MessageType":"NFM205","MessageGroupNumber":"20180001722190"},"GeData":[{"Opportunity_Code":"HKBJ-GI-BJ0588881","Bidding_No":"as123121","Bidding_Content":"招标内容","Bid_Project_Name":"招标项目名","Bid_Date":"20181203","Authorized_Status":"1","Authorized_Finish_Sales":"30033","Authorized_DB_No":"MGZWESQHN201812001","Authorized_Date":"20190316","Autholization_Activated_Date":"20190415"}]}';
        req.requestURI = 'services/apexrest/NFM205/execute';
        req.httpMethod = 'POST';
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        RestContext.response= res;
 
        NFM205Rest.execute();
 
        Test.stopTest();
    }
}