@isTest
|
private class ProductRepairQuoteControllerTest
|
{
|
static testMethod void testasset() {
|
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',Asset_Model_No__c='n01',Serial_Lot_No__c='S/N tracing',ProductCode_Ext__c='pc01',Manual_Entry__c=false,RepairListPriceLevelA__c = 111);
|
Product2 pro2 = new Product2(Name='name02',IsActive=true,Family='GI',Asset_Model_No__c='n02',Serial_Lot_No__c='Lot tracing',ProductCode_Ext__c='pc02',Manual_Entry__c=false,RepairListPriceLevelA__c = 222);
|
insert new Product2[] {pro1, pro2};
|
|
// 资产
|
Asset asset1 = new Asset(Asset_Owner__c = 'Olympus');
|
asset1.RecordTypeId = System.Label.Asset_RecordType;
|
asset1.SerialNumber = 'ass01';
|
asset1.Loaner_accsessary__c = true;
|
asset1.Name = 'ass01';
|
asset1.AccountId = dep.Id;
|
asset1.Department_Class__c = strategicDep[0].Id;
|
asset1.Hospital__c = hospital.Id;
|
asset1.Product2Id = pro1.Id;
|
|
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;
|
|
insert new Asset[] {asset1, asset2};
|
|
PageReference page = new PageReference('/apex/ProductRepairQuote?productid=' + asset1.Id + '&flag=asset');
|
System.Test.setCurrentPage(page);
|
|
ProductRepairQuoteController controller = new ProductRepairQuoteController();
|
// 初始化
|
controller.init();
|
System.assertEquals(111, controller.product.RepairListPriceLevelA__c);
|
}
|
|
static testMethod void testProduct() {
|
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',Asset_Model_No__c='n01',Serial_Lot_No__c='S/N tracing',ProductCode_Ext__c='pc01',Manual_Entry__c=false,RepairListPriceLevelA__c = 111);
|
Product2 pro2 = new Product2(Name='name02',IsActive=true,Family='GI',Asset_Model_No__c='n02',Serial_Lot_No__c='Lot tracing',ProductCode_Ext__c='pc02',Manual_Entry__c=false,RepairListPriceLevelA__c = 222);
|
insert new Product2[] {pro1, pro2};
|
|
// 资产
|
Asset asset1 = new Asset(Asset_Owner__c = 'Olympus');
|
asset1.RecordTypeId = System.Label.Asset_RecordType;
|
asset1.SerialNumber = 'ass01';
|
asset1.Loaner_accsessary__c = true;
|
asset1.Name = 'ass01';
|
asset1.AccountId = dep.Id;
|
asset1.Department_Class__c = strategicDep[0].Id;
|
asset1.Hospital__c = hospital.Id;
|
asset1.Product2Id = pro1.Id;
|
|
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;
|
|
insert new Asset[] {asset1, asset2};
|
|
PageReference page = new PageReference('/apex/ProductRepairQuote?productid=' + pro2.Id + '&flag=product');
|
System.Test.setCurrentPage(page);
|
|
ProductRepairQuoteController controller = new ProductRepairQuoteController();
|
// 初始化
|
controller.init();
|
System.assertEquals(222, controller.product.RepairListPriceLevelA__c);
|
}
|
|
static testMethod void testProductsearch() {
|
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',Asset_Model_No__c='n01',Serial_Lot_No__c='S/N tracing',ProductCode_Ext__c='pc01',Manual_Entry__c=false,RepairListPriceLevelA__c = 111);
|
Product2 pro2 = new Product2(Name='name02',IsActive=true,Family='GI',Asset_Model_No__c='n02',Serial_Lot_No__c='Lot tracing',ProductCode_Ext__c='pc02',Manual_Entry__c=false,RepairListPriceLevelA__c = 222);
|
insert new Product2[] {pro1, pro2};
|
Product2__c proserc1 = new Product2__c(Name='Pro001',OT_CODE_Text__c='Test001',Product2__c = pro1.Id);
|
Product2__c proserc2 = new Product2__c(Name='Pro002',OT_CODE_Text__c='Test002',Product2__c = pro2.Id);
|
insert new Product2__c[] {proserc1, proserc2};
|
|
PageReference page = new PageReference('/apex/ProductRepairQuote?productid=' + proserc2.Id + '&flag=productsearch');
|
System.Test.setCurrentPage(page);
|
|
ProductRepairQuoteController controller = new ProductRepairQuoteController();
|
// 初始化
|
controller.init();
|
System.assertEquals(222, controller.product.RepairListPriceLevelA__c);
|
}
|
}
|