@isTest private class AssetModifyBelongsControllerTest { static testMethod void test_method_one() { // Implement test code List rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP']; if (rectHp.size() == 0) { return; } List 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; User hpOwner2 = new User(Test_staff__c = true, LastName = 'hp2', FirstName = 'owner', 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; // 病院作成 Account 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; Account dc = [select Id, Name, RecordType_DeveloperName__c, Account2__c from Account where ParentId = :hp.Id and RecordType_DeveloperName__c = 'Department_Class_GI']; // 診療科を作る Account 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; 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 = dpt.Id; asset.Department_Class__c = dc.Id; asset.Hospital__c = hp.Id; asset.SerialNumber = 'testserial'; insert asset; //AssetModifyBelongsChange__c ambc = new AssetModifyBelongsChange__c(); //ambc.rawAccount__c = dpt.Id; //ambc.AccountField__c = dpt1.Id; //ambc.Change_status__c = '已提交'; //insert ambc; //AssetModifyBelongsChangeDetail__c ambcDetail = new AssetModifyBelongsChangeDetail__c(); //ambcDetail.ChangeAndChangeDetail__c = ambc.Id; //ambcDetail.Asset__c = asset.Id; //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'; 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'; insert asset1; PageReference page = new PageReference('/apex/AssetModifyBelongs?accountId=' +dpt.Id); page.setRedirect(true); System.Test.setCurrentPage(page); AssetModifyBelongsController conTest = new AssetModifyBelongsController(new ApexPages.StandardController(dpt)); System.Test.startTest(); conTest.init(); conTest.searchConsumableorderdetails(); System.assertEquals(3, conTest.ConsumableorderdetailsviewCount); conTest.ambc.Change_status__c = '草案中'; conTest.ambc.AccountField__c = dpt1.Id; conTest.assetModifyBelongsChangeDetailRecordsview[0].check= true; conTest.save(); } static testMethod void test_method_two() { List rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP']; if (rectHp.size() == 0) { return; } List 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; User hpOwner2 = new User(Test_staff__c = true, LastName = 'hp2', FirstName = 'owner', 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; // 病院作成 Account 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; Account dc = [select Id, Name, RecordType_DeveloperName__c, Account2__c from Account where ParentId = :hp.Id and RecordType_DeveloperName__c = 'Department_Class_GI']; // 診療科を作る Account 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; 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 = dpt.Id; asset.Department_Class__c = dc.Id; asset.Hospital__c = hp.Id; asset.SerialNumber = 'testserial'; insert asset; AssetModifyBelongsChange__c ambc = new AssetModifyBelongsChange__c(); ambc.rawAccount__c = dpt.Id; ambc.AccountField__c = dpt1.Id; ambc.Change_status__c = '草案中'; insert ambc; AssetModifyBelongsChangeDetail__c ambcDetail = new AssetModifyBelongsChangeDetail__c(); ambcDetail.ChangeAndChangeDetail__c = ambc.Id; ambcDetail.Asset__c = asset.Id; 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'; 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'; insert asset1; PageReference page = new PageReference('/apex/AssetModifyBelongs?Id=' +ambc.Id); page.setRedirect(true); System.Test.setCurrentPage(page); AssetModifyBelongsController conTest = new AssetModifyBelongsController(new ApexPages.StandardController(dpt)); System.Test.startTest(); conTest.init(); //conTest.searchConsumableorderdetails(); System.assertEquals(1, conTest.ConsumableorderdetailsviewCount); //conTest.ambc.Change_status__c = '草案中'; //conTest.consumableorderdetailsRecordsview[0].check= true; conTest.Sorder(); // Implement test code } static testMethod void test_method_three() { List rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP']; if (rectHp.size() == 0) { return; } List 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; User hpOwner2 = new User(Test_staff__c = true, LastName = 'hp2', FirstName = 'owner', 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; // 病院作成 Account 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; Account dc = [select Id, Name, RecordType_DeveloperName__c, Account2__c from Account where ParentId = :hp.Id and RecordType_DeveloperName__c = 'Department_Class_GI']; // 診療科を作る Account 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; 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 = dpt.Id; asset.Department_Class__c = dc.Id; asset.Hospital__c = hp.Id; asset.SerialNumber = 'testserial'; insert asset; AssetModifyBelongsChange__c ambc = new AssetModifyBelongsChange__c(); ambc.rawAccount__c = dpt.Id; ambc.AccountField__c = dpt1.Id; ambc.Change_status__c = '草案中'; insert ambc; AssetModifyBelongsChangeDetail__c ambcDetail = new AssetModifyBelongsChangeDetail__c(); ambcDetail.ChangeAndChangeDetail__c = ambc.Id; ambcDetail.Asset__c = asset.Id; 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'; 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'; insert asset1; PageReference page = new PageReference('/apex/AssetModifyBelongs?Id=' +ambc.Id+'&KeyWords=Redirect&accountId='+ambc.rawAccount__c); page.setRedirect(true); System.Test.setCurrentPage(page); AssetModifyBelongsController conTest = new AssetModifyBelongsController(new ApexPages.StandardController(dpt)); System.Test.startTest(); conTest.init(); conTest.searchConsumableorderdetails(); System.assertEquals(3, conTest.ConsumableorderdetailsviewCount); //conTest.ambc.Change_status__c = '草案中'; conTest.setEditAble(); conTest.assetModifyBelongsChangeDetailRecordsview[1].check= true; conTest.save(); conTest.DelConsumable(); // Implement test code } static testMethod void test_method_four() { List rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP']; if (rectHp.size() == 0) { return; } List 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; User hpOwner2 = new User(Test_staff__c = true, LastName = 'hp2', FirstName = 'owner', 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; // 病院作成 Account 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; Account dc = [select Id, Name, RecordType_DeveloperName__c, Account2__c from Account where ParentId = :hp.Id and RecordType_DeveloperName__c = 'Department_Class_GI']; // 診療科を作る Account 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; 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 = dpt.Id; asset.Department_Class__c = dc.Id; asset.Hospital__c = hp.Id; asset.SerialNumber = 'testserial'; insert asset; AssetModifyBelongsChange__c ambc = new AssetModifyBelongsChange__c(); ambc.rawAccount__c = dpt.Id; ambc.AccountField__c = dpt1.Id; ambc.Change_status__c = '驳回'; insert ambc; AssetModifyBelongsChangeDetail__c ambcDetail = new AssetModifyBelongsChangeDetail__c(); ambcDetail.ChangeAndChangeDetail__c = ambc.Id; ambcDetail.Asset__c = asset.Id; 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'; 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'; insert asset1; PageReference page = new PageReference('/apex/AssetModifyBelongs?Id=' +ambc.Id+'&KeyWords=Redirect&accountId='+ambc.rawAccount__c); page.setRedirect(true); System.Test.setCurrentPage(page); AssetModifyBelongsController conTest = new AssetModifyBelongsController(new ApexPages.StandardController(dpt)); System.Test.startTest(); conTest.init(); conTest.searchConsumableorderdetails(); System.assertEquals(3, conTest.ConsumableorderdetailsviewCount); //conTest.ambc.Change_status__c = '草案中'; conTest.backOrder(); conTest.assetModifyBelongsChangeDetailRecordsview[1].check= true; conTest.save(); //conTest.DelConsumable(); // Implement test code } }