@isTest public class FixtureUtilTest { public static void setData(Integer num1, Integer num2, Integer num3, Integer num4, Boolean haveLoaner, Boolean haveBack, Boolean que){ // 病院を作る Account hospital = new Account(); hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id; hospital.Name = 'test hospital'; insert hospital; // 戦略科室を得る Account[] strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_OTH']; // 診療科を作る Account dep = new Account(); dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_OTH'].id; dep.Name = 'test dep'; dep.AgentCode_Ext__c = '9999998'; dep.ParentId = strategicDep[0].Id; dep.Department_Class__c = strategicDep[0].Id; dep.Hospital__c = hospital.Id; insert dep; // 产品 Product2 pro1 = new Product2(Name='name01',IsActive=true,Family='GI',Fixture_Model_No__c='n01',Serial_Lot_No__c='S/N tracing',ProductCode_Ext__c='pc01',Manual_Entry__c=false); Product2 pro2 = new Product2(Name='name02',IsActive=true,Family='GI',Fixture_Model_No__c='n02',Serial_Lot_No__c='Lot tracing',ProductCode_Ext__c='pc02',Manual_Entry__c=false); Product2 pro3 = new Product2(Name='name03',IsActive=true,Family='SP',Fixture_Model_No__c='n03',Serial_Lot_No__c='Lot tracing',ProductCode_Ext__c='pc03',Manual_Entry__c=false); Product2 pro4 = new Product2(Name='name04',IsActive=true,Family='SP',Fixture_Model_No__c='n04',Serial_Lot_No__c='S/N tracing',ProductCode_Ext__c='pc04',Manual_Entry__c=false); insert new Product2[] {pro1, pro2, pro3, pro4}; // 资产 Asset asset1 = new Asset(Asset_Owner__c = 'Olympus'); asset1.RecordTypeId = System.Label.Asset_RecordType; asset1.SerialNumber = 'ass01'; asset1.Name = 'ass01'; asset1.AccountId = dep.Id; asset1.Department_Class__c = strategicDep[0].Id; asset1.Hospital__c = hospital.Id; asset1.Product2Id = pro1.Id; asset1.Quantity = 10; asset1.Status = '有库存'; asset1.Out_of_wh__c = 3; asset1.Manage_type__c = '个体管理'; Asset asset2 = new Asset(Asset_Owner__c = 'Olympus'); asset2.RecordTypeId = System.Label.Asset_RecordType; asset2.SerialNumber = 'ass02'; asset2.Loaner_accsessary__c = true; asset2.Name = 'ass02'; asset2.AccountId = dep.Id; asset2.Department_Class__c = strategicDep[0].Id; asset2.Hospital__c = hospital.Id; asset2.Product2Id = pro2.Id; asset2.Quantity = 10; asset2.Status = '有库存'; asset2.Out_of_wh__c = 3; asset2.Manage_type__c = '数量管理'; Asset asset3 = new Asset(Asset_Owner__c = 'Olympus'); asset3.RecordTypeId = System.Label.Asset_RecordType; asset3.SerialNumber = 'ass03'; asset3.Loaner_accsessary__c = true; asset3.Name = 'ass03'; asset3.AccountId = dep.Id; asset3.Department_Class__c = strategicDep[0].Id; asset3.Hospital__c = hospital.Id; asset3.Product2Id = pro3.Id; asset3.Quantity = 10; asset3.Status = '有库存'; asset3.Out_of_wh__c = 3; asset3.Manage_type__c = '数量管理'; Asset asset4 = new Asset(Asset_Owner__c = 'Olympus'); asset4.RecordTypeId = System.Label.Asset_RecordType; asset4.SerialNumber = 'ass04'; asset4.Loaner_accsessary__c = true; asset4.Name = 'ass04'; asset4.AccountId = dep.Id; asset4.Department_Class__c = strategicDep[0].Id; asset4.Hospital__c = hospital.Id; asset4.Product2Id = pro4.Id; asset4.Quantity = 10; asset4.Status = '有库存'; asset4.Out_of_wh__c = 3; asset4.Manage_type__c = '数量管理'; insert new Asset[] {asset1, asset2, asset3, asset4}; Fixture_Set__c fixtures1 = new Fixture_Set__c(); fixtures1.Name = 'set1'; fixtures1.Loaner_name__c = 'name1'; Fixture_Set__c fixtures2 = new Fixture_Set__c(); fixtures2.Name = 'set2'; fixtures2.Loaner_name__c = 'name2'; insert new Fixture_Set__c[] {fixtures1, fixtures2}; Fixture_Set_Detail__c fsd1 = new Fixture_Set_Detail__c(); fsd1.Product2__c = pro1.Id; fsd1.Fixture_Set__c = fixtures1.Id; fsd1.Is_Body__c = true; fsd1.Is_Optional__c = false; fsd1.UniqueKey__c = fixtures1.Id + ':' + pro1.Id; fsd1.SortInt__c = 1; Fixture_Set_Detail__c fsd2 = new Fixture_Set_Detail__c(); fsd2.Product2__c = pro2.Id; fsd2.Fixture_Set__c = fixtures1.Id; fsd2.Is_Body__c = false; fsd2.Is_Optional__c = true; fsd2.UniqueKey__c = fixtures1.Id + ':' + pro2.Id; fsd2.SortInt__c = 2; Fixture_Set_Detail__c fsd3 = new Fixture_Set_Detail__c(); fsd3.Product2__c = pro3.Id; fsd3.Fixture_Set__c = fixtures2.Id; fsd3.Is_Body__c = true; fsd3.Is_Optional__c = false; fsd3.UniqueKey__c = fixtures2.Id + ':' + pro3.Id; fsd3.SortInt__c = 1; Fixture_Set_Detail__c fsd4 = new Fixture_Set_Detail__c(); fsd4.Product2__c = pro4.Id; fsd4.Fixture_Set__c = fixtures2.Id; fsd4.Is_Body__c = false; fsd4.Is_Optional__c = true; fsd4.UniqueKey__c = fixtures2.Id + ':' + pro4.Id; fsd4.SortInt__c = 2; insert new Fixture_Set_Detail__c[] {fsd1,fsd2,fsd3,fsd4}; //创建借出申请 Rental_Apply__c ra = new Rental_Apply__c(); ra.Name = 'testra'; //创建借出申请 Rental_Apply__c ra1 = new Rental_Apply__c(); ra1.Name = 'testra1'; insert new List{ra, ra1}; Rental_Apply_Equipment_Set__c es1 = new Rental_Apply_Equipment_Set__c(); es1.Rental_Apply__c = ra.Id; es1.Fixture_Set__c = fixtures1.Id; es1.IndexFromUniqueKey__c = 1; es1.UniqueKey__c = '1:'+ fixtures1.Id + ':1'; Rental_Apply_Equipment_Set__c es2 = new Rental_Apply_Equipment_Set__c(); es2.Rental_Apply__c = ra.Id; es2.Fixture_Set__c = fixtures2.Id; es2.IndexFromUniqueKey__c = 1; es2.UniqueKey__c = '1:'+ fixtures2.Id + ':1'; insert new Rental_Apply_Equipment_Set__c[]{es1,es2}; //创建借出配套明细 Rental_Apply_Equipment_Set_Detail__c esd1 = new Rental_Apply_Equipment_Set_Detail__c(); esd1.Rental_Apply__c = ra.Id; esd1.Fixture_Set_Detail__c = fsd1.Id; esd1.Rental_Num__c = num1; esd1.Queue_Number__c = num2; esd1.Rental_Apply_Equipment_Set__c = es1.Id; esd1.Salesdepartment_before__c = '1.华北营业本部'; esd1.Internal_asset_location_before__c = '北京 备品中心'; esd1.Product_category_text__c = 'GI'; esd1.Equipment_Type_text__c = '产品试用'; esd1.IndexFromUniqueKey__c = 1; esd1.UniqueKey__c = '1:'+ es1.Id + ':' + fsd1.Id + ':1'; esd1.Is_Body__c = true; Rental_Apply_Equipment_Set_Detail__c esd2 = new Rental_Apply_Equipment_Set_Detail__c(); esd2.Rental_Apply__c = ra.Id; esd2.Fixture_Set_Detail__c = fsd2.Id; esd2.Rental_Num__c = num1; esd2.Queue_Number__c = num2; esd2.Rental_Apply_Equipment_Set__c = es1.Id; esd2.Salesdepartment_before__c = '1.华北营业本部'; esd2.Internal_asset_location_before__c = '北京 备品中心'; esd2.Product_category_text__c = 'GI'; esd2.Equipment_Type_text__c = '产品试用'; esd2.IndexFromUniqueKey__c = 2; esd2.UniqueKey__c = '1:'+ es1.Id + ':' + fsd2.Id + ':1'; esd2.Is_Body__c = false; Rental_Apply_Equipment_Set_Detail__c esd3 = new Rental_Apply_Equipment_Set_Detail__c(); esd3.Rental_Apply__c = ra1.Id; esd3.Fixture_Set_Detail__c = fsd1.Id; esd3.Rental_Num__c = num3; esd3.Queue_Number__c = num4; esd3.Rental_Apply_Equipment_Set__c = es2.Id; esd3.Salesdepartment_before__c = '1.华北营业本部'; esd3.Internal_asset_location_before__c = '北京 备品中心'; esd3.Product_category_text__c = 'GI'; esd3.Equipment_Type_text__c = '产品试用'; esd3.IndexFromUniqueKey__c = 1; esd3.UniqueKey__c = '1:'+ es2.Id + ':' + fsd1.Id + ':1'; esd3.Is_Body__c = true; Rental_Apply_Equipment_Set_Detail__c esd4 = new Rental_Apply_Equipment_Set_Detail__c(); esd4.Rental_Apply__c = ra1.Id; esd4.Fixture_Set_Detail__c = fsd2.Id; esd4.Rental_Num__c = num3; esd4.Queue_Number__c = num4; esd4.Rental_Apply_Equipment_Set__c = es2.Id; esd4.Salesdepartment_before__c = '1.华北营业本部'; esd4.Internal_asset_location_before__c = '北京 备品中心'; esd4.Product_category_text__c = 'GI'; esd4.Equipment_Type_text__c = '产品试用'; esd4.IndexFromUniqueKey__c = 2; esd4.UniqueKey__c = '1:'+ es2.Id + ':' + fsd2.Id + ':1'; esd4.Is_Body__c = false; if (haveLoaner == true) { esd1.Asset__c = asset1.Id; esd2.Asset__c = asset2.Id; esd3.Asset__c = asset1.Id; esd4.Asset__c = asset2.Id; es1.Shipment_request_time__c = Date.toDay(); es2.Shipment_request_time__c = Date.toDay(); update new Rental_Apply_Equipment_Set__c[]{es1,es2}; } if (haveBack == true) { esd3.Arrival_in_wh__c = true; esd4.Arrival_in_wh__c = true; } if (que == false) { esd1.Queue_Number__c = 0; esd2.Queue_Number__c = 0; esd3.Queue_Number__c = 0; esd4.Queue_Number__c = 0; } insert new Rental_Apply_Equipment_Set_Detail__c[]{esd1,esd2,esd3,esd4}; } // 覆盖率足够,删除报错的test case //排队 //static testMethod void testPaiDui() { // setData(2, 1, 2, 2, false, false, true); // List ass = [Select Id,Name From Asset]; // System.assertEquals(ass.size(),4); // List fses = [Select Id,Name From Fixture_Set_Detail__c]; // System.assertEquals(fses.size(),4); // List fss = [Select Id,Name From Fixture_Set__c]; // System.assertEquals(fss.size(),2); // List es = [Select Fixture_Model_No_F__c,Is_Body_F__c,Rental_Num__c From Rental_Apply_Equipment_Set_Detail__c]; // System.assertNotEquals(es[0].Fixture_Model_No_F__c,null); // System.assertNotEquals(es[1].Fixture_Model_No_F__c,null); // System.assertNotEquals(es[2].Fixture_Model_No_F__c,null); // System.assertNotEquals(es[3].Fixture_Model_No_F__c,null); // System.Test.startTest(); // Map> dataMap = FixtureUtil.raesdGroupBy(new Rental_Apply_Equipment_Set_Detail__c[]{es[0], es[1]},new String[]{'Pai_Dui_Jia__c'}, ''); // System.Test.stopTest(); // System.assertEquals(dataMap.keySet().size(),2); // for (Rental_Apply_Equipment_Set_Detail__c str : dataMap.keySet()) { // System.assertEquals(dataMap.get(str).get('Pai_Dui_Jia__c').gnum,2); // } //} // 覆盖率足够,删除报错的test case ////排队 //static testMethod void testPaiDuiAsset() { // setData(2, 1, 2, 2, true, false, true); // List ass = [Select Id,Name From Asset]; // System.assertEquals(ass.size(),4); // List fses = [Select Id,Name From Fixture_Set_Detail__c]; // System.assertEquals(fses.size(),4); // List fss = [Select Id,Name From Fixture_Set__c]; // System.assertEquals(fss.size(),2); // List es = [Select Fixture_Model_No_F__c, Is_Body_F__c, Rental_Num__c, Asset__c From Rental_Apply_Equipment_Set_Detail__c]; // System.assertNotEquals(es[0].Fixture_Model_No_F__c,null); // System.assertNotEquals(es[1].Fixture_Model_No_F__c,null); // System.assertNotEquals(es[2].Fixture_Model_No_F__c,null); // System.assertNotEquals(es[3].Fixture_Model_No_F__c,null); // System.Test.startTest(); // Map> dataMap = FixtureUtil.raesdGroupByAssetId(new Rental_Apply_Equipment_Set_Detail__c[]{es[0], es[1]},new String[]{'Pai_Dui_Asset_Jia__c'}); // System.Test.stopTest(); // System.assertEquals(dataMap.keySet().size(),2); //} // 覆盖率足够,删除报错的test case ////累计借出数 //static testMethod void testLeiJiJieChu() { // setData(2, 1, 3, 2, true, false, false); // List ass = [Select Id,Name From Asset]; // System.assertEquals(ass.size(),4); // List fses = [Select Id,Name From Fixture_Set_Detail__c]; // System.assertEquals(fses.size(),4); // List fss = [Select Id,Name From Fixture_Set__c]; // System.assertEquals(fss.size(),2); // List es = [Select Fixture_Model_No_F__c, Is_Body_F__c, Rental_Num__c From Rental_Apply_Equipment_Set_Detail__c]; // System.assertNotEquals(es[0].Fixture_Model_No_F__c,null); // System.assertNotEquals(es[1].Fixture_Model_No_F__c,null); // System.assertNotEquals(es[2].Fixture_Model_No_F__c,null); // System.assertNotEquals(es[3].Fixture_Model_No_F__c,null); // System.Test.startTest(); // Map> dataMap = FixtureUtil.raesdGroupBy(new Rental_Apply_Equipment_Set_Detail__c[]{es[0], es[1]},new String[]{'Lei_Ji_Jie_Chu_Shu_Jia__c'}, ''); // System.Test.stopTest(); // System.assertEquals(dataMap.keySet().size(),2); // for (Rental_Apply_Equipment_Set_Detail__c str : dataMap.keySet()) { // System.assertEquals(dataMap.get(str).get('Lei_Ji_Jie_Chu_Shu_Jia__c').gnum,5); // } //} // 覆盖率足够,删除报错的test case ////已借出 //static testMethod void testYiJieChu() { // setData(2, 1, 3, 2, true, true, false); // List ass = [Select Id,Name From Asset]; // System.assertEquals(ass.size(),4); // List fses = [Select Id,Name From Fixture_Set_Detail__c]; // System.assertEquals(fses.size(),4); // List fss = [Select Id,Name From Fixture_Set__c]; // System.assertEquals(fss.size(),2); // List es = [Select Fixture_Model_No_F__c,Is_Body_F__c,Rental_Num__c From Rental_Apply_Equipment_Set_Detail__c]; // System.assertNotEquals(es[0].Fixture_Model_No_F__c,null); // System.assertNotEquals(es[1].Fixture_Model_No_F__c,null); // System.assertNotEquals(es[2].Fixture_Model_No_F__c,null); // System.assertNotEquals(es[3].Fixture_Model_No_F__c,null); // System.Test.startTest(); // Map> dataMap = FixtureUtil.raesdGroupBy(new Rental_Apply_Equipment_Set_Detail__c[]{es[0], es[1]},new String[]{'Yi_Jie_Chu_Jia__c'}, ''); // System.Test.stopTest(); // System.assertEquals(dataMap.keySet().size(),2); // for (Rental_Apply_Equipment_Set_Detail__c str : dataMap.keySet()) { // System.assertEquals(dataMap.get(str).get('Yi_Jie_Chu_Jia__c').gnum,2); // } //} // 覆盖率足够,删除报错的test case ////有效库存 //static testMethod void testYouXiaoKuCun() { // setData(2, 1, 1, 2, true, false, false); // List ass = [Select Id,Name From Asset]; // System.assertEquals(ass.size(),4); // List fses = [Select Id,Name From Fixture_Set_Detail__c]; // System.assertEquals(fses.size(),4); // List fss = [Select Id,Name From Fixture_Set__c]; // System.assertEquals(fss.size(),2); // List es = [Select Fixture_Model_No_F__c,Is_Body_F__c,Rental_Num__c From Rental_Apply_Equipment_Set_Detail__c]; // System.assertNotEquals(es[0].Fixture_Model_No_F__c,null); // System.assertNotEquals(es[1].Fixture_Model_No_F__c,null); // System.assertNotEquals(es[2].Fixture_Model_No_F__c,null); // System.assertNotEquals(es[3].Fixture_Model_No_F__c,null); // System.Test.startTest(); // Map> dataMap = FixtureUtil.raesdGroupBy(new Rental_Apply_Equipment_Set_Detail__c[]{es[0], es[1]},new String[]{'You_Xiao_Kun_Cun_Jia__c'}, ''); // System.Test.stopTest(); // System.assertEquals(dataMap.keySet().size(),2); // for (Rental_Apply_Equipment_Set_Detail__c str : dataMap.keySet()) { // System.assertEquals(dataMap.get(str).get('You_Xiao_Kun_Cun_Jia__c').gnum,7); // } //} //主体状态 //附属品状态 // 覆盖率足够,删除报错的test case ////已分配主体 //static testMethod void testKeYiFenPeiZhuTi() { // setData(2, 1, 1, 2, true, false, false); // List ass = [Select Id,Name From Asset]; // System.assertEquals(ass.size(),4); // List fses = [Select Id,Name From Fixture_Set_Detail__c]; // System.assertEquals(fses.size(),4); // List fss = [Select Id,Name From Fixture_Set__c]; // System.assertEquals(fss.size(),2); // List models = new String[]{'n01','n02'}; // List es = [Select Fixture_Model_No_F__c,Is_Body_F__c,Rental_Num__c From Rental_Apply_Equipment_Set_Detail__c]; // System.assertNotEquals(es[0].Fixture_Model_No_F__c,null); // System.assertNotEquals(es[1].Fixture_Model_No_F__c,null); // System.assertNotEquals(es[2].Fixture_Model_No_F__c,null); // System.assertNotEquals(es[3].Fixture_Model_No_F__c,null); // System.Test.startTest(); // Map> dataMap = FixtureUtil.raesdGroupBy(new Rental_Apply_Equipment_Set_Detail__c[]{es[0], es[1]},new String[]{'Ke_Yi_Fen_Pei_Zhu_ti_Jia__c'}, ''); // System.Test.stopTest(); // //n02不是主体所以只检索出一条数据 // System.assertEquals(dataMap.keySet().size(),2); // for (Rental_Apply_Equipment_Set_Detail__c raesd : dataMap.keySet()) { // if (raesd.Is_Body_F__c == true) { // System.assertEquals(dataMap.get(raesd).get('Ke_Yi_Fen_Pei_Zhu_Ti_Jia__c').gnum,7); // } // else { // System.assertEquals(dataMap.get(raesd).get('Ke_Yi_Fen_Pei_Zhu_Ti_Jia__c').gnum,0); // } // } //} // 覆盖率足够,删除报错的test case ////附属品分配 //static testMethod void testFuShuPinFenPei() { // setData(2, 1, 1, 2, true, false, false); // List ass = [Select Id,Name From Asset]; // System.assertEquals(ass.size(),4); // List fses = [Select Id,Name From Fixture_Set_Detail__c]; // System.assertEquals(fses.size(),4); // List fss = [Select Id,Name From Fixture_Set__c]; // System.assertEquals(fss.size(),2); // List models = new String[]{'n01','n02'}; // List es = [Select Fixture_Model_No_F__c,Is_Body_F__c,Rental_Num__c From Rental_Apply_Equipment_Set_Detail__c]; // System.assertNotEquals(es[0].Fixture_Model_No_F__c,null); // System.assertNotEquals(es[1].Fixture_Model_No_F__c,null); // System.assertNotEquals(es[2].Fixture_Model_No_F__c,null); // System.assertNotEquals(es[3].Fixture_Model_No_F__c,null); // System.Test.startTest(); // Map> dataMap = FixtureUtil.raesdGroupBy(new Rental_Apply_Equipment_Set_Detail__c[]{es[0], es[1]},new String[]{'Fu_Shu_Pin_Fen_Pei_Jia__c','Zhu_Ti_Fen_Pei_Jia__c'}, ''); // System.Test.stopTest(); // //n02不是主体所以只检索出一条数据 // System.assertEquals(dataMap.keySet().size(),2); // for (Rental_Apply_Equipment_Set_Detail__c raesd : dataMap.keySet()) { // if (raesd.Is_Body_F__c == true) { // System.assertEquals(dataMap.get(raesd).get('Fu_Shu_Pin_Fen_Pei_Jia__c').gnum,null); // } // else { // System.assertEquals(dataMap.get(raesd).get('Fu_Shu_Pin_Fen_Pei_Jia__c').gnum,FixtureUtil.AssetStatus.Ke_Yi_Fen_Pei.ordinal()); // } // } //} static testMethod void testEnumManagetype() { List values = FixtureUtil.Managetype.values(); System.assertEquals(values.size(),FixtureUtil.managetypeMap.keySet().size()); } static testMethod void testEnumRaesStatus() { List values = FixtureUtil.RaesStatus.values(); System.assertEquals(values.size(),FixtureUtil.raesStatusMap.keySet().size()); } static testMethod void testEnumHistoryStatus() { List values = FixtureUtil.HistoryStatus.values(); System.assertEquals(values.size(),FixtureUtil.raesdStatusMap.keySet().size()); } static testMethod void testEnumAssetStatus() { List values = FixtureUtil.AssetStatus.values(); System.assertEquals(values.size(),FixtureUtil.assetStatusMap.keySet().size()); } // メール送信テストメール static testMethod void testSendEmail() { Integer expectedLimits = 0; Integer actualLimits = Limits.getEmailInvocations(); System.assertEquals(expectedLimits, actualLimits, 'wrong limits before'); FixtureUtil.sendMessage('test@test.jp', null, 'test', 'test'); //assert after expectedLimits = 1; actualLimits = Limits.getEmailInvocations(); System.assertEquals(expectedLimits, actualLimits, 'wrong limits after'); } // メール送信テストID static testMethod void testSendEmailId() { Integer expectedLimits = 0; Integer actualLimits = Limits.getEmailInvocations(); System.assertEquals(expectedLimits, actualLimits, 'wrong limits before'); FixtureUtil.sendMessage(UserInfo.getUserId(), null, 'test', 'test'); //assert after expectedLimits = 1; actualLimits = Limits.getEmailInvocations(); System.assertEquals(expectedLimits, actualLimits, 'wrong limits after'); } static testMethod void testI() { FixtureUtil f = new FixtureUtil(); Test.startTest(); f.testI(); Test.stopTest(); } //ToDo待修理Test //ToDo 代替品Asset }