高章伟
2022-02-18 8b5f4c6c281cfa548f92de52c8021e37aa81901e
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
@isTest
private class NFM012WebServiceTest {
    //resend_test
    static testMethod void resend_test() {
        // テストデータ
        List<BatchIF_Transfer__c> transfers = new List<BatchIF_Transfer__c>();
        BatchIF_Transfer__c transfer = new BatchIF_Transfer__c();
        transfer.Table__c          = 'Account';
        transfer.Column__c         = 'Sales_Shop_Class__c';
        transfer.External_Value__c = '02';
        transfer.Internal_Value__c = '02Internal';
        transfers.add(transfer);
        transfer = new BatchIF_Transfer__c();
        transfer.Table__c          = 'Account';
        transfer.Column__c         = 'Sales_Shop_Class__c';
        transfer.External_Value__c = '03';
        transfer.Internal_Value__c = '03Internal';
        transfers.add(transfer);
        insert transfers;
 
        List<RecordType> rects = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
        if (rects.size() == 0) {
            return;
        }
        Account myAccount2 = new Account(name='NFM012Tst1',AgentCode_Ext__c = 'NFM012Tst1',RecordTypeId = rects[0].Id);
        insert myAccount2;
        NFM012WebService.Deposit Deposit = new NFM012WebService.Deposit();
        NFM012WebService.GeneralData GeneralData = new NFM012WebService.GeneralData();
        Deposit.GeneralData = new NFM012WebService.GeneralData[] { GeneralData };
 
        // Monitoringの設定
        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        Deposit.Monitoring = new NFMUtil.Monitoring();
        Deposit.Monitoring.MessageGroupNumber = nowStr + '21';
 
        // insert
        GeneralData.EndUserNo                              = 'NFM012Tst1';
        GeneralData.UpdateDate                             = String.valueOf(Date.today());
        GeneralData.DepositAmount                          = Decimal.valueOf('10000000');
        System.Test.startTest();
        NFM012WebService.NFM012(Deposit);
        System.Test.stopTest();
        Account[] rslts = [select Management_Code__c, Delete_Flag__c,
                                  Name,
                                  Phone,
                                  Fax,
                                  Postal_Code__c,
                                  Address_Together__c,
                                  Tax_Practice_No__c,
                                  Tax_Practice_Expiration_Date__c,
                                  Business_Authorization_No__c,
                                  Business_Paper_Expiration_Date__c,
                                  Medical_Equipment_Num__c,
                                  Medical_Equipment_Expiration_Date__c,
                                  Registration_Day__c,
                                  Ban_On_Use_Date__c,
                                  Sales_Shop_Class__c
                             from Account where Deposit_Receipt_Finished__c = :GeneralData.DepositAmount];
        System.assertEquals(1, rslts.size());
        if (rslts.size() == 1) {
            System.assertEquals('NFM012Tst1', rslts[0].Management_Code__c);
            System.assertEquals('NFM012Tst1', rslts[0].Name);
            System.assertEquals(False, rslts[0].Delete_Flag__c);
        }
        
        List<BatchIF_Log__c> rowbl = [Select Id, Log__c, ErrorLog__c
                                        from BatchIF_Log__c
                                        where RowDataFlg__c = true
                                        and Type__c = 'NFM012'
                                        order by CreatedDate desc];
        System.assertEquals(1, rowbl.size());
        rowbl[0].retry_cnt__c = 1;
        update rowbl;
        NFM012WebService.execute(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(0, bl[0].retry_cnt__c);
    }
    static testMethod void testNFM012_void() {
      List<BatchIF_Transfer__c> transfers = new List<BatchIF_Transfer__c>();
        BatchIF_Transfer__c transfer = new BatchIF_Transfer__c();
        transfer.Table__c          = 'Account';
        transfer.Column__c         = 'Sales_Shop_Class__c';
        transfer.External_Value__c = '02';
        transfer.Internal_Value__c = '02Internal';
        transfers.add(transfer);
        transfer = new BatchIF_Transfer__c();
        transfer.Table__c          = 'Account';
        transfer.Column__c         = 'Sales_Shop_Class__c';
        transfer.External_Value__c = '03';
        transfer.Internal_Value__c = '03Internal';
        transfers.add(transfer);
        insert transfers;
        // null
        NFM012WebService.NFM012(null);
 
        NFM012WebService.GeneralData GeneralData = new NFM012WebService.GeneralData();
        NFM012WebService.Deposit Deposit = new NFM012WebService.Deposit();
        Deposit.GeneralData = new NFM012WebService.GeneralData[] { GeneralData };
        // Monitoringをセットしない
        NFM012WebService.NFM012(Deposit);
        
        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        Deposit.Monitoring = new NFMUtil.Monitoring();
        Deposit.Monitoring.MessageGroupNumber = nowStr + '01';
        // 必須項目をセットしない
        NFM012WebService.NFM012(Deposit);
 
        Account[] rslts = [select Id from Account];
        System.assertEquals(0, rslts.size());
    }
 
    static testMethod void testNFM012_insert(){
 
      // テストデータ
        List<BatchIF_Transfer__c> transfers = new List<BatchIF_Transfer__c>();
        BatchIF_Transfer__c transfer = new BatchIF_Transfer__c();
        transfer.Table__c          = 'Account';
        transfer.Column__c         = 'Sales_Shop_Class__c';
        transfer.External_Value__c = '02';
        transfer.Internal_Value__c = '02Internal';
        transfers.add(transfer);
        transfer = new BatchIF_Transfer__c();
        transfer.Table__c          = 'Account';
        transfer.Column__c         = 'Sales_Shop_Class__c';
        transfer.External_Value__c = '03';
        transfer.Internal_Value__c = '03Internal';
        transfers.add(transfer);
        insert transfers;
 
        NFM012WebService.GeneralData GeneralData = new NFM012WebService.GeneralData();
        NFM012WebService.GeneralData GeneralData2 = new NFM012WebService.GeneralData();
        NFM012WebService.Deposit Deposit = new NFM012WebService.Deposit();
        Deposit.GeneralData = new NFM012WebService.GeneralData[] { GeneralData, GeneralData2 };
 
        // Monitoringの設定
        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        Deposit.Monitoring = new NFMUtil.Monitoring();
        Deposit.Monitoring.MessageGroupNumber = nowStr + '11';
 
        // insert
        GeneralData.EndUserNo                              = 'NFM012Tst1';
        GeneralData.UpdateDate                             = String.valueOf(Date.today());
        GeneralData.DepositAmount                          = Decimal.valueOf('12345678');
 
        System.Test.startTest();
        NFM012WebService.NFM012(Deposit);
        System.Test.stopTest();
        Account[] rslts = [select Management_Code__c, Delete_Flag__c,
                                  Name,
                                  Phone,
                                  Fax,
                                  Postal_Code__c,
                                  Address_Together__c,
                                  Tax_Practice_No__c,
                                  Tax_Practice_Expiration_Date__c,
                                  Business_Authorization_No__c,
                                  Business_Paper_Expiration_Date__c,
                                  Medical_Equipment_Num__c,
                                  Medical_Equipment_Expiration_Date__c,
                                  Registration_Day__c,
                                  Ban_On_Use_Date__c,
                                  Sales_Shop_Class__c
                             from Account where AgentCode_Ext__c = :GeneralData.EndUserNo];
        System.assertEquals(0, rslts.size());
        List<BatchIF_Log__c> bl = [Select Id, Is_Error__c, Type__c, Log__c, ErrorLog__c from BatchIF_Log__c where Type__c = 'NFM012' and RowDataFlg__c = False order by CreatedDate desc];
        System.assertEquals(true, bl[0].ErrorLog__c.indexOf('NFM012Tst1, FIELD_CUSTOM_VALIDATION_EXCEPTION') >= 0, bl[0].ErrorLog__c);
    }
 
    static testMethod void testNFM012_update(){
 
        List<BatchIF_Transfer__c> transfers = new List<BatchIF_Transfer__c>();
        BatchIF_Transfer__c transfer = new BatchIF_Transfer__c();
        transfer.Table__c          = 'Account';
        transfer.Column__c         = 'Sales_Shop_Class__c';
        transfer.External_Value__c = '02';
        transfer.Internal_Value__c = '02Internal';
        transfers.add(transfer);
        transfer = new BatchIF_Transfer__c();
        transfer.Table__c          = 'Account';
        transfer.Column__c         = 'Sales_Shop_Class__c';
        transfer.External_Value__c = '03';
        transfer.Internal_Value__c = '03Internal';
        transfers.add(transfer);
        insert transfers;
        List<RecordType> rects = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
        if (rects.size() == 0) {
            return;
        }
        Account myAccount2 = new Account(name='NFM012Tst1',AgentCode_Ext__c = 'NFM012Tst1',RecordTypeId = rects[0].Id);
        insert myAccount2;
        NFM012WebService.Deposit Deposit = new NFM012WebService.Deposit();
        NFM012WebService.GeneralData GeneralData = new NFM012WebService.GeneralData();
        Deposit.GeneralData = new NFM012WebService.GeneralData[] { GeneralData };
 
        // Monitoringの設定
        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        Deposit.Monitoring = new NFMUtil.Monitoring();
        Deposit.Monitoring.MessageGroupNumber = nowStr + '21';
 
        // insert
        GeneralData.EndUserNo                              = 'NFM012Tst1';
        GeneralData.UpdateDate                             = String.valueOf(Date.today());
        GeneralData.DepositAmount                          = Decimal.valueOf('10000000');
 
        System.Test.startTest();
        NFM012WebService.NFM012(Deposit);
        System.Test.stopTest();
        Account[] rslts = [select Management_Code__c, Delete_Flag__c,
                                  Name,
                                  Phone,
                                  Fax,
                                  Postal_Code__c,
                                  Address_Together__c,
                                  Tax_Practice_No__c,
                                  Tax_Practice_Expiration_Date__c,
                                  Business_Authorization_No__c,
                                  Business_Paper_Expiration_Date__c,
                                  Medical_Equipment_Num__c,
                                  Medical_Equipment_Expiration_Date__c,
                                  Registration_Day__c,
                                  Ban_On_Use_Date__c,
                                  Sales_Shop_Class__c
                             from Account where Deposit_Receipt_Finished__c = :GeneralData.DepositAmount];
        System.assertEquals(1, rslts.size());
        if (rslts.size() == 1) {
            System.assertEquals('NFM012Tst1', rslts[0].Management_Code__c);
            System.assertEquals('NFM012Tst1', rslts[0].Name);
            System.assertEquals(False, rslts[0].Delete_Flag__c);
        }
    }
}