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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
@isTest
private class SBGITMRestTest {
    public static Product2 prd1;
    public static Product2 prd2;
    public static Product2 prd3;
    public static Product2 prd4;
 
    static void inittransfersData() { 
        prd1 = new Product2();
        prd1.Product_ECCode__c      = 'testSBG001';
        prd1.ProductCode            = 'SBGITMTst1';
        prd1.Name                   = 'testSBG001';
        prd1.IsActive               = true;
        prd1.MaterialStatus_one_Start__c = Date.today().addDays(-2);
        prd1.MaterialStatus_one_End__c = Date.today().addDays(-1);
        prd1.MaterialStatus_two_Start__c = Date.today().addDays(-3);
        prd1.MaterialStatus_two_End__c = Date.today().addDays(-1);
 
        prd2 = new Product2();
        prd2.Product_ECCode__c      = 'testSBG002';
        prd2.ProductCode            = 'SBGITMTst2';
        prd2.Name                   = 'testSBG002';
        prd2.IsActive               = true;
        prd2.MaterialStatus_one_Start__c = Date.today().addDays(-2);
        prd2.MaterialStatus_one_End__c = Date.today().addDays(22);
        prd2.MaterialStatus_two_Start__c = Date.today().addDays(-3);
        prd2.MaterialStatus_two_End__c = Date.today().addDays(-1);
 
        prd3 = new Product2();
        prd3.Product_ECCode__c      = 'testSBG002';
        prd3.ProductCode            = 'SBGITMTst22';
        prd3.Name                   = 'testSBG002';
        prd3.IsActive               = true;
        prd3.MaterialStatus_one_Start__c = Date.today().addDays(-2);
        prd3.MaterialStatus_one_End__c = Date.today().addDays(22);
        prd3.MaterialStatus_two_Start__c = Date.today().addDays(-3);
        prd3.MaterialStatus_two_End__c = Date.today().addDays(122);
 
        prd4 = new Product2();
        prd4.Product_ECCode__c      = 'testSBG002';
        prd4.ProductCode            = 'SBGITMTst222';
        prd4.Name                   = 'testSBG002';
        prd4.IsActive               = true;
        prd4.MaterialStatus_one_Start__c = Date.today().addDays(-2);
        prd4.MaterialStatus_one_End__c = Date.today().addDays(22);
        prd4.MaterialStatus_two_Start__c = Date.today().addDays(-3);
        prd4.MaterialStatus_two_End__c = Date.today().addDays(21);
        insert new Product2[] {prd1, prd2,prd3,prd4};
    }
    //@isTest
    static void testSBGITM_insert() {
        inittransfersData();
        Id pricebookId = ControllerUtil.getStandardPricebook().Id;
        SBGITMRest.GeDatas GeDatas = new SBGITMRest.GeDatas();
        SBGITMRest.GeData GeData = new SBGITMRest.GeData();
        SBGITMRest.GeData GeData2 = new SBGITMRest.GeData();
        GeDatas.GeData = new SBGITMRest.GeData[] { GeData, GeData2 };
        // Monitoringの設定
        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        GeDatas.Monitoring = new NFMUtil.Monitoring();
        GeDatas.Monitoring.MessageGroupNumber = nowStr + '11';
 
        // insert
        GeData.ProductCode                = 'SBGITMTst3';
        GeData.ProductDescription                 = 'ABCD1234:ABC';
        GeData.ProductStatus                    = '1';
        GeData.EffectiveDateTo                      = '20121101';
        GeData.Exemption = '1';
        GeData.IsRadiant = '1';
        GeData.StatusEffectiveDateFrom = '20200522';
 
 
        // insert2
        GeData2.ProductCode                = 'SBGITMTst4';
        GeData2.ProductDescription                 = 'ABCD12345:ABC';
        GeData2.ProductStatus                    = '0';
        GeData2.EffectiveDateTo                      = '20121101';
 
        System.Test.startTest();
        BatchIF_Log__c rowData = NFMUtil.saveRowData(GeDatas.Monitoring, 'SBGITM', GeDatas.GeData);
        SBGITMRest.executefuture(rowData.Id);
        System.Test.stopTest();
        Product2[] rslts = [select Id, Name,
                            ProductCode,
                            Product_ECCode__c,
                            EffectiveDateTo__c,
                            ProductModels__c,
                            ProductStatus__c
                            from Product2
                            where Product_ECCode__c = 'ABCD1234'];
        System.assertEquals(1, rslts.size());
        if (rslts.size() == 1) {
            System.assertEquals('SBGITMTst3', rslts[0].ProductCode);
        }
        rslts = [select Id,
                 ProductCode, Name,
                 Product_ECCode__c,
                 EffectiveDateTo__c,
                 ProductModels__c,
                 ProductStatus__c
                 from Product2
                 where Product_ECCode__c = 'ABCD12345'];
        System.assertEquals(1, rslts.size());
        if (rslts.size() == 1) {
            System.assertEquals('SBGITMTst4', rslts[0].ProductCode);
            System.assertEquals('ABC', rslts[0].Name);
        }
    }
 
    //@isTest
    static void testSBGITM_update() {
        inittransfersData();
        Id pricebookId = ControllerUtil.getStandardPricebook().Id;
        SBGITMRest.GeDatas GeDatas = new SBGITMRest.GeDatas();
        SBGITMRest.GeData GeData = new SBGITMRest.GeData();
        GeDatas.GeData = new SBGITMRest.GeData[] { GeData };
        // Monitoringの設定
        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        GeDatas.Monitoring = new NFMUtil.Monitoring();
        GeDatas.Monitoring.MessageGroupNumber = nowStr + '11';
 
        // insert
        GeData.ProductCode                = 'SBGITMTst1';
        GeData.ProductDescription                 = 'ABCD1234:ABC';
        GeData.ProductStatus                    = '1';
        GeData.EffectiveDateTo                      = '20121101';
        GeData.Exemption = '1';
        GeData.IsRadiant = '1';
        GeData.StatusEffectiveDateFrom = '20200522';
 
        // insert
        GeData.ProductCode                = 'SBGITMTst2';
        GeData.ProductDescription                 = 'ABCD1234:ABC';
        GeData.ProductStatus                    = '1';
        GeData.EffectiveDateTo                      = '20121101';
        GeData.Exemption = '1';
        GeData.IsRadiant = '1';
        GeData.StatusEffectiveDateFrom = '20200522';
 
        // insert
        GeData.ProductCode                = 'SBGITMTst22';
        GeData.ProductDescription                 = 'ABCD1234:ABC';
        GeData.ProductStatus                    = '1';
        GeData.EffectiveDateTo                      = '20121101';
        GeData.Exemption = '1';
        GeData.IsRadiant = '1';
        GeData.StatusEffectiveDateFrom = '20200522';
        
        GeData.ProductCode                = 'SBGITMTst222';
        GeData.ProductDescription                 = 'ABCD1234:ABC';
        GeData.ProductStatus                    = '1';
        GeData.EffectiveDateTo                      = '20121101';
        GeData.Exemption = '1';
        GeData.IsRadiant = '1';
        GeData.StatusEffectiveDateFrom = '20200522';
        System.Test.startTest();
        BatchIF_Log__c rowData = NFMUtil.saveRowData(GeDatas.Monitoring, 'SBGITM', GeDatas.GeData);
        SBGITMRest.executefuture(rowData.Id);
        System.Test.stopTest();
        Product2[] rslts = [select Id,
                            ProductCode,
                            Product_ECCode__c,
                            EffectiveDateTo__c,
                            ProductModels__c,
                            ProductStatus__c
                            from Product2
                            where Product_ECCode__c = 'ABCD1234'];
        System.assertEquals(1, rslts.size());
        if (rslts.size() == 1) {
            System.assertEquals('SBGITMTst222', rslts[0].ProductCode);
        }
    }
 
    //@isTest
    static void testSBGITM_resend() {
        Id pricebookId = ControllerUtil.getStandardPricebook().Id;
        SBGITMRest.GeDatas GeDatas = new SBGITMRest.GeDatas();
        SBGITMRest.GeData GeData = new SBGITMRest.GeData();
        GeDatas.GeData = new SBGITMRest.GeData[] { GeData };
        // Monitoringの設定
        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        GeDatas.Monitoring = new NFMUtil.Monitoring();
        GeDatas.Monitoring.MessageGroupNumber = nowStr + '11';
 
        // insert
        GeData.ProductCode                = 'SBGITMTst1';
        GeData.ProductDescription                 = 'ABCD1234:ABC';
        GeData.ProductStatus                    = '1';
        GeData.EffectiveDateTo                      = '20121101';
 
 
        System.Test.startTest();
        BatchIF_Log__c rowData = NFMUtil.saveRowData(GeDatas.Monitoring, 'SBGITM', GeDatas.GeData);
        SBGITMRest.executefuture(rowData.Id);
        System.Test.stopTest();
        Product2[] rslts = [select Id,
                            ProductCode,
                            Product_ECCode__c,
                            EffectiveDateTo__c,
                            ProductModels__c,
                            ProductStatus__c
                            from Product2
                            where Product_ECCode__c = 'ABCD1234'];
        System.assertEquals(1, rslts.size());
        if (rslts.size() == 1) {
            System.assertEquals('SBGITMTst1', rslts[0].ProductCode);
        }
        List<BatchIF_Log__c> rowbl = [Select Id, Log__c,
                                      ErrorLog__c
                                      from BatchIF_Log__c
                                      where RowDataFlg__c = true
                                              and Type__c = 'SBGITM'
                                                      order by CreatedDate desc];
        List<BatchIF_Log__c> rowbl1 = [Select Id, Log__c,
                                       ErrorLog__c
                                       from BatchIF_Log__c
                                       where RowDataFlg__c = true
                                               order by CreatedDate desc];
        System.debug(rowbl1);
        System.assertEquals(1, rowbl.size());
        rowbl[0].retry_cnt__c = 1;
        update rowbl;
 
        SBGITMRest.executefuture(rowbl[0].id);
 
        List<BatchIF_Log__c> bl = [Select Id, Is_Error__c,
                                   Type__c, Log__c, ErrorLog__c, retry_cnt__c
                                   from BatchIF_Log__c
                                   where Id = :rowbl[0].id];
        System.assertEquals(1, bl.size());
        // System.assertEquals(1, bl[0].retry_cnt__c);
    }
 
 
 
    @isTest static void test_method_Seven() {
 
        Test.startTest();
 
        RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();
 
        String JsonMsg = '{"GeDatas": {"Monitoring": {"Tag": "MSGH","Sender": 1330,"Receiver": 1592,"MessageType": "SBGITM","MessageGroupNumber": 331591,"NumberOfRecord": 1,"TransmissionDateTime": 201903251115},"GeData": [{"ProductStatus": "1","ProductDescription": "SP-KIT-WEDGE-MQIV1072:111 ","ProductCode":"U8831946","Other3": "","Other2": "","Other1": "","EffectiveDateTo": "99991231"}]}}';
        req.requestURI = 'services/apexrest/SBGITM/execute';
        req.httpMethod = 'POST';
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        RestContext.response = res;
 
        SBGITMRest.execute();
 
        Test.stopTest();
 
        // { "GeDatas": {"Monitoring": {"Tag": "MSGH","Sender": 1330,"Receiver": 1592,"MessageType": "SBG017", "MessageGroupNumber": 331591, "NumberOfRecord": 1, "TransmissionDateTime": 201903251115 },"GeData": [{ "StockAnswer": "OK111","SAPQuotationCode": "20022780  ", "Other3": "", "Other2": "", "Other1": "",  "OpportunityCode": "O-2018-067607"}]}}
 
        //Test.setMock(HttpCalloutMock.class, new NFM205RestCalloutMock());
        //NFM205Rest.execute1('{"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"}]}');
    }
}