/**
|
* This class contains unit tests for validating the behavior of Apex classes
|
* and triggers.
|
*
|
* Unit tests are class methods that verify whether a particular piece
|
* of code is working properly. Unit test methods take no arguments,
|
* commit no data to the database, and are flagged with the testMethod
|
* keyword in the method definition.
|
*
|
* All test methods in an organization are executed whenever Apex code is deployed
|
* to a production organization to confirm correctness, ensure code
|
* coverage, and prevent regressions. All Apex classes are
|
* required to have at least 75% code coverage in order to be deployed
|
* to a production organization. In addition, all triggers must have some code coverage.
|
*
|
* The @isTest class annotation indicates this class only contains test
|
* methods. Classes defined with the @isTest annotation do not count against
|
* the organization size limit for all Apex scripts.
|
*
|
* See the Apex Language Reference for more information about Testing and Code Coverage.
|
*/
|
@isTest
|
private class AccountWebServiceTest {
|
|
static testMethod void myUnitTest() {
|
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;
|
|
Account hp = new Account(
|
RecordTypeId = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'].Id,
|
Name = 'AccountCaseHistoryTestHp1',
|
OwnerId = hpOwner.Id
|
);
|
insert hp;
|
|
RecordType rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 消化科'];
|
Account section = [Select Name, Department_Class_Label__c, OwnerId, ParentId, Hospital_Department_Class__c from Account where ParentId = :hp.Id and RecordTypeId = :rectSct.Id];
|
|
Account depart = new Account();
|
depart.RecordTypeId = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'].Id;
|
depart.Name = '*';
|
depart.Department_Name__c = 'dept1';
|
depart.ParentId = section.Id;
|
depart.Department_Class__c = section.Id;
|
depart.Hospital__c = hp.Id;
|
insert depart;
|
|
// 診療科テスト
|
depart.Is_Active__c = '無効';
|
update depart;
|
|
AccountWebService.toBatchOwner(hp.Id);
|
depart = [select OwnerId from Account where Id = :depart.Id];
|
System.assertEquals('00510000000fSYI', depart.OwnerId);
|
|
// 病院テスト
|
hp.Is_Active__c = '無効';
|
update hp;
|
|
AccountWebService.toBatchOwner(hp.Id);
|
hp = [select OwnerId from Account where Id = :hp.Id];
|
System.assertEquals('00510000000fSYI', hp.OwnerId);
|
section = [select OwnerId from Account where Id = :section.Id];
|
System.assertEquals('00510000000fSYI', section.OwnerId);
|
}
|
}
|