@isTest
public class ISOpportunityDemandTest {
    static testMethod void testISOpportunityDemand() {
        User u3 = new User();
        u3.LastName = '_サンブリッジ';
        u3.FirstName = 'う';
        u3.Alias = 'う';
        u3.Email = 'olympusTest03@sunbridge.com';
        u3.Username = 'olympusTest03@sunbridge.com';
        u3.CommunityNickname = 'う';
        u3.IsActive = true;
        u3.EmailEncodingKey = 'ISO-2022-JP';
        u3.TimeZoneSidKey = 'Asia/Tokyo';
        u3.LocaleSidKey = 'ja_JP';
        u3.LanguageLocaleKey = 'ja';
        u3.ProfileId = System.Label.ProfileId_SystemAdmin;
        // u3.Job_Category__c = '销售推广';
        u3.Job_Category__c = '销售服务';
        u3.Province__c = '北京市';
        u3.Use_Start_Date__c = Date.today().addMonths(-6);
        insert u3;

        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;

        system.runAs(u3) {
        ControllerUtil.EscapeNFM001Trigger = true;
        // 客户
        Account hospital = new Account();
        // 记录类型ID
        // 01210000000QemGAAS
        hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
        // 客户名
        hospital.Name = '北京市医院';
        insert hospital;
        
        // 戦略科室を得る
        
        List<Account> strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_GI'];
        
        // 客户
        Account dep = new Account();
        // 01210000000Qfm7AAC
        // 记录类型ID
        dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'].id;
        // 客户名
        dep.Name = 'test de/p';
        dep.ParentId = strategicDep[0].Id;
        // 战略科室分类
        dep.Department_Class__c = strategicDep[0].Id;
        // 医院
        dep.Hospital__c = hospital.Id;
        insert dep;
        
        // 产品
        Product2 productA = new Product2(
            // 产品名称
             Name='テスト商品',
            //  维修合同报价
             Maintenance_Price_Year__c = 12000, 
            //  手动登录区分
             Manual_Entry__c = false
            );
        insert productA;

        RecordType Type = [select id from RecordType where DeveloperName='SI_Oppor'];
		String TypeID = Type.Id;
		Opportunity opp1 = new Opportunity();
		opp1.Name = '引合1';
		opp1.AccountId = dep.Id;
		opp1.Opportunity_Category__c = 'ENT';
		opp1.Trade__c = '外貿';
		opp1.StageName = '引合';
		opp1.CurrencyIsoCode = 'CNY';
		opp1.Close_Forecasted_Date__c = date.today().addMonths(1);
		opp1.CloseDate = date.today().addMonths(1);
		opp1.Competitor__c = 'B';
		opp1.Purchase_Type__c ='SI（手術室案件）';
		opp1.Sales_Root__c = 'OCM直接販売';
		opp1.Hospital__c = hospital.id;
		opp1.StageName = '引合';
		opp1.RecordTypeid = TypeID;
		insert opp1;
        
		// SI需求表
		IS_Opportunity_Demand__c ISOhead = new IS_Opportunity_Demand__c();
		ISOhead.Operating_Room_Count__c = '2';
		ISOhead.Demonstration_Number__c = '1';
		ISOhead.Opportunity_ID__c = opp1.Id;
		ISOhead.Transmission_Mode__c = '光线直连';
		ISOhead.Demand_DemonstrationType__c = 'HD示教系统';
		ISOhead.OperatingRoomName__c = 'test1';
        ISOhead.Approval_Date__c =Date.today().addMonths(-12);
		insert ISOhead;

        ISOpportunityDemand.initISOpportunityController(ISOhead.Id);
        ISOpportunityDemand.submit(ISOhead.Id);

        }
    }
}