/**
|
* 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 {
|
|
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());
|
}
|
}
|