@isTest
private class NFM005WebServiceTest {

    static Product2 testNFM005Init() {
        // テストデータ
        Product2 prd = new Product2();
        prd.ProductCode_Ext__c     = 'testNFM005';
        prd.ProductCode            = 'testNFM005';
        prd.Name                   = 'testNFM005';
        prd.Manual_Entry__c        = false;
        insert prd;
        return prd;
    }

    // そのままreturn
    @isTest
    static void testNFM005_void() {
        testNFM005Init();
        // null
        NFM005WebService.NFM005(null);

        NFM005WebService.SalesPrice SalesPrice = new NFM005WebService.SalesPrice();
        NFM005WebService.SalesPrices SalesPrices = new NFM005WebService.SalesPrices();
        SalesPrices.SalesPrice = new NFM005WebService.SalesPrice[] { SalesPrice };
        // Monitoringをセットしない
        NFM005WebService.NFM005(SalesPrices);
        
        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        SalesPrices.Monitoring = new NFMUtil.Monitoring();
        SalesPrices.Monitoring.MessageGroupNumber = nowStr + '01';
        // 必須項目をセットしない
        NFM005WebService.NFM005(SalesPrices);

        // 商品コードが存在しない
        SalesPrices.Monitoring.MessageGroupNumber = nowStr + '02';
        SalesPrice.SuppliersItemCode  = 'testNFM005X';
        System.Test.startTest();
        NFM005WebService.NFM005(SalesPrices);
        System.Test.stopTest();

        Product2[] rslts = [select Id from Product2 where ProductCode_Ext__c = :SalesPrice.SuppliersItemCode];
        System.assertEquals(0, rslts.size());
    }

    @isTest
    static void testNFM005_update_RMB_1() {
        testNFM005Init();

        NFM005WebService.SalesPrice SalesPrice = new NFM005WebService.SalesPrice();
        NFM005WebService.SalesPrices SalesPrices = new NFM005WebService.SalesPrices();

        // Monitoringの設定
        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        SalesPrices.Monitoring = new NFMUtil.Monitoring();
        SalesPrices.Monitoring.MessageGroupNumber = nowStr + '11';

        // update RMB 内貿 1回目
        SalesPrices.SalesPrice = new NFM005WebService.SalesPrice[] { SalesPrice };
        SalesPrice.SuppliersItemCode  = 'testNFM005';
        SalesPrice.PriceType          = 'OCM-001S';
        SalesPrice.Currency_x         = 'RMB';
        SalesPrice.SalesPrice      = 1.12;
        SalesPrice.EffectiveDateFrom  = '20121101';
        SalesPrice.EffectiveDateTo    = '29121103';
        SalesPrice.PurposeOfAdvice    = '3';

        System.Test.startTest();
        NFM005WebService.NFM005(SalesPrices);
        System.Test.stopTest();

        List<Product2> rslts = [select Id, ProductCode, ProductCode_Ext__c,
                                       Intra_Trade_List_RMB_1__c,
                                       Intra_Trade_List_RMB_Date1__c,
                                       Intra_Trade_List_RMB_End_Date1__c,
                                       Intra_Trade_List_RMB_2__c,
                                       Intra_Trade_List_RMB_Date2__c,
                                       Intra_Trade_List_RMB_End_Date2__c,
                                       Foreign_Trade_List_US_1__c,
                                       Foreign_Trade_List_US_Date1__c,
                                       Foreign_Trade_List_US_End_Date1__c,
                                       Foreign_Trade_List_US_2__c,
                                       Foreign_Trade_List_US_Date2__c,
                                       Foreign_Trade_List_US_End_Date2__c,
                                       Intra_Trade_List_US__c,
                                       Intra_Trade_List_US_Date__c,
                                       Intra_Trade_List_US_End_Date__c,
                                       Foreign_Trade_List_RMB__c,
                                       Foreign_Trade_List_RMB_Date__c,
                                       Foreign_Trade_List_RMB_End_Date__c
                                  from Product2
                                 where ProductCode_Ext__c = :SalesPrice.SuppliersItemCode];
        System.assertEquals(1, rslts.size());
        if (rslts.size() == 1) {
            System.assertEquals('testNFM005', rslts[0].ProductCode);
            System.assertEquals(1.12, rslts[0].Intra_Trade_List_RMB_1__c);
            System.assertEquals(date.newinstance(2012, 11, 1), rslts[0].Intra_Trade_List_RMB_Date1__c);
            System.assertEquals(date.newinstance(2912, 11, 3), rslts[0].Intra_Trade_List_RMB_End_Date1__c);
            System.assertEquals(null, rslts[0].Intra_Trade_List_RMB_2__c);
            System.assertEquals(null, rslts[0].Intra_Trade_List_RMB_Date2__c);
            System.assertEquals(null, rslts[0].Intra_Trade_List_RMB_End_Date2__c);
            System.assertEquals(null, rslts[0].Foreign_Trade_List_US_1__c);
            System.assertEquals(null, rslts[0].Foreign_Trade_List_US_Date1__c);
            System.assertEquals(null, rslts[0].Foreign_Trade_List_US_End_Date1__c);
            System.assertEquals(null, rslts[0].Foreign_Trade_List_US_2__c);
            System.assertEquals(null, rslts[0].Foreign_Trade_List_US_Date2__c);
            System.assertEquals(null, rslts[0].Foreign_Trade_List_US_End_Date2__c);
            System.assertEquals(null, rslts[0].Intra_Trade_List_US__c);
            System.assertEquals(null, rslts[0].Intra_Trade_List_US_Date__c);
            System.assertEquals(null, rslts[0].Intra_Trade_List_US_End_Date__c);
            System.assertEquals(null, rslts[0].Foreign_Trade_List_RMB__c);
            System.assertEquals(null, rslts[0].Foreign_Trade_List_RMB_Date__c);
            System.assertEquals(null, rslts[0].Foreign_Trade_List_RMB_End_Date__c);
        }
    }
    
    @isTest
    static void testNFM005_update_RMB_2() {
        Product2 prd = testNFM005Init();
        prd.Intra_Trade_List_RMB_1__c = 1.12;
        prd.Intra_Trade_List_RMB_Date1__c = date.newinstance(2012, 11, 1);
        prd.Intra_Trade_List_RMB_End_Date1__c = date.newinstance(2912, 11, 3);
        update prd;

        NFM005WebService.SalesPrice SalesPrice = new NFM005WebService.SalesPrice();
        NFM005WebService.SalesPrices SalesPrices = new NFM005WebService.SalesPrices();

        // Monitoringの設定
        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        SalesPrices.Monitoring = new NFMUtil.Monitoring();

        // update RMB 内貿 2回目
        SalesPrices.SalesPrice = new NFM005WebService.SalesPrice[] { SalesPrice };
        SalesPrices.Monitoring.MessageGroupNumber = nowStr + '12';
        SalesPrice.SuppliersItemCode  = 'testNFM005';
        SalesPrice.PriceType          = 'OCM-001S';
        SalesPrice.Currency_x         = 'RMB';
        SalesPrice.SalesPrice      = 1.34;
        SalesPrice.EffectiveDateFrom  = '20121111';
        SalesPrice.EffectiveDateTo    = '29121113';
        SalesPrice.PurposeOfAdvice    = '3';

        System.Test.startTest();
        NFM005WebService.NFM005(SalesPrices);
        System.Test.stopTest();

        List<Product2> rslts = [select Id, ProductCode, ProductCode_Ext__c,
                            Intra_Trade_List_RMB_1__c,
                            Intra_Trade_List_RMB_Date1__c,
                            Intra_Trade_List_RMB_End_Date1__c,
                            Intra_Trade_List_RMB_2__c,
                            Intra_Trade_List_RMB_Date2__c,
                            Intra_Trade_List_RMB_End_Date2__c,
                            Foreign_Trade_List_US_1__c,
                            Foreign_Trade_List_US_Date1__c,
                            Foreign_Trade_List_US_End_Date1__c,
                            Foreign_Trade_List_US_2__c,
                            Foreign_Trade_List_US_Date2__c,
                            Foreign_Trade_List_US_End_Date2__c,
                            Intra_Trade_List_US__c,
                            Intra_Trade_List_US_Date__c,
                            Intra_Trade_List_US_End_Date__c,
                            Foreign_Trade_List_RMB__c,
                            Foreign_Trade_List_RMB_Date__c,
                            Foreign_Trade_List_RMB_End_Date__c
                      from Product2
                     where ProductCode_Ext__c = :SalesPrice.SuppliersItemCode];
        System.assertEquals(1, rslts.size());
        if (rslts.size() == 1) {
            System.assertEquals('testNFM005', rslts[0].ProductCode);
            System.assertEquals(1.12, rslts[0].Intra_Trade_List_RMB_1__c);
            System.assertEquals(date.newinstance(2012, 11, 1), rslts[0].Intra_Trade_List_RMB_Date1__c);
            System.assertEquals(date.newinstance(2912, 11, 3), rslts[0].Intra_Trade_List_RMB_End_Date1__c);
            System.assertEquals(1.34, rslts[0].Intra_Trade_List_RMB_2__c);
            System.assertEquals(date.newinstance(2012, 11, 11), rslts[0].Intra_Trade_List_RMB_Date2__c);
            System.assertEquals(date.newinstance(2912, 11, 13), rslts[0].Intra_Trade_List_RMB_End_Date2__c);
            System.assertEquals(null, rslts[0].Foreign_Trade_List_US_1__c);
            System.assertEquals(null, rslts[0].Foreign_Trade_List_US_Date1__c);
            System.assertEquals(null, rslts[0].Foreign_Trade_List_US_End_Date1__c);
            System.assertEquals(null, rslts[0].Foreign_Trade_List_US_2__c);
            System.assertEquals(null, rslts[0].Foreign_Trade_List_US_Date2__c);
            System.assertEquals(null, rslts[0].Foreign_Trade_List_US_End_Date2__c);
            System.assertEquals(null, rslts[0].Intra_Trade_List_US__c);
            System.assertEquals(null, rslts[0].Intra_Trade_List_US_Date__c);
            System.assertEquals(null, rslts[0].Intra_Trade_List_US_End_Date__c);
            System.assertEquals(null, rslts[0].Foreign_Trade_List_RMB__c);
            System.assertEquals(null, rslts[0].Foreign_Trade_List_RMB_Date__c);
            System.assertEquals(null, rslts[0].Foreign_Trade_List_RMB_End_Date__c);
        }
    }
    
    @isTest
    static void testNFM005_update_RMB_3() {
        Product2 prd = testNFM005Init();
        prd.Intra_Trade_List_RMB_1__c = 1.12;
        prd.Intra_Trade_List_RMB_Date1__c = date.newinstance(2012, 11, 1);
        prd.Intra_Trade_List_RMB_End_Date1__c = date.newinstance(2912, 11, 3);
        prd.Intra_Trade_List_RMB_2__c = 1.34;
        prd.Intra_Trade_List_RMB_Date2__c = date.newinstance(2012, 11, 11);
        prd.Intra_Trade_List_RMB_End_Date2__c = date.newinstance(2912, 11, 13);
        update prd;

        NFM005WebService.SalesPrice SalesPrice = new NFM005WebService.SalesPrice();
        NFM005WebService.SalesPrices SalesPrices = new NFM005WebService.SalesPrices();

        // Monitoringの設定
        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        SalesPrices.Monitoring = new NFMUtil.Monitoring();

        // update RMB 内貿 3回目
        SalesPrices.SalesPrice = new NFM005WebService.SalesPrice[] { SalesPrice };
        SalesPrices.Monitoring.MessageGroupNumber = nowStr + '13';
        SalesPrice.SuppliersItemCode  = 'testNFM005';
        SalesPrice.PriceType          = 'OCM-001S';
        SalesPrice.Currency_x         = 'RMB';
        SalesPrice.SalesPrice      = 1.56;
        SalesPrice.EffectiveDateFrom  = '20121121';
        SalesPrice.EffectiveDateTo    = '29121123';
        SalesPrice.PurposeOfAdvice    = '3';

        System.Test.startTest();
        NFM005WebService.NFM005(SalesPrices);
        System.Test.stopTest();

        List<Product2> rslts = [select Id, ProductCode, ProductCode_Ext__c,
                            Intra_Trade_List_RMB_1__c,
                            Intra_Trade_List_RMB_Date1__c,
                            Intra_Trade_List_RMB_End_Date1__c,
                            Intra_Trade_List_RMB_2__c,
                            Intra_Trade_List_RMB_Date2__c,
                            Intra_Trade_List_RMB_End_Date2__c,
                            Foreign_Trade_List_US_1__c,
                            Foreign_Trade_List_US_Date1__c,
                            Foreign_Trade_List_US_End_Date1__c,
                            Foreign_Trade_List_US_2__c,
                            Foreign_Trade_List_US_Date2__c,
                            Foreign_Trade_List_US_End_Date2__c,
                            Intra_Trade_List_US__c,
                            Intra_Trade_List_US_Date__c,
                            Intra_Trade_List_US_End_Date__c,
                            Foreign_Trade_List_RMB__c,
                            Foreign_Trade_List_RMB_Date__c,
                            Foreign_Trade_List_RMB_End_Date__c
                      from Product2
                     where ProductCode_Ext__c = :SalesPrice.SuppliersItemCode];
        System.assertEquals(1, rslts.size());
        if (rslts.size() == 1) {
            System.assertEquals('testNFM005', rslts[0].ProductCode);
            System.assertEquals(1.56, rslts[0].Intra_Trade_List_RMB_1__c);
            System.assertEquals(date.newinstance(2012, 11, 21), rslts[0].Intra_Trade_List_RMB_Date1__c);
            System.assertEquals(date.newinstance(2912, 11, 23), rslts[0].Intra_Trade_List_RMB_End_Date1__c);
            System.assertEquals(1.34, rslts[0].Intra_Trade_List_RMB_2__c);
            System.assertEquals(date.newinstance(2012, 11, 11), rslts[0].Intra_Trade_List_RMB_Date2__c);
            System.assertEquals(date.newinstance(2912, 11, 13), rslts[0].Intra_Trade_List_RMB_End_Date2__c);
            System.assertEquals(null, rslts[0].Foreign_Trade_List_US_1__c);
            System.assertEquals(null, rslts[0].Foreign_Trade_List_US_Date1__c);
            System.assertEquals(null, rslts[0].Foreign_Trade_List_US_End_Date1__c);
            System.assertEquals(null, rslts[0].Foreign_Trade_List_US_2__c);
            System.assertEquals(null, rslts[0].Foreign_Trade_List_US_Date2__c);
            System.assertEquals(null, rslts[0].Foreign_Trade_List_US_End_Date2__c);
            System.assertEquals(null, rslts[0].Intra_Trade_List_US__c);
            System.assertEquals(null, rslts[0].Intra_Trade_List_US_Date__c);
            System.assertEquals(null, rslts[0].Intra_Trade_List_US_End_Date__c);
            System.assertEquals(null, rslts[0].Foreign_Trade_List_RMB__c);
            System.assertEquals(null, rslts[0].Foreign_Trade_List_RMB_Date__c);
            System.assertEquals(null, rslts[0].Foreign_Trade_List_RMB_End_Date__c);
        }
    }

    @isTest
    static void testNFM005_update_RMB_4() {
        Product2 prd = testNFM005Init();
        prd.Intra_Trade_List_RMB_1__c = 1.56;
        prd.Intra_Trade_List_RMB_Date1__c = date.newinstance(2012, 11, 21);
        prd.Intra_Trade_List_RMB_End_Date1__c = date.newinstance(2912, 11, 23);
        prd.Intra_Trade_List_RMB_2__c = 1.34;
        prd.Intra_Trade_List_RMB_Date2__c = date.newinstance(2012, 11, 11);
        prd.Intra_Trade_List_RMB_End_Date2__c = date.newinstance(2912, 11, 13);
        update prd;

        NFM005WebService.SalesPrice SalesPrice = new NFM005WebService.SalesPrice();
        NFM005WebService.SalesPrice SalesPrice2 = new NFM005WebService.SalesPrice();
        NFM005WebService.SalesPrices SalesPrices = new NFM005WebService.SalesPrices();

        // Monitoringの設定
        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        SalesPrices.Monitoring = new NFMUtil.Monitoring();

        // update RMB 内貿 4回目
        SalesPrices.SalesPrice = new NFM005WebService.SalesPrice[] { SalesPrice, SalesPrice2 };
        SalesPrices.Monitoring.MessageGroupNumber = nowStr + '14';
        SalesPrice.SuppliersItemCode  = 'testNFM005';
        SalesPrice.PriceType          = 'OCM-001S';
        SalesPrice.Currency_x         = 'RMB';
        SalesPrice.SalesPrice      = 1.78;
        SalesPrice.EffectiveDateFrom  = '20121201';
        SalesPrice.EffectiveDateTo    = '29121203';
        SalesPrice.PurposeOfAdvice    = '3';
        // update US 内貿
        SalesPrice2.SuppliersItemCode  = 'testNFM005';
        SalesPrice2.PriceType          = 'OCM-001S';
        SalesPrice2.Currency_x         = 'USD';
        SalesPrice2.SalesPrice      = 101.12;
        SalesPrice2.EffectiveDateFrom  = '20121112';
        SalesPrice2.EffectiveDateTo    = '29121123';
        SalesPrice2.PurposeOfAdvice    = '3';

        System.Test.startTest();
        NFM005WebService.NFM005(SalesPrices);
        System.Test.stopTest();

        List<Product2> rslts = [select Id, ProductCode, ProductCode_Ext__c,
                            Intra_Trade_List_RMB_1__c,
                            Intra_Trade_List_RMB_Date1__c,
                            Intra_Trade_List_RMB_End_Date1__c,
                            Intra_Trade_List_RMB_2__c,
                            Intra_Trade_List_RMB_Date2__c,
                            Intra_Trade_List_RMB_End_Date2__c,
                            Foreign_Trade_List_US_1__c,
                            Foreign_Trade_List_US_Date1__c,
                            Foreign_Trade_List_US_End_Date1__c,
                            Foreign_Trade_List_US_2__c,
                            Foreign_Trade_List_US_Date2__c,
                            Foreign_Trade_List_US_End_Date2__c,
                            Intra_Trade_List_US__c,
                            Intra_Trade_List_US_Date__c,
                            Intra_Trade_List_US_End_Date__c,
                            Foreign_Trade_List_RMB__c,
                            Foreign_Trade_List_RMB_Date__c,
                            Foreign_Trade_List_RMB_End_Date__c
                      from Product2
                     where ProductCode_Ext__c = :SalesPrice.SuppliersItemCode];
        System.assertEquals(1, rslts.size());
        if (rslts.size() == 1) {
            System.assertEquals('testNFM005', rslts[0].ProductCode);
            System.assertEquals(1.56, rslts[0].Intra_Trade_List_RMB_1__c);
            System.assertEquals(date.newinstance(2012, 11, 21), rslts[0].Intra_Trade_List_RMB_Date1__c);
            System.assertEquals(date.newinstance(2912, 11, 23), rslts[0].Intra_Trade_List_RMB_End_Date1__c);
            System.assertEquals(1.78, rslts[0].Intra_Trade_List_RMB_2__c);
            System.assertEquals(date.newinstance(2012, 12, 01), rslts[0].Intra_Trade_List_RMB_Date2__c);
            System.assertEquals(date.newinstance(2912, 12, 03), rslts[0].Intra_Trade_List_RMB_End_Date2__c);
            System.assertEquals(null, rslts[0].Foreign_Trade_List_US_1__c);
            System.assertEquals(null, rslts[0].Foreign_Trade_List_US_Date1__c);
            System.assertEquals(null, rslts[0].Foreign_Trade_List_US_End_Date1__c);
            System.assertEquals(null, rslts[0].Foreign_Trade_List_US_2__c);
            System.assertEquals(null, rslts[0].Foreign_Trade_List_US_Date2__c);
            System.assertEquals(null, rslts[0].Foreign_Trade_List_US_End_Date2__c);
            System.assertEquals(101.12, rslts[0].Intra_Trade_List_US__c);
            System.assertEquals(date.newinstance(2012, 11, 12), rslts[0].Intra_Trade_List_US_Date__c);
            System.assertEquals(date.newinstance(2912, 11, 23), rslts[0].Intra_Trade_List_US_End_Date__c);
            System.assertEquals(null, rslts[0].Foreign_Trade_List_RMB__c);
            System.assertEquals(null, rslts[0].Foreign_Trade_List_RMB_Date__c);
            System.assertEquals(null, rslts[0].Foreign_Trade_List_RMB_End_Date__c);
        }
    }

    @isTest
    static void testNFM005_update_USD_1() {
        Product2 prd = testNFM005Init();
        prd.Intra_Trade_List_RMB_1__c = 1.56;
        prd.Intra_Trade_List_RMB_Date1__c = date.newinstance(2012, 11, 21);
        prd.Intra_Trade_List_RMB_End_Date1__c = date.newinstance(2912, 11, 23);
        prd.Intra_Trade_List_RMB_2__c = 1.78;
        prd.Intra_Trade_List_RMB_Date2__c = date.newinstance(2012, 12, 1);
        prd.Intra_Trade_List_RMB_End_Date2__c = date.newinstance(2912, 12, 3);
        prd.Intra_Trade_List_US__c = 101.12;
        prd.Intra_Trade_List_US_Date__c = date.newinstance(2012, 11, 12);
        prd.Intra_Trade_List_US_End_Date__c = date.newinstance(2912, 11, 23);
        update prd;

        NFM005WebService.SalesPrice SalesPrice = new NFM005WebService.SalesPrice();
        NFM005WebService.SalesPrices SalesPrices = new NFM005WebService.SalesPrices();

        // Monitoringの設定
        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        SalesPrices.Monitoring = new NFMUtil.Monitoring();

        // update USD 外貿 1回目
        SalesPrices.SalesPrice = new NFM005WebService.SalesPrice[] { SalesPrice };
        SalesPrices.Monitoring.MessageGroupNumber = nowStr + '21';
        SalesPrice.SuppliersItemCode  = 'testNFM005';
        SalesPrice.PriceType          = 'OHC-001S';
        SalesPrice.Currency_x         = 'USD';
        SalesPrice.SalesPrice      = 201.21;
        SalesPrice.EffectiveDateFrom  = '20121102';
        SalesPrice.EffectiveDateTo    = '29121104';
        SalesPrice.PurposeOfAdvice    = '3';

        System.Test.startTest();
        NFM005WebService.NFM005(SalesPrices);
        System.Test.stopTest();

        List<Product2> rslts = [select Id, ProductCode, ProductCode_Ext__c,
                                       Intra_Trade_List_RMB_1__c,
                                       Intra_Trade_List_RMB_Date1__c,
                                       Intra_Trade_List_RMB_End_Date1__c,
                                       Intra_Trade_List_RMB_2__c,
                                       Intra_Trade_List_RMB_Date2__c,
                                       Intra_Trade_List_RMB_End_Date2__c,
                                       Foreign_Trade_List_US_1__c,
                                       Foreign_Trade_List_US_Date1__c,
                                       Foreign_Trade_List_US_End_Date1__c,
                                       Foreign_Trade_List_US_2__c,
                                       Foreign_Trade_List_US_Date2__c,
                                       Foreign_Trade_List_US_End_Date2__c,
                                       Intra_Trade_List_US__c,
                                       Intra_Trade_List_US_Date__c,
                                       Intra_Trade_List_US_End_Date__c,
                                       Foreign_Trade_List_RMB__c,
                                       Foreign_Trade_List_RMB_Date__c,
                                       Foreign_Trade_List_RMB_End_Date__c
                                  from Product2
                                 where ProductCode_Ext__c = :SalesPrice.SuppliersItemCode];
        System.assertEquals(1, rslts.size());
        if (rslts.size() == 1) {
            System.assertEquals('testNFM005', rslts[0].ProductCode);
            System.assertEquals(1.56, rslts[0].Intra_Trade_List_RMB_1__c);
            System.assertEquals(date.newinstance(2012, 11, 21), rslts[0].Intra_Trade_List_RMB_Date1__c);
            System.assertEquals(date.newinstance(2912, 11, 23), rslts[0].Intra_Trade_List_RMB_End_Date1__c);
            System.assertEquals(1.78, rslts[0].Intra_Trade_List_RMB_2__c);
            System.assertEquals(date.newinstance(2012, 12, 01), rslts[0].Intra_Trade_List_RMB_Date2__c);
            System.assertEquals(date.newinstance(2912, 12, 03), rslts[0].Intra_Trade_List_RMB_End_Date2__c);
            System.assertEquals(201.21, rslts[0].Foreign_Trade_List_US_1__c);
            System.assertEquals(date.newinstance(2012, 11, 02), rslts[0].Foreign_Trade_List_US_Date1__c);
            System.assertEquals(date.newinstance(2912, 11, 04), rslts[0].Foreign_Trade_List_US_End_Date1__c);
            System.assertEquals(null, rslts[0].Foreign_Trade_List_US_2__c);
            System.assertEquals(null, rslts[0].Foreign_Trade_List_US_Date2__c);
            System.assertEquals(null, rslts[0].Foreign_Trade_List_US_End_Date2__c);
            System.assertEquals(101.12, rslts[0].Intra_Trade_List_US__c);
            System.assertEquals(date.newinstance(2012, 11, 12), rslts[0].Intra_Trade_List_US_Date__c);
            System.assertEquals(date.newinstance(2912, 11, 23), rslts[0].Intra_Trade_List_US_End_Date__c);
            System.assertEquals(null, rslts[0].Foreign_Trade_List_RMB__c);
            System.assertEquals(null, rslts[0].Foreign_Trade_List_RMB_Date__c);
            System.assertEquals(null, rslts[0].Foreign_Trade_List_RMB_End_Date__c);
        }
    }

    @isTest
    static void testNFM005_update_USD_2() {
        Product2 prd = testNFM005Init();
        prd.Intra_Trade_List_RMB_1__c = 1.56;
        prd.Intra_Trade_List_RMB_Date1__c = date.newinstance(2012, 11, 21);
        prd.Intra_Trade_List_RMB_End_Date1__c = date.newinstance(2912, 11, 23);
        prd.Intra_Trade_List_RMB_2__c = 1.78;
        prd.Intra_Trade_List_RMB_Date2__c = date.newinstance(2012, 12, 1);
        prd.Intra_Trade_List_RMB_End_Date2__c = date.newinstance(2912, 12, 3);
        prd.Intra_Trade_List_US__c = 101.12;
        prd.Intra_Trade_List_US_Date__c = date.newinstance(2012, 11, 12);
        prd.Intra_Trade_List_US_End_Date__c = date.newinstance(2912, 11, 23);
        prd.Foreign_Trade_List_US_1__c = 201.21;
        prd.Foreign_Trade_List_US_Date1__c = date.newinstance(2012, 11, 02);
        prd.Foreign_Trade_List_US_End_Date1__c = date.newinstance(2912, 11, 04);
        update prd;

        NFM005WebService.SalesPrice SalesPrice = new NFM005WebService.SalesPrice();
        NFM005WebService.SalesPrices SalesPrices = new NFM005WebService.SalesPrices();

        // Monitoringの設定
        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        SalesPrices.Monitoring = new NFMUtil.Monitoring();

        // update USD 外貿 2回目
        SalesPrices.SalesPrice = new NFM005WebService.SalesPrice[] { SalesPrice };
        SalesPrices.Monitoring.MessageGroupNumber = nowStr + '22';
        SalesPrice.SuppliersItemCode  = 'testNFM005';
        SalesPrice.PriceType          = 'OHC-001S';
        SalesPrice.Currency_x         = 'USD';
        SalesPrice.SalesPrice      = 201.43;
        SalesPrice.EffectiveDateFrom  = '20121112';
        SalesPrice.EffectiveDateTo    = '29121114';
        SalesPrice.PurposeOfAdvice    = '3';

        System.Test.startTest();
        NFM005WebService.NFM005(SalesPrices);
        System.Test.stopTest();

        List<Product2> rslts = [select Id, ProductCode, ProductCode_Ext__c,
                            Intra_Trade_List_RMB_1__c,
                            Intra_Trade_List_RMB_Date1__c,
                            Intra_Trade_List_RMB_End_Date1__c,
                            Intra_Trade_List_RMB_2__c,
                            Intra_Trade_List_RMB_Date2__c,
                            Intra_Trade_List_RMB_End_Date2__c,
                            Foreign_Trade_List_US_1__c,
                            Foreign_Trade_List_US_Date1__c,
                            Foreign_Trade_List_US_End_Date1__c,
                            Foreign_Trade_List_US_2__c,
                            Foreign_Trade_List_US_Date2__c,
                            Foreign_Trade_List_US_End_Date2__c,
                            Intra_Trade_List_US__c,
                            Intra_Trade_List_US_Date__c,
                            Intra_Trade_List_US_End_Date__c,
                            Foreign_Trade_List_RMB__c,
                            Foreign_Trade_List_RMB_Date__c,
                            Foreign_Trade_List_RMB_End_Date__c
                      from Product2
                     where ProductCode_Ext__c = :SalesPrice.SuppliersItemCode];
        System.assertEquals(1, rslts.size());
        if (rslts.size() == 1) {
            System.assertEquals('testNFM005', rslts[0].ProductCode);
            System.assertEquals(1.56, rslts[0].Intra_Trade_List_RMB_1__c);
            System.assertEquals(date.newinstance(2012, 11, 21), rslts[0].Intra_Trade_List_RMB_Date1__c);
            System.assertEquals(date.newinstance(2912, 11, 23), rslts[0].Intra_Trade_List_RMB_End_Date1__c);
            System.assertEquals(1.78, rslts[0].Intra_Trade_List_RMB_2__c);
            System.assertEquals(date.newinstance(2012, 12, 01), rslts[0].Intra_Trade_List_RMB_Date2__c);
            System.assertEquals(date.newinstance(2912, 12, 03), rslts[0].Intra_Trade_List_RMB_End_Date2__c);
            System.assertEquals(201.21, rslts[0].Foreign_Trade_List_US_1__c);
            System.assertEquals(date.newinstance(2012, 11, 02), rslts[0].Foreign_Trade_List_US_Date1__c);
            System.assertEquals(date.newinstance(2912, 11, 04), rslts[0].Foreign_Trade_List_US_End_Date1__c);
            System.assertEquals(201.43, rslts[0].Foreign_Trade_List_US_2__c);
            System.assertEquals(date.newinstance(2012, 11, 12), rslts[0].Foreign_Trade_List_US_Date2__c);
            System.assertEquals(date.newinstance(2912, 11, 14), rslts[0].Foreign_Trade_List_US_End_Date2__c);
            System.assertEquals(101.12, rslts[0].Intra_Trade_List_US__c);
            System.assertEquals(date.newinstance(2012, 11, 12), rslts[0].Intra_Trade_List_US_Date__c);
            System.assertEquals(date.newinstance(2912, 11, 23), rslts[0].Intra_Trade_List_US_End_Date__c);
            System.assertEquals(null, rslts[0].Foreign_Trade_List_RMB__c);
            System.assertEquals(null, rslts[0].Foreign_Trade_List_RMB_Date__c);
            System.assertEquals(null, rslts[0].Foreign_Trade_List_RMB_End_Date__c);
        }
    }

    @isTest
    static void testNFM005_update_USD_3() {
        Product2 prd = testNFM005Init();
        prd.Intra_Trade_List_RMB_1__c = 1.56;
        prd.Intra_Trade_List_RMB_Date1__c = date.newinstance(2012, 11, 21);
        prd.Intra_Trade_List_RMB_End_Date1__c = date.newinstance(2912, 11, 23);
        prd.Intra_Trade_List_RMB_2__c = 1.78;
        prd.Intra_Trade_List_RMB_Date2__c = date.newinstance(2012, 12, 1);
        prd.Intra_Trade_List_RMB_End_Date2__c = date.newinstance(2912, 12, 3);
        prd.Intra_Trade_List_US__c = 101.12;
        prd.Intra_Trade_List_US_Date__c = date.newinstance(2012, 11, 12);
        prd.Intra_Trade_List_US_End_Date__c = date.newinstance(2912, 11, 23);
        prd.Foreign_Trade_List_US_1__c = 201.21;
        prd.Foreign_Trade_List_US_Date1__c = date.newinstance(2012, 11, 2);
        prd.Foreign_Trade_List_US_End_Date1__c = date.newinstance(2912, 11, 4);
        prd.Foreign_Trade_List_US_2__c = 201.43;
        prd.Foreign_Trade_List_US_Date2__c = date.newinstance(2012, 11, 12);
        prd.Foreign_Trade_List_US_End_Date2__c = date.newinstance(2912, 11, 14);
        update prd;

        NFM005WebService.SalesPrice SalesPrice = new NFM005WebService.SalesPrice();
        NFM005WebService.SalesPrices SalesPrices = new NFM005WebService.SalesPrices();

        // Monitoringの設定
        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        SalesPrices.Monitoring = new NFMUtil.Monitoring();

        // update USD 外貿 3回目
        SalesPrices.SalesPrice = new NFM005WebService.SalesPrice[] { SalesPrice };
        SalesPrices.Monitoring.MessageGroupNumber = nowStr + '23';
        SalesPrice.SuppliersItemCode  = 'testNFM005';
        SalesPrice.PriceType          = 'OHC-001S';
        SalesPrice.Currency_x         = 'USD';
        SalesPrice.SalesPrice      = 201.65;
        SalesPrice.EffectiveDateFrom  = '20121122';
        SalesPrice.EffectiveDateTo    = '29121124';
        SalesPrice.PurposeOfAdvice    = '3';

        System.Test.startTest();
        NFM005WebService.NFM005(SalesPrices);
        System.Test.stopTest();

        List<Product2> rslts = [select Id, ProductCode, ProductCode_Ext__c,
                            Intra_Trade_List_RMB_1__c,
                            Intra_Trade_List_RMB_Date1__c,
                            Intra_Trade_List_RMB_End_Date1__c,
                            Intra_Trade_List_RMB_2__c,
                            Intra_Trade_List_RMB_Date2__c,
                            Intra_Trade_List_RMB_End_Date2__c,
                            Foreign_Trade_List_US_1__c,
                            Foreign_Trade_List_US_Date1__c,
                            Foreign_Trade_List_US_End_Date1__c,
                            Foreign_Trade_List_US_2__c,
                            Foreign_Trade_List_US_Date2__c,
                            Foreign_Trade_List_US_End_Date2__c,
                            Intra_Trade_List_US__c,
                            Intra_Trade_List_US_Date__c,
                            Intra_Trade_List_US_End_Date__c,
                            Foreign_Trade_List_RMB__c,
                            Foreign_Trade_List_RMB_Date__c,
                            Foreign_Trade_List_RMB_End_Date__c
                      from Product2
                     where ProductCode_Ext__c = :SalesPrice.SuppliersItemCode];
        System.assertEquals(1, rslts.size());
        if (rslts.size() == 1) {
            System.assertEquals('testNFM005', rslts[0].ProductCode);
            System.assertEquals(1.56, rslts[0].Intra_Trade_List_RMB_1__c);
            System.assertEquals(date.newinstance(2012, 11, 21), rslts[0].Intra_Trade_List_RMB_Date1__c);
            System.assertEquals(date.newinstance(2912, 11, 23), rslts[0].Intra_Trade_List_RMB_End_Date1__c);
            System.assertEquals(1.78, rslts[0].Intra_Trade_List_RMB_2__c);
            System.assertEquals(date.newinstance(2012, 12, 01), rslts[0].Intra_Trade_List_RMB_Date2__c);
            System.assertEquals(date.newinstance(2912, 12, 03), rslts[0].Intra_Trade_List_RMB_End_Date2__c);
            System.assertEquals(201.65, rslts[0].Foreign_Trade_List_US_1__c);
            System.assertEquals(date.newinstance(2012, 11, 22), rslts[0].Foreign_Trade_List_US_Date1__c);
            System.assertEquals(date.newinstance(2912, 11, 24), rslts[0].Foreign_Trade_List_US_End_Date1__c);
            System.assertEquals(201.43, rslts[0].Foreign_Trade_List_US_2__c);
            System.assertEquals(date.newinstance(2012, 11, 12), rslts[0].Foreign_Trade_List_US_Date2__c);
            System.assertEquals(date.newinstance(2912, 11, 14), rslts[0].Foreign_Trade_List_US_End_Date2__c);
            System.assertEquals(101.12, rslts[0].Intra_Trade_List_US__c);
            System.assertEquals(date.newinstance(2012, 11, 12), rslts[0].Intra_Trade_List_US_Date__c);
            System.assertEquals(date.newinstance(2912, 11, 23), rslts[0].Intra_Trade_List_US_End_Date__c);
            System.assertEquals(null, rslts[0].Foreign_Trade_List_RMB__c);
            System.assertEquals(null, rslts[0].Foreign_Trade_List_RMB_Date__c);
            System.assertEquals(null, rslts[0].Foreign_Trade_List_RMB_End_Date__c);
        }
    }

    @isTest
    static void testNFM005_update_USD_4() {
        Product2 prd = testNFM005Init();
        prd.Intra_Trade_List_RMB_1__c = 1.56;
        prd.Intra_Trade_List_RMB_Date1__c = date.newinstance(2012, 11, 21);
        prd.Intra_Trade_List_RMB_End_Date1__c = date.newinstance(2912, 11, 23);
        prd.Intra_Trade_List_RMB_2__c = 1.78;
        prd.Intra_Trade_List_RMB_Date2__c = date.newinstance(2012, 12, 1);
        prd.Intra_Trade_List_RMB_End_Date2__c = date.newinstance(2912, 12, 3);
        prd.Intra_Trade_List_US__c = 101.12;
        prd.Intra_Trade_List_US_Date__c = date.newinstance(2012, 11, 12);
        prd.Intra_Trade_List_US_End_Date__c = date.newinstance(2912, 11, 23);
        prd.Foreign_Trade_List_US_1__c = 201.65;
        prd.Foreign_Trade_List_US_Date1__c = date.newinstance(2012, 11, 22);
        prd.Foreign_Trade_List_US_End_Date1__c = date.newinstance(2912, 11, 24);
        prd.Foreign_Trade_List_US_2__c = 201.43;
        prd.Foreign_Trade_List_US_Date2__c = date.newinstance(2012, 11, 12);
        prd.Foreign_Trade_List_US_End_Date2__c = date.newinstance(2912, 11, 14);
        update prd;

        NFM005WebService.SalesPrice SalesPrice = new NFM005WebService.SalesPrice();
        NFM005WebService.SalesPrice SalesPrice2 = new NFM005WebService.SalesPrice();
        NFM005WebService.SalesPrices SalesPrices = new NFM005WebService.SalesPrices();

        // Monitoringの設定
        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        SalesPrices.Monitoring = new NFMUtil.Monitoring();

        // update USD 外貿 4回目
        SalesPrices.SalesPrice = new NFM005WebService.SalesPrice[] { SalesPrice, SalesPrice2 };
        SalesPrices.Monitoring.MessageGroupNumber = nowStr + '24';
        SalesPrice.SuppliersItemCode  = 'testNFM005';
        SalesPrice.PriceType          = 'OHC-001S';
        SalesPrice.Currency_x         = 'USD';
        SalesPrice.SalesPrice      = 201.87;
        SalesPrice.EffectiveDateFrom  = '20121202';
        SalesPrice.EffectiveDateTo    = '29121204';
        SalesPrice.PurposeOfAdvice    = '3';
        // update RMB 外貿
        SalesPrice2.SuppliersItemCode  = 'testNFM005';
        SalesPrice2.PriceType          = 'OHC-001S';
        SalesPrice2.Currency_x         = 'RMB';
        SalesPrice2.SalesPrice      = 222.12;
        SalesPrice2.EffectiveDateFrom  = '20121212';
        SalesPrice2.EffectiveDateTo    = '29121214';
        SalesPrice2.PurposeOfAdvice    = '3';

        System.Test.startTest();
        NFM005WebService.NFM005(SalesPrices);
        System.Test.stopTest();

        List<Product2> rslts = [select Id, ProductCode, ProductCode_Ext__c,
                            Intra_Trade_List_RMB_1__c,
                            Intra_Trade_List_RMB_Date1__c,
                            Intra_Trade_List_RMB_End_Date1__c,
                            Intra_Trade_List_RMB_2__c,
                            Intra_Trade_List_RMB_Date2__c,
                            Intra_Trade_List_RMB_End_Date2__c,
                            Foreign_Trade_List_US_1__c,
                            Foreign_Trade_List_US_Date1__c,
                            Foreign_Trade_List_US_End_Date1__c,
                            Foreign_Trade_List_US_2__c,
                            Foreign_Trade_List_US_Date2__c,
                            Foreign_Trade_List_US_End_Date2__c,
                            Intra_Trade_List_US__c,
                            Intra_Trade_List_US_Date__c,
                            Intra_Trade_List_US_End_Date__c,
                            Foreign_Trade_List_RMB__c,
                            Foreign_Trade_List_RMB_Date__c,
                            Foreign_Trade_List_RMB_End_Date__c
                      from Product2
                     where ProductCode_Ext__c = :SalesPrice.SuppliersItemCode];
        System.assertEquals(1, rslts.size());
        if (rslts.size() == 1) {
            System.assertEquals('testNFM005', rslts[0].ProductCode);
            System.assertEquals(1.56, rslts[0].Intra_Trade_List_RMB_1__c);
            System.assertEquals(date.newinstance(2012, 11, 21), rslts[0].Intra_Trade_List_RMB_Date1__c);
            System.assertEquals(date.newinstance(2912, 11, 23), rslts[0].Intra_Trade_List_RMB_End_Date1__c);
            System.assertEquals(1.78, rslts[0].Intra_Trade_List_RMB_2__c);
            System.assertEquals(date.newinstance(2012, 12, 01), rslts[0].Intra_Trade_List_RMB_Date2__c);
            System.assertEquals(date.newinstance(2912, 12, 03), rslts[0].Intra_Trade_List_RMB_End_Date2__c);
            System.assertEquals(201.65, rslts[0].Foreign_Trade_List_US_1__c);
            System.assertEquals(date.newinstance(2012, 11, 22), rslts[0].Foreign_Trade_List_US_Date1__c);
            System.assertEquals(date.newinstance(2912, 11, 24), rslts[0].Foreign_Trade_List_US_End_Date1__c);
            System.assertEquals(201.87, rslts[0].Foreign_Trade_List_US_2__c);
            System.assertEquals(date.newinstance(2012, 12, 02), rslts[0].Foreign_Trade_List_US_Date2__c);
            System.assertEquals(date.newinstance(2912, 12, 04), rslts[0].Foreign_Trade_List_US_End_Date2__c);
            System.assertEquals(101.12, rslts[0].Intra_Trade_List_US__c);
            System.assertEquals(date.newinstance(2012, 11, 12), rslts[0].Intra_Trade_List_US_Date__c);
            System.assertEquals(date.newinstance(2912, 11, 23), rslts[0].Intra_Trade_List_US_End_Date__c);
            System.assertEquals(222.12, rslts[0].Foreign_Trade_List_RMB__c);
            System.assertEquals(date.newinstance(2012, 12, 12), rslts[0].Foreign_Trade_List_RMB_Date__c);
            System.assertEquals(date.newinstance(2912, 12, 14), rslts[0].Foreign_Trade_List_RMB_End_Date__c);
        }
    }

    @isTest
    static void testNFM005_delete_1() {
        Product2 prd = testNFM005Init();
        prd.Intra_Trade_List_RMB_1__c = 1.56;
        prd.Intra_Trade_List_RMB_Date1__c = date.newinstance(2012, 11, 21);
        prd.Intra_Trade_List_RMB_End_Date1__c = date.newinstance(2912, 11, 23);
        prd.Intra_Trade_List_RMB_2__c = 1.78;
        prd.Intra_Trade_List_RMB_Date2__c = date.newinstance(2012, 12, 1);
        prd.Intra_Trade_List_RMB_End_Date2__c = date.newinstance(2912, 12, 3);
        prd.Intra_Trade_List_US__c = 101.12;
        prd.Intra_Trade_List_US_Date__c = date.newinstance(2012, 11, 12);
        prd.Intra_Trade_List_US_End_Date__c = date.newinstance(2912, 11, 23);
        prd.Foreign_Trade_List_US_1__c = 201.65;
        prd.Foreign_Trade_List_US_Date1__c = date.newinstance(2012, 11, 22);
        prd.Foreign_Trade_List_US_End_Date1__c = date.newinstance(2912, 11, 24);
        prd.Foreign_Trade_List_US_2__c = 201.43;
        prd.Foreign_Trade_List_US_Date2__c = date.newinstance(2012, 11, 12);
        prd.Foreign_Trade_List_US_End_Date2__c = date.newinstance(2912, 11, 14);
        prd.Foreign_Trade_List_RMB__c = 222.12;
        prd.Foreign_Trade_List_RMB_Date__c = date.newinstance(2012, 12, 12);
        prd.Foreign_Trade_List_RMB_End_Date__c = date.newinstance(2912, 12, 14);
        update prd;

        NFM005WebService.SalesPrice SalesPrice = new NFM005WebService.SalesPrice();
        NFM005WebService.SalesPrices SalesPrices = new NFM005WebService.SalesPrices();

        // Monitoringの設定
        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        SalesPrices.Monitoring = new NFMUtil.Monitoring();

        // 削除、２世代目の金額
        SalesPrices.SalesPrice = new NFM005WebService.SalesPrice[] { SalesPrice };
        SalesPrices.Monitoring.MessageGroupNumber = nowStr + '31';
        SalesPrice.SuppliersItemCode  = 'testNFM005';
        SalesPrice.PriceType          = 'OHC-001S';
        SalesPrice.Currency_x         = 'USD';
        SalesPrice.SalesPrice      = 201.87;
        SalesPrice.EffectiveDateFrom  = '20121202';
        SalesPrice.EffectiveDateTo    = '29121204';
        SalesPrice.PurposeOfAdvice    = '1';

        System.Test.startTest();
        NFM005WebService.NFM005(SalesPrices);
        System.Test.stopTest();

        List<Product2> rslts = [select Id, ProductCode, ProductCode_Ext__c,
                                       Intra_Trade_List_RMB_1__c,
                                       Intra_Trade_List_RMB_Date1__c,
                                       Intra_Trade_List_RMB_End_Date1__c,
                                       Intra_Trade_List_RMB_2__c,
                                       Intra_Trade_List_RMB_Date2__c,
                                       Intra_Trade_List_RMB_End_Date2__c,
                                       Foreign_Trade_List_US_1__c,
                                       Foreign_Trade_List_US_Date1__c,
                                       Foreign_Trade_List_US_End_Date1__c,
                                       Foreign_Trade_List_US_2__c,
                                       Foreign_Trade_List_US_Date2__c,
                                       Foreign_Trade_List_US_End_Date2__c,
                                       Intra_Trade_List_US__c,
                                       Intra_Trade_List_US_Date__c,
                                       Intra_Trade_List_US_End_Date__c,
                                       Foreign_Trade_List_RMB__c,
                                       Foreign_Trade_List_RMB_Date__c,
                                       Foreign_Trade_List_RMB_End_Date__c
                                  from Product2
                                 where ProductCode_Ext__c = :SalesPrice.SuppliersItemCode];
        // deleteの場合、EffectiveDateTo が前日
        System.assertEquals(1, rslts.size());
        System.assertEquals(Date.today().addDays(-1), rslts[0].Foreign_Trade_List_US_End_Date2__c);
    }
    
    @isTest
    static void testNFM005_delete_2() {
        Product2 prd = testNFM005Init();
        prd.Intra_Trade_List_RMB_1__c = 1.56;
        prd.Intra_Trade_List_RMB_Date1__c = date.newinstance(2012, 11, 21);
        prd.Intra_Trade_List_RMB_End_Date1__c = date.newinstance(2912, 11, 23);
        prd.Intra_Trade_List_RMB_2__c = 1.78;
        prd.Intra_Trade_List_RMB_Date2__c = date.newinstance(2012, 12, 1);
        prd.Intra_Trade_List_RMB_End_Date2__c = date.newinstance(2912, 12, 3);
        prd.Intra_Trade_List_US__c = 101.12;
        prd.Intra_Trade_List_US_Date__c = date.newinstance(2012, 11, 12);
        prd.Intra_Trade_List_US_End_Date__c = date.newinstance(2912, 11, 23);
        prd.Foreign_Trade_List_US_1__c = 201.65;
        prd.Foreign_Trade_List_US_Date1__c = date.newinstance(2012, 11, 22);
        prd.Foreign_Trade_List_US_End_Date1__c = date.newinstance(2912, 11, 24);
        prd.Foreign_Trade_List_US_2__c = 201.43;
        prd.Foreign_Trade_List_US_Date2__c = date.newinstance(2012, 11, 12);
        prd.Foreign_Trade_List_US_End_Date2__c = Date.today().addDays(-1);
        prd.Foreign_Trade_List_RMB__c = 222.12;
        prd.Foreign_Trade_List_RMB_Date__c = date.newinstance(2012, 12, 12);
        prd.Foreign_Trade_List_RMB_End_Date__c = date.newinstance(2912, 12, 14);
        update prd;

        NFM005WebService.SalesPrice SalesPrice = new NFM005WebService.SalesPrice();
        NFM005WebService.SalesPrices SalesPrices = new NFM005WebService.SalesPrices();

        // Monitoringの設定
        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        SalesPrices.Monitoring = new NFMUtil.Monitoring();

        // 料金更新、２世代目に反映
        SalesPrices.SalesPrice = new NFM005WebService.SalesPrice[] { SalesPrice };
        SalesPrices.Monitoring.MessageGroupNumber = nowStr + '32';
        SalesPrice.SuppliersItemCode  = 'testNFM005';
        SalesPrice.PriceType          = 'OHC-001S';
        SalesPrice.Currency_x         = 'USD';
        SalesPrice.SalesPrice      = 201.87;
        SalesPrice.EffectiveDateFrom  = '20121201';
        SalesPrice.EffectiveDateTo    = '29121204';
        SalesPrice.PurposeOfAdvice    = '3';

        System.Test.startTest();
        NFM005WebService.NFM005(SalesPrices);
        System.Test.stopTest();

        List<Product2> rslts = [select Id, ProductCode, ProductCode_Ext__c,
                                       Intra_Trade_List_RMB_1__c,
                                       Intra_Trade_List_RMB_Date1__c,
                                       Intra_Trade_List_RMB_End_Date1__c,
                                       Intra_Trade_List_RMB_2__c,
                                       Intra_Trade_List_RMB_Date2__c,
                                       Intra_Trade_List_RMB_End_Date2__c,
                                       Foreign_Trade_List_US_1__c,
                                       Foreign_Trade_List_US_Date1__c,
                                       Foreign_Trade_List_US_End_Date1__c,
                                       Foreign_Trade_List_US_2__c,
                                       Foreign_Trade_List_US_Date2__c,
                                       Foreign_Trade_List_US_End_Date2__c,
                                       Intra_Trade_List_US__c,
                                       Intra_Trade_List_US_Date__c,
                                       Intra_Trade_List_US_End_Date__c,
                                       Foreign_Trade_List_RMB__c,
                                       Foreign_Trade_List_RMB_Date__c,
                                       Foreign_Trade_List_RMB_End_Date__c
                                  from Product2
                                 where ProductCode_Ext__c = :SalesPrice.SuppliersItemCode];
        // deleteの場合、EffectiveDateTo が前日
        System.assertEquals(1, rslts.size());
        System.assertEquals(201.87, rslts[0].Foreign_Trade_List_US_2__c);
        System.assertEquals(date.newinstance(2012, 12, 01), rslts[0].Foreign_Trade_List_US_Date2__c);
        System.assertEquals(date.newinstance(2912, 12, 04), rslts[0].Foreign_Trade_List_US_End_Date2__c);
    }
}