@isTest
|
private class NFM208RestTest {
|
static testMethod void testNFM028_void() {
|
List<BatchIF_Transfer__c> transfers = new List<BatchIF_Transfer__c>();
|
BatchIF_Transfer__c transfer = new BatchIF_Transfer__c();
|
transfer.Table__c = 'Account';
|
transfer.Column__c = 'Sales_Shop_Class__c';
|
transfer.External_Value__c = '04';
|
transfer.Internal_Value__c = '04Internal';
|
transfers.add(transfer);
|
transfer = new BatchIF_Transfer__c();
|
transfer.Table__c = 'Account';
|
transfer.Column__c = 'Sales_Shop_Class__c';
|
transfer.External_Value__c = '05';
|
transfer.Internal_Value__c = '05Internal';
|
transfers.add(transfer);
|
insert transfers;
|
|
//新建助残
|
// List<Statu_Achievements__c> sac = new List<Statu_Achievements__c>();
|
// Statu_Achievements__c sa = new Statu_Achievements__c();
|
// sa.Opportunity__c = '0061000000n0GuYAAU'; //测试意向询价
|
// sa.ContractNO__c = 'SH-GI-182431'; //假想的合同编号
|
// sa.Order_no_without_0__c = '30087883'; //假想的凭证号码
|
// sa.ContractAmount__c = '1900000'; //合同金额 不能为空
|
// sac.add(sa);
|
// insert sac;
|
|
//新建几个保有设备
|
|
// 病院作成
|
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);
|
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);
|
Product2 pro3 = new Product2(Name='name03',IsActive=true,Family='GI',Asset_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='GI',Asset_Model_No__c='n04',Serial_Lot_No__c='Lot tracing',ProductCode_Ext__c='pc04',Manual_Entry__c=false);
|
Product2 pro5 = new Product2(Name='name05',IsActive=true,Family='GI',Asset_Model_No__c='n05',Serial_Lot_No__c='Lot tracing',ProductCode_Ext__c='pc05',Manual_Entry__c=false);
|
Product2 pro6 = new Product2(Name='name06',IsActive=true,Family='GI',Asset_Model_No__c='n06',Serial_Lot_No__c='Lot tracing',ProductCode_Ext__c='pc06',Manual_Entry__c=false);
|
insert new Product2[] {pro1, pro2,pro3,pro4,pro5,pro6};
|
|
|
Datetime nowDT = Datetime.now();
|
String nowStr = nowDT.format('yyyyMMddHHmm');
|
|
// 资产
|
Asset asset1 = new Asset(Asset_Owner__c = 'Olympus');
|
asset1.RecordTypeId = System.Label.Asset_RecordType;
|
asset1.SerialNumber = 'ass01';
|
asset1.Internal_Asset_number__c = 'ian01';
|
asset1.Name = 'ass01';
|
asset1.AccountId = dep.Id;
|
asset1.Department_Class__c = strategicDep[0].Id;
|
asset1.Hospital__c = hospital.Id;
|
asset1.Product2Id = pro1.Id;
|
asset1.Internal_asset_location__c = '北京';
|
asset1.SerialNumber = '9412222';
|
asset1.Product_Serial_No__c = 'N1021430:9412222';
|
asset1.ProductionDate__c = Date.today();
|
asset1.Guaranteen_end__c = Date.today().addDays(+10);
|
asset1.Order_No__c = '150024';
|
|
Asset asset2 = new Asset(Asset_Owner__c = 'Olympus');
|
asset2.RecordTypeId = System.Label.Asset_RecordType;
|
asset2.SerialNumber = 'ass02';
|
asset2.Internal_Asset_number__c = 'ian02';
|
asset2.Name = 'ass02';
|
asset2.AccountId = dep.Id;
|
asset2.Department_Class__c = strategicDep[0].Id;
|
asset2.Hospital__c = hospital.Id;
|
asset2.Product2Id = pro2.Id;
|
asset2.Internal_asset_location__c = '北京';
|
asset2.SerialNumber = '9412236';
|
asset2.Product_Serial_No__c = 'N1021430:9412236';
|
asset2.ProductionDate__c = Date.today();
|
asset2.Guaranteen_end__c = Date.today().addDays(+10);
|
asset2.Order_No__c = '150024';
|
|
Asset asset3 = new Asset(Asset_Owner__c = 'Olympus');
|
asset3.RecordTypeId = System.Label.Asset_RecordType;
|
asset3.SerialNumber = 'ass03';
|
asset3.Internal_Asset_number__c = 'ian03';
|
asset3.Name = 'ass03';
|
asset3.AccountId = dep.Id;
|
asset3.Department_Class__c = strategicDep[0].Id;
|
asset3.Hospital__c = hospital.Id;
|
asset3.Product2Id = pro3.Id;
|
asset3.Internal_asset_location__c = '上海';
|
asset3.SerialNumber = '8439612';
|
asset3.Product_Serial_No__c = 'N1401661:8439612';
|
asset3.ProductionDate__c = Date.today();
|
asset3.Guaranteen_end__c = Date.today().addDays(+10);
|
asset3.Order_No__c = '150024';
|
|
Asset asset4 = new Asset(Asset_Owner__c = 'Olympus');
|
asset4.RecordTypeId = System.Label.Asset_RecordType;
|
asset4.SerialNumber = 'ass04';
|
asset4.Internal_Asset_number__c = 'ian04';
|
asset4.Name = 'ass04';
|
asset4.AccountId = dep.Id;
|
asset4.Department_Class__c = strategicDep[0].Id;
|
asset4.Hospital__c = hospital.Id;
|
asset4.Product2Id = pro4.Id;
|
asset4.Internal_asset_location__c = '广东';
|
asset4.SerialNumber = '8439617';
|
asset4.Product_Serial_No__c = 'N1401661:8439617';
|
asset4.ProductionDate__c = Date.today();
|
asset4.Guaranteen_end__c = Date.today().addDays(+10);
|
asset4.Order_No__c = '150024';
|
|
Asset asset5 = new Asset(Asset_Owner__c = 'Olympus');
|
asset5.RecordTypeId = System.Label.Asset_RecordType;
|
asset5.SerialNumber = 'ass05';
|
asset5.Internal_Asset_number__c = 'ian05';
|
asset5.Name = 'ass05';
|
asset5.AccountId = dep.Id;
|
asset5.Department_Class__c = strategicDep[0].Id;
|
asset5.Hospital__c = hospital.Id;
|
asset5.Product2Id = pro5.Id;
|
asset5.Internal_asset_location__c = '广州';
|
asset5.SerialNumber = '8439626';
|
asset5.Product_Serial_No__c = 'N1401661:8439626';
|
asset5.ProductionDate__c = Date.today();
|
asset5.Guaranteen_end__c = Date.today().addDays(+10);
|
asset5.Order_No__c = '150024';
|
|
Asset asset6 = new Asset(Asset_Owner__c = 'Olympus');
|
asset6.RecordTypeId = System.Label.Asset_RecordType;
|
asset6.SerialNumber = 'ass06';
|
asset6.Internal_Asset_number__c = 'ian06';
|
asset6.Name = 'ass06';
|
asset6.AccountId = dep.Id;
|
asset6.Department_Class__c = strategicDep[0].Id;
|
asset6.Hospital__c = hospital.Id;
|
asset6.Product2Id = pro6.Id;
|
asset6.Internal_asset_location__c = '北京';
|
asset6.SerialNumber = '6577842';
|
asset6.Product_Serial_No__c = 'N2644060:6577842';
|
asset6.ProductionDate__c = Date.today();
|
asset6.Guaranteen_end__c = Date.today().addDays(+10);
|
asset6.Order_No__c = '150024';
|
|
insert new Asset[] {asset1, asset2,asset3,asset4,asset5,asset6};
|
|
// System.Test.startTest();
|
|
|
// System.Test.stopTest();
|
Test.startTest();
|
|
RestRequest req = new RestRequest();
|
RestResponse res = new RestResponse();
|
|
String JsonMsg = '[{"ProductCode": "N1021430","ReturnProductModel": [{"SerialNumber": "9412222","ManagementNumber": "N1021430:9412222","CreateDate": "","EndDate": ""}, {"SerialNumber": "9412236","ManagementNumber": "N1021430:9412236","CreateDate": "2019-10-09T15:04:44.7545165+08:00","EndDate": "2022-10-11T15:04:44.7545165+08:00"}]}, {"ProductCode": "N1401661","ReturnProductModel": [{"SerialNumber": "8439612","ManagementNumber": "N1401661:8439612","CreateDate": "","EndDate": ""}, {"SerialNumber": "8439626","ManagementNumber": "N1401661:8439626","CreateDate": "","EndDate": ""}, {"SerialNumber": "8439617","ManagementNumber": "N1401661:8439617","CreateDate": "","EndDate": ""}]}, {"ProductCode": "N2644060","ReturnProductModel": [{"SerialNumber": "6577842","ManagementNumber": "N2644060:6577842","CreateDate": "","EndDate": ""}]}]';
|
req.requestURI = 'services/apexrest/NFM208/getProduct';
|
req.httpMethod = 'GET';
|
req.addParameter('ContractNumber' ,'150024');
|
req.requestBody = Blob.valueof(JsonMsg);
|
RestContext.request = req;
|
RestContext.response = res;
|
|
NFM208Rest.getProduct();
|
|
Test.stopTest();
|
|
}
|
// @isTest
|
// static void test_method_execute() {
|
|
|
//}
|
|
}
|