@isTest
private class OFSRepairConsignPDFOuterControllerTest {

    static testMethod void myUnitTest() {
    	// recode type を取得
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科'];
        if (rectSct.size() == 0) {
            return;
        }
        List<RecordType> rectDpt = [select Id, Name from RecordType where IsActive = true and SobjectType = 'Account' and Name IN ('診療科 消化科', '診療科 呼吸科') order by Name desc];
        if (rectDpt.size() == 0) {
            return;
        }

        // insert
        Account company1 = new Account();
        Account company2 = new Account();
        company1.RecordTypeId = rectCo[0].Id;
        company1.Name = '病院テスト1';
        company2.RecordTypeId = rectCo[0].Id;
        company2.Name = '病院テスト2';
        List<Account> hps = new Account[] {company1, company2};
        insert hps;
  
        List<Account> dc1s = [Select Id, Name, Department_Class_Label__c, Sys_Dept_Name_Change_Chk__c from Account where Parent.Id = :company1.Id order by Department_Class_Label__c];
        List<Account> dc2s = [Select Id, Name, Department_Class_Label__c, Sys_Dept_Name_Change_Chk__c from Account where Parent.Id = :company2.Id order by Department_Class_Label__c];

        Account depart1 = new Account();
        depart1.RecordTypeId = rectDpt[0].Id;
        depart1.Name         = '*';
        depart1.Department_Name__c  = '診療科1';
        depart1.ParentId            = dc1s[0].Id;
        depart1.Department_Class__c = dc1s[0].Id;
        depart1.Hospital__c         = company1.Id;
        
        Account depart2 = new Account();
        depart2.RecordTypeId = rectDpt[1].Id;
        depart2.Name         = '*';
        depart2.Department_Name__c  = '診療科2';
        depart2.ParentId            = dc2s[1].Id;
        depart2.Department_Class__c = dc2s[1].Id;
        depart2.Hospital__c         = company2.Id;

        insert new Account[] {depart1, depart2};

        //産品を作成する
        Product2 prd1 = new Product2();
        prd1.ProductCode_Ext__c     = 'HistoryPrd1';
        prd1.ProductCode            = 'HistoryPrd1';
        prd1.Repair_Product_Code__c = 'HistoryPrd1_RP';
        prd1.Name                   = 'HistoryPrd1';
        prd1.Manual_Entry__c        = false;
        
        insert prd1;

        //保有設備を作成する
        Asset ast = new Asset();
        ast.Name                   = '保有設備';
        ast.AccountId              = depart1.Id;
        ast.Department_Class__c    = dc1s[0].Id;
        ast.Hospital__c            = company1.Id;
        //ast.Product2Id             = prd1.Id;
        ast.SerialNumber           = 'HistorySerialNumber';

        insert ast;
        
        // 修理を作成する
        Repair__c repair1 = new Repair__c();
        repair1.Account__c = depart1.Id;
        repair1.Delivered_Product__c = ast.Id;
        repair1.Department_Class__c = ast.Department_Class__c;
        repair1.Hospital__c = ast.Hospital__c;
        
        insert repair1;
        
        // PDFテスト
        Test.startTest();
        PageReference page = new PageReference('/apex/OFSRepairConsignPDF?id=' + repair1.Id);
        System.Test.setCurrentPage(page);
        OFSRepairConsignPDFController irpdf = new OFSRepairConsignPDFController();
        irpdf.init();
        
        page = new PageReference('/apex/OFSRepairConsignPDFOuter?id=' + repair1.Id);
        System.Test.setCurrentPage(page);
        OFSRepairConsignPDFOuterController irpdf2 = new OFSRepairConsignPDFOuterController();
        irpdf2.init();
        
        irpdf2.signStr = 'aaaaabbbbbccccc';
        irpdf2.saveSign();
        irpdf2.savePDF();
        Test.stopTest();
    }
}