buli
2022-05-14 ead4df22dca33a867279471821ca675f91dec760
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
@isTest
private class SBG019RestTest {
 
    @testSetup
    static void testSBG019RestInit() {
 
        Product2 prd = new Product2();
        prd.Product_ECCode__c     = 'testSBG019';
        prd.ProductCode            = 'testSBG019';
        prd.Name                   = 'testSBG019';
        prd.IsActive               = true;
        insert prd;
        Pricebook2 prdbook1 = new Pricebook2(
            Name = 'testSBG019',
            ProductSegment__c  = 'BS',
            TradeType__c = 'Taxation',
            SalesChannel__c = 'dealer',
            MachineParts__c = 'Machine',
            isActive = true);
 
        insert prdbook1;
        Pricebook2 prdbook2 = new Pricebook2(
            Name = 'testSBG019',
            ProductSegment__c  = 'BS',
            TradeType__c = 'Taxation',
            SalesChannel__c = 'direct',
            MachineParts__c = 'Machine',
            isActive = true);
 
        insert prdbook2;
 
        Product2 prd3 = new Product2();
        prd3.Product_ECCode__c     = 'testSBG01901';
        prd3.ProductCode            = 'testSBG01901';
        prd3.Name                   = 'testSBG01901';
        prd3.IsActive               = true;
        insert prd3;
        Pricebook2 prdbook3 = new Pricebook2(
            Name = 'testSBG01901',
            ProductSegment__c  = 'BS',
            TradeType__c = 'Taxation',
            SalesChannel__c = 'dealer',
            MachineParts__c = 'Machine',
            isActive = true);
 
        insert prdbook3;
 
        PricebookEntry pbe3 = new PricebookEntry();
        pbe3.Pricebook2Id = ControllerUtil.getStandardPricebook().Id;
        pbe3.Product2Id      = prd3.Id;
        pbe3.UnitPrice       = 0;
        pbe3.CurrencyIsoCode = 'CNY';
        pbe3.IsActive        = true;
        insert pbe3;
 
 
        PricebookEntry pbe = new PricebookEntry();
        pbe.Pricebook2Id = ControllerUtil.getStandardPricebook().Id;
        pbe.Product2Id      = prd.Id;
        pbe.UnitPrice       = 0;
        pbe.CurrencyIsoCode = 'CNY';
        pbe.IsActive        = true;
        insert pbe;
        PricebookEntry pbe1 = new PricebookEntry();
        pbe1.Pricebook2Id = ControllerUtil.getStandardPricebook().Id;
        pbe1.Product2Id      = prd.Id;
        pbe1.UnitPrice       = 0;
        pbe1.CurrencyIsoCode = 'USD';
        pbe1.IsActive        = true;
        insert pbe1;
 
    }
 
    //测试SBG019Rest execute部分 以及必填字段的验证覆盖
    @isTest static void test_execute() {
        // testSBG019RestInit();
        Test.startTest();
        RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();
 
        //String JsonMsg = '{"GeDatas":{"Monitoring":{"Tag":"MSGH","Sender":1330,"Receiver":1592,"MessageType":"SBG019","MessageGroupNumber":570985,"NumberOfRecord":2,"TransmissionDateTime":202102021106},"GeData":[{"TransforDate":20210202,"GeDataDetails":[{"ProductCode":"000000000001100500","ProductDate":"20210202"},{"ProductCode":"","ProductDate":""}]}]}}';
        String JsonMsg = '{"GeDatas":{"Monitoring":{"Tag":"MSGH","Sender":1330,"Receiver":1592,"MessageType":"SBG019","MessageGroupNumber":570985,"NumberOfRecord":2,"TransmissionDateTime":202102021106},"GeData":[{"TransforDate":20210202,"GeDataDetails":[{"ProductCode":"testSBG01901","ProductDate":"20210202"},{"ProductCode":"testSBG019","ProductDate":"20210202"},{"ProductCode":"","ProductDate":""},{"ProductCode":"testSBG019","ProductDate":""},{"ProductCode":"testSBG019","ProductDate":"20210202"},{"ProductCode":"123456","ProductDate":"20210202"}]}]}}';
        req.requestURI = 'services/apexrest/SBG019/execute';
        req.httpMethod = 'POST';
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        RestContext.response = res;
 
        SBG019Rest.execute();
 
        Test.stopTest();
    }
 
}