高章伟
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
/**
 * This class contains unit tests for validating the behavior of Apex classes
 * and triggers.
 *
 * Unit tests are class methods that verify whether a particular piece
 * of code is working properly. Unit test methods take no arguments,
 * commit no data to the database, and are flagged with the testMethod
 * keyword in the method definition.
 *
 * All test methods in an organization are executed whenever Apex code is deployed
 * to a production organization to confirm correctness, ensure code
 * coverage, and prevent regressions. All Apex classes are
 * required to have at least 75% code coverage in order to be deployed
 * to a production organization. In addition, all triggers must have some code coverage.
 * 
 * The @isTest class annotation indicates this class only contains test
 * methods. Classes defined with the @isTest annotation do not count against
 * the organization size limit for all Apex scripts.
 *
 * See the Apex Language Reference for more information about Testing and Code Coverage.
 */
@isTest
private class SearchVistorControllerTest {
    
    private static String loginId{get;set;}
    private static User u1{get;set;}
    private static User u2{get;set;}
    private static User u3{get;set;}
    private static Account accHP{get;set;}
    private static Account accDepClass{get;set;}
    private static Account accDep{get;set;}
    private static Contact con1{get;set;}
    private static Contact con2{get;set;}
    private static Contact con3{get;set;}
    private static Contact con4{get;set;}
    private static Contact con5{get;set;}
    private static String accDepId{get;set;}
    private static String accDepName{get;set;}
    
    /**
     * 初期処理.
     */
    private static void init() {
        loginId = UserInfo.getUserId();
        
        Profile p = [select id from Profile where id =:System.Label.ProfileId_SystemAdmin];
        
        u3 = new User(Test_staff__c = true);
        u3.LastName = '_サンブリッジ';
        u3.FirstName = 'う';
        u3.Alias = 'うFF';
        u3.Email = 'olympusTest03@sunbridge.com';
        u3.Username = 'olympusTest03@sunbridge.com';
        u3.CommunityNickname = 'う';
        u3.IsActive = true;
        u3.EmailEncodingKey = 'ISO-2022-JP';
        u3.TimeZoneSidKey = 'Asia/Tokyo';
        u3.LocaleSidKey = 'ja_JP';
        u3.LanguageLocaleKey = 'ja';
        u3.ProfileId = p.id;
        u3.Job_Category__c = '支援';
        u3.Province__c = '東京';
        insert u3;
        
        u1 = new User(Test_staff__c = true);
        u1.LastName = '_サンブリッジ';
        u1.FirstName = 'あZZ';
        u1.Alias = 'あ';
        u1.Email = 'olympusTest01@sunbridge.com';
        u1.Username = 'olympusTest01@sunbridge.com';
        u1.CommunityNickname = 'あ';
        u1.IsActive = true;
        u1.EmailEncodingKey = 'ISO-2022-JP';
        u1.TimeZoneSidKey = 'Asia/Tokyo';
        u1.LocaleSidKey = 'ja_JP';
        u1.LanguageLocaleKey = 'ja';
        u1.ProfileId = p.id;
        u1.Job_Category__c = '销售服务';
        u1.Province__c = '東京';
        u1.ManagerId = u3.id;
        insert u1;
        
        u2 = new User(Test_staff__c = true);
        u2.LastName = '_サンブリッジ';
        u2.FirstName = 'いDD';
        u2.Alias = 'い';
        u2.Email = 'olympusTest02@sunbridge.com';
        u2.Username = 'olympusTest02@sunbridge.com';
        u2.CommunityNickname = 'い';
        u2.IsActive = true;
        u2.EmailEncodingKey = 'ISO-2022-JP';
        u2.TimeZoneSidKey = 'Asia/Tokyo';
        u2.LocaleSidKey = 'ja_JP';
        u2.LanguageLocaleKey = 'ja';
        u2.ProfileId = p.id;
        u2.Job_Category__c = '销售推广';
        u2.Province__c = '東京';
        insert u2;
        
        RecordType rtHP = [select id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName =:'HP'];
        RecordType rtDepClass = [select id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName =:'Department_Class_ENT'];           // 耳鼻喉科
        RecordType rtDep = [select id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName =:'Department_ENT'];
        RecordType rtDoc = [select id from RecordType where IsActive = true and SobjectType = 'Contact' and DeveloperName =:'Doctor'];
        
        //Address_Level__c al = [select id from Address_Level__c where Level1_Code__c =:'CN-01'];
        //Address_Level2__c al2 = [select id from Address_Level2__c where Name =:'延庆县'];
        Address_Level__c al = new Address_Level__c();
        al.Name = '東京';
        al.Level1_Code__c = 'CN-99';
        al.Level1_Sys_No__c = '999999';
        insert al;
        
        Address_Level2__c al2 = new Address_Level2__c();
        al2.Level1_Code__c = 'CN-99';
        al2.Level1_Sys_No__c = '999999';
        al2.Level1_Name__c = '東京';
        al2.Name = '渋谷区';
        al2.Level2_Code__c = 'CN-9999';
        al2.Level2_Sys_No__c = '9999999';
        al2.Address_Level__c = al.id;
        insert al2;
        
        accHP = new Account();
        accHP.Name = '病院1';
        accHP.Grade__c = '一般';
        accHP.OCM_Category__c = '一般';
        accHP.Attribute_Type__c = '保険省';
        accHP.Speciality_Type__c = '総合病院';
        accHP.Is_Active__c = '有効';
        accHP.State_Master__c = al.id;
        accHP.City_Master__c = al2.id;
        accHP.RecordTypeId = rtHP.id;
        insert accHP;
        
        accDepClass = new Account();
        accDepClass.Name = '戦略科室分類1';
        accDepClass.Department_Class_Label__c = '耳鼻喉科';
        accDepClass.Hospital_Department_Class__c = accHP.id;
        accDepClass.ParentId = accHP.id;
        accDepClass.RecordTypeId = rtDepClass.id;
        insert accDepClass;
        
        accDep = new Account();
        accDep.Name = '診療科1';
        accDep.Department_Class_Label__c = '診療科1';
        accDep.Hospital__c = accHP.id;
        accDep.ParentId = accDepClass.id;
        accDep.Department_Class__c = accDepClass.id;
        accDep.Department_Name__c = '診療科1';
        accDep.CurrencyIsoCode = 'CNY';
        accDep.RecordTypeId = rtDep.id;
        insert accDep;
        accDepId = accDep.Id;
        accDep = [select Name from Account where Id = :accDep.Id];
        accDepName = accDep.Name;
// 取引先責任者の住所を数式項目に変更の為、当該項目を削除
// 省の参照先は病院の住所になったため、カバレッジテストを行うには
// 所属する病院の賞を変更して実施してください。by 宗像(真)
        List<Contact> conList = new List<Contact>();
        con1 = new Contact();
        con1.LastName = '取引先責任者1';
        con1.FirstName = 'zz1';
        con1.RecordTypeId = rtDoc.id;
        con1.AccountId = accDep.id;
//        con1.State__c = '北京市';
        con2 = new Contact();
        con2.FirstName = 'zz2';
        con2.LastName = '取引先責任者2';
        con2.RecordTypeId = rtDoc.id;
        con2.AccountId = accDep.id;
//        con2.State__c = '北京市';
        con3 = new Contact();
        con3.FirstName = 'zz3';
        con3.LastName = '取引先責任者3';
        con3.RecordTypeId = rtDoc.id;
        con3.AccountId = accDep.id;
//        con3.State__c = '北京市';
        con4 = new Contact();
        con4.FirstName = 'zz4';
        con4.LastName = '取引先責任者4';
        con4.RecordTypeId = rtDoc.id;
        con4.AccountId = accDep.id;
//        con4.State__c = '北京市';
        con5 = new Contact();
        con5.FirstName = 'zz5';
        con5.LastName = '取引先責任者5';
        con5.RecordTypeId = rtDoc.id;
        con5.AccountId = accDep.id;
//        con5.State__c = '北京市';
        conList.add(con1);
        conList.add(con2);
        conList.add(con3);
        conList.add(con4);
        conList.add(con5);
        insert conList;
    }
 
    static testMethod void test01_01() {
        init();
        Apexpages.currentPage().getParameters().put('vp', accDep.id);
        Apexpages.currentPage().getParameters().put('idVa1',con1.Id);
        Apexpages.currentPage().getParameters().put('idVa2',con2.Id);
        Apexpages.currentPage().getParameters().put('idVa3',con3.Id);
        Apexpages.currentPage().getParameters().put('idVa4',con4.Id);
        Apexpages.currentPage().getParameters().put('idVa5',con5.Id);
        System.runAs(u1) {
            SearchVisitorController svc = new SearchVisitorController();
            svc.rc.MyDr_Flg__c = true;
            svc.rc.Search_LastName__c = 'testLastName';
            svc.rc.FirstName = 'testFirstName';
            svc.rc.Account_Visitor_Search__c = accDep.id;
            svc.rc.Type__c = 'test';
            svc.rc.Doctor_Division1__c = 'test';
            svc.regContact();
            
            svc.sc.Search_LastName__c = 'testLastName';
            svc.sc.Search_FirstName__c = 'testFirstName';
            svc.sc.Type__c = 'test';
            svc.sc.Doctor_Division1__c = 'test';
            svc.sc.MyDr_Flg__c = true;
            svc.serContact();
        }
    }
    static testMethod void test01_02() {
        init();
        Apexpages.currentPage().getParameters().put('vp', accDep.id);
        Apexpages.currentPage().getParameters().put('idVa1',con1.Id);
        Apexpages.currentPage().getParameters().put('idVa2',con2.Id);
        Apexpages.currentPage().getParameters().put('idVa3',con3.Id);
        Apexpages.currentPage().getParameters().put('idVa4',con4.Id);
        Apexpages.currentPage().getParameters().put('idVa5',con5.Id);
        
        System.runAs(u1) {
            SearchVisitorController svc = new SearchVisitorController();
            svc.index = '1';
            svc.editVistor();
            svc.rc.MyDr_Flg__c = true;
            svc.rc.Search_LastName__c = 'testLastName';
            svc.rc.FirstName = 'testFirstName';
            svc.rc.Account_Visitor_Search__c = accDep.id;
            svc.rc.Type__c = 'test';
            svc.rc.Doctor_Division1__c = 'test';
            svc.regContact();
            
            svc.sc.Search_LastName__c = 'testLastName';
            svc.sc.Search_FirstName__c = 'testFirstName';
            svc.sc.Type__c = 'test';
            svc.sc.Doctor_Division1__c = 'test';
            svc.sc.MyDr_Flg__c = true;
            svc.serContact();
        }
    }
        static testMethod void test01_03() {
        init();
        Apexpages.currentPage().getParameters().put('vp', accDep.id);
        Apexpages.currentPage().getParameters().put('idVa1',con1.Id);
        Apexpages.currentPage().getParameters().put('idVa2',con2.Id);
        Apexpages.currentPage().getParameters().put('idVa3',con3.Id);
        Apexpages.currentPage().getParameters().put('idVa4',con4.Id);
        Apexpages.currentPage().getParameters().put('idVa5',con5.Id);
        
        System.runAs(u1) {
            SearchVisitorController svc = new SearchVisitorController();
            svc.index = '1';
            svc.updContactP();
            svc.updContactM();
            svc.rc.MyDr_Flg__c = true;
            svc.rc.Search_LastName__c = 'testLastName';
            svc.rc.FirstName = 'testFirstName';
            svc.rc.Account_Visitor_Search__c = accDep.id;
            svc.rc.Type__c = 'test';
            svc.rc.Doctor_Division1__c = 'test';
            svc.regContact();
            svc.clearRC();
            
            svc.sc.Search_LastName__c = 'testLastName';
            svc.sc.Search_FirstName__c = 'testFirstName';
            svc.sc.Type__c = 'test';
            svc.sc.Doctor_Division1__c = 'test';
            svc.sc.MyDr_Flg__c = true;
            svc.serContact();
        }
    }
}