@isTest
private class GuaranteePeriodAlterationControllerTest {

	//测试了GuaranteePeriodAlterationController
	//测试了AssetGuaranteeTimeChange
	//测试了AssetGuaranteeTimeChangeHandler
	
	public static List<RecordType> rectHp;
	public static List<RecordType> rectDpt;
	public static Profile p;
	public static User hpOwner; 
	public static User hpOwner2;
	public static Account hp;
	public static Account dc;
	public static Account dpt;
	public static Account dpt1;
	public static Statu_Achievements__c Sac;

	static void  basicData() {
		rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'];
        if (rectHp.size() == 0) {
            return;
        }
        rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'];
        if (rectDpt.size() == 0) {
            return;
        }
        p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin];

		//FirstName = 'owner',
        hpOwner = new User(Test_staff__c = true, LastName = 'hp', Alias = 'hp', Work_Location__c = '北京', 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;
        hpOwner2 = new User(Test_staff__c = true, LastName = 'hp2', Alias = 'hp2', Work_Location__c = '重庆', CommunityNickname = 'hpOwner2', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner2@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
        insert hpOwner2;
        // 病院作成
        hp = new Account(RecordTypeId = rectHp[0].Id, Name = 'hp', OwnerId = hpOwner.Id);
        hp.FSE_GI_Main_Leader__c = hpOwner.Id;
        hp.FSE_SP_Main_Leader__c = hpOwner2.Id;
        insert hp;

        dc = [select Id, Name, RecordType_DeveloperName__c, Account2__c from Account where ParentId = :hp.Id and RecordType_DeveloperName__c = 'Department_Class_GI'];
        
        // 診療科を作る
        dpt = new Account(RecordTypeId = rectDpt[0].Id);
        dpt.Name         = '*';
        dpt.Department_Name__c  = 'TestDepart';
        dpt.ParentId            = dc.Id;
        dpt.Department_Class__c = dc.Id;
        dpt.Hospital__c         = hp.Id;
        insert dpt;

        dpt1 = new Account(RecordTypeId = rectDpt[0].Id);
        dpt1.Name         = '*';
        dpt1.Department_Name__c  = 'TestDepart1';
        dpt1.ParentId            = dc.Id;
        dpt1.Department_Class__c = dc.Id;
        dpt1.Hospital__c         = hp.Id;
        insert dpt1;

        RecordType rectOpp = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity' and DeveloperName = 'Opportunity' ];
        Opportunity opp = new Opportunity(
               Name='testOpp1',
               StageName='引合',
               CloseDate=Date.today(),
               AccountId=dpt1.Id,
               Sales_Root__c = 'OCM直接販売',
               Competitor__c ='A',
               Click_Close_Date__c = null,
               RecordType = rectOpp
        );
        insert opp;
        //注残
        
        Sac = new Statu_Achievements__c(
            name = 'zhucan_one',
            Opportunity__c = opp.id,
            DeliveryDate__c = Date.today(),
            ContractNO__c = 'ContractNO1',
            ContractAmount__c = 1234
        );
	}
	
	@isTest static void test_method_one() {
		basicData();
        System.Test.startTest();
        insert Sac;


        Asset asset = new Asset();
        asset.Name = 'テスト機器';
        asset.AccountId = dpt.Id;
        asset.Department_Class__c = dc.Id;
        asset.Hospital__c = hp.Id;
        asset.SerialNumber = 'testserial';
        asset.Backorder__c = Sac.Id;
        insert asset;

        //insert ambcDetail;
		Asset asset3 = new Asset();
	    asset3.Name = 'テスト機器3';
	    asset3.AccountId = dpt.Id;
	    asset3.Department_Class__c = dc.Id;
	    asset3.Hospital__c = hp.Id;
	    asset3.SerialNumber = 'testserial3';
	    asset.Backorder__c = Sac.Id;
	    insert asset3;

	    Asset asset1 = new Asset();
	    asset1.Name = 'テスト機器1';
	    asset1.AccountId = dpt.Id;
	    asset1.Department_Class__c = dc.Id;
	    asset1.Hospital__c = hp.Id;
	    asset1.SerialNumber = 'testserial2';
	    asset.Backorder__c = Sac.Id;
	    insert asset1;

	    PageReference page = new PageReference('/apex/AssetGuaranteePeriodAlteration?Statu_AchievementsId=' +Sac.Id);
	    page.setRedirect(true);
	    System.Test.setCurrentPage(page);

	    GuaranteePeriodAlterationController conTest = new GuaranteePeriodAlterationController(new ApexPages.StandardController(Sac));
	    
	    conTest.init();
	    conTest.searchConsumableorderdetails();
	    System.Test.stopTest();
	    // System.assertEquals(1, conTest.ConsumableorderdetailsviewCount);
	    conTest.ambc.Change_status__c = '草案中';
	    // conTest.guaranteePeriodAlterationDetaiRecordsview[0].check= true;
	    conTest.save();

	    conTest.ambc.Change_status__c = '草案中';
	    conTest.ambc.ChangeReason__c = '其他';
	    // conTest.guaranteePeriodAlterationDetaiRecordsview[0].check= true;
	    conTest.save();

	    conTest.ambc.Change_status__c = '草案中';
	    conTest.ambc.ChangeReason__c ='集中采购,未分配到医院';
	    // conTest.guaranteePeriodAlterationDetaiRecordsview[0].check= true;
	    conTest.save();

	    conTest.ambc.Change_status__c = '草案中';
	    conTest.ambc.ChangeReason__c ='集中采购,未分配到医院';
	    conTest.ambc.WarrantyStartDate__c = null;
	    // conTest.guaranteePeriodAlterationDetaiRecordsview[0].check= true;
	    conTest.save();

	    conTest.ambc.Change_status__c = '草案中';
	    conTest.ambc.ChangeReason__c ='集中采购,未分配到医院';
	    conTest.ambc.WarrantyStartDate__c = Date.today();
	    //conTest.guaranteePeriodAlterationDetaiRecordsview[0].check= true;
	    conTest.save();

	    conTest.ambc.Change_status__c = '草案中';
	    conTest.ambc.ChangeReason__c ='集中采购,未分配到医院';
	    conTest.ambc.WarrantyStartDate__c = Date.today();
	    //conTest.guaranteePeriodAlterationDetaiRecordsview[0].check= true;
	    conTest.save();

	    conTest.ambc.Change_status__c = '草案中';
	    conTest.ambc.ChangeReason__c ='集中采购,未分配到医院';
	    conTest.ambc.WarrantyStartDate__c = Date.today();
	    // conTest.guaranteePeriodAlterationDetaiRecordsview[0].check= true;
	    conTest.uploadingAttachment();
	    conTest.save();
	 	Integer i=conTest.ConsumableorderdetailsCount;
	 	conTest.uploadingAttachment();
	 	conTest.uploadingAttachmentLightning();
	 	conTest.uploadingAttachment();
	 	conTest.Id=null;
	 	conTest.save();


	}
	
	@isTest static void test_method_two() {
		basicData();

		System.Test.startTest();
        insert Sac;


        Asset asset = new Asset();
        asset.Name = 'テスト機器';
        asset.AccountId = dpt.Id;
        asset.Department_Class__c = dc.Id;
        asset.Hospital__c = hp.Id;
        asset.SerialNumber = 'testserial';
        asset.Backorder__c = Sac.Id;
        insert asset;

        //insert ambcDetail;
		Asset asset3 = new Asset();
	    asset3.Name = 'テスト機器3';
	    asset3.AccountId = dpt.Id;
	    asset3.Department_Class__c = dc.Id;
	    asset3.Hospital__c = hp.Id;
	    asset3.SerialNumber = 'testserial3';
	    asset.Backorder__c = Sac.Id;
	    insert asset3;

	    Asset asset1 = new Asset();
	    asset1.Name = 'テスト機器1';
	    asset1.AccountId = dpt.Id;
	    asset1.Department_Class__c = dc.Id;
	    asset1.Hospital__c = hp.Id;
	    asset1.SerialNumber = 'testserial2';
	    asset.Backorder__c = Sac.Id;
	    insert asset1;

	    GuaranteePeriodAlterationApplication__c gpaa = new GuaranteePeriodAlterationApplication__c();
	    gpaa.GpaaStatu_Achievements__c = Sac.Id;
	    gpaa.WarrantyStartDate__c = Date.today();
	    gpaa.ChangeReason__c = '其他';
	    gpaa.ChangeReason_text__c = 'test20190627';
	    gpaa.Change_status__c = '草案中';
	    insert gpaa ;
	    PageReference page = new PageReference('/apex/AssetGuaranteePeriodAlteration?Id='+gpaa.Id+'&KeyWords=Redirect');
	    page.setRedirect(true);
	    System.Test.setCurrentPage(page);

	    GuaranteePeriodAlterationController conTest = new GuaranteePeriodAlterationController(new ApexPages.StandardController(Sac));
	    
	    conTest.init();
	    conTest.searchConsumableorderdetails();
	    System.Test.stopTest();
	    // System.assertEquals(1, conTest.ConsumableorderdetailsviewCount);
	    conTest.ambc.Change_status__c = '草案中';
	    //conTest.ambc.AccountField__c = dpt1.Id;
	    // conTest.guaranteePeriodAlterationDetaiRecordsview[0].check= true;
	    conTest.save();
		//GuaranteePeriodAlterationApplication__c
	}

	@isTest static void test_method_three() {
		basicData();

		System.Test.startTest();
        insert Sac;


        Asset asset = new Asset();
        asset.Name = 'テスト機器';
        asset.AccountId = dpt.Id;
        asset.Department_Class__c = dc.Id;
        asset.Hospital__c = hp.Id;
        asset.SerialNumber = 'testserial';
        asset.Backorder__c = Sac.Id;
        insert asset;

        //insert ambcDetail;
		Asset asset3 = new Asset();
	    asset3.Name = 'テスト機器3';
	    asset3.AccountId = dpt.Id;
	    asset3.Department_Class__c = dc.Id;
	    asset3.Hospital__c = hp.Id;
	    asset3.SerialNumber = 'testserial3';
	    asset.Backorder__c = Sac.Id;
	    insert asset3;

	    Asset asset1 = new Asset();
	    asset1.Name = 'テスト機器1';
	    asset1.AccountId = dpt.Id;
	    asset1.Department_Class__c = dc.Id;
	    asset1.Hospital__c = hp.Id;
	    asset1.SerialNumber = 'testserial2';
	    asset.Backorder__c = Sac.Id;
	    insert asset1;

	    GuaranteePeriodAlterationApplication__c gpaa = new GuaranteePeriodAlterationApplication__c();
	    gpaa.GpaaStatu_Achievements__c = Sac.Id;
	    gpaa.WarrantyStartDate__c = Date.today();
	    gpaa.ChangeReason__c = '其他';
	    gpaa.ChangeReason_text__c = 'test20190627';
	    gpaa.Change_status__c = '草案中';
	    insert gpaa ;

	    GuaranteePeriodAlterationDetail__c gpaaDetail = new GuaranteePeriodAlterationDetail__c();
	    gpaaDetail.GuaranteePeriodAlteration__c = gpaa.Id;
	    gpaaDetail.Asset__c = asset1.Id;
	    insert gpaaDetail;
	    PageReference page = new PageReference('/apex/AssetGuaranteePeriodAlteration?Id='+gpaa.Id+'&KeyWords=Redirect');
	    page.setRedirect(true);
	    System.Test.setCurrentPage(page);

	    GuaranteePeriodAlterationController conTest = new GuaranteePeriodAlterationController(new ApexPages.StandardController(Sac));
	    
	    conTest.init();
	    conTest.searchConsumableorderdetails();
	    System.Test.stopTest();
	    // System.assertEquals(2, conTest.ConsumableorderdetailsviewCount);
	    conTest.ambc.Change_status__c = '草案中';
	    //conTest.ambc.AccountField__c = dpt1.Id;
	    // conTest.guaranteePeriodAlterationDetaiRecordsview[0].check= true;
	    conTest.save();
	    conTest.setEditAble();
	    conTest.Sorder();
	    conTest.DelConsumable();
		//GuaranteePeriodAlterationApplication__c
	}


	@isTest static void test_method_four() {
		basicData();

		System.Test.startTest();
        insert Sac;


        Asset asset = new Asset();
        asset.Name = 'テスト機器';
        asset.AccountId = dpt.Id;
        asset.Department_Class__c = dc.Id;
        asset.Hospital__c = hp.Id;
        asset.SerialNumber = 'testserial';
        asset.Backorder__c = Sac.Id;
        insert asset;

        //insert ambcDetail;
		Asset asset3 = new Asset();
	    asset3.Name = 'テスト機器3';
	    asset3.AccountId = dpt.Id;
	    asset3.Department_Class__c = dc.Id;
	    asset3.Hospital__c = hp.Id;
	    asset3.SerialNumber = 'testserial3';
	    asset.Backorder__c = Sac.Id;
	    insert asset3;

	    Asset asset1 = new Asset();
	    asset1.Name = 'テスト機器1';
	    asset1.AccountId = dpt.Id;
	    asset1.Department_Class__c = dc.Id;
	    asset1.Hospital__c = hp.Id;
	    asset1.SerialNumber = 'testserial2';
	    asset.Backorder__c = Sac.Id;
	    insert asset1;

	    GuaranteePeriodAlterationApplication__c gpaa = new GuaranteePeriodAlterationApplication__c();
	    gpaa.GpaaStatu_Achievements__c = Sac.Id;
	    gpaa.WarrantyStartDate__c = Date.today();
	    gpaa.ChangeReason__c = '其他';
	    gpaa.ChangeReason_text__c = 'test20190627';
	    gpaa.Change_status__c = '驳回';
	    insert gpaa ;
	    PageReference page = new PageReference('/apex/AssetGuaranteePeriodAlteration?Id='+gpaa.Id+'&KeyWords=Redirect');
	    page.setRedirect(true);
	    System.Test.setCurrentPage(page);

	    GuaranteePeriodAlterationController conTest = new GuaranteePeriodAlterationController(new ApexPages.StandardController(Sac));
	    
	    conTest.init();
	    conTest.searchConsumableorderdetails();
	    System.Test.stopTest();
	    // System.assertEquals(1, conTest.ConsumableorderdetailsviewCount);
	    //conTest.ambc.Change_status__c = '草案中';
	    //conTest.ambc.AccountField__c = dpt1.Id;
	    // conTest.guaranteePeriodAlterationDetaiRecordsview[0].check= true;
	    conTest.save();
	    conTest.backOrder();
		//GuaranteePeriodAlterationApplication__c
	}


	@isTest static void test_method_five() {
		basicData();

		System.Test.startTest();
        insert Sac;


        Asset asset = new Asset();
        asset.Name = 'テスト機器';
        asset.AccountId = dpt.Id;
        asset.Department_Class__c = dc.Id;
        asset.Hospital__c = hp.Id;
        asset.SerialNumber = 'testserial';
        asset.Backorder__c = Sac.Id;
        insert asset;

        //insert ambcDetail;
		Asset asset3 = new Asset();
	    asset3.Name = 'テスト機器3';
	    asset3.AccountId = dpt.Id;
	    asset3.Department_Class__c = dc.Id;
	    asset3.Hospital__c = hp.Id;
	    asset3.SerialNumber = 'testserial3';
	    asset.Backorder__c = Sac.Id;
	    insert asset3;

	    Asset asset1 = new Asset();
	    asset1.Name = 'テスト機器1';
	    asset1.AccountId = dpt.Id;
	    asset1.Department_Class__c = dc.Id;
	    asset1.Hospital__c = hp.Id;
	    asset1.SerialNumber = 'testserial2';
	    asset.Backorder__c = Sac.Id;
	    insert asset1;

	    GuaranteePeriodAlterationApplication__c gpaa = new GuaranteePeriodAlterationApplication__c();
	    gpaa.GpaaStatu_Achievements__c = Sac.Id;
	    gpaa.WarrantyStartDate__c = Date.today();
	    gpaa.ChangeReason__c = '集中采购,未分配到医院';
	    gpaa.ChangeReason_text__c = 'test20190627';
	    gpaa.Change_status__c = '驳回';
	    insert gpaa ;
	    PageReference page = new PageReference('/apex/AssetGuaranteePeriodAlteration?Id='+gpaa.Id+'&KeyWords=Redirect');
	    page.setRedirect(true);
	    System.Test.setCurrentPage(page);

	    GuaranteePeriodAlterationController conTest = new GuaranteePeriodAlterationController(new ApexPages.StandardController(Sac));
	    
	    conTest.init();
	    conTest.searchConsumableorderdetails();
	    System.Test.stopTest();
	    // System.assertEquals(1, conTest.ConsumableorderdetailsviewCount);
	    //conTest.ambc.Change_status__c = '草案中';
	    //conTest.ambc.AccountField__c = dpt1.Id;
	    // conTest.guaranteePeriodAlterationDetaiRecordsview[0].check= true;
	    conTest.save();
	    conTest.Sorder();
		//GuaranteePeriodAlterationApplication__c
	}

	@isTest static void test_method_six() {
		basicData();

		System.Test.startTest();
        insert Sac;


        Asset asset = new Asset();
        asset.Name = 'テスト機器';
        asset.AccountId = dpt.Id;
        asset.Department_Class__c = dc.Id;
        asset.Hospital__c = hp.Id;
        asset.SerialNumber = 'testserial';
        asset.Backorder__c = Sac.Id;
        insert asset;

        //insert ambcDetail;
		Asset asset3 = new Asset();
	    asset3.Name = 'テスト機器3';
	    asset3.AccountId = dpt.Id;
	    asset3.Department_Class__c = dc.Id;
	    asset3.Hospital__c = hp.Id;
	    asset3.SerialNumber = 'testserial3';
	    asset3.Backorder__c = Sac.Id;
	    insert asset3;

	    Asset asset1 = new Asset();
	    asset1.Name = 'テスト機器1';
	    asset1.AccountId = dpt.Id;
	    asset1.Department_Class__c = dc.Id;
	    asset1.Hospital__c = hp.Id;
	    asset1.SerialNumber = 'testserial2';
	    asset1.Backorder__c = Sac.Id;
	    insert asset1;

	    Repair__c repair01 = new Repair__c();
        repair01.Account__c = dpt.Id;
        repair01.Department_Class__c = dc.Id;
        repair01.Hospital__c = hp.Id;
        repair01.Delivered_Product__c = asset.Id;
        repair01.SERVICE_CONTRACT_JUDEGE_DAY__C = Date.today().addDays(0);  // 维修合同判断日がサービス契約の中間辺りの日付
        repair01.FSE_Work_Location__c = '上海';
		repair01.AWS_Data_Id__c = '123456';
        insert repair01;

        QIS_Report__c qis = new QIS_Report__c();
        qis.nonyushohin__c = asset.Id;
        qis.Hospital__c = hp.Id;
        qis.RC__c = UserInfo.getUserId();
        qis.Department_Class__c = dc.Id;
        qis.Hospital_Department__c = dpt.Id;
        qis.Damage_For_Doc_Or_Pat__c = '有';
        qis.Relation_With_The_Problem__c = '有可能';
        qis.Report_For_Goz__c = '不知道';
        insert qis;

	    GuaranteePeriodAlterationApplication__c gpaa = new GuaranteePeriodAlterationApplication__c();
	    gpaa.GpaaStatu_Achievements__c = Sac.Id;
	    gpaa.WarrantyStartDate__c = Date.today();
	    gpaa.ChangeReason__c = '集中采购,未分配到医院';
	    gpaa.ChangeReason_text__c = 'test20190627';
	    gpaa.Change_status__c = '驳回';
	    insert gpaa ;

	    GuaranteePeriodAlterationDetail__c gpaaDetail = new GuaranteePeriodAlterationDetail__c();
	    gpaaDetail.GuaranteePeriodAlteration__c = gpaa.Id;
	    gpaaDetail.Asset__c = asset1.Id;
	    insert gpaaDetail;
	    PageReference page = new PageReference('/apex/AssetGuaranteePeriodAlteration?Id='+gpaa.Id+'&KeyWords=Redirect');
	    page.setRedirect(true);
	    System.Test.setCurrentPage(page);

	    GuaranteePeriodAlterationController conTest = new GuaranteePeriodAlterationController(new ApexPages.StandardController(Sac));
	    
	    conTest.init();
	    conTest.searchConsumableorderdetails();
	    System.Test.stopTest();
	    // System.assertEquals(3, conTest.ConsumableorderdetailsviewCount);
	    conTest.guaranteePeriodAlterationDetaiRecordsview[0].check= true;
	    // conTest.guaranteePeriodAlterationDetaiRecordsview[1].check= true;
	    // conTest.guaranteePeriodAlterationDetaiRecordsview[2].check= true;
	    conTest.save();
	    conTest.refreshFile();
	    //conTest.find_QIS_Repair(gpaa.Id);
	    //conTest.Sorder();
		//GuaranteePeriodAlterationApplication__c
	}
	@isTest static void test_method_six2() {
		basicData();

		System.Test.startTest();
        insert Sac;


        Asset asset = new Asset();
        asset.Name = 'テスト機器';
        asset.AccountId = dpt.Id;
        asset.Department_Class__c = dc.Id;
        asset.Hospital__c = hp.Id;
        asset.SerialNumber = 'testserial';
        asset.Backorder__c = Sac.Id;
        insert asset;

        //insert ambcDetail;
		Asset asset3 = new Asset();
	    asset3.Name = 'テスト機器3';
	    asset3.AccountId = dpt.Id;
	    asset3.Department_Class__c = dc.Id;
	    asset3.Hospital__c = hp.Id;
	    asset3.SerialNumber = 'testserial3';
	    asset3.Backorder__c = Sac.Id;
	    insert asset3;

	    Asset asset1 = new Asset();
	    asset1.Name = 'テスト機器1';
	    asset1.AccountId = dpt.Id;
	    asset1.Department_Class__c = dc.Id;
	    asset1.Hospital__c = hp.Id;
	    asset1.SerialNumber = 'testserial2';
	    asset1.Backorder__c = Sac.Id;
	    insert asset1;

	    Repair__c repair01 = new Repair__c();
        repair01.Account__c = dpt.Id;
        repair01.Department_Class__c = dc.Id;
        repair01.Hospital__c = hp.Id;
        repair01.Delivered_Product__c = asset.Id;
        repair01.SERVICE_CONTRACT_JUDEGE_DAY__C = Date.today().addDays(0);  // 维修合同判断日がサービス契約の中間辺りの日付
        repair01.FSE_Work_Location__c = '上海';
		repair01.AWS_Data_Id__c = '123456';
        insert repair01;

        QIS_Report__c qis = new QIS_Report__c();
        qis.nonyushohin__c = asset.Id;
        qis.Hospital__c = hp.Id;
        qis.RC__c = UserInfo.getUserId();
        qis.Department_Class__c = dc.Id;
        qis.Hospital_Department__c = dpt.Id;
        qis.Damage_For_Doc_Or_Pat__c = '有';
        qis.Relation_With_The_Problem__c = '有可能';
        qis.Report_For_Goz__c = '不知道';
        insert qis;

	    GuaranteePeriodAlterationApplication__c gpaa = new GuaranteePeriodAlterationApplication__c();
	    gpaa.GpaaStatu_Achievements__c = Sac.Id;
	    gpaa.WarrantyStartDate__c = Date.today();
	    gpaa.ChangeReason__c = '集中采购,未分配到医院';
	    gpaa.ChangeReason_text__c = 'test20190627';
	    gpaa.Change_status__c = '驳回';
	    insert gpaa ;

	    GuaranteePeriodAlterationDetail__c gpaaDetail = new GuaranteePeriodAlterationDetail__c();
	    gpaaDetail.GuaranteePeriodAlteration__c = gpaa.Id;
	    gpaaDetail.Asset__c = asset1.Id;
	    insert gpaaDetail;
	    PageReference page = new PageReference('/apex/AssetGuaranteePeriodAlteration?KeyWords=Redirect&Statu_AchievementsId='+gpaa.Id);
	    page.setRedirect(true);
	    System.Test.setCurrentPage(page);

	    GuaranteePeriodAlterationController conTest = new GuaranteePeriodAlterationController(new ApexPages.StandardController(Sac));
	    
	    conTest.save();
	    System.Test.stopTest();
	}
	@isTest static void test_method_seven() {
		basicData();

		System.Test.startTest();
        insert Sac;


        Asset asset = new Asset();
        asset.Name = 'テスト機器';
        asset.AccountId = dpt.Id;
        asset.Department_Class__c = dc.Id;
        asset.Hospital__c = hp.Id;
        asset.SerialNumber = 'testserial';
        asset.Backorder__c = Sac.Id;
        insert asset;

        //insert ambcDetail;
		Asset asset3 = new Asset();
	    asset3.Name = 'テスト機器3';
	    asset3.AccountId = dpt.Id;
	    asset3.Department_Class__c = dc.Id;
	    asset3.Hospital__c = hp.Id;
	    asset3.SerialNumber = 'testserial3';
	    asset3.Backorder__c = Sac.Id;
	    insert asset3;

	    Asset asset1 = new Asset();
	    asset1.Name = 'テスト機器1';
	    asset1.AccountId = dpt.Id;
	    asset1.Department_Class__c = dc.Id;
	    asset1.Hospital__c = hp.Id;
	    asset1.SerialNumber = 'testserial2';
	    asset1.Backorder__c = Sac.Id;
	    insert asset1;

	    GuaranteePeriodAlterationApplication__c gpaa = new GuaranteePeriodAlterationApplication__c();
	    gpaa.GpaaStatu_Achievements__c = Sac.Id;
	    gpaa.WarrantyStartDate__c = Date.today();
	    gpaa.ChangeReason__c = '其他';
	    gpaa.ChangeReason_text__c = 'test20190627';
	    gpaa.Change_status__c = '已提交';
	    insert gpaa ;
	    //gpaa.Change_status__c = '申请中';

	    GuaranteePeriodAlterationDetail__c gpaaDetail = new GuaranteePeriodAlterationDetail__c();
	    gpaaDetail.GuaranteePeriodAlteration__c = gpaa.Id;
	    gpaaDetail.Asset__c = asset1.Id;
	    insert gpaaDetail;

	    gpaa.Change_status__c = '批准';
	    update gpaa;
	}		
	
}