/** * 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 McePDFControllerTest { private static Id pricebookId = ControllerUtil.getStandardPricebook().Id; static Asset createAsset(String input, String accountid, String dcId, String hpId, String serialNo, String prId) { Asset asset = new Asset(); asset.Name = input; asset.AccountId = accountid; asset.Department_Class__c = dcId; asset.Hospital__c = hpId; asset.SerialNumber = serialNo; asset.Product2Id = prId; insert asset; return asset; } static testMethod void myUnitTest() { // 病院を作る Account hospital = new Account(); hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id; hospital.Name = 'test hospital'; insert hospital; // 戦略科室を得る List strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_GI']; // 診療科を作る Account dep = new Account(); dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'].id; dep.Name = 'test dep'; dep.ParentId = strategicDep[0].Id; dep.Department_Class__c = strategicDep[0].Id; dep.Hospital__c = hospital.Id; insert dep; // 製品を作る Product2 productA = new Product2( Name='テスト商品', Maintenance_Price_Year__c = 12000, Manual_Entry__c = false); insert productA; // 価格表エントリを作成する PricebookEntry entry = new PricebookEntry( Pricebook2Id=pricebookId, Product2Id=productA.Id); entry.UnitPrice = 0; entry.IsActive = true; entry.UseStandardPrice = false; entry.CurrencyIsoCode = 'CNY'; entry.Product2Id = productA.Id; insert entry; // 納入機器を作成する Asset asset01 = createAsset('asset01', dep.Id, strategicDep[0].Id, hospital.Id, '00001', productA.Id); Asset asset02 = createAsset('asset02', dep.Id, strategicDep[0].Id, hospital.Id, '00002', productA.Id); Asset asset03 = createAsset('asset03', dep.Id, strategicDep[0].Id, hospital.Id, '00003', productA.Id); Asset asset04 = createAsset('asset04', dep.Id, strategicDep[0].Id, hospital.Id, '00004', productA.Id); Asset asset05 = createAsset('asset05', dep.Id, strategicDep[0].Id, hospital.Id, '00005', productA.Id); // 维修合同を作成する Maintenance_Contract__c contract = new Maintenance_Contract__c(); contract.Name = 'tect contract'; contract.Hospital__c = hospital.Id; contract.Department_Class__c = strategicDep[0].Id; contract.Department__c = dep.Id; insert contract; // 维修合同报价を作成する Maintenance_Contract_Estimate__c contactEsti = new Maintenance_Contract_Estimate__c( Name = 'contract estimate 1', Maintenance_Contract__c = contract.Id, Estimate_Trial_Money__c = 4000, Maintenance_Price__c = 2000, Examination_Price__c = 500, Discount_Percentage__c = 50, Contract_Esti_Start_Date__c = Date.today(), Contract_Start_Date__c = Date.today(), Contract_Range__c = 2, NotUse_Oxygenated_Water__c = true ); insert contactEsti; // 维修合同报价/保有设备を作成する Maintenance_Contract_Asset_Estimate__c mcae1 = new Maintenance_Contract_Asset_Estimate__c( Asset__c = asset01.Id, Estimate_List_Price__c = 100, Maintenance_Price_Month__c = 50, Maintenance_Contract_Estimate__c = contactEsti.Id ); Maintenance_Contract_Asset_Estimate__c mcae2 = new Maintenance_Contract_Asset_Estimate__c( Asset__c = asset02.Id, Estimate_List_Price__c = 200, Maintenance_Price_Month__c = 100, IsNew__c = true, Maintenance_Contract_Estimate__c = contactEsti.Id ); Maintenance_Contract_Asset_Estimate__c mcae3 = new Maintenance_Contract_Asset_Estimate__c( Asset__c = asset03.Id, Estimate_List_Price__c = 300, Maintenance_Price_Month__c = 150, Maintenance_Contract_Estimate__c = contactEsti.Id ); Maintenance_Contract_Asset_Estimate__c mcae4 = new Maintenance_Contract_Asset_Estimate__c( Asset__c = asset04.Id, Estimate_List_Price__c = 400, Maintenance_Price_Month__c = 200, IsNew__c = true, Maintenance_Contract_Estimate__c = contactEsti.Id ); Maintenance_Contract_Asset_Estimate__c mcae5 = new Maintenance_Contract_Asset_Estimate__c( Asset__c = asset05.Id, Estimate_List_Price__c = 500, Maintenance_Price_Month__c = 250, Maintenance_Contract_Estimate__c = contactEsti.Id ); insert new Maintenance_Contract_Asset_Estimate__c[] {mcae1, mcae2, mcae3, mcae4, mcae5}; Apexpages.currentPage().getParameters().put('id', contactEsti.Id); ApexPages.StandardController sc = new ApexPages.StandardController(contactEsti); MaintenanceContractEstimatePDFController mcep = new MaintenanceContractEstimatePDFController(sc); mcep.init(); System.assertEquals(1, mcep.targetObjList.size()); System.assertEquals(7, mcep.targetObjList[0].assetInfoList.size()); } }