/**
 * 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 AfterCreateHospitalTriggerTest {

    static testMethod void testAfterCreateHospital() {
        // recode type を取得
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectCo.size() == 0) {
            return;
        }
        
        // insert
        Account company = new Account();
        company.RecordTypeId = rectCo[0].Id;
        company.Name = 'Katsu テスト';
        company.OCM_Category__c = 'Normal';
        insert company;

        // Assert
        List<Account> dcList = [select Id, Name, OCM_Category__c, Hospital_Department_Class__c, Department_Class_Label__c from Account where ParentId = :company.Id];
        
        System.assertEquals(8, dcList.size());
        System.assertEquals(company.Id, dcList[0].Hospital_Department_Class__c);
        System.assertEquals(company.Id, dcList[7].Hospital_Department_Class__c);
        System.assertEquals(company.OCM_Category__c, dcList[0].OCM_Category__c);
        System.assertEquals(company.OCM_Category__c, dcList[7].OCM_Category__c);
    }
    @isTest static void test_method_two() {
        // Implement test code
        Profile prof = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin];
        List<RecordType> rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];

        List<String> classDeptStr = new List<String>();
        classDeptStr.add('Department_Class_GI');
        classDeptStr.add('Department_Class_ET');
        classDeptStr.add('Department_Class_BF');
        classDeptStr.add('Department_Class_GS');
        classDeptStr.add('Department_Class_URO');
        classDeptStr.add('Department_Class_GYN');
        classDeptStr.add('Department_Class_ENT');
        classDeptStr.add('Department_Class_OTH');
        List<RecordType> rectDept = [select Id,developername from RecordType where IsActive = true and SobjectType = 'Account' and developername  in:classDeptStr];
        
        Map<String,String> classDeptMap = new Map<String,String>();
        if (rectHp.size() == 0) {
            return;
        }
        for(String Str : classDeptStr){
            for(RecordType rt : rectDept){
                if(rt.developername == Str){
                    classDeptMap.put(Str, rt.Id);
                }
            }
        }
        Account myAccount1 = new Account(name='testaccount001',RecordTypeId = rectHp[0].Id );
        insert myAccount1;
        Contact core = new Contact(email='jplumber@salesforce.com',
        firstname='Joe',
        lastname='Plumber',
        accountid=myAccount1.id);
        insert core;
        List<User> insertUser = new List<User>();
        user UserGI = New User(
            Alias = 'GI_User',
            Email='GI_User@testorg.com',
            EmailEncodingKey='UTF-8',
            LastName='testUserGI',
            Firstname ='GI',
            LanguageLocaleKey='zh_CN',
            LocaleSidKey='zh_CN',
            ProfileId = System.Label.ProfileId_SystemAdmin,
            TimeZoneSidKey='Asia/Shanghai',
            UserName='testUserGI@testorg.com');
        insertUser.add(UserGI);
        user UserET = New User(
            
            Alias = 'ET_User',
            Email='ET_User@testorg.com',
            EmailEncodingKey='UTF-8',
            LastName='testUserET',
            Firstname ='ET',
            LanguageLocaleKey='zh_CN',
            LocaleSidKey='zh_CN',
            ProfileId = System.Label.ProfileId_SystemAdmin,
            TimeZoneSidKey='Asia/Shanghai',
            UserName='testUserET@testorg.com');
        insertUser.add(UserET);
        user UserBF = New User(
            
            Alias = 'BF_User',
            Email='BF_User@testorg.com',
            EmailEncodingKey='UTF-8',
            LastName='testUserBF',
            Firstname ='BF',
            LanguageLocaleKey='zh_CN',
            LocaleSidKey='zh_CN',
            ProfileId = System.Label.ProfileId_SystemAdmin,
            TimeZoneSidKey='Asia/Shanghai',
            UserName='testUserBF@testorg.com');
        insertUser.add(UserBF);
        user UserGS = New User(
            
            Alias = 'SP_User',
            Email='SP_User@testorg.com',
            EmailEncodingKey='UTF-8',
            LastName='testUserGS',
            Firstname ='GS',
            LanguageLocaleKey='zh_CN',
            LocaleSidKey='zh_CN',
            ProfileId = System.Label.ProfileId_SystemAdmin,
            TimeZoneSidKey='Asia/Shanghai',
            UserName='testUserGS@testorg.com');
        insertUser.add(UserGS);
        user UserURO = New User(
            
            Alias = 'URO_User',
            Email='URO_User@testorg.com',
            EmailEncodingKey='UTF-8',
            LastName='testUserURO',
            Firstname ='URO',
            LanguageLocaleKey='zh_CN',
            LocaleSidKey='zh_CN',
            ProfileId = System.Label.ProfileId_SystemAdmin,
            TimeZoneSidKey='Asia/Shanghai',
            UserName='testUseUROr@testorg.com');
        insertUser.add(UserURO);
        user UserGYN = New User(
            
            Alias = 'GYN_User',
            Email='GYN_User@testorg.com',
            EmailEncodingKey='UTF-8',
            LastName='testUserGYN',
            Firstname ='GYN',
            LanguageLocaleKey='zh_CN',
            LocaleSidKey='zh_CN',
            ProfileId = System.Label.ProfileId_SystemAdmin,
            TimeZoneSidKey='Asia/Shanghai',
            UserName='testUserGYN@testorg.com');
        insertUser.add(UserGYN);
        user UserENT = New User(
            
            Alias = 'ENT_User',
            Email='ENT_User@testorg.com',
            EmailEncodingKey='UTF-8',
            LastName='testUserENT',
            Firstname ='ENT',
            LanguageLocaleKey='zh_CN',
            LocaleSidKey='zh_CN',
            ProfileId = System.Label.ProfileId_SystemAdmin,
            TimeZoneSidKey='Asia/Shanghai',
            UserName='testUserENT@testorg.com');
        insertUser.add(UserENT);
        user UserFSE = New User(
            
            Alias = 'FSE_User',
            Email='FSE_User@testorg.com',
            EmailEncodingKey='UTF-8',
            LastName='testUserFSE',
            Firstname ='FSE',
            LanguageLocaleKey='zh_CN',
            LocaleSidKey='zh_CN',
            ProfileId = System.Label.ProfileId_SystemAdmin,
            TimeZoneSidKey='Asia/Shanghai',
            UserName='testUserFSE@testorg.com');
        insertUser.add(UserFSE);
        user UserFSE_1 = New User(
            
            Alias = 'FSEUser1',
            Email='FSE_User@testorg.com',
            EmailEncodingKey='UTF-8',
            LastName='testUserFSE1',
            Firstname ='FSE1',
            LanguageLocaleKey='zh_CN',
            LocaleSidKey='zh_CN',
            ProfileId = System.Label.ProfileId_SystemAdmin,
            TimeZoneSidKey='Asia/Shanghai',
            UserName='testUserFSE1@testorg.com');
        insertUser.add(UserFSE_1);
        user UserFSE_2 = New User(
            
            Alias = 'FSEUser2',
            Email='FSE_User@testorg.com',
            EmailEncodingKey='UTF-8',
            LastName='testUserFSE2',
            Firstname ='FSE2',
            LanguageLocaleKey='zh_CN',
            LocaleSidKey='zh_CN',
            ProfileId = System.Label.ProfileId_SystemAdmin,
            TimeZoneSidKey='Asia/Shanghai',
            UserName='testUserFSE2@testorg.com');
        insertUser.add(UserFSE_2);
        user UserFSE_3 = New User(
            
            Alias = 'FSEUser3',
            Email='FSE_User@testorg.com',
            EmailEncodingKey='UTF-8',
            LastName='testUserFSE3',
            Firstname ='FSE3',
            LanguageLocaleKey='zh_CN',
            LocaleSidKey='zh_CN',
            ProfileId = System.Label.ProfileId_SystemAdmin,
            TimeZoneSidKey='Asia/Shanghai',
            UserName='testUserFSE3@testorg.com');
        insertUser.add(UserFSE_3);
        user UserTeamMember1 = New User(
            
            Alias = 'TMem1',
            Email='TeamMember1@testorg.com',
            EmailEncodingKey='UTF-8',
            LastName='testUserTeamMember1',
            Firstname ='FSE',
            LanguageLocaleKey='zh_CN',
            LocaleSidKey='zh_CN',
            ProfileId = System.Label.ProfileId_SystemAdmin,
            TimeZoneSidKey='Asia/Shanghai',
            UserName='testUserTeamMember1@testorg.com');
        insertUser.add(UserTeamMember1);
        insert insertUser;
        Account Hospital = new Account(
                                name = 'Test Hospital',
                                RecordTypeId = rectHp[0].Id,
                                FSE_Main__c = UserFSE.Id,
                                ENT_owner_ID__c = UserENT.Id,
                                GYN_owner__c = UserGYN.Id,
                                URO_owner_ID__c = UserURO.Id,
                                SP_Main__c = UserGS.Id,
                                BF_owner__c = UserBF.Id,
                                ET_owner__c = UserET.Id,
                                GI_Main__c = UserGI.Id,
                                GI_Product_Leader__c = 'testUserGSGS',
                                GS_Product_Leader__c = 'testUserGSGS',
                                GYN_Product_Leader__c = 'testUserGSGS',
                                ET_Product_Leader__c = 'testUserGSGS',
                                URO_Produc_Leader__c = 'testUserGSGS',
                                BF_Product_Leader__c = 'testUserGSGS',
                                ENT_Product_Leader__c = 'testUserGSGS',
                                FSE_GI_Vice_Leader__c = 'testUserGSGS',
                                FSE_SP_Vice_Leader__c = 'testUserGSGS',
                                Energy_LeaderStr__c = 'FSE_User,FSE_User3',
                                FSE_Extend_viceLeaderStr__c = 'FSE_User1,FSE_User3',
                                Extend_Leader_Str__c = 'FSE_User2,FSE_User'
                                );
        System.Test.startTest();
        insert Hospital;
        Hospital = [select id,Is_Active__c,Original_Date_Flag__c,RecordTypeId from Account where id = :Hospital.id];
        Hospital.Original_Date_Flag__c = true;
        Hospital.Is_Active__c = '申请中';
        update Hospital;
        Hospital.Original_Date_Flag__c = false;
        Hospital.Is_Active__c ='有効';
        update Hospital;
        
    }
}