Li Jun
2022-04-06 fb04e7c01d119c60632b4298d18fd93f3ccb3d79
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
/**
 * 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 InsReportPDFControllerTest {
 
    @TestSetup
    static void makeData(){
        List<String> strList= new List<String>();
        strList.add('Inspection_Report__c');
        strList.add('Document');
        TestDataUtility.CreatePIPolicyConfigurations(strList);
    }
    static testMethod void myUnitTest() {
        Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin];
        // ユーザー作成
        User hpOwner = new User(Test_staff__c = true, Job_Category__c='销售服务' ,LastName = 'hp', FirstName = 'owner', Alias = 'hp', CommunityNickname = 'hpOwner', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
        insert hpOwner;
        // 取引先作成
        RecordType rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        RecordType rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
        Account hp = new Account(RecordTypeId = rectHp.Id, Name = 'InsReportPDFControllerTestHp1', OwnerId = hpOwner.Id);
        insert hp;
        Account section = [Select Id from Account where RecordType.Name = '戦略科室分類 消化科' and ParentId =: hp.Id];
        Account depart = new Account();
        depart.RecordTypeId = rectDpt.Id;
        depart.Name         = '*';
        depart.Department_Name__c  = 'HistoryTestDepart';
        depart.ParentId            = section.Id;
        depart.Department_Class__c = section.Id;
        depart.Hospital__c         = hp.Id;
        insert depart;
        
        Asset ass1 = new Asset(
            AccountId = depart.Id,
            Hospital__c = hp.Id,
            SerialNumber = 'lw0001',
            Name = '测试设备0001:aaaaa'
        );
        Asset ass2 = new Asset(
            AccountId = depart.Id,
            Hospital__c = hp.Id,
            SerialNumber = 'lw0002',
            Name = '测试设备0002:aaaaa'
        );
        insert new Asset[] {ass1, ass2};
        Inspection_Report__c ir = new Inspection_Report__c(Name = '*',
            Hospital__c = hp.Id,
            Reporter__c = hpOwner.id
        );
        insert ir;
        
        Inspection_Item__c ii1 = new Inspection_Item__c(
            Inspection_ReportId__c = ir.Id,
            AssetId__c = ass1.Id
        );
        Inspection_Item__c ii2 = new Inspection_Item__c(
            Inspection_ReportId__c = ir.Id,
            AssetId__c = ass2.Id
        );
        insert new Inspection_Item__c[] {ii1, ii2};
        
        PageReference page = new PageReference('/apex/InsReportPDF?id=' + ir.Id);
        System.Test.setCurrentPage(page);
        InsReportPDFController irpdf = new InsReportPDFController();
        irpdf.init();
        
        System.assertEquals(1, irpdf.getItemCount());
    }
}