@isTest
|
private class SBG204RestTest {
|
|
@isTest
|
static void test_method_one() {
|
|
// product
|
Product2 prd1 = new Product2();
|
prd1.ProductCode = 'Prd1';
|
prd1.Name = 'Prd1';
|
|
insert prd1;
|
|
// 产品注册证
|
Product_Register__c prc = new Product_Register__c();
|
prc.Name = 'SFDC测试用2018001';
|
insert prc;
|
|
// 产品-注册证关系
|
Product_Register_Link__c prl = new Product_Register_Link__c();
|
prl.Product_Register__c = prc.id;
|
prl.Product2__c = prd1.id;
|
insert prl;
|
|
// IF转送表
|
BatchIF_Transfer__c trans1 = new BatchIF_Transfer__c();
|
trans1.Table__c = 'Product2';
|
trans1.Column__c = 'Product_Status__c';
|
trans1.External_Value__c = '20';
|
trans1.Internal_Value__c = '正常销售';
|
insert trans1;
|
|
BatchIF_Transfer__c trans2 = new BatchIF_Transfer__c();
|
trans2.Table__c = 'Product_Register__c';
|
trans2.Column__c = 'RegisterNoStatus__c';
|
trans2.External_Value__c = '20';
|
trans2.Internal_Value__c = '有效';
|
insert trans2;
|
|
SBG204Rest.GeDatas GeDatas = new SBG204Rest.GeDatas();
|
SBG204Rest.GeData GeData = new SBG204Rest.GeData();
|
GeDatas.GeData = new SBG204Rest.GeData[] {GeData};
|
|
Datetime nowDT = Datetime.now();
|
String nowStr = nowDT.format('yyyyMMddHHmm');
|
GeDatas.Monitoring = new NFMUtil.Monitoring();
|
GeDatas.Monitoring.MessageGroupNumber = nowStr + '01';
|
|
// test1
|
GeData.MaterialNo = 'Prd1';
|
GeData.MaterialStatus = '20';
|
GeData.RegisterNo = 'SFDC测试用2018001';
|
GeData.RegisterNoStatus = '20';
|
GeData.REG_Name = '北京市 亮马桥;北京市 酒仙桥';
|
GeData.ValidFrom = '20180522';
|
|
NFMUtil.Monitoring Monitoring = GeDatas.Monitoring;
|
BatchIF_Log__c rowData = NFMUtil.saveRowData(Monitoring, 'SBG204', GeDatas.GeData);
|
SBG204Rest.executefuture(rowData.Id);
|
|
// test2
|
GeData.MaterialNo = 'Prd1';
|
GeData.MaterialStatus = '20';
|
GeData.RegisterNo = 'SFDC测试用2018001';
|
GeData.RegisterNoStatus = '30';
|
GeData.REG_Name = '北京市 亮马桥;北京市 酒仙桥';
|
GeData.ValidFrom = '20180522';
|
|
|
rowData = NFMUtil.saveRowData(Monitoring, 'SBG204', GeDatas.GeData);
|
SBG204Rest.executefuture(rowData.Id);
|
|
}
|
|
@isTest static void test_method_two() {
|
Test.startTest();
|
|
RestRequest req = new RestRequest();
|
RestResponse res = new RestResponse();
|
|
String JsonMsg = '{"Monitoring":{"TransmissionDateTime":"201812201320","Text":"","Tag":"MSGH","Sender":"SFDC","Receiver":"SPO","NumberOfRecord":"1","MessageType":"NFM204","MessageGroupNumber":"20180001722190"},"GeData":[{"Z3PLAuthorizedNo":"","Z3PLAuthorized":"","YXQX":"1年","ValidTo":null,"ValidFrom":"20180522","Unit":null,"TransCondition":null,"StroageCondition":null,"RegisterNoStatus":"50","RegisterNoClass_Old":"","RegisterNoClass_New":"","RegisterNo":"FYL","ProductName":"SSC6024 : Sof-Curl 输尿管支架管 6Fr.X 24cm","PrdValidTo":null,"PrdValidFrom":null,"PrdCompanyLicense":"","PrdCompanyAddr":"","Other3":null,"Other2":null,"Other1":null,"Model":"SSC6024 ","MedPrdClass":"","MaterialStatusType":null,"MaterialStatus":"10","MaterialNo":"SSC6024","MaterialGroup":null,"BusinessScope":"","AuthorizedCompany_SH":"","AuthorizedCompany":"","ApprovedDate_SH":null,"ApprovedDate":null}]}';
|
req.requestURI = 'services/apexrest/SBG204Rest/execute';
|
req.httpMethod = 'POST';
|
req.requestBody = Blob.valueof(JsonMsg);
|
RestContext.request = req;
|
RestContext.response = res;
|
|
SBG204Rest.execute();
|
|
Test.stopTest();
|
}
|
}
|