@isTest
|
private class SBG010TRestTest {
|
static String setdata(){
|
Id pricebookId = Test.getStandardPricebookId();
|
Pricebook2 pricebook = new Pricebook2(
|
Name = 'BS',
|
isActive = true
|
);
|
insert pricebook;
|
Product2 product1 = new Product2();
|
product1.Name = 'product1';
|
Product2 product2 = new Product2();
|
product2.Name = 'product2';
|
Product2 product3 = new Product2();
|
product3.Name = 'product3';
|
insert new Product2[] {product1,product2,product3};
|
PricebookEntry standardPrice1 = new PricebookEntry(
|
Pricebook2Id = pricebookId,
|
Product2Id = product1.Id,
|
UnitPrice = 0,
|
CurrencyIsoCode = 'CNY',
|
IsActive = true
|
);
|
PricebookEntry standardPrice2 = new PricebookEntry(
|
Pricebook2Id = pricebookId,
|
Product2Id = product2.Id,
|
UnitPrice = 0,
|
CurrencyIsoCode = 'CNY',
|
IsActive = true
|
);
|
PricebookEntry standardPrice3 = new PricebookEntry(
|
Pricebook2Id = pricebookId,
|
Product2Id = product3.Id,
|
UnitPrice = 0,
|
CurrencyIsoCode = 'CNY',
|
IsActive = true
|
);
|
insert new PricebookEntry[] {standardPrice1,standardPrice2,standardPrice3};
|
|
PricebookEntry entry1 = new PricebookEntry( Pricebook2Id=pricebook.Id, Product2Id=product1.Id);
|
entry1.UnitPrice = 0;
|
entry1.IsActive = true;
|
entry1.UseStandardPrice = false;
|
entry1.CurrencyIsoCode = 'CNY';
|
PricebookEntry entry2 = new PricebookEntry( Pricebook2Id=pricebook.Id, Product2Id=product2.Id);
|
entry2.UnitPrice = 0;
|
entry2.IsActive = true;
|
entry2.UseStandardPrice = false;
|
entry2.CurrencyIsoCode = 'CNY';
|
PricebookEntry entry3 = new PricebookEntry( Pricebook2Id=pricebook.Id, Product2Id=product3.Id);
|
entry3.UnitPrice = 0;
|
entry3.IsActive = true;
|
entry3.UseStandardPrice = false;
|
entry3.CurrencyIsoCode = 'CNY';
|
insert new PricebookEntry[] {entry1,entry2,entry3};
|
List<RecordType> rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer IE'];
|
Account accIE = new Account(
|
Name = '*',
|
RecordTypeId = rectIE[0].Id,
|
OwnerId = UserInfo.getUserId(),
|
DivisionName__c='Customer IE',
|
FacilityName__c='abc',
|
PostCode__c = '123456'
|
);
|
insert accIE;
|
|
|
Date day1 = Date.today();
|
List<RecordType> rectOpp = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity'];
|
// 有预定下单日
|
Opportunity opp = new Opportunity();
|
opp.Name = 'test opp';
|
opp.AccountId = accIE.Id;
|
opp.RecordTypeId = rectOpp[0].Id;
|
opp.OwnerId = UserInfo.getUserId();
|
opp.StageName = 'Prospect Created';
|
opp.CurrencyIsoCode = 'CNY';
|
opp.ProductSegment__c = 'IE';
|
opp.CloseDate = Date.today();
|
opp.NewInquiryDate__c = Date.today().addDays(-2);
|
opp.ExpectedOrderDate__c = Date.today().addDays(2);
|
opp.ApprovalStatus_D__c = 'Pass';
|
opp.LeadSource = 'LeadSource_D__c';
|
opp.BudgetAmount__c = 111;
|
opp.CancelReasonText__c = 'Cancel_Reason_Text_D__c';
|
opp.CancelReason__c = 'Cancel_reason_D__c';
|
opp.CompetitorCompany__c = 'Competitor_Company_D__c';
|
opp.Competitor_Product__c = 'Competitor_Product_D__c';
|
opp.Competitor_Product2__c = 'Competitor_Product2_D__c';
|
opp.Competitor_Product3__c = 'Competitor_Product3_D__c';
|
opp.Competitor_Product4__c = 'Competitor_Product4_D__c';
|
opp.Competitor_Product5__c = 'Competitor_Product5_D__c';
|
opp.Competitor_Product6__c = 'Competitor_Product6_D__c';
|
opp.Competitor_Product7__c = 'Competitor_Product7_D__c';
|
opp.Competitor_Product8__c = 'Competitor_Product8_D__c';
|
opp.CompetitorProductCode__c = 'Competitor_Product_Code_D__c';
|
opp.CompetitorProductCode2__c = 'Competitor_Product_Code2_D__c';
|
opp.CompetitorProductCode3__c = 'Competitor_Product_Code3_D__c';
|
opp.CompetitorProductCode4__c = 'Competitor_Product_Code4_D__c';
|
opp.CompetitorProductCode5__c = 'Competitor_Product_Code5_D__c';
|
opp.CompetitorProductCode6__c = 'Competitor_Product_Code6_D__c';
|
opp.CompetitorProductCode7__c = 'Competitor_Product_Code7_D__c';
|
opp.CompetitorProductCode8__c = 'Competitor_Product_Code8_D__c';
|
opp.DealerSalesStaffName__c = 'Dealer_Sales_Staff_Name_D__c';
|
opp.DealerService__c = 'Dealer_Service_D__c';
|
opp.ExpectedDeliveryDate__c = day1;
|
opp.InquiryResult__c = 'InquiryResultD__c';
|
//opp.InquiryResultCancel__c = day1;
|
//opp.InquiryResultLost__c = day1;
|
opp.InquiryResultOrder__c = day1;
|
opp.LostAmount__c = 111;
|
opp.LostCompetitorProduct__c = 'Lost_competitor_product_D__c';
|
opp.LostReasonText__c = 'LostReasonText_D__c';
|
opp.LostReason__c = 'Lostreason_D__c';
|
opp.Phase1Date__c = day1;
|
opp.Phase2Date__c = day1;
|
opp.Phase3Date__c = day1;
|
opp.SalesChannel__c = 'Sales_Channel_D__c';
|
opp.SubDealer__c = 'Sub_Dealer_D__c';
|
opp.TradeType__c = 'Trade_Type_D__c';
|
//opp.Machine_Parts__c = 'Machine_Parts_D__c';
|
//opp.SpecialDeliveryAddress__c = 'SpecialDeliveryAddress_D__c';
|
//opp.ForeignTradeCompany__c = 'ForeignTradeCompany_D__c';
|
insert opp;
|
OpportunityLineItem oli = new OpportunityLineItem();
|
oli.OpportunityId = opp.Id;
|
oli.Quantity = 2;
|
oli.UnitPrice = 111;
|
oli.Description = 'test';
|
oli.PricebookEntryId = entry1.Id;
|
insert oli;
|
List<RecordType> rectOrder = [select id from RecordType where IsActive = true and SobjectType = 'Order'];
|
Order odr = new Order(
|
Name = '',
|
Status = 'Draft',
|
AccountId = accIE.Id,
|
ApproveStatus__c = 'Draft',
|
OpportunityId = opp.Id,
|
EffectiveDate = Date.today(),
|
CurrencyIsoCode = 'CNY',
|
RecordTypeId = '01228000000NJt6'
|
);
|
insert odr;
|
|
Delivery__c de1 = new Delivery__c();
|
de1.SSBD_Contract__c = odr.Id;
|
|
insert de1;
|
Order ordd = [Select OrderNumber,Id,Name From Order];
|
return ordd.OrderNumber;
|
|
}
|
@isTest static void test_method_one() {
|
|
|
SBG010Rest.GeData GeData = new SBG010Rest.GeData();
|
SBG010Rest.GeDatas GeDatas = new SBG010Rest.GeDatas();
|
GeDatas.GeData = new SBG010Rest.GeData[] { GeData };
|
|
Datetime nowDT = Datetime.now();
|
String nowStr = nowDT.format('yyyyMMddHHmm');
|
GeDatas.Monitoring = new NFMUtil.Monitoring();
|
GeDatas.Monitoring.MessageGroupNumber = nowStr + '01';
|
|
String ocode = setdata();
|
GeData.OrderCode = ocode;
|
|
BatchIF_Log__c rowData = NFMUtil.saveRowData(GeDatas.Monitoring, 'SBG004', GeDatas.GeData);
|
|
SBG010Rest.main(rowData.Id);
|
}
|
|
@isTest static void test_method2() {
|
|
|
SBG010Rest.GeData GeData = new SBG010Rest.GeData();
|
SBG010Rest.GeDatas GeDatas = new SBG010Rest.GeDatas();
|
GeDatas.GeData = new SBG010Rest.GeData[] { GeData };
|
|
Datetime nowDT = Datetime.now();
|
String nowStr = nowDT.format('yyyyMMddHHmm');
|
GeDatas.Monitoring = new NFMUtil.Monitoring();
|
GeDatas.Monitoring.MessageGroupNumber = nowStr + '01';
|
|
String ocode = setdata();
|
GeData.OrderCode = ocode;
|
GeData.SoNo = '123131';
|
GeData.SoShippingStatus = '未发货';
|
|
BatchIF_Log__c rowData = NFMUtil.saveRowData(GeDatas.Monitoring, 'SBG004', GeDatas.GeData);
|
|
SBG010Rest.main(rowData.Id);
|
}
|
@isTest static void test_method3() {
|
|
|
SBG010Rest.GeData GeData = new SBG010Rest.GeData();
|
SBG010Rest.GeDatas GeDatas = new SBG010Rest.GeDatas();
|
GeDatas.GeData = new SBG010Rest.GeData[] { GeData };
|
|
Datetime nowDT = Datetime.now();
|
String nowStr = nowDT.format('yyyyMMddHHmm');
|
GeDatas.Monitoring = new NFMUtil.Monitoring();
|
GeDatas.Monitoring.MessageGroupNumber = nowStr + '01';
|
|
String ocode = setdata();
|
GeData.OrderCode = ocode;
|
GeData.SoNo = '123131';
|
|
|
BatchIF_Log__c rowData = NFMUtil.saveRowData(GeDatas.Monitoring, 'SBG004', GeDatas.GeData);
|
|
SBG010Rest.main(rowData.Id);
|
}
|
@isTest static void test_method4() {
|
|
|
SBG010Rest.GeData GeData = new SBG010Rest.GeData();
|
SBG010Rest.GeDatas GeDatas = new SBG010Rest.GeDatas();
|
GeDatas.GeData = new SBG010Rest.GeData[] { GeData };
|
|
Datetime nowDT = Datetime.now();
|
String nowStr = nowDT.format('yyyyMMddHHmm');
|
GeDatas.Monitoring = new NFMUtil.Monitoring();
|
GeDatas.Monitoring.MessageGroupNumber = nowStr + '01';
|
|
String ocode = setdata();
|
|
GeData.SoNo = '123131';
|
GeData.SoShippingStatus = '未发货';
|
|
BatchIF_Log__c rowData = NFMUtil.saveRowData(GeDatas.Monitoring, 'SBG004', GeDatas.GeData);
|
|
SBG010Rest.main(rowData.Id);
|
}
|
|
|
@isTest static void test_method_Send() {
|
|
Test.startTest();
|
|
RestRequest req = new RestRequest();
|
RestResponse res = new RestResponse();
|
|
// String JsonMsg = '{"GeDatas": {"Monitoring": {"Tag": "MSGH","Sender": 1330,"Receiver": 1592,"MessageType": "SBG004","MessageGroupNumber": 331591,"NumberOfRecord": 1,"TransmissionDateTime": 201908081115},"GeData": [{"TradeType": "Taxation","SalesChannel": "99","PurposeOfAdvice": "3","ProductSegment": "IE","ProductCode": "N5702700","Other3": "","Other2": "","Other1": "","MachineParts": "Machine","EffectiveDateTo": "99991231","EffectiveDateFrom": "20190801","Currency_x": "RMB","CostPrice": 12241.00}]}}';
|
String JsonMsg = '{"GeDatas": {"Monitoring": {"Tag": "MSGH"},"GeData":[{"SoShippingStatus": "全部发货"}]}}';
|
req.requestURI = 'services/apexrest/SBG004/execute';
|
req.httpMethod = 'POST';
|
req.requestBody = Blob.valueof(JsonMsg);
|
RestContext.request = req;
|
RestContext.response= res;
|
|
SBG010Rest.execute();
|
|
Test.stopTest();
|
|
// { "GeDatas": {"Monitoring": {"Tag": "MSGH","Sender": 1330,"Receiver": 1592,"MessageType": "SBG017", "MessageGroupNumber": 331591, "NumberOfRecord": 1, "TransmissionDateTime": 201903251115 },"GeData": [{ "StockAnswer": "OK111","SAPQuotationCode": "20022780 ", "Other3": "", "Other2": "", "Other1": "", "OpportunityCode": "O-2018-067607"}]}}
|
|
//Test.setMock(HttpCalloutMock.class, new NFM205RestCalloutMock());
|
//NFM205Rest.execute1('{"Monitoring":{"TransmissionDateTime":"201812201320","Text":"","Tag":"MSGH","Sender":"SFDC","Receiver":"SPO","NumberOfRecord":"1","MessageType":"NFM205","MessageGroupNumber":"20180001722190"},"GeData":[{"Opportunity_Code":"HKBJ-GI-BJ0588881","Bidding_No":"as123121","Bidding_Content":"招标内容","Bid_Project_Name":"招标项目名","Bid_Date":"20181203","Authorized_Status":"1","Authorized_Finish_Sales":"30033","Authorized_DB_No":"MGZWESQHN201812001","Authorized_Date":"20190316","Autholization_Activated_Date":"20190415"}]}');
|
}
|
|
}
|