@isTest
private class AssetTableControllerTest {
	
	@isTest 
	static void test_method_one() {
        ControllerUtil.EscapeNFM001Trigger = true;
		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', 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;
        // 取引先作成
        List<RecordType> rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectHp.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;
        }
        Account hp1 = new Account(RecordTypeId = rectHp[0].Id, Name = 'testHp1', OwnerId = hpOwner.Id);
        insert hp1;

        List<Account> dc1s = [Select Id, Name, Department_Class_Label__c from Account where Parent.Id = :hp1.Id and Department_Class_Label__c in ('消化科', '呼吸科') order by Department_Class_Label__c];
        
        Account depart1 = new Account();
        depart1.RecordTypeId = rectDpt[1].Id;
        depart1.Name         = '*';
        depart1.Department_Name__c  = '診療科1';
        depart1.ParentId            = dc1s[0].Id;
        depart1.Department_Class__c = dc1s[0].Id;
        depart1.Hospital__c         = hp1.Id;
        
        insert depart1;
        
        Product2 prd1 = new Product2();
        prd1.ProductCode_Ext__c     = 'Prd1';
        prd1.ProductCode            = 'Prd1';
        prd1.Repair_Product_Code__c = 'Prd1_RP';
        prd1.Name                   = 'Prd1';
        prd1.Manual_Entry__c        = false;
        prd1.Category3__c = '';
        prd1.Category4__c = 'CV';
        
        insert prd1;
        
        Asset ast1 = new Asset();
        ast1.Name                   = '保有設備1';
        ast1.Hospital__c            = hp1.Id;
        ast1.Department_Class__c    = dc1s[0].Id;
        ast1.AccountId              = depart1.Id;
        ast1.Product2Id             = prd1.Id;
        ast1.SerialNumber           = 'SerialNumber1';
        ast1.Guarantee_period_for_products__c = Date.today();
        ast1.InstallDate                      = Date.today();
        
        //insert ast1;
        
        Asset ast2 = new Asset();
        ast2.Name                   = '保有設備2';
        ast2.Hospital__c            = hp1.Id;
        ast2.Department_Class__c    = dc1s[0].Id;
        ast2.AccountId              = depart1.Id;
        ast2.Product2Id             = prd1.Id;
        ast2.SerialNumber           = 'SerialNumber2';
        ast2.Guarantee_period_for_products__c = Date.today();
        ast2.InstallDate                      = Date.today();
        
        //insert ast2;
        
        
        System.Test.startTest();
        insert new Asset[] {ast1,ast2};
        System.Test.stopTest();
        
        PageReference page = new PageReference('/apex/AssetTable');
        System.Test.setCurrentPage(page);
        AssetTableController controller = new AssetTableController();
        // 初始化测试
        controller.init();
        
        System.assertEquals(2, controller.oppRecords.size());
        
        // 排序测试
        controller.sortKey = '1';
        controller.sortTable();
        controller.sortTable();
        
        //// 检索测试
        controller.accSearch = 'testHp1';
        controller.text = 'S:SerialNumber';
        controller.condition = 'equals';
        controller.value = 'SerialNumber2';
        controller.searchOpp();
        controller.condition = 'contains';
        controller.value = 'SerialNumber';
        controller.searchOpp();
        
        System.assertEquals(2, controller.oppRecords.size());
        
     
	}
	
	//@isTest 
	//static void test_method_two() {
	//	// Implement test code
	//}
	
}