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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
@isTest
private class SBG018RestTest {
 
    public static ProductInventory__c productInventory;
    public static void init() {
        Product2 prd1 = testSBG018Init();
        productInventory = new ProductInventory__c();
        productInventory.TransforDate__c = Date.today() ;
        productInventory.ProductCode__c = prd1.Id;
        productInventory.Plant__c = 'CCTV' ;
        productInventory.ProductSegment__c = 'LS' ;
        productInventory.ProductType__c = 'SP';
        productInventory.InventoryQuantity__c = 22;
        productInventory.TradeType__c = 'Taxation';
        productInventory.ManagementCode__c = prd1.ProductCode +'_LS_SP';
        productInventory.InventoryCode__c =prd1.ProductCode +'_LS_SP_CCTV_Taxation';
 
        insert productInventory;
 
    }
    static Product2 testSBG018Init() {
 
        Product2 prd = new Product2();
        prd.Product_ECCode__c     = 'testSBG018';
        prd.ProductCode            = 'testSBG018';
        prd.Name                   = 'testSBG018';
        prd.IsActive               = true;
        insert prd;
        Pricebook2 prdbook1 = new Pricebook2(
            Name = 'testSBG018',
            ProductSegment__c  = 'BS',
            TradeType__c = 'Taxation',
            SalesChannel__c = 'dealer',
            MachineParts__c = 'Machine',
            isActive = true);
 
        insert prdbook1;
        Pricebook2 prdbook2 = new Pricebook2(
            Name = 'testSBG018',
            ProductSegment__c  = 'BS',
            TradeType__c = 'Taxation',
            SalesChannel__c = 'direct',
            MachineParts__c = 'Machine',
            isActive = true);
 
        insert prdbook2;
 
        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;
 
        return prd;
 
    }
    // 测试业务逻辑
    @isTest static void testSBG018_void() {
 
        init();
 
        SBG018Rest.GeData GeData = new SBG018Rest.GeData();
        SBG018Rest.GeDatas GeDatas = new SBG018Rest.GeDatas();
        GeDatas.GeData = new SBG018Rest.GeData[] { GeData };
        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        GeDatas.Monitoring = new NFMUtil.Monitoring();
        GeDatas.Monitoring.MessageGroupNumber = nowStr + '01';
        SBG018Rest.GeDataDetails GeDataDetail01 = new  SBG018Rest.GeDataDetails();
        SBG018Rest.GeDataDetails GeDataDetail02 = new  SBG018Rest.GeDataDetails();
        GeData.GeDataDetails = new  SBG018Rest.GeDataDetails[] {GeDataDetail01, GeDataDetail02};
        GeData.Status = 'Z5';
        GeData.TransforDate = String.valueOf(Date.today());//'20210113';
        GeDataDetail01.ProductCode = 'testSBG018';
        GeDataDetail01.Plant = 'CCTV';
        GeDataDetail01.Department = 'LS';
        GeDataDetail01.FGSP = 'SP';
        GeDataDetail01.Qty = '11';
        GeDataDetail01.TradeType = 'Taxation';
        GeDataDetail02.ProductCode = 'testSBG018';
        // 用于触发异常 进入Catch
        GeDataDetail02.Plant = 'CCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTV';
        GeDataDetail02.Plant += 'CCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTV';
        GeDataDetail02.Plant += 'CCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTV';
        GeDataDetail02.Plant += 'CCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTV';
        GeDataDetail02.Plant += 'CCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTV';
        GeDataDetail02.Plant += 'CCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTV';
        GeDataDetail02.Plant += 'CCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTV';
        GeDataDetail02.Plant += 'CCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTV';
        GeDataDetail02.Plant += 'CCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTV';
        GeDataDetail02.Plant += 'CCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTV';
        GeDataDetail02.Plant += 'CCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTV';
        GeDataDetail02.Plant += 'CCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTVCCTV';
        GeDataDetail02.TradeType = 'Taxation';
 
        GeDataDetail02.Department = 'LS';
        GeDataDetail02.FGSP = 'FG';
        GeDataDetail02.Qty = '11';
        System.Test.startTest();
        BatchIF_Log__c rowData = NFMUtil.saveRowData(GeDatas.Monitoring, 'SBG018', GeDatas.GeData);
        SBG018Rest.main(rowData.Id);
 
        System.Test.stopTest();
 
    }
 
 
    @isTest static void testSBG018_void2() {
 
        init();
 
        SBG018Rest.GeData GeData = new SBG018Rest.GeData();
        SBG018Rest.GeDatas GeDatas = new SBG018Rest.GeDatas();
        GeDatas.GeData = new SBG018Rest.GeData[] { GeData };
        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        GeDatas.Monitoring = new NFMUtil.Monitoring();
        GeDatas.Monitoring.MessageGroupNumber = nowStr + '01';
        SBG018Rest.GeDataDetails GeDataDetail01 = new  SBG018Rest.GeDataDetails();
        SBG018Rest.GeDataDetails GeDataDetail02 = new  SBG018Rest.GeDataDetails();
        GeData.GeDataDetails = new  SBG018Rest.GeDataDetails[] {GeDataDetail01, GeDataDetail02};
        GeData.Status = 'Z5';
        GeData.TransforDate = String.valueOf(Date.today());//'20210113';
        GeDataDetail01.ProductCode = 'testSBG018';
        GeDataDetail01.Plant = 'CCTV';
        GeDataDetail01.Department = 'LS';
        GeDataDetail01.FGSP = 'SP';
        GeDataDetail01.Qty = '11';
        GeDataDetail01.TradeType = 'Taxation';
        GeDataDetail02.ProductCode = 'testSBG018';
        // 用于触发异常 进入Catch
        GeDataDetail02.Plant = 'CC31';
 
        GeDataDetail02.Department = 'LS';
        GeDataDetail02.FGSP = 'FG';
        GeDataDetail02.Qty = '11';
        GeDataDetail02.TradeType = 'Taxation';
        System.Test.startTest();
        BatchIF_Log__c rowData = NFMUtil.saveRowData(GeDatas.Monitoring, 'SBG018', GeDatas.GeData);
        SBG018Rest.main(rowData.Id);
 
        System.Test.stopTest();
 
    }
    // 测试SBG018Rest execute部分 以及必填字段的验证覆盖
    @isTest static void test_execute() {
        testSBG018Init();
        Test.startTest();
        RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();
 
        String JsonMsg = '{"GeDatas":{"Monitoring":{"Tag":"MSGH","Sender":1330,"Receiver":1592,"MessageType":"SBG018","MessageGroupNumber":570968,"NumberOfRecord":18,"TransmissionDateTime":202101131323},"GeData":[{"Status":"Z5","TransforDate":20210203,"GeDataDetails":[{"ProductCode":"","Plant":"CC20","Department":"IE","FGSP":"FG","Qty":"0.000","TradeType":"Tax Exemption"},{"ProductCode":"000000000001100500","Plant":"CC40","Department":"","FGSP":"FG","Qty":"0.000"},{"ProductCode":"000000000001100500","Plant":"","Department":"IE","FGSP":"SP","Qty":"0.000","TradeType":"Tax Exemption"},{"ProductCode":"000000000003914083","Plant":"CC19","Department":"LS","FGSP":"","Qty":"0.000","TradeType":"Tax Exemption"},{"ProductCode":"000000000003914083","Plant":"CC20","Department":"IE","FGSP":"FG","Qty":"1.000","TradeType":"Tax Exemption"},{"ProductCode":"000000000003914083","Plant":"CC40","Department":"IE","FGSP":"FG","Qty":"","TradeType":"Tax Exemption"},{"ProductCode":"000000000003914083","Plant":"CC41","Department":"LS","FGSP":"FG","Qty":"Test","TradeType":"Tax Exemption"},{"ProductCode":"000000000003914083","Plant":"CC42","Department":"IE","FGSP":"SP","Qty":"0.000","TradeType":"Tax Exemption"},{"ProductCode":"000000000003914083","Plant":"CC46","Department":"LS","FGSP":"SP","Qty":"6.000","TradeType":"Tax Exemption"},{"ProductCode":"000000000003914083","Plant":"CC54","Department":"LS","FGSP":"FG","Qty":"11.000","TradeType":"Tax Exemption"},{"ProductCode":"000000000003980500","Plant":"CC19","Department":"LS","FGSP":"FG","Qty":"0.000","TradeType":"Tax Exemption"},{"ProductCode":"000000000003980500","Plant":"CC20","Department":"IE","FGSP":"FG","Qty":"0.000","TradeType":"Tax Exemption"},{"ProductCode":"000000000003980500","Plant":"CC40","Department":"IE","FGSP":"FG","Qty":"0.000","TradeType":"Tax Exemption"},{"ProductCode":"000000000003980500","Plant":"CC41","Department":"LS","FGSP":"FG","Qty":"0.000","TradeType":"Tax Exemption"},{"ProductCode":"000000000003980500","Plant":"CC42","Department":"IE","FGSP":"SP","Qty":"0.000","TradeType":"Tax Exemption"},{"ProductCode":"000000000003980500","Plant":"CC54","Department":"LS","FGSP":"FG","Qty":"0.000","TradeType":"Tax Exemption"},{"ProductCode":"Q0500040","Plant":"CC22","Department":"NDT","FGSP":"FG","Qty":"0.000","TradeType":"Taxation"},{"ProductCode":"Q0500040","Plant":"CC45","Department":"NDT","FGSP":"FG","Qty":"0.000","TradeType":""}]}]}}';
        req.requestURI = 'services/apexrest/SBG018/execute';
        req.httpMethod = 'POST';
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        RestContext.response = res;
 
        SBG018Rest.execute();
 
        Test.stopTest();
    }
    // static testMethod void testMethod1() {
 
    // }
}