@isTest
|
private class DiscountProductApplicationControllerTest {
|
static Account myAccount2; //经销商
|
static Product2__c pro1; //产品检索1
|
static Product2__c pro2; //产品检索2
|
static Product2__c pro3; //产品检索3
|
static Product2__c pro4; //产品检索4
|
static Product2__c pro5; //产品检索5
|
|
static void initData(){
|
List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
|
if (rectCo.size() == 0) {
|
return;
|
}
|
myAccount2 = new Account(Name='Testaccount002',Dealer_discount__c =20,RecordTypeId = rectCo[0].Id,Product_Limit_Date__c = 'Test01|2|4,Test02|3|5');
|
insert myAccount2;
|
Product2 prod01 = new Product2(Name='Test01',
|
ProductCode='Test01',
|
Asset_Model_No__c = 'Test01',
|
SFDA_Status__c = '有効',
|
Product_Status__c = '正常销售',
|
SFDA_Approbated_Status__c = '有效',
|
Category3__c = 'CDS',
|
Category4__c = 'OER',
|
Category5__c = '其它',
|
Dealer_special_Object__c = true,
|
SFDA_Approbation_No__c = 'Test001',
|
Packing_list_manual__c = 1,
|
SFDA_Expiration_Date__c= Date.today(),
|
Intra_Trade_List_RMB_1__c = 1000,
|
Intra_Trade_List_RMB_Date1__c = Date.today().addDays(-1),
|
Intra_Trade_List_RMB_Date2__c = Date.today().addDays(-1),
|
Intra_Trade_List_RMB_End_Date1__c = Date.today().addDays(1),
|
ENG_DeaerProFlag__c = true
|
);
|
|
Product2 prod02 = new Product2(Name='Test02',
|
ProductCode='Test02',
|
Asset_Model_No__c = 'Test02',
|
SFDA_Status__c = '有効',
|
Product_Status__c = '正常销售',
|
SFDA_Approbated_Status__c = '有效',
|
Category3__c = 'ENT',
|
Category4__c = 'Celon',
|
Category5__c = 'Celon',
|
Dealer_special_Object__c = true,
|
SFDA_Approbation_No__c = 'Test002',
|
Packing_list_manual__c = 1,
|
SFDA_Expiration_Date__c= Date.today(),
|
Intra_Trade_List_RMB_1__c = 1000,
|
Intra_Trade_List_RMB_Date1__c = Date.today().addDays(-1),
|
Intra_Trade_List_RMB_Date2__c = Date.today().addDays(-1),
|
Intra_Trade_List_RMB_End_Date1__c = Date.today().addDays(1),
|
ENG_DeaerProFlag__c = true
|
|
);
|
|
Product2 prod03 = new Product2(Name='Test03',
|
ProductCode='Test03',
|
Asset_Model_No__c = 'Test03',
|
SFDA_Status__c = '有効',
|
Dealer_special_Object__c = true,
|
Product_Status__c = '正常销售',
|
SFDA_Approbated_Status__c = '有效',
|
Category3__c = 'US',
|
Category4__c = 'ALOKA',
|
Category5__c = '体外超声',
|
Intra_Trade_List_RMB_1__c = 1000,
|
Intra_Trade_List_RMB_Date1__c = Date.today().addDays(-1),
|
Intra_Trade_List_RMB_End_Date1__c = Date.today().addDays(1),
|
ENG_DeaerProFlag__c = true
|
);
|
|
Product2 prod04 = new Product2(Name='Test04',
|
ProductCode='Test04',Asset_Model_No__c = 'Test04',
|
SFDA_Status__c = '有効',
|
Dealer_special_Object__c = true,
|
Product_Status__c = '正常销售',
|
SFDA_Approbated_Status__c = '有效',
|
Category3__c = 'OCS',
|
Category4__c = '附属品',
|
Category5__c = 'OCS',
|
Intra_Trade_List_RMB_1__c = 1000,
|
Intra_Trade_List_RMB_Date1__c = Date.today().addDays(-1),
|
Intra_Trade_List_RMB_End_Date1__c = Date.today().addDays(1),
|
ENG_DeaerProFlag__c = true
|
);
|
Product2 prod05 = new Product2(Name='Test05',
|
ProductCode='Test05',
|
Asset_Model_No__c = 'Test05',
|
SFDA_Status__c = '有効',
|
Dealer_special_Object__c = true,
|
Product_Status__c = '正常销售',
|
SFDA_Approbated_Status__c = '有效',
|
Category3__c = '光源',
|
Category4__c = 'CLV',
|
Category5__c = 'S45',
|
Intra_Trade_List_RMB_1__c = 1000,
|
Intra_Trade_List_RMB_Date1__c = Date.today().addDays(-1),
|
Intra_Trade_List_RMB_End_Date1__c = Date.today().addDays(1),
|
ENG_DeaerProFlag__c = true
|
);
|
insert new Product2[] {prod01,prod02,prod03, prod04, prod05};
|
pro1 = new Product2__c(Name='Pro001',OT_CODE_Text__c='Test001',Product2__c = prod01.Id);
|
pro2 = new Product2__c(Name='Pro002',OT_CODE_Text__c='Test002',Product2__c = prod02.Id);
|
pro3 = new Product2__c(Name='Pro003',OT_CODE_Text__c='Test003',Product2__c = prod03.Id);
|
pro4 = new Product2__c(Name='Pro004',OT_CODE_Text__c='Test004',Product2__c = prod04.Id);
|
pro5 = new Product2__c(Name='Pro005',OT_CODE_Text__c='Test005',Product2__c = prod05.Id);
|
insert new Product2__c[] {pro1,pro2,pro3,pro4, pro5};
|
}
|
|
//init 方法
|
static testMethod void testInit() {
|
//1.accountid 不为空
|
initData();
|
Account hospital = new Account();
|
hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
|
hospital.Name = 'test hospital';
|
hospital.Is_Active__c = '有効';
|
hospital.Attribute_Type__c = '卫生部';
|
hospital.Speciality_Type__c = '综合医院';
|
hospital.Grade__c = '一级';
|
hospital.OCM_Category__c = 'SLTV';
|
hospital.Is_Medical__c = '医疗机构';
|
// hospital.State_Master__c = al.id;
|
// hospital.City_Master__c = al2.id;
|
hospital.Town__c = '东京';
|
insert hospital;
|
DiscountProductApplication__c dpc = new DiscountProductApplication__c();
|
dpc.AimsAccount__c = hospital.Id;
|
dpc.RawAccount__c = myAccount2.Id;
|
dpc.ApplicationStatus__c = '草案中';
|
dpc.Product_Type__c = 'ENG';
|
insert dpc;
|
PageReference page = new PageReference('/apex/DiscountProductApplication?Id='+myAccount2.Id);
|
|
System.Test.setCurrentPage(page);
|
DiscountProductApplicationController conTest = new DiscountProductApplicationController(new ApexPages.StandardController(myAccount2));
|
Test.startTest();
|
conTest.init();
|
//测试检索
|
// conTest.text1 = 'Pro';
|
// conTest.text2 = 'Test';
|
conTest.searchAllProduct2();
|
//报错
|
conTest.savesaveDiscountProduct();
|
//---
|
conTest.AimsAccountId = hospital.Id;
|
conTest.dpa = dpc;
|
conTest.DiscountProductApplicationDetailList[0].check = true;
|
conTest.DiscountProductApplicationDetailList[0].dp.ProductDiscount__c = 1234;
|
conTest.DiscountProductApplicationDetailList[0].Pr2 = pro2;
|
conTest.savesaveDiscountProduct();
|
conTest.ProtypeChange();
|
Test.stopTest();
|
|
//1.dpaId 不为空 1.设置医院
|
|
DiscountProductApplicationDetail__c dpac1 = new DiscountProductApplicationDetail__c();
|
dpac1.DiscountProductApplication__c = dpc.id;
|
dpac1.ProductDiscount__c = 123;
|
dpac1.Product2__c = pro1.Id;
|
DiscountProductApplicationDetail__c dpac2 = new DiscountProductApplicationDetail__c();
|
dpac2.DiscountProductApplication__c = dpc.id;
|
dpac2.ProductDiscount__c = 1234;
|
dpac2.Product2__c = pro2.Id;
|
DiscountProductApplicationDetail__c dpac3 = new DiscountProductApplicationDetail__c();
|
dpac3.DiscountProductApplication__c = dpc.id;
|
dpac3.ProductDiscount__c = 1235;
|
dpac3.Product2__c = pro3.Id;
|
insert new DiscountProductApplicationDetail__c[] {dpac1,dpac2,dpac3};
|
|
|
page = new PageReference('/apex/DiscountProductApplication?Id='+dpc.Id);
|
System.Test.setCurrentPage(page);
|
conTest = new DiscountProductApplicationController(new ApexPages.StandardController(myAccount2));
|
conTest.init();
|
|
}
|
|
//init 方法
|
static testMethod void testInit2() {
|
//1.accountid 不为空
|
initData();
|
Account hospital = new Account();
|
hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
|
hospital.Name = 'test hospital';
|
hospital.Is_Active__c = '有効';
|
hospital.Attribute_Type__c = '卫生部';
|
hospital.Speciality_Type__c = '综合医院';
|
hospital.Grade__c = '一级';
|
hospital.OCM_Category__c = 'SLTV';
|
hospital.Is_Medical__c = '医疗机构';
|
// hospital.State_Master__c = al.id;
|
// hospital.City_Master__c = al2.id;
|
hospital.Town__c = '东京';
|
insert hospital;
|
DiscountProductApplication__c dpc = new DiscountProductApplication__c();
|
dpc.AimsAccount__c = hospital.Id;
|
dpc.RawAccount__c = myAccount2.Id;
|
dpc.ApplicationStatus__c = '草案中';
|
dpc.Product_Type__c = 'ENG';
|
insert dpc;
|
PageReference page = new PageReference('/apex/DiscountProductApplication');
|
|
System.Test.setCurrentPage(page);
|
DiscountProductApplicationController conTest = new DiscountProductApplicationController(new ApexPages.StandardController(myAccount2));
|
Test.startTest();
|
conTest.init();
|
}
|
}
|