@isTest
public with sharing class EquipmentRentalResponseControllerTest {
	
	    final static Integer okStatus = 99;

	    //public Rental_Apply__c rentalApplyselect { get; set; }

		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;
        // 戦略科室を得る
        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;

        //用户
        User wanghaijuan = new User();
        //wanghaijuan.Name = '王海娟';
        //wanghaijuan.Employee_No__c = '12345';
        //insert wanghaijuan;

        // システム管理者=jingliwanghaijuan
        User wanghaijuan_user = new User(Test_staff__c = true);
        wanghaijuan_user.LastName = '_haijuan';
        wanghaijuan_user.FirstName = 'wang';
        wanghaijuan_user.Alias = 'う';
        wanghaijuan_user.Email = 'olympusTest03@sunbridge.com';
        wanghaijuan_user.Username = 'wanghaijuan@sunbridge.com';
        wanghaijuan_user.CommunityNickname = 'wanghaijuan';
        wanghaijuan_user.IsActive = true;
        wanghaijuan_user.EmailEncodingKey = 'ISO-2022-JP';
        wanghaijuan_user.TimeZoneSidKey = 'Asia/Tokyo';
        wanghaijuan_user.LocaleSidKey = 'ja_JP';
        wanghaijuan_user.LanguageLocaleKey = 'ja';
        wanghaijuan_user.ProfileId = System.Label.ProfileId_SystemAdmin;
        wanghaijuan_user.Job_Category__c = '销售推广';
        wanghaijuan_user.Province__c = '上海市';
        wanghaijuan_user.Use_Start_Date__c = Date.today().addMonths(-6);
        insert wanghaijuan_user;

        User sl_test_user = new User(Test_staff__c = true);
        sl_test_user.LastName = '_sl';
        sl_test_user.FirstName = 'test';
        sl_test_user.Alias = 'う';
        sl_test_user.Email = 'olympusTest03@sunbridge.com';
        sl_test_user.Username = 'sl_test_user@sunbridge.com';
        sl_test_user.CommunityNickname = 'sl_test_user';
        sl_test_user.IsActive = true;
        sl_test_user.EmailEncodingKey = 'ISO-2022-JP';
        sl_test_user.TimeZoneSidKey = 'Asia/Tokyo';
        sl_test_user.LocaleSidKey = 'ja_JP';
        sl_test_user.LanguageLocaleKey = 'ja';
        sl_test_user.ProfileId = System.Label.ProfileId_SystemAdmin;
        sl_test_user.Job_Category__c = '销售推广';
        sl_test_user.Province__c = '上海市';
        sl_test_user.Use_Start_Date__c = Date.today().addMonths(-6);
        sl_test_user.JingliApprovalManager__c = wanghaijuan_user.UserId__c;
        insert sl_test_user;

        
        Shipment_address__c SAC = new Shipment_address__c();
        SAC.Name = 'Test办事处地址';
        SAC.Address__c = '北京市朝阳区酒仙桥';
        SAC.Post_Code__c = '137001';
        insert SAC;

        //借出申请bean
        Rental_Apply__c rentalApply =  new Rental_Apply__c();
        rentalApply.Status__c = FixtureUtil.raStatusMap.get(FixtureUtil.RaStatus.Yi_Chu_Ku_Zhi_Shi.ordinal());
        //rentalApply.Shippment_adreess__c = '直送';
        //rentalApply.direct_shippment_address__c = 'test直送';
        rentalApply.delivery_company__c = '嘉里大通';
        rentalApply.Distributor_method__c = '陆运';
        rentalApply.Tracking_Number__c = '23333333';
        rentalApply.Return_to_wh_staff__c = 
        rentalApply.applyUser__c = UserInfo.getUserId();
        //rentalApply.applyUser__c = sl_test_user.ID;
        rentalApply.direct_send__c = '办事处';
        rentalApply.Shipment_address__c = SAC.id;
        rentalApply.direct_shippment_address__c = 'test';
        rentalApply.Request_return_day__c = Date.today() + 30;
        rentalApply.demo_purpose1__c = '其他';
        rentalApply.demo_purpose2__c = '其他';
        //rentalApply.Loaner_centre_mail_address__c = 'hiroki_hotta@olympus.com.cn';
        rentalApply.JingliApprovalManager__c = wanghaijuan.Employee_No__c ;
        rentalApply.SalesManager__c = wanghaijuan.Employee_No__c;
        rentalApply.Response__c = 'test goutongyingda';
        rentalApply.Hope_Lonaer_date_Num__c = 10;
        insert rentalApply;

        EquipmentRentalResponseController.test();// 20211130 ljh
        //画面迁移--沟通应答画面
        PageReference page = new PageReference('/apex/EquipmentRentalResponsePopUp?raid=' + rentalApply.Id + '&type=response2center');
        System.Test.setCurrentPage(page);
        
        EquipmentRentalResponseController controller = new EquipmentRentalResponseController();
        

        //取得借出申请
        Rental_Apply__c rentalApplyselect = [select Id, Name, Account__r.Name, Account__r.Owner.Name, Campaign__r.Name, Loaner_medical_Staff__r.Name, Repair__r.Name, Prepare_Day__c, Demo_purpose1__c, Phone_number__c, 
								  OPD__r.Name, Follow_UP_Opp__r.Name, Calendar_start_date__c, Request_demo_detail__c, Owner.Name , Status__c, RA_Status__c, 
								  Loaner_centre_mail_address__c
                                  ,Response__c
							 from Rental_Apply__c where Id = :rentalApply.Id];

        //初始化
        controller.init();
        
        System.assertEquals(rentalApplyselect.Loaner_centre_mail_address__c, controller.ra.Loaner_centre_mail_address__c);
        //System.assertEquals(wanghaijuan_user.ID, controller.cc.JingliApprovalManager__c);
        System.assertEquals(wanghaijuan_user.NAME, controller.cc.JingliApprovalManager__r.name);
        //System.assertEquals('name01', controller.equipmentSetDetailRecords[0].esd.Asset__r.Product2.Name);

        //发送按钮
        controller.cc.Response__c = 'test goutong';
        controller.cc.ResponseNew__c = 'test';

        //保存后
        controller.saveBtn();

       
    }

    static testMethod void TestToPersen() {
        
        // 病院を作る
        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;
        // 戦略科室を得る
        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;

        //用户
        User wanghaijuan = new User();
        //wanghaijuan.Name = '王海娟';
        //wanghaijuan.Employee_No__c = '12345';
        //insert wanghaijuan;

        // システム管理者=jingliwanghaijuan
        User wanghaijuan_user = new User(Test_staff__c = true);
        wanghaijuan_user.LastName = '_haijuan';
        wanghaijuan_user.FirstName = 'wang';
        wanghaijuan_user.Alias = 'う';
        wanghaijuan_user.Email = 'olympusTest03@sunbridge.com';
        wanghaijuan_user.Username = 'wanghaijuan@sunbridge.com';
        wanghaijuan_user.CommunityNickname = 'wanghaijuan';
        wanghaijuan_user.IsActive = true;
        wanghaijuan_user.EmailEncodingKey = 'ISO-2022-JP';
        wanghaijuan_user.TimeZoneSidKey = 'Asia/Tokyo';
        wanghaijuan_user.LocaleSidKey = 'ja_JP';
        wanghaijuan_user.LanguageLocaleKey = 'ja';
        wanghaijuan_user.ProfileId = System.Label.ProfileId_SystemAdmin;
        wanghaijuan_user.Job_Category__c = '销售推广';
        wanghaijuan_user.Province__c = '上海市';
        wanghaijuan_user.Use_Start_Date__c = Date.today().addMonths(-6);
        insert wanghaijuan_user;

        User sl_test_user = new User(Test_staff__c = true);
        sl_test_user.LastName = '_sl';
        sl_test_user.FirstName = 'test';
        //sl_test_user. = 'test';
        sl_test_user.Alias = 'う';
        sl_test_user.Email = 'olympusTest03@sunbridge.com';
        sl_test_user.Username = 'sl_test_user@sunbridge.com';
        sl_test_user.CommunityNickname = 'sl_test_user';
        sl_test_user.IsActive = true;
        sl_test_user.EmailEncodingKey = 'ISO-2022-JP';
        sl_test_user.TimeZoneSidKey = 'Asia/Tokyo';
        sl_test_user.LocaleSidKey = 'ja_JP';
        sl_test_user.LanguageLocaleKey = 'ja';
        sl_test_user.ProfileId = System.Label.ProfileId_SystemAdmin;
        sl_test_user.Job_Category__c = '销售推广';
        sl_test_user.Province__c = '上海市';
        sl_test_user.Dept__c = '医疗华北营业本部';
        sl_test_user.Use_Start_Date__c = Date.today().addMonths(-6);
        sl_test_user.JingliApprovalManager__c = wanghaijuan_user.UserId__c;
        insert sl_test_user;

        
        Shipment_address__c SAC = new Shipment_address__c();
        SAC.Name = 'Test办事处地址';
        SAC.Address__c = '北京市朝阳区酒仙桥';
        SAC.Post_Code__c = '137001';
        insert SAC;

        //借出申请bean
        Rental_Apply__c rentalApply =  new Rental_Apply__c();
        rentalApply.Status__c = FixtureUtil.raStatusMap.get(FixtureUtil.RaStatus.Yi_Chu_Ku_Zhi_Shi.ordinal());
        //rentalApply.Shippment_adreess__c = '直送';
        //rentalApply.direct_shippment_address__c = 'test直送';
        rentalApply.delivery_company__c = '嘉里大通';
        rentalApply.Distributor_method__c = '陆运';
        rentalApply.Tracking_Number__c = '23333333';
        rentalApply.Return_to_wh_staff__c = 
        //rentalApply.applyUser__c = UserInfo.getUserId();
        rentalApply.applyUser__c = sl_test_user.ID;
        rentalApply.Person_In_Charge__c = sl_test_user.ID;
        rentalApply.direct_send__c = '办事处';
        rentalApply.Shipment_address__c = SAC.id;
        rentalApply.direct_shippment_address__c = 'test';
        rentalApply.Request_return_day__c = Date.today() + 30;
        rentalApply.demo_purpose1__c = '其他';
        rentalApply.demo_purpose2__c = '其他';
        //rentalApply.Loaner_centre_mail_address__c = 'hiroki_hotta@olympus.com.cn';
        rentalApply.JingliApprovalManager__c = wanghaijuan.Employee_No__c ;
        rentalApply.SalesManager__c = wanghaijuan.Employee_No__c;
        rentalApply.Response__c = 'test goutongyingda';
        rentalApply.Hope_Lonaer_date_Num__c = 10;
        insert rentalApply;

        
        //画面迁移--沟通应答画面
        PageReference page = new PageReference('/apex/EquipmentRentalResponsePopUp?raid=' + rentalApply.Id + '&type=response2user');
        System.Test.setCurrentPage(page);
        
        EquipmentRentalResponseController controller = new EquipmentRentalResponseController();
        

        //取得借出申请
        Rental_Apply__c rentalApplyselect = [select Id, Name, Account__r.Name, Account__r.Owner.Name, Campaign__r.Name, Loaner_medical_Staff__r.Name, Repair__r.Name, Prepare_Day__c, Demo_purpose1__c, Phone_number__c, 
								  OPD__r.Name, Follow_UP_Opp__r.Name, Calendar_start_date__c, Request_demo_detail__c, Owner.Name , Status__c, RA_Status__c, 
								  Loaner_centre_mail_address__c
                                  ,Response__c
							 from Rental_Apply__c where Id = :rentalApply.Id];

        //初始化
        controller.init();
        System.assertEquals(rentalApplyselect.Loaner_centre_mail_address__c, controller.ra.Loaner_centre_mail_address__c);
        //System.assertEquals(wanghaijuan_user.ID, controller.cc.JingliApprovalManager__c);
        //System.assertEquals(wanghaijuan_user.NAME, controller.cc.JingliApprovalManager__r.name);
        //System.assertEquals('name01', controller.equipmentSetDetailRecords[0].esd.Asset__r.Product2.Name);

        //发送按钮
        controller.cc.Response__c = 'test goutong';
        //System.assertEquals('name01', controller.ra.Person_In_Charge__c);
        controller.cc.JingliApprovalManager__c = sl_test_user.ID;
        controller.cc.SalesManager__c = sl_test_user.ID;
        controller.cc.BuchangApprovalManager__c = sl_test_user.ID;
        controller.cc.BuchangApprovalManagerSales__c = sl_test_user.ID;
        controller.cc.ZongjianApprovalManager__c = sl_test_user.ID;
        controller.cc.ResponseNew__c = 'test';


        //保存后
        controller.saveBtn();

       
    }

     static testMethod void TestToStrcut() {
        
        // 病院を作る
        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;
        // 戦略科室を得る
        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;

        // システム管理者=jingliwanghaijuan
        User wanghaijuan_user = new User(Test_staff__c = true);
        wanghaijuan_user.LastName = '_haijuan';
        wanghaijuan_user.FirstName = 'wang';
        wanghaijuan_user.Alias = 'う';
        wanghaijuan_user.Email = 'olympusTest03@sunbridge.com';
        wanghaijuan_user.Username = 'wanghaijuan@sunbridge.com';
        wanghaijuan_user.CommunityNickname = 'wanghaijuan';
        wanghaijuan_user.IsActive = true;
        wanghaijuan_user.EmailEncodingKey = 'ISO-2022-JP';
        wanghaijuan_user.TimeZoneSidKey = 'Asia/Tokyo';
        wanghaijuan_user.LocaleSidKey = 'ja_JP';
        wanghaijuan_user.LanguageLocaleKey = 'ja';
        wanghaijuan_user.ProfileId = System.Label.ProfileId_SystemAdmin;
        wanghaijuan_user.Job_Category__c = '销售推广';
        wanghaijuan_user.Province__c = '上海市';
        wanghaijuan_user.Use_Start_Date__c = Date.today().addMonths(-6);
        insert wanghaijuan_user;

        User sl_test_user = new User(Test_staff__c = true);
        sl_test_user.LastName = '_sl';
        sl_test_user.FirstName = 'test';
        //sl_test_user. = 'test';
        sl_test_user.Alias = 'う';
        sl_test_user.Email = 'olympusTest03@sunbridge.com';
        sl_test_user.Username = 'sl_test_user@sunbridge.com';
        sl_test_user.CommunityNickname = 'sl_test_user';
        sl_test_user.IsActive = true;
        sl_test_user.EmailEncodingKey = 'ISO-2022-JP';
        sl_test_user.TimeZoneSidKey = 'Asia/Tokyo';
        sl_test_user.LocaleSidKey = 'ja_JP';
        sl_test_user.LanguageLocaleKey = 'ja';
        sl_test_user.ProfileId = System.Label.ProfileId_SystemAdmin;
        sl_test_user.Job_Category__c = '销售推广';
        sl_test_user.Province__c = '上海市';
        sl_test_user.Dept__c = '医疗华北营业本部';
        sl_test_user.Use_Start_Date__c = Date.today().addMonths(-6);
        sl_test_user.JingliApprovalManager__c = wanghaijuan_user.UserId__c;
        insert sl_test_user;

        
        Shipment_address__c SAC = new Shipment_address__c();
        SAC.Name = 'Test办事处地址';
        SAC.Address__c = '北京市朝阳区酒仙桥';
        SAC.Post_Code__c = '137001';
        insert SAC;

        //借出申请bean
        Rental_Apply__c rentalApply =  new Rental_Apply__c();
        rentalApply.Status__c = FixtureUtil.raStatusMap.get(FixtureUtil.RaStatus.Yi_Chu_Ku_Zhi_Shi.ordinal());
        //rentalApply.Shippment_adreess__c = '直送';
        //rentalApply.direct_shippment_address__c = 'test直送';
        rentalApply.delivery_company__c = '嘉里大通';
        rentalApply.Distributor_method__c = '陆运';
        rentalApply.Tracking_Number__c = '23333333';
        rentalApply.Return_to_wh_staff__c = 
        //rentalApply.applyUser__c = UserInfo.getUserId();
        rentalApply.applyUser__c = sl_test_user.ID;
        rentalApply.Person_In_Charge__c = sl_test_user.ID;
        rentalApply.direct_send__c = '办事处';
        rentalApply.Shipment_address__c = SAC.id;
        rentalApply.direct_shippment_address__c = 'test';
        rentalApply.Request_return_day__c = Date.today() + 30;
        rentalApply.demo_purpose1__c = '其他';
        rentalApply.demo_purpose2__c = '其他';
        //rentalApply.Loaner_centre_mail_address__c = 'hiroki_hotta@olympus.com.cn';
        rentalApply.JingliApprovalManager__c = wanghaijuan_user.ID ;
        rentalApply.SalesManager__c = wanghaijuan_user.ID;
        rentalApply.Response__c = 'test goutongyingda';
        rentalApply.Hope_Lonaer_date_Num__c = 10;
        insert rentalApply;

        
        //画面迁移--沟通应答画面
        PageReference page = new PageReference('/apex/EquipmentRentalResponsePopUp?raid=' + rentalApply.Id + '&type=response2user');
        System.Test.setCurrentPage(page);
        
        EquipmentRentalResponseController controller = new EquipmentRentalResponseController(new ApexPages.StandardController(rentalApply));

    }

}