高章伟
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
@isTest(SeeAllData = false)
public with sharing class NFM211RestTest {
 
    /* 目前只是作为接数据用,且数据中没有关联其他表字段 故直接捏造接口日志
     *  未来如果增加逻辑,需要对应修改。
    */
 
    /* 测试促销政策 正常+必填验证 */
    static testMethod void testNFM211_01() {
        BatchIF_Log__c iflog = new BatchIF_Log__c();
        iflog.MessageGroupNumber__c = '20210525';
        iflog.Type__c ='NFM211' ;
        iflog.Log__c = '[{"SpoID":"SR052501","PromotionNo":"052501","Description":"测试01","Memo":"测试01","Category":"促销政策","DateFrom":"20210101","DateTo":"20211010","IfContainsGuarantee":null,"IsCheckProductCount":false,"Price":null,"ProductType":"","ifNecessary":false,"OrderNo":null,"ApplyStatus":"完成","PromotionProduct_Info":[{"Model":"AR-T12E","Quantity":3},{"Model":"CF-H260AI","Quantity":1}]},{"SpoID":"SR052502","PromotionNo":"052502","Description":"测试02","Memo":"测试02","Category":"促销政策","DateFrom":"20210101","DateTo":"20211010","IfContainsGuarantee":false,"IsCheckProductCount":null,"Price":120.0,"ProductType":"测试02","ifNecessary":false,"OrderNo":0,"ApplyStatus":"完成","PromotionProduct_Info":[{"Model":"AR-T12E","Quantity":3}]},{"SpoID":"SR052503","PromotionNo":"052503","Description":"测试03","Memo":"测试03","Category":"促销政策","DateFrom":"20210101","DateTo":"20211010","IfContainsGuarantee":false,"IsCheckProductCount":false,"Price":null,"ProductType":"测试03","ifNecessary":false,"OrderNo":0,"ApplyStatus":"完成","PromotionProduct_Info":[{"Model":"AR-T12E","Quantity":3}]},{"SpoID":"SR052504","PromotionNo":"052504","Description":"测试04","Memo":"测试04","Category":"促销政策","DateFrom":"20210101","DateTo":"20211010","IfContainsGuarantee":false,"IsCheckProductCount":false,"Price":120.0,"ProductType":"测试04","ifNecessary":false,"OrderNo":0,"ApplyStatus":"作废","PromotionProduct_Info":[{"Model":"AR-T12E","Quantity":3}]}]';
        iflog.RowDataFlg__c = true;
 
        insert iflog;
        System.Test.startTest();
        NFM211Rest.executefuture(iflog.id);
        System.Test.stopTest();
 
    }
    /* 测试一般产品 正常 + 必填验证*/
    static testMethod void testNFM211_02() {
        BatchIF_Log__c iflog = new BatchIF_Log__c();
        iflog.MessageGroupNumber__c = '20210525';
        iflog.Type__c ='NFM211' ;
        iflog.Log__c = '[{"SpoID":"SR052501","PromotionNo":"052501","Description":"测试01","Memo":"测试01","Category":"促销价格产品","DateFrom":"20210101","DateTo":"20211010","IfContainsGuarantee":null,"IsCheckProductCount":null,"Price":null,"ProductType":null,"ifNecessary":false,"OrderNo":null,"ApplyStatus":"完成","PromotionProduct_Info":[{"Model":"AR-T12E","Quantity":3},{"Model":"CF-H260AI","Quantity":1}]},{"SpoID":"SR052502","PromotionNo":"052502","Description":"测试02","Memo":"测试02","Category":"促销价格产品","DateFrom":"20210101","DateTo":"20211010","IfContainsGuarantee":false,"IsCheckProductCount":false,"Price":120.0,"ProductType":"测试02","ifNecessary":null,"OrderNo":0,"ApplyStatus":"完成","PromotionProduct_Info":[{"Model":"AR-T12E","Quantity":3}]},{"SpoID":"SR052503","PromotionNo":"052503","Description":"测试03","Memo":"测试03","Category":"促销价格产品","DateFrom":"20210101","DateTo":"20211010","IfContainsGuarantee":false,"IsCheckProductCount":false,"Price":120.0,"ProductType":"测试03","ifNecessary":false,"OrderNo":null,"ApplyStatus":"完成","PromotionProduct_Info":[{"Model":"AR-T12E","Quantity":3}]},{"SpoID":"SR052504","PromotionNo":"052504","Description":"测试04","Memo":"测试04","Category":"促销价格产品","DateFrom":"20210101","DateTo":"20211010","IfContainsGuarantee":false,"IsCheckProductCount":false,"Price":120.0,"ProductType":"测试04","ifNecessary":false,"OrderNo":0,"ApplyStatus":"作废","PromotionProduct_Info":[{"Model":"AR-T12E","Quantity":3}]}]';
        iflog.RowDataFlg__c = true;
 
        insert iflog;
        System.Test.startTest();
        NFM211Rest.executefuture(iflog.id);
        System.Test.stopTest();
 
    }
    /* 测试报错 */
    static testMethod void testNFM211_03() {
        BatchIF_Log__c iflog = new BatchIF_Log__c();
        iflog.MessageGroupNumber__c = '20210525';
        iflog.Type__c ='NFM211' ;
        iflog.Log__c = '[{"SpoID":"SR052501","PromotionNo":"052501","Description":"测试01","Memo":"测试01","Category":"促销价格产品","DateFrom":"测试01","DateTo":"测试01","IfContainsGuarantee":null,"IsCheckProductCount":null,"Price":null,"ProductType":null,"ifNecessary":false,"OrderNo":null,"ApplyStatus":"完成","PromotionProduct_Info":[{"Model":"AR-T12E","Quantity":3},{"Model":"CF-H260AI","Quantity":1}]},{"SpoID":"SR052502","PromotionNo":"052502","Description":"测试02","Memo":"测试02","Category":"促销价格产品","DateFrom":"20210101","DateTo":"20211010","IfContainsGuarantee":false,"IsCheckProductCount":false,"Price":120.0,"ProductType":"测试02","ifNecessary":null,"OrderNo":0,"ApplyStatus":"完成","PromotionProduct_Info":[{"Model":"AR-T12E","Quantity":3}]},{"SpoID":"SR052503","PromotionNo":"052503","Description":"测试03","Memo":"测试03","Category":"促销价格产品","DateFrom":"20210101","DateTo":"20211010","IfContainsGuarantee":false,"IsCheckProductCount":false,"Price":120.0,"ProductType":"测试03","ifNecessary":false,"OrderNo":null,"ApplyStatus":"完成","PromotionProduct_Info":[{"Model":"AR-T12E","Quantity":3}]},{"SpoID":"SR052504","PromotionNo":"052504","Description":"测试04","Memo":"测试04","Category":"促销价格产品","DateFrom":"20210101","DateTo":"20211010","IfContainsGuarantee":false,"IsCheckProductCount":false,"Price":120.0,"ProductType":"测试04","ifNecessary":false,"OrderNo":0,"ApplyStatus":"作废","PromotionProduct_Info":[{"Model":"AR-T12E","Quantity":3}]}]';
        iflog.RowDataFlg__c = true;
 
        insert iflog;
        System.Test.startTest();
        NFM211Rest.executefuture(iflog.id);
        System.Test.stopTest();
 
    }
    /* 测试调用execute方法 */
    @isTest static void test_method_execute() {
 
        Test.startTest();
        
        RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();
 
        String JsonMsg = '{"Monitoring":{"Tag":"MSGH","Sender":"SPO","Receiver":"SFDC","MessageType":"NFM211","MessageGroupNumber":"20210000004695","NumberOfRecord":"4","TransmissionDateTime":"2021-06-23","Text":""},"Header":[{"SpoID":"94","PromotionNo":"202","Description":"2019年9月5日 测试","Memo":"测试","Category":"1","DateFrom":"20190912","DateTo":"20221016","IfContainsGuarantee":true,"IsCheckProductCount":true,"Price":12.0,"ProductType":"","ifNecessary":false,"OrderNo":0,"ApplyStatus":"同意","Items":[{"Model":"01","Quantity":2}]}]}';
        req.requestURI = 'services/apexrest/NFM211/execute';
        req.httpMethod = 'POST';
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        RestContext.response= res;
 
        NFM211Rest.execute();
 
        Test.stopTest();
    }
}