@isTest private class CreateTargetCmpTest { public static Account account1 = new Account(); public static Account account2 = new Account(); public static Contact contact1 = new Contact(); public static Contact contact2 = new Contact(); public static User user = new User(); public static Agency_Hospital_Link__c agency_hospital_link = new Agency_Hospital_Link__c(); public static Agency_Contact__c agency_contact = new Agency_Contact__c(); public static ProductTypes__c product_types = new ProductTypes__c(); public static ProductTypes__c product_types2 = new ProductTypes__c(); public static ProductTypes__c product_types3 = new ProductTypes__c(); public static Agency_Opportunity__c agency_opportunity = new Agency_Opportunity__c(); public static OlympusCalendar__c olympus_calendar = new OlympusCalendar__c(); public static String report_id; public static String report_header_id; private static void testInit() { // 取引先 account1.Name = 'test1医院'; account1.RecordTypeId = '01210000000QemG'; insert account1; account2.Name = 'test1经销商'; account2.RecordTypeId = '01210000000Qem1'; insert account2; // 取引先責任者 contact1.AccountId = account1.Id; contact1.FirstName = '責任者'; contact1.LastName = 'test1医院'; insert contact1; contact2.AccountId = account2.Id; contact2.FirstName = '責任者'; contact2.LastName = 'test1经销商'; insert contact2; // ユーザー Profile p = [select Id from Profile where Name = '901_经销商活动系统']; user.ProfileId = p.Id; user.ContactId = contact2.Id; user.FirstName = 'ユーザー'; user.LastName = 'テスト'; user.Email = 'test_user@example.com'; user.emailencodingkey='UTF-8'; user.languagelocalekey='zh_CN'; user.localesidkey='ja_JP'; user.timezonesidkey='Asia/Shanghai'; user.Username = 'test_user@example.com'; user.Alias = 'テユ'; user.CommunityNickname = 'テストユーザー'; // user.SalesManager__c = UserInfo.getUserId(); insert user; // 代理店医院 agency_hospital_link.Name = 'test1代理店医院'; agency_hospital_link.Hospital__c = account1.Id; agency_hospital_link.Agency__c = account2.Id; agency_hospital_link.OwnerId = user.Id; agency_hospital_link.Agency_Campaign_Obj__c = true; insert agency_hospital_link; // 先生 agency_contact.Name = 'test1医院先生'; agency_contact.Doctor_Division1__c = '院长'; agency_contact.Type__c = '医生'; agency_contact.Agency_Hospital__c = agency_hospital_link.Id; agency_contact.OwnerId = user.Id; insert agency_contact; agency_contact.Doctor_Division1__c = '副院长'; update agency_contact; // 製品区分 product_types.Name = '製品区分1'; product_types.OwnerId = user.Id; product_types.Department_Cateogy__c = 'GI;ET;BF;GS;URO;GYN;ENT;OTH'; insert product_types; // 製品区分2 product_types2.Name = '製品区分2'; product_types2.OwnerId = user.Id; product_types2.Department_Cateogy__c = 'GI;ET;BF;GS;URO;GYN;ENT;OTH'; insert product_types2; // 製品区分3 product_types3.Name = '製品区分3'; product_types3.OwnerId = user.Id; product_types3.Department_Cateogy__c = 'GI;ET;BF;GS;URO;GYN;ENT;OTH'; insert product_types3; // 引合 Oly_TriggerHandler.bypass('AgencyOpportunityHandler'); agency_opportunity.RecordTypeId = [select Id,DeveloperName from RecordType where IsActive = true and SobjectType = 'Agency_Opportunity__c' and DeveloperName = 'Opportunity'].Id; agency_opportunity.Name = '引合1'; agency_opportunity.Hospital_Target__c = account1.Id; agency_opportunity.Agency__c = account2.Id; agency_opportunity.Agency_Hospital__c = agency_hospital_link.Id; agency_opportunity.StageName__c = '还没申请预算'; agency_opportunity.OwnerId = user.Id; agency_opportunity.NewOpportunity_Agency_Apply_Status__c = '草案中'; insert agency_opportunity; // オリンパスカレンダー olympus_calendar.Date__c = Date.valueOf('2017-04-10'); olympus_calendar.OwnerId = user.Id; insert olympus_calendar; } @isTest static void getProductTest() { testInit(); System.runAs(user) { // 病院リスト取得 ProductTypes__c test = CreateTargetCmp.getProduct(product_types.Id); System.assertEquals(test.Department_Cateogy__c, 'GI;ET;BF;GS;URO;GYN;ENT;OTH'); } } @isTest static void getProductListTest() { testInit(); System.runAs(user) { // 病院リスト取得 Map test = CreateTargetCmp.getProductList(); System.assertNotEquals(test.get('GI'), null); } } @isTest static void getHospitalTest() { testInit(); System.runAs(user) { // 病院リスト取得 Map test = CreateTargetCmp.getHospital(agency_opportunity.Id); System.assertNotEquals(test, null); } } @isTest static void setGetDeptAmountTest() { testInit(); System.runAs(user) { // 病院リスト取得 CreateTargetCmp.createSFTarget(agency_hospital_link.Id, false, new String[]{product_types.Id,product_types2.Id,product_types3.Id,'1','1','1'}, new String[]{product_types.Id,product_types2.Id,product_types3.Id,'1','1','1'}, new String[]{product_types.Id,product_types2.Id,product_types3.Id,'1','1','1'}, new String[]{product_types.Id,product_types2.Id,product_types3.Id,'1','1','1'}, new String[]{product_types.Id,product_types2.Id,product_types3.Id,'1','1','1'}, new String[]{product_types.Id,product_types2.Id,product_types3.Id,'1','1','1'}, new String[]{product_types.Id,product_types2.Id,product_types3.Id,'1','1','1'}, new String[]{product_types.Id,product_types2.Id,product_types3.Id,'1','1','1'}, '150P'); //System.assertNotEquals(test, null); Map test = CreateTargetCmp.getDeptAmount(agency_hospital_link.Id); System.assertNotEquals(test, null); System.assertNotEquals(test.get('GI'), null); } } /* @isTest static void test_method_one() { // 取引先 Account account2 = new Account(); account2.Name = 'test1经销商'; account2.RecordTypeId = '01210000000Qem1'; insert account2; Account account1 = new Account(); account1.Name = 'test1医院'; account1.RecordTypeId = '01210000000QemG'; insert account1; Account account3 = new Account(); account3.Name = 'test2医院'; account3.RecordTypeId = '01210000000QemG'; insert account3; // 取引先責任者 Contact contact2 = new Contact(); contact2.AccountId = account2.Id; contact2.FirstName = '責任者'; contact2.LastName = 'test1经销商'; insert contact2; //userデータを作る Profile cpprofile = [select id from Profile where Name = '901_经销商周报']; List UserList = new List(); User us = new User( Username = 'TestNam1e@acme.com', Email = 'TestName1@acme.com', Alias = 'TestNam1', CommunityNickname = 'TestName2', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', EmailEncodingKey = 'ISO-2022-JP', ProfileId = cpprofile.Id, ContactId = contact2.Id, LanguageLocaleKey = 'ja', //STAFF_CODE__c = '555555', LastName = '鈴木', FirstName = '美一' ); UserList.add(us); insert UserList; User uuu = [SELECT Id, LastName FROM User WHERE Id =:us.Id]; System.assertEquals('鈴木', uuu.LastName); //System.runAs(uuu) { Id rtId = [select Id,DeveloperName from RecordType where IsActive = true and SobjectType = 'Agency_Opportunity__c' and DeveloperName = 'Target'].Id; //经销商医院データを作る List aHosLinkList = new List(); Agency_Hospital_Link__c aHosLink1 = new Agency_Hospital_Link__c( Name = 'Test医院1' , Hospital__c = account1.Id //RecordTypeId = '01210000000QemG' , Agency__c = account2.Id ); aHosLinkList.add(aHosLink1); Agency_Hospital_Link__c aHosLink2 = new Agency_Hospital_Link__c( Name = 'Test经销商' , Hospital__c = account3.Id , Agency__c = account2.Id //RecordTypeId = '01210000000Qem1' ); aHosLinkList.add(aHosLink2); //Agency_Hospital_Link__c aHosLink3 = new Agency_Hospital_Link__c( // Name = 'Test医院3'); //aHosLinkList.add(aHosLink3); insert aHosLinkList; List aHosLinkTestList = [SELECT Id, Name FROM Agency_Hospital_Link__c]; System.assertEquals(2, aHosLinkTestList.size()); List aOppList = new List(); Agency_Opportunity__c aOpp = new Agency_Opportunity__c( Name = 'Test询价', OwnerId = uuu.Id); //} } @isTest static void test_method_two() { // Implement test code } */ }