@isTest
private class lexMaintenanceContractUrlControllerTest {
    static testMethod void testMethod1() {
         List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
       List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
        List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科'];
        Account hospital = new Account();
        hospital.RecordTypeId = rectCo[0].Id;
        hospital.Name         = 'NFM007Testhospital';
        insert hospital;

        // 戦略科室を得る
        List<Account> strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_GI'];
        Account section = new Account();
        section.RecordTypeId = rectSct[0].Id;
        section.Name         = '*';
        section.Department_Class_Label__c = '消化科';
        section.ParentId                  = hospital.Id;
        section.Hospital_Department_Class__c = hospital.Id;
        section.AgentCode_Ext__c = '9999900';
        insert section;

        Account depart = new Account();
        depart.RecordTypeId = rectDpt[0].Id;
        depart.Name         = '*';
        depart.Department_Name__c  = 'NFM007TestDepart';
        depart.ParentId = strategicDep[0].Id;
        depart.Department_Class__c = strategicDep[0].Id;
        depart.Hospital__c = hospital.Id;
        insert depart;

         Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin];
        User MacOwner = new User(Test_staff__c = true, LastName = 'hp1', FirstName = 'owner1', Alias = 'hp', CommunityNickname = 'hpOwner1', Email = 'olympus_hpowner@sunbridge.com',Job_Category__c = '销售服务', Username = 'olympus_hpowner@sunbridge.com1', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
        insert MacOwner;
        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 = depart.Id;
        contract.Service_Contract_Staff__c = MacOwner.Id;
        contract.Payment_Plan_Sum_First__c = 1;
        contract.Status__c = '契約満了';
        contract.Maintenance_Contract_No__c = '11123';
         contract.recordtypeId = 
        Schema.SObjectType.Maintenance_Contract__c.getRecordTypeInfosByDeveloperName().get('NewMaintenance_Contract').getRecordTypeId();
        contract.Not_Upper_limit_reason__c = ' 1';
        contract.Contract_Start_Date__c = Date.newInstance(2021,10,5);   
        contract.Contract_End_Date__c = Date.newInstance(2021,11,1);       
        contract.SalesOfficeCode_selection__c = '北京RC';
        contract.New_Contract_TypeF_Text__c = '续签合同';
        contract.IF_Target_Renew__c='1';
        contract.Contract_Conclusion_Date__c=Date.newInstance(2021,10,5);
        insert contract;
        // String reportId = [select Id from Report where DeveloperName ='Repair_maitenance_list_bottun'].Id;
        Test.StartTest();
        lexMaintenanceContractUrlController.lexCustomNewContract(contract.id);
        lexMaintenanceContractUrlController.initOne(contract.id);
        lexMaintenanceContractUrlController.initTwo(contract.id);
        Test.stopTest();
    }
    static testMethod void testMethod2() {
        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;
        
         Account hospital = new Account();
        hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
        hospital.Name = 'test hospital';
        hospital.Is_Active__c = '有効';
        hospital.Attribute_Type__c = '卫生部';
        hospital.Speciality_Type__c = '综合医院';
        hospital.Grade__c = '一级';
        hospital.OCM_Category__c = 'SLTV';
        hospital.Is_Medical__c = '医疗机构';
        hospital.State_Master__c = al.id;
        hospital.City_Master__c = al2.id;
        hospital.Town__c = '东京';
        insert hospital;
         // 戦略科室を得る
        Account[] strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_OTH'];
        // 診療科を作る
        Account dep = new Account();
        dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_OTH'].id;
        dep.Name = 'test dep';
        dep.AgentCode_Ext__c = '9999998';
        dep.ParentId = strategicDep[0].Id;
        dep.Department_Class__c = strategicDep[0].Id;
        dep.Hospital__c = hospital.Id;
        insert dep;
        Date toDate = Date.today();
         Asset report = new Asset();
        report.AssetMark__c = '耗材';
        report.Asset_Owner__c = '病院資産';
        report.InstallDate = Date.today();
        report.Posting_Date__c = Date.today();
        report.Asset_day__c = Date.today();
        report.SerialNumber = '09K(IOSJA)';
        report.Order_No__c = 'BJ-ET-203044-7';
        report.Name = 'FD-410LR:一次性高频止血';
        report.AccountId = dep.Id;
        report.Department_Class__c = strategicDep[0].Id;
        report.Hospital__c = hospital.Id;
        insert report;
         Repair__c repair1 = new Repair__c();
        repair1.Service_Repair_No__c = 'repair1';
        repair1.Account__c = dep.Id;
        repair1.Department_Class__c = strategicDep[0].Id;
        repair1.Hospital__c = hospital.Id;
        // repair1.Delivered_Product__c = ast1.Id;
        repair1.Repair_List_Price__c = 100;
        repair1.Delivered_Product__c = report.id;
        repair1.Billing_Amount__c = 10;
        repair1.Paid_Amount__c = 1;
        repair1.FSE_ApplyForRepair_time__c = Date.today().addMonths(6);
        repair1.Failure_Occurrence_Date__c = Date.today().addDays(-1);
        repair1.Repair_Returned_To_HP_Date__c = Date.today().addDays(3);
        repair1.Repair_Shipped_Date__c = Date.today().addDays(1);
        
        insert repair1;

         Rental_Apply__c ra = new Rental_Apply__c();
        ra.Rental_Start_Date__c = Date.today().addDays(1);
        ra.Request_return_day__c=Date.today().addDays(5);
        ra.DataMigration_Flag__c = true;
        //ra.demo_purpose2__c = '其他';
        //ra.Person_In_Charge__c = hpOwner.Id;
        //System.runAs(hpOwner) {
            insert ra;
        lexMaintenanceContractUrlController.initThree(repair1.id);
        lexMaintenanceContractUrlController.initFour(ra.id);
    }
    
}