@isTest
private class CreateMaintenanceTaskBatchTest {
    static Maintenance_Contract__c createMaintenanceContract( Account hospital, Account strategicDep, Account dep) {
        Maintenance_Contract__c contract = new Maintenance_Contract__c();
        contract.Name = 'tect contract';
        contract.status__c ='契約';
        contract.Maintenance_Contract_No__c = 'Kami_Contract_No';
        contract.Contract_Conclusion_Date__c = Date.newInstance(2020, 1, 1);
        contract.Hospital__c = hospital.Id;
        contract.Department_Class__c = strategicDep.Id;
        contract.Department__c = dep.Id;
        contract.Contract_Start_Date__c = Date.newInstance(2020, 1, 1);
        contract.Contract_End_Date__c = Date.newInstance(2023, 1, 1);
        contract.SalesOfficeCode_selection__c = '北京RC';
        contract.Service_Contract_Staff__c = UserInfo.getUserId();
        contract.RecordTypeId = Schema.SObjectType.Maintenance_Contract__c.getRecordTypeInfosByDeveloperName().get('VM_Contract').getRecordTypeId();
        insert contract;
        return contract;
    }
    
    static Maintenance_Contract_Asset__c createMiddleTable( Asset asset, Maintenance_Contract__c contract) {
        // 中間テーブルを設ける
        Maintenance_Contract_Asset__c middleTable = new Maintenance_Contract_Asset__c();
        middleTable.Asset__c = asset.Id;
        middleTable.Maintenance_Contract__c = contract.id;
        middleTable.endDateGurantee_changeAcc__c = Date.newInstance(2023, 1, 1);
        middleTable.startDateGurantee_changgeAcc__c = Date.newInstance(2020, 1, 1);
        insert middleTable;
        return middleTable;
    }
    
    static testMethod void testMethod1() {
        // Implement test code
        List<RecordType> rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'];
        if (rectHp.size() == 0) {
            return;
        }
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'];
        if (rectDpt.size() == 0) {
            return;
        }
        Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin];

        User hpOwner = new User(Test_staff__c = true, LastName = 'hp', FirstName = 'owner', 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;
        // 病院作成
        Account hp = new Account(RecordTypeId = rectHp[0].Id, Name = 'hp', OwnerId = hpOwner.Id);
        insert hp;

        Account dc = [select Id, Name, RecordType_DeveloperName__c, Account2__c from Account where ParentId = :hp.Id and RecordType_DeveloperName__c = 'Department_Class_GI'];
        
        // 診療科を作る
        Account 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;


        Asset asset = new Asset();
        asset.Name = 'テスト機器';
        asset.AccountId = dpt1.Id;
        asset.Department_Class__c = dc.Id;
        asset.Hospital__c = hp.Id;
        asset.SerialNumber = 'testserial';
        asset.InstallDate = Date.newInstance(2020, 1, 1);
        asset.Guarantee_period_year__c = 3;
        asset.Posting_Date__c = Date.newInstance(2020, 1, 1);
        insert asset;
        Maintenance_Contract__c mContract = createMaintenanceContract(hp, dc, dpt1);
        
        Maintenance_Contract_Asset__c mca = createMiddleTable( asset, mContract);
        Maintenance_Contract_Asset__c lcaTemp = [select Id,startDate_sum__c,Asset_Status__c,Maintenance_Contract__r.RecordType.DeveloperName,endDateGurantee_Text__c from Maintenance_Contract_Asset__c WHERE Id = :mca.Id];
        System.assertEquals(Date.newInstance(2020, 1, 1), lcaTemp.startDate_sum__c);
        // Maintenance_Task__c mainTask = new Maintenance_Task__c();
        // mainTask.Interval_Start_Date__c = Date.newInstance(2020, 1, 1);
        // mainTask.Interval_End_Date__c   = Date.newInstance(2020, 6, 31);
        // mainTask.Reference_Consumption_Rate__c = 100;
        // mainTask.Maintenance_Consumption_rate__c = 80;
        // mainTask.Maintenance_Contract__c = mContract.Id;
        // mainTask.Is_Generate_Task__c = false;
        // insert mainTask;
        
        System.Test.StartTest();
        Database.executeBatch(new CreateMaintenanceTaskBatch(true));
        System.Test.StopTest();
    }
    static testMethod void testMethod2() {
        // Implement test code
        List<RecordType> rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'];
        if (rectHp.size() == 0) {
            return;
        }
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'];
        if (rectDpt.size() == 0) {
            return;
        }
        Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin];

        User hpOwner = new User(Test_staff__c = true, LastName = 'hp', FirstName = 'owner', 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;
        // 病院作成
        Account hp = new Account(RecordTypeId = rectHp[0].Id, Name = 'hp', OwnerId = hpOwner.Id);
        insert hp;

        Account dc = [select Id, Name, RecordType_DeveloperName__c, Account2__c from Account where ParentId = :hp.Id and RecordType_DeveloperName__c = 'Department_Class_GI'];
        
        // 診療科を作る
        Account 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;


        Asset asset = new Asset();
        asset.Name = 'テスト機器';
        asset.AccountId = dpt1.Id;
        asset.Department_Class__c = dc.Id;
        asset.Hospital__c = hp.Id;
        asset.SerialNumber = 'testserial';
        asset.InstallDate = Date.newInstance(2020, 1, 1);
        asset.Guarantee_period_year__c = 3;
        insert asset;
        Maintenance_Contract__c mContract = createMaintenanceContract(hp, dc, dpt1);
        mContract.currentTotalRepairAmount__c = 300000;
        mContract.previousTotalRepairAmount__c = 2;
        update mContract;
        Maintenance_Contract_Asset__c middleTable = new Maintenance_Contract_Asset__c();
        middleTable.Asset__c = asset.Id;
        middleTable.Maintenance_Contract__c = mContract.id;
        middleTable.endDateGurantee_changeAcc__c = Date.newInstance(2020, 12, 31);
        middleTable.startDateGurantee_changgeAcc__c = Date.newInstance(2017, 1, 1);
        middleTable.Return_Flag__c = false;
        middleTable.ChangeAcc_flag__c = false;
        middleTable.No_discount__c = 1;
        insert middleTable;
        
        // Maintenance_Task__c mainTask = new Maintenance_Task__c();
        // mainTask.Interval_Start_Date__c = Date.newInstance(2017, 1, 1);
        // mainTask.Interval_End_Date__c   = Date.newInstance(2017, 6, 31);
        // mainTask.Reference_Consumption_Rate__c = 100;
        // mainTask.Maintenance_Consumption_rate__c = 80;
        // mainTask.Maintenance_Contract__c = mContract.Id;
        // mainTask.Is_Generate_Task__c = false;
        // insert mainTask;
        
        System.Test.StartTest();
        Maintenance_Contract__c mc1 = [select id,Maintenance_Price_Amount__c from Maintenance_Contract__c where currentTotalRepairAmount__c = 300000 limit 1];
        system.debug('mc1==****==========================================='+mc1.Maintenance_Price_Amount__c);
        Database.executeBatch(new CreateMaintenanceTaskBatch(mContract.Id));
        System.Test.StopTest();
    }
    static testMethod void testMethod3() {
        // Implement test code
        List<RecordType> rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'];
        if (rectHp.size() == 0) {
            return;
        }
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'];
        if (rectDpt.size() == 0) {
            return;
        }
        Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin];

        User hpOwner = new User(Test_staff__c = true, LastName = 'hp', FirstName = 'owner', 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;
        // 病院作成
        Account hp = new Account(RecordTypeId = rectHp[0].Id, Name = 'hp', OwnerId = hpOwner.Id);
        insert hp;

        Account dc = [select Id, Name, RecordType_DeveloperName__c, Account2__c from Account where ParentId = :hp.Id and RecordType_DeveloperName__c = 'Department_Class_GI'];
        
        // 診療科を作る
        Account 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;


        Asset asset = new Asset();
        asset.Name = 'テスト機器';
        asset.AccountId = dpt1.Id;
        asset.Department_Class__c = dc.Id;
        asset.Hospital__c = hp.Id;
        asset.SerialNumber = 'testserial';
        asset.InstallDate = Date.newInstance(2020, 1, 1);
        asset.Guarantee_period_year__c = 3;
        insert asset;
        Maintenance_Contract__c mContract = createMaintenanceContract(hp, dc, dpt1);
        mContract.currentTotalRepairAmount__c = 300;
        mContract.previousTotalRepairAmount__c = 2;
        update mContract;

        Maintenance_Contract_Asset__c middleTable = new Maintenance_Contract_Asset__c();
        middleTable.Asset__c = asset.Id;
        middleTable.Maintenance_Contract__c = mContract.id;
        middleTable.endDateGurantee_changeAcc__c = Date.newInstance(2020, 12, 31);
        middleTable.startDateGurantee_changgeAcc__c = Date.newInstance(2017, 1, 1);
        middleTable.Return_Flag__c = false;
        middleTable.ChangeAcc_flag__c = false;
        middleTable.No_discount__c = 1;
        insert middleTable;
        
        Maintenance_Task__c mainTask = new Maintenance_Task__c();
        mainTask.Interval_Start_Date__c = Date.newInstance(2017, 1, 1);
        mainTask.Interval_End_Date__c   = Date.newInstance(2017, 6, 31);
        mainTask.Reference_Consumption_Rate__c = 100;
        mainTask.Maintenance_Consumption_rate__c = 80;
        mainTask.Maintenance_Contract__c = mContract.Id;
        mainTask.Is_Generate_Task__c = false;
        insert mainTask;
        // task__c task = new task__c();
        // task.RecordTypeId = Schema.SObjectType.task__c.getRecordTypeInfosByDeveloperName().get('MaintenanceTask').getRecordTypeId();
        // task.taskDifferent__c = '主动任务';
        // task.taskStatus__c = '02 接受';
        // task.Maintenance_Contract__c = mContract.id;
        // task.ConfirmDate__c = Date.newInstance(2017, 7, 3);
        // task.Activity_Date__c = Date.newInstance(2017, 7, 3);
        // insert task;
        
        System.Test.StartTest();
        Maintenance_Contract__c mc1 = [select id,Maintenance_Price_Amount__c from Maintenance_Contract__c where currentTotalRepairAmount__c = 300 limit 1];
        system.debug('mc1==****'+mc1.Maintenance_Price_Amount__c);
        Database.executeBatch(new CreateMaintenanceTaskBatch());
        System.Test.StopTest();
    }



    static testMethod  void testMethod4() {

        ControllerUtil.EscapeNFM001Trigger = true;
        ControllerUtil.EscapeMaintenanceContractAfterUpdateTrigger = true;
        StaticParameter.EscapeNFM001Trigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger2 = true;
        StaticParameter.EscapeMaintenanceContractAfterUpdateTrigger = true;


         // Implement test code
        List<RecordType> rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'];
        if (rectHp.size() == 0) {
            return;
        }
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'];
        if (rectDpt.size() == 0) {
            return;
        }
        Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin];

        User hpOwner = new User(Test_staff__c = true, LastName = 'hp', FirstName = 'owner', 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;
        // 病院作成
        Account hp = new Account(RecordTypeId = rectHp[0].Id, Name = 'hp', OwnerId = hpOwner.Id);
        insert hp;

        Account dc = [select Id, Name, RecordType_DeveloperName__c, Account2__c from Account where ParentId = :hp.Id and RecordType_DeveloperName__c = 'Department_Class_GI'];
        
        // 診療科を作る
        Account 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;
        //保有设备
        Asset asset = new Asset();
        asset.Name = 'テスト機器';
        asset.AccountId = dpt1.Id;
        asset.Department_Class__c = dc.Id;
        asset.Hospital__c = hp.Id;
        asset.SerialNumber = 'testserial';
        asset.InstallDate = Date.newInstance(2020, 1, 1);
        asset.Guarantee_period_year__c = 3;
        insert asset;

        //维修合同
        Maintenance_Contract__c contract = new Maintenance_Contract__c();
        contract.Name = 'tect contract';
        contract.Hospital__c = hp.Id;
        contract.Department_Class__c = dc.Id;
        contract.Department__c = dpt1.Id;
        contract.currentTotalRepairAmount__c = 300000;
        contract.previousTotalRepairAmount__c = 2;
        contract.Service_Contract_Staff__c = UserInfo.getUserId();
        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(2020, 12, 31);
        contract.Contract_End_Date__c = Date.newInstance(2023, 12, 31);      
        contract.SalesOfficeCode_selection__c = '北京RC';

        insert contract;

        //多年保
        Maintenance_Contract__c contract2 = new Maintenance_Contract__c();
        contract2.Name = 'tect contract2';
        contract2.status__c ='契約';
        contract2.Maintenance_Contract_No__c = 'VM_Contract_No';
        contract2.Contract_Conclusion_Date__c = Date.newInstance(2020, 1, 1);
        contract2.Hospital__c = hp.Id;
        contract2.Department_Class__c = dc.Id;
        contract2.Department__c = dpt1.Id;
        contract2.currentTotalRepairAmount__c = 300000;
        contract2.previousTotalRepairAmount__c = 2;
        contract2.Contract_Start_Date__c = Date.newInstance(2020, 12, 31);
        contract2.Contract_End_Date__c = Date.newInstance(2023, 12, 31);
        contract2.SalesOfficeCode_selection__c = '北京RC';
        contract2.Service_Contract_Staff__c = UserInfo.getUserId();
        contract2.RecordTypeId = Schema.SObjectType.Maintenance_Contract__c.getRecordTypeInfosByDeveloperName().get('VM_Contract').getRecordTypeId();
        insert contract2;

        Maintenance_Contract_Asset__c middleTable = new Maintenance_Contract_Asset__c();
        middleTable.Asset__c = asset.Id;
        middleTable.Maintenance_Contract__c = contract2.id;
        middleTable.endDateGurantee_changeAcc__c = Date.newInstance(2023, 12, 31);
        middleTable.startDateGurantee_changgeAcc__c = Date.newInstance(2020, 12,31);
        middleTable.Return_Flag__c = false;
        middleTable.ChangeAcc_flag__c = false;
        middleTable.Maintenance_Price_Amount_Text__c = 120000;
        middleTable.No_discount__c = 1;
        insert middleTable;
        
        Maintenance_Task__c mainTask = new Maintenance_Task__c();
        mainTask.Interval_Start_Date__c = Date.newInstance(2016, 6, 31);
        mainTask.Interval_End_Date__c   = Date.newInstance(2021, 6, 31);
        mainTask.Reference_Consumption_Rate__c = 100;
        mainTask.Maintenance_Consumption_rate__c = 80;
        mainTask.Maintenance_Contract__c = contract2.Id;
        mainTask.Is_Generate_Task__c = false;
        insert mainTask;

        Repair__c repair01 = new Repair__c();        
        repair01.Service_Repair_No__c = 'repair01';
        repair01.Status__c = '草案中';
        repair01.Account__c = dpt1.Id;
        repair01.Department_Class__c = dc.Id;
        repair01.Hospital__c = hp.Id;
        repair01.Dealer__c = dpt1.Id;
        repair01.Delivered_Product__c = asset.Id;
        repair01.SERVICE_CONTRACT_JUDEGE_DAY__C = Date.today().addDays( -11);   
        repair01.Failure_Occurrence_Date__c = Date.today().addDays( -2);
        repair01.Repair_Start_Date__c = Date.today().addDays(-9);
        repair01.Repair_Final_Inspection_Date__c = null;
        repair01.Repair_Ordered_Date__c = Date.today();
        repair01.SAP_Transfer_time__c = Date.today();   
        repair01.Maintenance_Contract__c = contract2.Id;
        insert repair01;


        System.Test.StartTest();
        Database.executeBatch(new CreateMaintenanceTaskBatch(true));   
        System.Test.StopTest();        

    }

    static testMethod  void testMethod5() {

        ControllerUtil.EscapeNFM001Trigger = true;
        ControllerUtil.EscapeMaintenanceContractAfterUpdateTrigger = true;
        StaticParameter.EscapeNFM001Trigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger2 = true;
        StaticParameter.EscapeMaintenanceContractAfterUpdateTrigger = true;


         // Implement test code
        List<RecordType> rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'];
        if (rectHp.size() == 0) {
            return;
        }
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'];
        if (rectDpt.size() == 0) {
            return;
        }
        Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin];

        User hpOwner = new User(Test_staff__c = true, LastName = 'hp', FirstName = 'owner', 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;
        // 病院作成
        Account hp = new Account(RecordTypeId = rectHp[0].Id, Name = 'hp', OwnerId = hpOwner.Id);
        insert hp;

        Account dc = [select Id, Name, RecordType_DeveloperName__c, Account2__c from Account where ParentId = :hp.Id and RecordType_DeveloperName__c = 'Department_Class_GI'];
        
        // 診療科を作る
        Account 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;
        //保有设备
        Asset asset = new Asset();
        asset.Name = 'テスト機器';
        asset.AccountId = dpt1.Id;
        asset.Department_Class__c = dc.Id;
        asset.Hospital__c = hp.Id;
        asset.SerialNumber = 'testserial';
        asset.InstallDate = Date.newInstance(2020, 1, 1);
        asset.Guarantee_period_year__c = 3;
        insert asset;

        //维修合同
        Maintenance_Contract__c contract = new Maintenance_Contract__c();
        contract.Name = 'tect contract';
        contract.Hospital__c = hp.Id;
        contract.Department_Class__c = dc.Id;
        contract.Department__c = dpt1.Id;
        contract.Service_Contract_Staff__c = UserInfo.getUserId();
        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.today().addYears(-3).addMonths(6).addDays(-3);
        contract.Contract_End_Date__c = Date.today().addMonths(6).addDays(-3);      
        contract.SalesOfficeCode_selection__c = '北京RC';

        insert contract;

        Maintenance_Contract_Asset__c middleTable = new Maintenance_Contract_Asset__c();
        middleTable.Asset__c = asset.Id;
        middleTable.Maintenance_Contract__c = contract.id;
        middleTable.endDateGurantee_changeAcc__c = Date.newInstance(2023, 12, 31);
        middleTable.startDateGurantee_changgeAcc__c = Date.newInstance(2020, 12,31);
        middleTable.Return_Flag__c = false;
        middleTable.ChangeAcc_flag__c = false;
        middleTable.No_discount__c = 1;
        insert middleTable;

        System.Test.StartTest();
        Database.executeBatch(new CreateMaintenanceTaskBatch(true));   
        System.Test.StopTest();        

    }


   
}