@isTest private class NFM004RestTest { static Product2 testNFM004Init() { // テストデータ Product2 prd = new Product2(); prd.ProductCode_Ext__c = 'testNFM004'; prd.ProductCode = 'testNFM004'; prd.Name = 'testNFM004'; prd.Manual_Entry__c = false; insert prd; return prd; } // そのままreturn @isTest static void testNFM004_void() { testNFM004Init(); // null // NFM004Rest.NFM004(null); NFM004Rest.PurchasePrice PurchasePrice = new NFM004Rest.PurchasePrice(); NFM004Rest.PurchasePrices PurchasePrices = new NFM004Rest.PurchasePrices(); PurchasePrices.PurchasePrice = new NFM004Rest.PurchasePrice[] { PurchasePrice }; Datetime nowDT = Datetime.now(); String nowStr = nowDT.format('yyyyMMddHHmm'); PurchasePrices.Monitoring = new NFMUtil.Monitoring(); PurchasePrices.Monitoring.MessageGroupNumber = nowStr + '07'; // Monitoringをセットしない // rowData = NFMUtil.saveRowData(PurchasePrices.Monitoring, 'NFM004', PurchasePrices.PurchasePrice); BatchIF_Log__c rowData = NFMUtil.saveRowData(PurchasePrices.Monitoring, 'NFM004', PurchasePrices.PurchasePrice); NFM004Rest u = new NFM004Rest(rowData.Id, 0, PurchasePrices.PurchasePrice.size()); Database.executeBatch(u, 1); // Datetime nowDT = Datetime.now(); // String nowStr = nowDT.format('yyyyMMddHHmm'); PurchasePrices.Monitoring = new NFMUtil.Monitoring(); PurchasePrices.Monitoring.MessageGroupNumber = nowStr + '01'; // 必須項目をセットしない rowData = NFMUtil.saveRowData(PurchasePrices.Monitoring, 'NFM004', PurchasePrices.PurchasePrice); // 商品コードが存在しない PurchasePrices.Monitoring.MessageGroupNumber = nowStr + '02'; PurchasePrice.SuppliersItemCode = 'testNFM004X'; System.Test.startTest(); // rowData = NFMUtil.saveRowData(PurchasePrices.Monitoring, 'NFM004', PurchasePrices.PurchasePrice); rowData = NFMUtil.saveRowData(PurchasePrices.Monitoring, 'NFM004', PurchasePrices.PurchasePrice); u = new NFM004Rest(rowData.Id, 0, PurchasePrices.PurchasePrice.size()); System.Test.stopTest(); Product2[] rslts = [select Id from Product2 where ProductCode_Ext__c = :PurchasePrice.SuppliersItemCode]; System.assertEquals(0, rslts.size()); } @isTest static void testNFM004_update_RMB_1() { testNFM004Init(); NFM004Rest.PurchasePrice PurchasePrice = new NFM004Rest.PurchasePrice(); NFM004Rest.PurchasePrices PurchasePrices = new NFM004Rest.PurchasePrices(); // Monitoringの設定 Datetime nowDT = Datetime.now(); String nowStr = nowDT.format('yyyyMMddHHmm'); PurchasePrices.Monitoring = new NFMUtil.Monitoring(); // update RMB 内貿 1回目 PurchasePrices.PurchasePrice = new NFM004Rest.PurchasePrice[] { PurchasePrice }; PurchasePrices.Monitoring.MessageGroupNumber = nowStr + '11'; PurchasePrice.SuppliersItemCode = 'testNFM004'; PurchasePrice.PriceType = 'OCM-001'; PurchasePrice.Currency_x = 'RMB'; PurchasePrice.PurchasePrice_x = 1.12; PurchasePrice.EffectiveDateFrom = '20121101'; PurchasePrice.EffectiveDateTo = '29121103'; PurchasePrice.PurposeOfAdvice = '3'; System.Test.startTest(); BatchIF_Log__c rowData = NFMUtil.saveRowData(PurchasePrices.Monitoring, 'NFM004', PurchasePrices.PurchasePrice); NFM004Rest u = new NFM004Rest(rowData.Id, 0, PurchasePrices.PurchasePrice.size()); Database.executeBatch(u, 1); System.Test.stopTest(); List rslts = [select Id, ProductCode, ProductCode_Ext__c, Intra_Trade_Cost_RMB_1__c, Intra_Trade_Cost_RMB_Date1__c, Intra_Trade_Cost_RMB_End_Date1__c, Intra_Trade_Cost_RMB_2__c, Intra_Trade_Cost_RMB_Date2__c, Intra_Trade_Cost_RMB_End_Date2__c, Foreign_Trade_Cost_US_1__c, Foreign_Trade_Cost_US_Date1__c, Foreign_Trade_Cost_US_End_Date1__c, Foreign_Trade_Cost_US_2__c, Foreign_Trade_Cost_US_Date2__c, Foreign_Trade_Cost_US_End_Date2__c, Intra_Trade_Cost_US__c, Intra_Trade_Cost_US_Date__c, Intra_Trade_Cost_US_End_Date__c, Foreign_Trade_Cost_RMB__c, Foreign_Trade_Cost_RMB_Date__c, Foreign_Trade_Cost_RMB_End_Date__c from Product2 where ProductCode_Ext__c = :PurchasePrice.SuppliersItemCode]; System.assertEquals(1, rslts.size()); if (rslts.size() == 1) { System.assertEquals('testNFM004', rslts[0].ProductCode); System.assertEquals(1.12, rslts[0].Intra_Trade_Cost_RMB_1__c); System.assertEquals(date.newinstance(2012, 11, 1), rslts[0].Intra_Trade_Cost_RMB_Date1__c); System.assertEquals(date.newinstance(2912, 11, 3), rslts[0].Intra_Trade_Cost_RMB_End_Date1__c); System.assertEquals(null, rslts[0].Intra_Trade_Cost_RMB_2__c); System.assertEquals(null, rslts[0].Intra_Trade_Cost_RMB_Date2__c); System.assertEquals(null, rslts[0].Intra_Trade_Cost_RMB_End_Date2__c); System.assertEquals(null, rslts[0].Foreign_Trade_Cost_US_1__c); System.assertEquals(null, rslts[0].Foreign_Trade_Cost_US_Date1__c); System.assertEquals(null, rslts[0].Foreign_Trade_Cost_US_End_Date1__c); System.assertEquals(null, rslts[0].Foreign_Trade_Cost_US_2__c); System.assertEquals(null, rslts[0].Foreign_Trade_Cost_US_Date2__c); System.assertEquals(null, rslts[0].Foreign_Trade_Cost_US_End_Date2__c); System.assertEquals(null, rslts[0].Intra_Trade_Cost_US__c); System.assertEquals(null, rslts[0].Intra_Trade_Cost_US_Date__c); System.assertEquals(null, rslts[0].Intra_Trade_Cost_US_End_Date__c); System.assertEquals(null, rslts[0].Foreign_Trade_Cost_RMB__c); System.assertEquals(null, rslts[0].Foreign_Trade_Cost_RMB_Date__c); System.assertEquals(null, rslts[0].Foreign_Trade_Cost_RMB_End_Date__c); } } @isTest static void testNFM004_update_RMB_2() { Product2 prd = testNFM004Init(); prd.Intra_Trade_Cost_RMB_1__c = 1.12; prd.Intra_Trade_Cost_RMB_Date1__c = date.newinstance(2012, 11, 1); prd.Intra_Trade_Cost_RMB_End_Date1__c = date.newinstance(2912, 11, 3); update prd; NFM004Rest.PurchasePrice PurchasePrice = new NFM004Rest.PurchasePrice(); NFM004Rest.PurchasePrices PurchasePrices = new NFM004Rest.PurchasePrices(); // Monitoringの設定 Datetime nowDT = Datetime.now(); String nowStr = nowDT.format('yyyyMMddHHmm'); PurchasePrices.Monitoring = new NFMUtil.Monitoring(); // update RMB 内貿 2回目 PurchasePrices.PurchasePrice = new NFM004Rest.PurchasePrice[] { PurchasePrice }; PurchasePrices.Monitoring.MessageGroupNumber = nowStr + '12'; PurchasePrice.SuppliersItemCode = 'testNFM004'; PurchasePrice.PriceType = 'OCM-001'; PurchasePrice.Currency_x = 'RMB'; PurchasePrice.PurchasePrice_x = 1.34; PurchasePrice.EffectiveDateFrom = '20121111'; PurchasePrice.EffectiveDateTo = '29121113'; PurchasePrice.PurposeOfAdvice = '3'; BatchIF_Log__c rowData = NFMUtil.saveRowData(PurchasePrices.Monitoring, 'NFM004', PurchasePrices.PurchasePrice); NFM004Rest u = new NFM004Rest(rowData.Id, 0, PurchasePrices.PurchasePrice.size()); System.Test.startTest(); Database.executeBatch(u, 1); System.Test.stopTest(); List rslts = [select Id, ProductCode, ProductCode_Ext__c, Intra_Trade_Cost_RMB_1__c, Intra_Trade_Cost_RMB_Date1__c, Intra_Trade_Cost_RMB_End_Date1__c, Intra_Trade_Cost_RMB_2__c, Intra_Trade_Cost_RMB_Date2__c, Intra_Trade_Cost_RMB_End_Date2__c, Foreign_Trade_Cost_US_1__c, Foreign_Trade_Cost_US_Date1__c, Foreign_Trade_Cost_US_End_Date1__c, Foreign_Trade_Cost_US_2__c, Foreign_Trade_Cost_US_Date2__c, Foreign_Trade_Cost_US_End_Date2__c, Intra_Trade_Cost_US__c, Intra_Trade_Cost_US_Date__c, Intra_Trade_Cost_US_End_Date__c, Foreign_Trade_Cost_RMB__c, Foreign_Trade_Cost_RMB_Date__c, Foreign_Trade_Cost_RMB_End_Date__c from Product2 where ProductCode_Ext__c = :PurchasePrice.SuppliersItemCode]; System.assertEquals(1, rslts.size()); if (rslts.size() == 1) { System.assertEquals('testNFM004', rslts[0].ProductCode); System.assertEquals(1.12, rslts[0].Intra_Trade_Cost_RMB_1__c); System.assertEquals(date.newinstance(2012, 11, 1), rslts[0].Intra_Trade_Cost_RMB_Date1__c); System.assertEquals(date.newinstance(2912, 11, 3), rslts[0].Intra_Trade_Cost_RMB_End_Date1__c); System.assertEquals(1.34, rslts[0].Intra_Trade_Cost_RMB_2__c); System.assertEquals(date.newinstance(2012, 11, 11), rslts[0].Intra_Trade_Cost_RMB_Date2__c); System.assertEquals(date.newinstance(2912, 11, 13), rslts[0].Intra_Trade_Cost_RMB_End_Date2__c); System.assertEquals(null, rslts[0].Foreign_Trade_Cost_US_1__c); System.assertEquals(null, rslts[0].Foreign_Trade_Cost_US_Date1__c); System.assertEquals(null, rslts[0].Foreign_Trade_Cost_US_End_Date1__c); System.assertEquals(null, rslts[0].Foreign_Trade_Cost_US_2__c); System.assertEquals(null, rslts[0].Foreign_Trade_Cost_US_Date2__c); System.assertEquals(null, rslts[0].Foreign_Trade_Cost_US_End_Date2__c); System.assertEquals(null, rslts[0].Intra_Trade_Cost_US__c); System.assertEquals(null, rslts[0].Intra_Trade_Cost_US_Date__c); System.assertEquals(null, rslts[0].Intra_Trade_Cost_US_End_Date__c); System.assertEquals(null, rslts[0].Foreign_Trade_Cost_RMB__c); System.assertEquals(null, rslts[0].Foreign_Trade_Cost_RMB_Date__c); System.assertEquals(null, rslts[0].Foreign_Trade_Cost_RMB_End_Date__c); } } @isTest static void testNFM004_update_RMB_3() { Product2 prd = testNFM004Init(); prd.Intra_Trade_Cost_RMB_1__c = 1.12; prd.Intra_Trade_Cost_RMB_Date1__c = date.newinstance(2012, 11, 1); prd.Intra_Trade_Cost_RMB_End_Date1__c = date.newinstance(2912, 11, 3); prd.Intra_Trade_Cost_RMB_2__c = 1.34; prd.Intra_Trade_Cost_RMB_Date2__c = date.newinstance(2012, 11, 11); prd.Intra_Trade_Cost_RMB_End_Date2__c = date.newinstance(2912, 11, 13); update prd; NFM004Rest.PurchasePrice PurchasePrice = new NFM004Rest.PurchasePrice(); NFM004Rest.PurchasePrices PurchasePrices = new NFM004Rest.PurchasePrices(); // Monitoringの設定 Datetime nowDT = Datetime.now(); String nowStr = nowDT.format('yyyyMMddHHmm'); PurchasePrices.Monitoring = new NFMUtil.Monitoring(); // update RMB 内貿 3回目 PurchasePrices.PurchasePrice = new NFM004Rest.PurchasePrice[] { PurchasePrice }; PurchasePrices.Monitoring.MessageGroupNumber = nowStr + '13'; PurchasePrice.SuppliersItemCode = 'testNFM004'; PurchasePrice.PriceType = 'OCM-001'; PurchasePrice.Currency_x = 'RMB'; PurchasePrice.PurchasePrice_x = 1.56; PurchasePrice.EffectiveDateFrom = '00000000'; PurchasePrice.EffectiveDateTo = '29121123'; PurchasePrice.PurposeOfAdvice = '3'; BatchIF_Log__c rowData = NFMUtil.saveRowData(PurchasePrices.Monitoring, 'NFM004', PurchasePrices.PurchasePrice); NFM004Rest u = new NFM004Rest(rowData.Id, 0, PurchasePrices.PurchasePrice.size()); System.Test.startTest(); Database.executeBatch(u, 1); System.Test.stopTest(); List rslts = [select Id, ProductCode, ProductCode_Ext__c, Intra_Trade_Cost_RMB_1__c, Intra_Trade_Cost_RMB_Date1__c, Intra_Trade_Cost_RMB_End_Date1__c, Intra_Trade_Cost_RMB_2__c, Intra_Trade_Cost_RMB_Date2__c, Intra_Trade_Cost_RMB_End_Date2__c, Foreign_Trade_Cost_US_1__c, Foreign_Trade_Cost_US_Date1__c, Foreign_Trade_Cost_US_End_Date1__c, Foreign_Trade_Cost_US_2__c, Foreign_Trade_Cost_US_Date2__c, Foreign_Trade_Cost_US_End_Date2__c, Intra_Trade_Cost_US__c, Intra_Trade_Cost_US_Date__c, Intra_Trade_Cost_US_End_Date__c, Foreign_Trade_Cost_RMB__c, Foreign_Trade_Cost_RMB_Date__c, Foreign_Trade_Cost_RMB_End_Date__c from Product2 where ProductCode_Ext__c = :PurchasePrice.SuppliersItemCode]; System.assertEquals(1, rslts.size()); if (rslts.size() == 1) { System.assertEquals('testNFM004', rslts[0].ProductCode); System.assertEquals(1.56, rslts[0].Intra_Trade_Cost_RMB_1__c); System.assertEquals(null, rslts[0].Intra_Trade_Cost_RMB_Date1__c); System.assertEquals(date.newinstance(2912, 11, 23), rslts[0].Intra_Trade_Cost_RMB_End_Date1__c); System.assertEquals(1.34, rslts[0].Intra_Trade_Cost_RMB_2__c); System.assertEquals(date.newinstance(2012, 11, 11), rslts[0].Intra_Trade_Cost_RMB_Date2__c); System.assertEquals(date.newinstance(2912, 11, 13), rslts[0].Intra_Trade_Cost_RMB_End_Date2__c); System.assertEquals(null, rslts[0].Foreign_Trade_Cost_US_1__c); System.assertEquals(null, rslts[0].Foreign_Trade_Cost_US_Date1__c); System.assertEquals(null, rslts[0].Foreign_Trade_Cost_US_End_Date1__c); System.assertEquals(null, rslts[0].Foreign_Trade_Cost_US_2__c); System.assertEquals(null, rslts[0].Foreign_Trade_Cost_US_Date2__c); System.assertEquals(null, rslts[0].Foreign_Trade_Cost_US_End_Date2__c); System.assertEquals(null, rslts[0].Intra_Trade_Cost_US__c); System.assertEquals(null, rslts[0].Intra_Trade_Cost_US_Date__c); System.assertEquals(null, rslts[0].Intra_Trade_Cost_US_End_Date__c); System.assertEquals(null, rslts[0].Foreign_Trade_Cost_RMB__c); System.assertEquals(null, rslts[0].Foreign_Trade_Cost_RMB_Date__c); System.assertEquals(null, rslts[0].Foreign_Trade_Cost_RMB_End_Date__c); } } @isTest static void testNFM004_update_RMB_4() { Product2 prd = testNFM004Init(); prd.Intra_Trade_Cost_RMB_1__c = 1.56; prd.Intra_Trade_Cost_RMB_Date1__c = date.newinstance(1900, 1, 1); prd.Intra_Trade_Cost_RMB_End_Date1__c = date.newinstance(2912, 11, 23); prd.Intra_Trade_Cost_RMB_2__c = 1.34; prd.Intra_Trade_Cost_RMB_Date2__c = date.newinstance(2012, 11, 11); prd.Intra_Trade_Cost_RMB_End_Date2__c = date.newinstance(2912, 11, 13); update prd; NFM004Rest.PurchasePrice PurchasePrice = new NFM004Rest.PurchasePrice(); NFM004Rest.PurchasePrice PurchasePrice2 = new NFM004Rest.PurchasePrice(); NFM004Rest.PurchasePrices PurchasePrices = new NFM004Rest.PurchasePrices(); // Monitoringの設定 Datetime nowDT = Datetime.now(); String nowStr = nowDT.format('yyyyMMddHHmm'); PurchasePrices.Monitoring = new NFMUtil.Monitoring(); // update RMB 内貿 4回目、複数 PurchasePrices.PurchasePrice = new NFM004Rest.PurchasePrice[] { PurchasePrice, PurchasePrice2 }; PurchasePrices.Monitoring.MessageGroupNumber = nowStr + '14'; PurchasePrice.SuppliersItemCode = 'testNFM004'; PurchasePrice.PriceType = 'OCM-001'; PurchasePrice.Currency_x = 'RMB'; PurchasePrice.PurchasePrice_x = 1.78; PurchasePrice.EffectiveDateFrom = '20121201'; PurchasePrice.EffectiveDateTo = '29121203'; PurchasePrice.PurposeOfAdvice = '3'; // update US 内貿 PurchasePrice2.SuppliersItemCode = 'testNFM004'; PurchasePrice2.PriceType = 'OCM-001'; PurchasePrice2.Currency_x = 'USD'; PurchasePrice2.PurchasePrice_x = 101.12; PurchasePrice2.EffectiveDateFrom = '00000000'; PurchasePrice2.EffectiveDateTo = '29121123'; PurchasePrice2.PurposeOfAdvice = '3'; BatchIF_Log__c rowData = NFMUtil.saveRowData(PurchasePrices.Monitoring, 'NFM004', PurchasePrices.PurchasePrice); NFM004Rest u = new NFM004Rest(rowData.Id, 0, PurchasePrices.PurchasePrice.size()); System.Test.startTest(); Database.executeBatch(u, 1); System.Test.stopTest(); List rslts = [select Id, ProductCode, ProductCode_Ext__c, Intra_Trade_Cost_RMB_1__c, Intra_Trade_Cost_RMB_Date1__c, Intra_Trade_Cost_RMB_End_Date1__c, Intra_Trade_Cost_RMB_2__c, Intra_Trade_Cost_RMB_Date2__c, Intra_Trade_Cost_RMB_End_Date2__c, Foreign_Trade_Cost_US_1__c, Foreign_Trade_Cost_US_Date1__c, Foreign_Trade_Cost_US_End_Date1__c, Foreign_Trade_Cost_US_2__c, Foreign_Trade_Cost_US_Date2__c, Foreign_Trade_Cost_US_End_Date2__c, Intra_Trade_Cost_US__c, Intra_Trade_Cost_US_Date__c, Intra_Trade_Cost_US_End_Date__c, Foreign_Trade_Cost_RMB__c, Foreign_Trade_Cost_RMB_Date__c, Foreign_Trade_Cost_RMB_End_Date__c from Product2 where ProductCode_Ext__c = :PurchasePrice.SuppliersItemCode]; System.assertEquals(1, rslts.size()); if (rslts.size() == 1) { System.assertEquals('testNFM004', rslts[0].ProductCode); System.assertEquals(1.78, rslts[0].Intra_Trade_Cost_RMB_1__c); System.assertEquals(date.newinstance(2012, 12, 01), rslts[0].Intra_Trade_Cost_RMB_Date1__c); System.assertEquals(date.newinstance(2912, 12, 03), rslts[0].Intra_Trade_Cost_RMB_End_Date1__c); System.assertEquals(1.34, rslts[0].Intra_Trade_Cost_RMB_2__c); System.assertEquals(date.newinstance(2012, 11, 11), rslts[0].Intra_Trade_Cost_RMB_Date2__c); System.assertEquals(date.newinstance(2912, 11, 13), rslts[0].Intra_Trade_Cost_RMB_End_Date2__c); System.assertEquals(null, rslts[0].Foreign_Trade_Cost_US_1__c); System.assertEquals(null, rslts[0].Foreign_Trade_Cost_US_Date1__c); System.assertEquals(null, rslts[0].Foreign_Trade_Cost_US_End_Date1__c); System.assertEquals(null, rslts[0].Foreign_Trade_Cost_US_2__c); System.assertEquals(null, rslts[0].Foreign_Trade_Cost_US_Date2__c); System.assertEquals(null, rslts[0].Foreign_Trade_Cost_US_End_Date2__c); System.assertEquals(101.12, rslts[0].Intra_Trade_Cost_US__c); System.assertEquals(null, rslts[0].Intra_Trade_Cost_US_Date__c); System.assertEquals(date.newinstance(2912, 11, 23), rslts[0].Intra_Trade_Cost_US_End_Date__c); System.assertEquals(null, rslts[0].Foreign_Trade_Cost_RMB__c); System.assertEquals(null, rslts[0].Foreign_Trade_Cost_RMB_Date__c); System.assertEquals(null, rslts[0].Foreign_Trade_Cost_RMB_End_Date__c); } } @isTest static void testNFM004_update_USD_1() { Product2 prd = testNFM004Init(); prd.Intra_Trade_Cost_RMB_1__c = 1.78; prd.Intra_Trade_Cost_RMB_Date1__c = date.newinstance(2012, 12, 1); prd.Intra_Trade_Cost_RMB_End_Date1__c = date.newinstance(2912, 12, 03); prd.Intra_Trade_Cost_RMB_2__c = 1.34; prd.Intra_Trade_Cost_RMB_Date2__c = date.newinstance(2012, 11, 11); prd.Intra_Trade_Cost_RMB_End_Date2__c = date.newinstance(2912, 11, 13); prd.Intra_Trade_Cost_US__c = 101.12; prd.Intra_Trade_Cost_US_Date__c = date.newinstance(1900, 1, 1); prd.Intra_Trade_Cost_US_End_Date__c = date.newinstance(2912, 11, 23); update prd; NFM004Rest.PurchasePrice PurchasePrice = new NFM004Rest.PurchasePrice(); NFM004Rest.PurchasePrices PurchasePrices = new NFM004Rest.PurchasePrices(); // Monitoringの設定 Datetime nowDT = Datetime.now(); String nowStr = nowDT.format('yyyyMMddHHmm'); PurchasePrices.Monitoring = new NFMUtil.Monitoring(); // update USD 外貿 1回目 PurchasePrices.PurchasePrice = new NFM004Rest.PurchasePrice[] { PurchasePrice }; PurchasePrices.Monitoring.MessageGroupNumber = nowStr + '21'; PurchasePrice.SuppliersItemCode = 'testNFM004'; PurchasePrice.PriceType = 'OHC-001'; PurchasePrice.Currency_x = 'USD'; PurchasePrice.PurchasePrice_x = 201.21; PurchasePrice.EffectiveDateFrom = '20121102'; PurchasePrice.EffectiveDateTo = '29121104'; PurchasePrice.PurposeOfAdvice = '3'; BatchIF_Log__c rowData = NFMUtil.saveRowData(PurchasePrices.Monitoring, 'NFM004', PurchasePrices.PurchasePrice); NFM004Rest u = new NFM004Rest(rowData.Id, 0, PurchasePrices.PurchasePrice.size()); System.Test.startTest(); Database.executeBatch(u, 1); System.Test.stopTest(); List rslts = [select Id, ProductCode, ProductCode_Ext__c, Intra_Trade_Cost_RMB_1__c, Intra_Trade_Cost_RMB_Date1__c, Intra_Trade_Cost_RMB_End_Date1__c, Intra_Trade_Cost_RMB_2__c, Intra_Trade_Cost_RMB_Date2__c, Intra_Trade_Cost_RMB_End_Date2__c, Foreign_Trade_Cost_US_1__c, Foreign_Trade_Cost_US_Date1__c, Foreign_Trade_Cost_US_End_Date1__c, Foreign_Trade_Cost_US_2__c, Foreign_Trade_Cost_US_Date2__c, Foreign_Trade_Cost_US_End_Date2__c, Intra_Trade_Cost_US__c, Intra_Trade_Cost_US_Date__c, Intra_Trade_Cost_US_End_Date__c, Foreign_Trade_Cost_RMB__c, Foreign_Trade_Cost_RMB_Date__c, Foreign_Trade_Cost_RMB_End_Date__c from Product2 where ProductCode_Ext__c = :PurchasePrice.SuppliersItemCode]; System.assertEquals(1, rslts.size()); if (rslts.size() == 1) { System.assertEquals('testNFM004', rslts[0].ProductCode); System.assertEquals(1.78, rslts[0].Intra_Trade_Cost_RMB_1__c); System.assertEquals(date.newinstance(2012, 12, 01), rslts[0].Intra_Trade_Cost_RMB_Date1__c); System.assertEquals(date.newinstance(2912, 12, 03), rslts[0].Intra_Trade_Cost_RMB_End_Date1__c); System.assertEquals(1.34, rslts[0].Intra_Trade_Cost_RMB_2__c); System.assertEquals(date.newinstance(2012, 11, 11), rslts[0].Intra_Trade_Cost_RMB_Date2__c); System.assertEquals(date.newinstance(2912, 11, 13), rslts[0].Intra_Trade_Cost_RMB_End_Date2__c); System.assertEquals(201.21, rslts[0].Foreign_Trade_Cost_US_1__c); System.assertEquals(date.newinstance(2012, 11, 02), rslts[0].Foreign_Trade_Cost_US_Date1__c); System.assertEquals(date.newinstance(2912, 11, 04), rslts[0].Foreign_Trade_Cost_US_End_Date1__c); System.assertEquals(null, rslts[0].Foreign_Trade_Cost_US_2__c); System.assertEquals(null, rslts[0].Foreign_Trade_Cost_US_Date2__c); System.assertEquals(null, rslts[0].Foreign_Trade_Cost_US_End_Date2__c); System.assertEquals(101.12, rslts[0].Intra_Trade_Cost_US__c); System.assertEquals(date.newinstance(1900, 1, 1), rslts[0].Intra_Trade_Cost_US_Date__c); System.assertEquals(date.newinstance(2912, 11, 23), rslts[0].Intra_Trade_Cost_US_End_Date__c); System.assertEquals(null, rslts[0].Foreign_Trade_Cost_RMB__c); System.assertEquals(null, rslts[0].Foreign_Trade_Cost_RMB_Date__c); System.assertEquals(null, rslts[0].Foreign_Trade_Cost_RMB_End_Date__c); } } @isTest static void testNFM004_update_USD_2() { Product2 prd = testNFM004Init(); prd.Intra_Trade_Cost_RMB_1__c = 1.78; prd.Intra_Trade_Cost_RMB_Date1__c = date.newinstance(2012, 12, 1); prd.Intra_Trade_Cost_RMB_End_Date1__c = date.newinstance(2912, 12, 03); prd.Intra_Trade_Cost_RMB_2__c = 1.34; prd.Intra_Trade_Cost_RMB_Date2__c = date.newinstance(2012, 11, 11); prd.Intra_Trade_Cost_RMB_End_Date2__c = date.newinstance(2912, 11, 13); prd.Intra_Trade_Cost_US__c = 101.12; prd.Intra_Trade_Cost_US_Date__c = date.newinstance(1900, 1, 1); prd.Intra_Trade_Cost_US_End_Date__c = date.newinstance(2912, 11, 23); prd.Foreign_Trade_Cost_US_1__c = 201.21; prd.Foreign_Trade_Cost_US_Date1__c = date.newinstance(2012, 11, 2); prd.Foreign_Trade_Cost_US_End_Date1__c = date.newinstance(2912, 11, 4); update prd; NFM004Rest.PurchasePrice PurchasePrice = new NFM004Rest.PurchasePrice(); NFM004Rest.PurchasePrices PurchasePrices = new NFM004Rest.PurchasePrices(); // Monitoringの設定 Datetime nowDT = Datetime.now(); String nowStr = nowDT.format('yyyyMMddHHmm'); PurchasePrices.Monitoring = new NFMUtil.Monitoring(); // update USD 外貿 2回目 PurchasePrices.PurchasePrice = new NFM004Rest.PurchasePrice[] { PurchasePrice }; PurchasePrices.Monitoring.MessageGroupNumber = nowStr + '22'; PurchasePrice.SuppliersItemCode = 'testNFM004'; PurchasePrice.PriceType = 'OHC-001'; PurchasePrice.Currency_x = 'USD'; PurchasePrice.PurchasePrice_x = 201.43; PurchasePrice.EffectiveDateFrom = '20121112'; PurchasePrice.EffectiveDateTo = '29121114'; PurchasePrice.PurposeOfAdvice = '3'; BatchIF_Log__c rowData = NFMUtil.saveRowData(PurchasePrices.Monitoring, 'NFM004', PurchasePrices.PurchasePrice); NFM004Rest u = new NFM004Rest(rowData.Id, 0, PurchasePrices.PurchasePrice.size()); System.Test.startTest(); Database.executeBatch(u, 1); System.Test.stopTest(); List rslts = [select Id, ProductCode, ProductCode_Ext__c, Intra_Trade_Cost_RMB_1__c, Intra_Trade_Cost_RMB_Date1__c, Intra_Trade_Cost_RMB_End_Date1__c, Intra_Trade_Cost_RMB_2__c, Intra_Trade_Cost_RMB_Date2__c, Intra_Trade_Cost_RMB_End_Date2__c, Foreign_Trade_Cost_US_1__c, Foreign_Trade_Cost_US_Date1__c, Foreign_Trade_Cost_US_End_Date1__c, Foreign_Trade_Cost_US_2__c, Foreign_Trade_Cost_US_Date2__c, Foreign_Trade_Cost_US_End_Date2__c, Intra_Trade_Cost_US__c, Intra_Trade_Cost_US_Date__c, Intra_Trade_Cost_US_End_Date__c, Foreign_Trade_Cost_RMB__c, Foreign_Trade_Cost_RMB_Date__c, Foreign_Trade_Cost_RMB_End_Date__c from Product2 where ProductCode_Ext__c = :PurchasePrice.SuppliersItemCode]; System.assertEquals(1, rslts.size()); if (rslts.size() == 1) { System.assertEquals('testNFM004', rslts[0].ProductCode); System.assertEquals(1.78, rslts[0].Intra_Trade_Cost_RMB_1__c); System.assertEquals(date.newinstance(2012, 12, 01), rslts[0].Intra_Trade_Cost_RMB_Date1__c); System.assertEquals(date.newinstance(2912, 12, 03), rslts[0].Intra_Trade_Cost_RMB_End_Date1__c); System.assertEquals(1.34, rslts[0].Intra_Trade_Cost_RMB_2__c); System.assertEquals(date.newinstance(2012, 11, 11), rslts[0].Intra_Trade_Cost_RMB_Date2__c); System.assertEquals(date.newinstance(2912, 11, 13), rslts[0].Intra_Trade_Cost_RMB_End_Date2__c); System.assertEquals(201.21, rslts[0].Foreign_Trade_Cost_US_1__c); System.assertEquals(date.newinstance(2012, 11, 02), rslts[0].Foreign_Trade_Cost_US_Date1__c); System.assertEquals(date.newinstance(2912, 11, 04), rslts[0].Foreign_Trade_Cost_US_End_Date1__c); System.assertEquals(201.43, rslts[0].Foreign_Trade_Cost_US_2__c); System.assertEquals(date.newinstance(2012, 11, 12), rslts[0].Foreign_Trade_Cost_US_Date2__c); System.assertEquals(date.newinstance(2912, 11, 14), rslts[0].Foreign_Trade_Cost_US_End_Date2__c); System.assertEquals(101.12, rslts[0].Intra_Trade_Cost_US__c); System.assertEquals(date.newinstance(1900, 1, 1), rslts[0].Intra_Trade_Cost_US_Date__c); System.assertEquals(date.newinstance(2912, 11, 23), rslts[0].Intra_Trade_Cost_US_End_Date__c); System.assertEquals(null, rslts[0].Foreign_Trade_Cost_RMB__c); System.assertEquals(null, rslts[0].Foreign_Trade_Cost_RMB_Date__c); System.assertEquals(null, rslts[0].Foreign_Trade_Cost_RMB_End_Date__c); } } @isTest static void testNFM004_update_USD_3() { Product2 prd = testNFM004Init(); prd.Intra_Trade_Cost_RMB_1__c = 1.78; prd.Intra_Trade_Cost_RMB_Date1__c = date.newinstance(2012, 12, 1); prd.Intra_Trade_Cost_RMB_End_Date1__c = date.newinstance(2912, 12, 03); prd.Intra_Trade_Cost_RMB_2__c = 1.34; prd.Intra_Trade_Cost_RMB_Date2__c = date.newinstance(2012, 11, 11); prd.Intra_Trade_Cost_RMB_End_Date2__c = date.newinstance(2912, 11, 13); prd.Intra_Trade_Cost_US__c = 101.12; prd.Intra_Trade_Cost_US_Date__c = date.newinstance(1900, 1, 1); prd.Intra_Trade_Cost_US_End_Date__c = date.newinstance(2912, 11, 23); prd.Foreign_Trade_Cost_US_1__c = 201.21; prd.Foreign_Trade_Cost_US_Date1__c = date.newinstance(2012, 11, 2); prd.Foreign_Trade_Cost_US_End_Date1__c = date.newinstance(2912, 11, 4); prd.Foreign_Trade_Cost_US_2__c = 201.43; prd.Foreign_Trade_Cost_US_Date2__c = date.newinstance(2012, 11, 12); prd.Foreign_Trade_Cost_US_End_Date2__c = date.newinstance(2912, 11, 14); update prd; NFM004Rest.PurchasePrice PurchasePrice = new NFM004Rest.PurchasePrice(); NFM004Rest.PurchasePrices PurchasePrices = new NFM004Rest.PurchasePrices(); // Monitoringの設定 Datetime nowDT = Datetime.now(); String nowStr = nowDT.format('yyyyMMddHHmm'); PurchasePrices.Monitoring = new NFMUtil.Monitoring(); // update USD 外貿 3回目 PurchasePrices.PurchasePrice = new NFM004Rest.PurchasePrice[] { PurchasePrice }; PurchasePrices.Monitoring.MessageGroupNumber = nowStr + '23'; PurchasePrice.SuppliersItemCode = 'testNFM004'; PurchasePrice.PriceType = 'OHC-001'; PurchasePrice.Currency_x = 'USD'; PurchasePrice.PurchasePrice_x = 201.65; PurchasePrice.EffectiveDateFrom = '20121122'; PurchasePrice.EffectiveDateTo = '29121124'; PurchasePrice.PurposeOfAdvice = '3'; BatchIF_Log__c rowData = NFMUtil.saveRowData(PurchasePrices.Monitoring, 'NFM004', PurchasePrices.PurchasePrice); NFM004Rest u = new NFM004Rest(rowData.Id, 0, PurchasePrices.PurchasePrice.size()); System.Test.startTest(); Database.executeBatch(u, 1); System.Test.stopTest(); List rslts = [select Id, ProductCode, ProductCode_Ext__c, Intra_Trade_Cost_RMB_1__c, Intra_Trade_Cost_RMB_Date1__c, Intra_Trade_Cost_RMB_End_Date1__c, Intra_Trade_Cost_RMB_2__c, Intra_Trade_Cost_RMB_Date2__c, Intra_Trade_Cost_RMB_End_Date2__c, Foreign_Trade_Cost_US_1__c, Foreign_Trade_Cost_US_Date1__c, Foreign_Trade_Cost_US_End_Date1__c, Foreign_Trade_Cost_US_2__c, Foreign_Trade_Cost_US_Date2__c, Foreign_Trade_Cost_US_End_Date2__c, Intra_Trade_Cost_US__c, Intra_Trade_Cost_US_Date__c, Intra_Trade_Cost_US_End_Date__c, Foreign_Trade_Cost_RMB__c, Foreign_Trade_Cost_RMB_Date__c, Foreign_Trade_Cost_RMB_End_Date__c from Product2 where ProductCode_Ext__c = :PurchasePrice.SuppliersItemCode]; System.assertEquals(1, rslts.size()); if (rslts.size() == 1) { System.assertEquals('testNFM004', rslts[0].ProductCode); System.assertEquals(1.78, rslts[0].Intra_Trade_Cost_RMB_1__c); System.assertEquals(date.newinstance(2012, 12, 01), rslts[0].Intra_Trade_Cost_RMB_Date1__c); System.assertEquals(date.newinstance(2912, 12, 03), rslts[0].Intra_Trade_Cost_RMB_End_Date1__c); System.assertEquals(1.34, rslts[0].Intra_Trade_Cost_RMB_2__c); System.assertEquals(date.newinstance(2012, 11, 11), rslts[0].Intra_Trade_Cost_RMB_Date2__c); System.assertEquals(date.newinstance(2912, 11, 13), rslts[0].Intra_Trade_Cost_RMB_End_Date2__c); System.assertEquals(201.65, rslts[0].Foreign_Trade_Cost_US_1__c); System.assertEquals(date.newinstance(2012, 11, 22), rslts[0].Foreign_Trade_Cost_US_Date1__c); System.assertEquals(date.newinstance(2912, 11, 24), rslts[0].Foreign_Trade_Cost_US_End_Date1__c); System.assertEquals(201.43, rslts[0].Foreign_Trade_Cost_US_2__c); System.assertEquals(date.newinstance(2012, 11, 12), rslts[0].Foreign_Trade_Cost_US_Date2__c); System.assertEquals(date.newinstance(2912, 11, 14), rslts[0].Foreign_Trade_Cost_US_End_Date2__c); System.assertEquals(101.12, rslts[0].Intra_Trade_Cost_US__c); System.assertEquals(date.newinstance(1900, 1, 1), rslts[0].Intra_Trade_Cost_US_Date__c); System.assertEquals(date.newinstance(2912, 11, 23), rslts[0].Intra_Trade_Cost_US_End_Date__c); System.assertEquals(null, rslts[0].Foreign_Trade_Cost_RMB__c); System.assertEquals(null, rslts[0].Foreign_Trade_Cost_RMB_Date__c); System.assertEquals(null, rslts[0].Foreign_Trade_Cost_RMB_End_Date__c); } } @isTest static void testNFM004_update_USD_4() { Product2 prd = testNFM004Init(); prd.Intra_Trade_Cost_RMB_1__c = 1.78; prd.Intra_Trade_Cost_RMB_Date1__c = date.newinstance(2012, 12, 1); prd.Intra_Trade_Cost_RMB_End_Date1__c = date.newinstance(2912, 12, 03); prd.Intra_Trade_Cost_RMB_2__c = 1.34; prd.Intra_Trade_Cost_RMB_Date2__c = date.newinstance(2012, 11, 11); prd.Intra_Trade_Cost_RMB_End_Date2__c = date.newinstance(2912, 11, 13); prd.Intra_Trade_Cost_US__c = 101.12; prd.Intra_Trade_Cost_US_Date__c = date.newinstance(1900, 1, 1); prd.Intra_Trade_Cost_US_End_Date__c = date.newinstance(2912, 11, 23); prd.Foreign_Trade_Cost_US_1__c = 201.65; prd.Foreign_Trade_Cost_US_Date1__c = date.newinstance(2012, 11, 22); prd.Foreign_Trade_Cost_US_End_Date1__c = date.newinstance(2912, 11, 24); prd.Foreign_Trade_Cost_US_2__c = 201.43; prd.Foreign_Trade_Cost_US_Date2__c = date.newinstance(2012, 11, 12); prd.Foreign_Trade_Cost_US_End_Date2__c = date.newinstance(2912, 11, 14); update prd; NFM004Rest.PurchasePrice PurchasePrice = new NFM004Rest.PurchasePrice(); NFM004Rest.PurchasePrice PurchasePrice2 = new NFM004Rest.PurchasePrice(); NFM004Rest.PurchasePrices PurchasePrices = new NFM004Rest.PurchasePrices(); // Monitoringの設定 Datetime nowDT = Datetime.now(); String nowStr = nowDT.format('yyyyMMddHHmm'); PurchasePrices.Monitoring = new NFMUtil.Monitoring(); // update USD 外貿 4回目 PurchasePrices.PurchasePrice = new NFM004Rest.PurchasePrice[] { PurchasePrice, PurchasePrice2 }; PurchasePrices.Monitoring.MessageGroupNumber = nowStr + '24'; PurchasePrice.SuppliersItemCode = 'testNFM004'; PurchasePrice.PriceType = 'OHC-001'; PurchasePrice.Currency_x = 'USD'; PurchasePrice.PurchasePrice_x = 201.87; PurchasePrice.EffectiveDateFrom = '20121202'; PurchasePrice.EffectiveDateTo = '29121204'; PurchasePrice.PurposeOfAdvice = '3'; // update RMB 外貿 PurchasePrice2.SuppliersItemCode = 'testNFM004'; PurchasePrice2.PriceType = 'OHC-001'; PurchasePrice2.Currency_x = 'RMB'; PurchasePrice2.PurchasePrice_x = 222.12; PurchasePrice2.EffectiveDateFrom = '20121212'; PurchasePrice2.EffectiveDateTo = '29121214'; PurchasePrice2.PurposeOfAdvice = '3'; BatchIF_Log__c rowData = NFMUtil.saveRowData(PurchasePrices.Monitoring, 'NFM004', PurchasePrices.PurchasePrice); NFM004Rest u = new NFM004Rest(rowData.Id, 0, PurchasePrices.PurchasePrice.size()); System.Test.startTest(); Database.executeBatch(u, 1); System.Test.stopTest(); List rslts = [select Id, ProductCode, ProductCode_Ext__c, Intra_Trade_Cost_RMB_1__c, Intra_Trade_Cost_RMB_Date1__c, Intra_Trade_Cost_RMB_End_Date1__c, Intra_Trade_Cost_RMB_2__c, Intra_Trade_Cost_RMB_Date2__c, Intra_Trade_Cost_RMB_End_Date2__c, Foreign_Trade_Cost_US_1__c, Foreign_Trade_Cost_US_Date1__c, Foreign_Trade_Cost_US_End_Date1__c, Foreign_Trade_Cost_US_2__c, Foreign_Trade_Cost_US_Date2__c, Foreign_Trade_Cost_US_End_Date2__c, Intra_Trade_Cost_US__c, Intra_Trade_Cost_US_Date__c, Intra_Trade_Cost_US_End_Date__c, Foreign_Trade_Cost_RMB__c, Foreign_Trade_Cost_RMB_Date__c, Foreign_Trade_Cost_RMB_End_Date__c from Product2 where ProductCode_Ext__c = :PurchasePrice.SuppliersItemCode]; System.assertEquals(1, rslts.size()); if (rslts.size() == 1) { System.assertEquals('testNFM004', rslts[0].ProductCode); System.assertEquals(1.78, rslts[0].Intra_Trade_Cost_RMB_1__c); System.assertEquals(date.newinstance(2012, 12, 01), rslts[0].Intra_Trade_Cost_RMB_Date1__c); System.assertEquals(date.newinstance(2912, 12, 03), rslts[0].Intra_Trade_Cost_RMB_End_Date1__c); System.assertEquals(1.34, rslts[0].Intra_Trade_Cost_RMB_2__c); System.assertEquals(date.newinstance(2012, 11, 11), rslts[0].Intra_Trade_Cost_RMB_Date2__c); System.assertEquals(date.newinstance(2912, 11, 13), rslts[0].Intra_Trade_Cost_RMB_End_Date2__c); System.assertEquals(201.65, rslts[0].Foreign_Trade_Cost_US_1__c); System.assertEquals(date.newinstance(2012, 11, 22), rslts[0].Foreign_Trade_Cost_US_Date1__c); System.assertEquals(date.newinstance(2912, 11, 24), rslts[0].Foreign_Trade_Cost_US_End_Date1__c); System.assertEquals(201.87, rslts[0].Foreign_Trade_Cost_US_2__c); System.assertEquals(date.newinstance(2012, 12, 02), rslts[0].Foreign_Trade_Cost_US_Date2__c); System.assertEquals(date.newinstance(2912, 12, 04), rslts[0].Foreign_Trade_Cost_US_End_Date2__c); System.assertEquals(101.12, rslts[0].Intra_Trade_Cost_US__c); System.assertEquals(date.newinstance(1900, 1, 1), rslts[0].Intra_Trade_Cost_US_Date__c); System.assertEquals(date.newinstance(2912, 11, 23), rslts[0].Intra_Trade_Cost_US_End_Date__c); System.assertEquals(222.12, rslts[0].Foreign_Trade_Cost_RMB__c); System.assertEquals(date.newinstance(2012, 12, 12), rslts[0].Foreign_Trade_Cost_RMB_Date__c); System.assertEquals(date.newinstance(2912, 12, 14), rslts[0].Foreign_Trade_Cost_RMB_End_Date__c); } } @isTest static void testNFM004_delete_1() { Product2 prd = testNFM004Init(); prd.Intra_Trade_Cost_RMB_1__c = 1.78; prd.Intra_Trade_Cost_RMB_Date1__c = date.newinstance(2012, 12, 1); prd.Intra_Trade_Cost_RMB_End_Date1__c = date.newinstance(2912, 12, 03); prd.Intra_Trade_Cost_RMB_2__c = 1.34; prd.Intra_Trade_Cost_RMB_Date2__c = date.newinstance(2012, 11, 11); prd.Intra_Trade_Cost_RMB_End_Date2__c = date.newinstance(2912, 11, 13); prd.Intra_Trade_Cost_US__c = 101.12; prd.Intra_Trade_Cost_US_Date__c = date.newinstance(1900, 1, 1); prd.Intra_Trade_Cost_US_End_Date__c = date.newinstance(2912, 11, 23); prd.Foreign_Trade_Cost_US_1__c = 201.65; prd.Foreign_Trade_Cost_US_Date1__c = date.newinstance(2012, 11, 22); prd.Foreign_Trade_Cost_US_End_Date1__c = date.newinstance(2912, 11, 24); prd.Foreign_Trade_Cost_US_2__c = 201.87; prd.Foreign_Trade_Cost_US_Date2__c = date.newinstance(2012, 12, 2); prd.Foreign_Trade_Cost_US_End_Date2__c = date.newinstance(2912, 12, 4); prd.Foreign_Trade_Cost_RMB__c = 222.12; prd.Foreign_Trade_Cost_RMB_Date__c = date.newinstance(2012, 12, 12); prd.Foreign_Trade_Cost_RMB_End_Date__c = date.newinstance(2912, 12, 14); update prd; NFM004Rest.PurchasePrice PurchasePrice = new NFM004Rest.PurchasePrice(); NFM004Rest.PurchasePrices PurchasePrices = new NFM004Rest.PurchasePrices(); // Monitoringの設定 Datetime nowDT = Datetime.now(); String nowStr = nowDT.format('yyyyMMddHHmm'); PurchasePrices.Monitoring = new NFMUtil.Monitoring(); // 削除、2世代目の金額 PurchasePrices.PurchasePrice = new NFM004Rest.PurchasePrice[] { PurchasePrice }; PurchasePrices.Monitoring.MessageGroupNumber = nowStr + '31'; PurchasePrice.SuppliersItemCode = 'testNFM004'; PurchasePrice.PriceType = 'OHC-001'; PurchasePrice.Currency_x = 'USD'; PurchasePrice.PurchasePrice_x = 201.87; PurchasePrice.EffectiveDateFrom = '20121202'; PurchasePrice.EffectiveDateTo = String.valueOf(Date.today().addDays(-1));//'29121204'; PurchasePrice.PurposeOfAdvice = '1'; BatchIF_Log__c rowData = NFMUtil.saveRowData(PurchasePrices.Monitoring, 'NFM004', PurchasePrices.PurchasePrice); NFM004Rest u = new NFM004Rest(rowData.Id, 0, PurchasePrices.PurchasePrice.size()); System.Test.startTest(); Database.executeBatch(u, 1); System.Test.stopTest(); List rslts = [select Id, ProductCode, ProductCode_Ext__c, Intra_Trade_Cost_RMB_1__c, Intra_Trade_Cost_RMB_Date1__c, Intra_Trade_Cost_RMB_End_Date1__c, Intra_Trade_Cost_RMB_2__c, Intra_Trade_Cost_RMB_Date2__c, Intra_Trade_Cost_RMB_End_Date2__c, Foreign_Trade_Cost_US_1__c, Foreign_Trade_Cost_US_Date1__c, Foreign_Trade_Cost_US_End_Date1__c, Foreign_Trade_Cost_US_2__c, Foreign_Trade_Cost_US_Date2__c, Foreign_Trade_Cost_US_End_Date2__c, Intra_Trade_Cost_US__c, Intra_Trade_Cost_US_Date__c, Intra_Trade_Cost_US_End_Date__c, Foreign_Trade_Cost_RMB__c, Foreign_Trade_Cost_RMB_Date__c, Foreign_Trade_Cost_RMB_End_Date__c from Product2 where ProductCode_Ext__c = :PurchasePrice.SuppliersItemCode]; // deleteの場合、EffectiveDateTo が前日 System.assertEquals(1, rslts.size()); System.assertEquals(Date.today().addDays(-1), rslts[0].Foreign_Trade_Cost_US_End_Date2__c); } @isTest static void testNFM004_delete_2() { Product2 prd = testNFM004Init(); prd.Intra_Trade_Cost_RMB_1__c = 1.78; prd.Intra_Trade_Cost_RMB_Date1__c = date.newinstance(2012, 12, 1); prd.Intra_Trade_Cost_RMB_End_Date1__c = date.newinstance(2912, 12, 03); prd.Intra_Trade_Cost_RMB_2__c = 1.34; prd.Intra_Trade_Cost_RMB_Date2__c = date.newinstance(2012, 11, 11); prd.Intra_Trade_Cost_RMB_End_Date2__c = date.newinstance(2912, 11, 13); prd.Intra_Trade_Cost_US__c = 101.12; prd.Intra_Trade_Cost_US_Date__c = date.newinstance(1900, 1, 1); prd.Intra_Trade_Cost_US_End_Date__c = date.newinstance(2912, 11, 23); prd.Foreign_Trade_Cost_US_1__c = 201.65; prd.Foreign_Trade_Cost_US_Date1__c = date.newinstance(2012, 11, 22); prd.Foreign_Trade_Cost_US_End_Date1__c = date.newinstance(2912, 11, 24); prd.Foreign_Trade_Cost_US_2__c = 201.87; prd.Foreign_Trade_Cost_US_Date2__c = date.newinstance(2012, 12, 2); prd.Foreign_Trade_Cost_US_End_Date2__c = Date.today().addDays(-1); prd.Foreign_Trade_Cost_RMB__c = 222.12; prd.Foreign_Trade_Cost_RMB_Date__c = date.newinstance(2012, 12, 12); prd.Foreign_Trade_Cost_RMB_End_Date__c = date.newinstance(2912, 12, 14); update prd; NFM004Rest.PurchasePrice PurchasePrice = new NFM004Rest.PurchasePrice(); NFM004Rest.PurchasePrices PurchasePrices = new NFM004Rest.PurchasePrices(); // Monitoringの設定 Datetime nowDT = Datetime.now(); String nowStr = nowDT.format('yyyyMMddHHmm'); PurchasePrices.Monitoring = new NFMUtil.Monitoring(); // 料金更新、2世代目に反映 PurchasePrices.PurchasePrice = new NFM004Rest.PurchasePrice[] { PurchasePrice }; PurchasePrices.Monitoring.MessageGroupNumber = nowStr + '32'; PurchasePrice.SuppliersItemCode = 'testNFM004'; PurchasePrice.PriceType = 'OHC-001'; PurchasePrice.Currency_x = 'USD'; PurchasePrice.PurchasePrice_x = 201.87; PurchasePrice.EffectiveDateFrom = '20121201'; PurchasePrice.EffectiveDateTo = '29121204'; PurchasePrice.PurposeOfAdvice = '2'; BatchIF_Log__c rowData = NFMUtil.saveRowData(PurchasePrices.Monitoring, 'NFM004', PurchasePrices.PurchasePrice); NFM004Rest u = new NFM004Rest(rowData.Id, 0, PurchasePrices.PurchasePrice.size()); System.Test.startTest(); Database.executeBatch(u, 1); System.Test.stopTest(); List rslts = [select Id, ProductCode, ProductCode_Ext__c, Intra_Trade_Cost_RMB_1__c, Intra_Trade_Cost_RMB_Date1__c, Intra_Trade_Cost_RMB_End_Date1__c, Intra_Trade_Cost_RMB_2__c, Intra_Trade_Cost_RMB_Date2__c, Intra_Trade_Cost_RMB_End_Date2__c, Foreign_Trade_Cost_US_1__c, Foreign_Trade_Cost_US_Date1__c, Foreign_Trade_Cost_US_End_Date1__c, Foreign_Trade_Cost_US_2__c, Foreign_Trade_Cost_US_Date2__c, Foreign_Trade_Cost_US_End_Date2__c, Intra_Trade_Cost_US__c, Intra_Trade_Cost_US_Date__c, Intra_Trade_Cost_US_End_Date__c, Foreign_Trade_Cost_RMB__c, Foreign_Trade_Cost_RMB_Date__c, Foreign_Trade_Cost_RMB_End_Date__c from Product2 where ProductCode_Ext__c = :PurchasePrice.SuppliersItemCode]; // deleteの場合、EffectiveDateTo が前日 System.assertEquals(1, rslts.size()); System.assertEquals(201.87, rslts[0].Foreign_Trade_Cost_US_2__c); System.assertEquals(date.newinstance(2012, 12, 01), rslts[0].Foreign_Trade_Cost_US_Date2__c); System.assertEquals(date.newinstance(2912, 12, 04), rslts[0].Foreign_Trade_Cost_US_End_Date2__c); } @isTest static void test_method_execute() { Test.startTest(); RestRequest req = new RestRequest(); RestResponse res = new RestResponse(); String JsonMsg = '{"PurchasePrices":{"Monitoring":{"TransmissionDateTime":"201812201320","Text":"","Tag":"MSGH","Sender":"SFDC","Receiver":"SPO","NumberOfRecord":"1","MessageType":"NFM004","MessageGroupNumber":"20180001722190"},"PurchasePrice":[{"SuppliersItemCode":"A06000003410,2000005152","ReportedDateTime":"20190710164300","PurposeOfAdvice":"2","PurchasePrice_x":2363.00,"PriceType":"OCM-001","EffectiveDateTo":"99991231","EffectiveDateFrom":"20190710","Currency_x":"RMB"}]}}'; req.requestURI = 'services/apexrest/NFM004/execute'; req.httpMethod = 'POST'; req.requestBody = Blob.valueof(JsonMsg); RestContext.request = req; RestContext.response = res; NFM004Rest.execute(); Test.stopTest(); } }