@isTest
private class SBG004RestTest {
    static Product2 testSBG004Init() {
        // テストデータ
        Product2 prd = new Product2();
        prd.Product_ECCode__c     = 'testSBG004';
        prd.ProductCode            = 'testSBG004';
        prd.Name                   = 'testSBG004';
        prd.IsActive               = true;
        insert prd;
        //Pricebook2 prdbook     = new Pricebook2();

        Pricebook2 prdbook1 = new Pricebook2(
            Name = 'testSBG004',
            ProductSegment__c  = 'BS',
            TradeType__c = 'Taxation',
            SalesChannel__c = 'dealer',
            MachineParts__c = 'Machine',
            isActive = true);

        insert prdbook1;
        Pricebook2 prdbook2 = new Pricebook2(
            Name = 'testSBG004',
            ProductSegment__c  = 'BS',
            TradeType__c = 'Taxation',
            SalesChannel__c = 'direct',
            MachineParts__c = 'Machine',
            isActive = true);

        insert prdbook2;

        PricebookEntry pbe = new PricebookEntry();
        pbe.Pricebook2Id = ControllerUtil.getStandardPricebook().Id;
        pbe.Product2Id      = prd.Id;
        pbe.UnitPrice       = 0;
        pbe.CurrencyIsoCode = 'CNY';
        pbe.IsActive        = true;
        insert pbe;
        PricebookEntry pbe1 = new PricebookEntry();
        pbe1.Pricebook2Id = ControllerUtil.getStandardPricebook().Id;
        pbe1.Product2Id      = prd.Id;
        pbe1.UnitPrice       = 0;
        pbe1.CurrencyIsoCode = 'USD';
        pbe1.IsActive        = true;
        insert pbe1;

        return prd;
    }


    @isTest
    static void testSBG004_void() {
        testSBG004Init();
        // null
        // SBG004Rest.SBG004(null);

        SBG004Rest.GeData GeData = new SBG004Rest.GeData();
        SBG004Rest.GeDatas GeDatas = new SBG004Rest.GeDatas();
        GeDatas.GeData = new SBG004Rest.GeData[] { GeData };
        // Monitoringをセットしない
        // SBG004Rest.SBG004(GeDatas);

        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        GeDatas.Monitoring = new NFMUtil.Monitoring();
        GeDatas.Monitoring.MessageGroupNumber = nowStr + '01';
        // 必須項目をセットしない
        // SBG004Rest.SBG004(GeDatas);

        // 商品コードが存在しない
        GeDatas.Monitoring.MessageGroupNumber = nowStr + '02';
        GeData.ProductCode  = 'testSBG004X';

        System.Test.startTest();
        // SBG004Rest.SBG004(GeDatas);
        BatchIF_Log__c rowData = NFMUtil.saveRowData(GeDatas.Monitoring, 'SBG004', GeDatas.GeData);
        SBG004Rest.main(rowData.Id);

        System.Test.stopTest();

        Product2[] rslts = [select Id from Product2 where Product_ECCode__c = :GeData.ProductCode];
        System.assertEquals(0, rslts.size());
    }

    @isTest
    static void testSBG004_update() {
        Product2 prd = testSBG004Init();
        prd.EffectiveDateTo__c = date.newinstance(2012, 12, 1);
        update prd;

        SBG004Rest.GeData GeData = new SBG004Rest.GeData();
        SBG004Rest.GeDatas GeDatas = new SBG004Rest.GeDatas();

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


        GeDatas.GeData = new SBG004Rest.GeData[] { GeData };
        GeDatas.Monitoring.MessageGroupNumber = nowStr + '32';
        GeData.ProductCode  = 'testSBG004';
        GeData.Currency_x         = 'USD';
        GeData.EffectiveDateFrom  = '20121201';
        GeData.EffectiveDateTo    = '29121204';
         GeData.PurposeOfAdvice    = '2';
        GeData.ProductSegment     = 'BS';
        GeData.MachineParts       = 'Machine';
        GeData.SalesChannel       = '99';
        GeData.TradeType          = 'Taxation';
        GeData.CostPrice          = 100;
        System.Test.startTest();
        // SBG004Rest.SBG004(GeDatas);
        BatchIF_Log__c rowData = NFMUtil.saveRowData(GeDatas.Monitoring, 'SBG004', GeDatas.GeData);
        SBG004Rest.main(rowData.Id);
        System.Test.stopTest();

        List<Product2> rslts = [select Id, ProductCode, Product_ECCode__c,
                                     EffectiveDateTo__c,
                                     ProductModels__c,
                                     ProductStatus__c
                                from Product2
                                where Product_ECCode__c = :GeData.ProductCode];
        // deleteの場合、EffectiveDateTo が前日
        System.assertEquals(1, rslts.size());
        System.assertEquals(date.newinstance(2012, 12, 01), rslts[0].EffectiveDateTo__c);

        List<BatchIF_Log__c> log = [Select ErrorLog__c,Id,Name,MessageGroupNumber__c,Log__c From BatchIF_Log__c];
        System.debug(log);

        List<PricebookEntry>  pres = [Select Id,Name,KEY__c,EffectiveDateFrom1__c,EffectiveDateFrom2__c,
                                 EffectiveDateTo1__c,EffectiveDateTo2__c,CostPrice1__c,CostPrice2__c,SalesPrice1__c,SalesPrice2__c
                                 from PricebookEntry Where KEY__c = 'BS_Taxation_direct_Machine_testSBG004_USD' OR KEY__c = 'BS_Taxation_dealer_Machine_testSBG004_USD'];
        System.debug(pres.size());
        System.assertEquals(2, pres.size());
    }

    @isTest
    static void testSBG004_delete() {
        Product2 prd = testSBG004Init();
        prd.EffectiveDateTo__c = date.newinstance(2012, 12, 1);
        update prd;

        SBG004Rest.GeData GeData = new SBG004Rest.GeData();
        SBG004Rest.GeDatas GeDatas = new SBG004Rest.GeDatas();

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


        GeDatas.GeData = new SBG004Rest.GeData[] { GeData };
        GeDatas.Monitoring.MessageGroupNumber = nowStr + '32';
        GeData.ProductCode  = 'testSBG004';
        GeData.Currency_x         = 'USD';
        GeData.EffectiveDateFrom  = '20121201';
        GeData.EffectiveDateTo    = '29121204';
        GeData.PurposeOfAdvice    = '2';
        GeData.ProductSegment     = 'BS';
        GeData.MachineParts       = 'Machine';
        GeData.SalesChannel       = 'direct';
        GeData.TradeType          = 'Taxation';
        GeData.CostPrice          = 100;
        GeData.Currency_x         = 'RMB';



        System.Test.startTest();
        // SBG004Rest.SBG004(GeDatas);
        BatchIF_Log__c rowData = NFMUtil.saveRowData(GeDatas.Monitoring, 'SBG004', GeDatas.GeData);
        SBG004Rest.main(rowData.Id);
        System.Test.stopTest();


         List<BatchIF_Log__c> log = [Select ErrorLog__c,Id,Name,MessageGroupNumber__c,Log__c From BatchIF_Log__c];
        System.debug(log);

        List<Product2> rslts = [select Id, ProductCode, Product_ECCode__c,
                                     EffectiveDateTo__c,
                                     ProductModels__c,
                                     ProductStatus__c
                                from Product2
                                where Product_ECCode__c = :GeData.ProductCode];
        // deleteの場合、EffectiveDateTo が前日
        System.assertEquals(1, rslts.size());
        System.assertEquals(date.newinstance(2012, 12, 01), rslts[0].EffectiveDateTo__c);
        String key1 = GeData.ProductSegment + '_' + GeData.TradeType + '_' + GeData.SalesChannel + '_' + GeData.MachineParts + '_' + GeData.ProductCode;
                List<PricebookEntry>  pres1 = [Select Id,Name,KEY__c from PricebookEntry ];
                System.debug(pres1);


        List<PricebookEntry>  pres = [Select Id,Name,Pricebook2Id,Product2Id,KEY__c,EffectiveDateFrom1__c,EffectiveDateFrom2__c,
                                 EffectiveDateTo1__c,EffectiveDateTo2__c,CostPrice1__c,CostPrice2__c,SalesPrice1__c,SalesPrice2__c
                                 from PricebookEntry Where KEY__c = 'BS_Taxation_direct_Machine_testSBG004_RMB'];
        List<Pricebook2> pr =   [Select Id,Name,ProductSegment__c,TradeType__c,SalesChannel__c,MachineParts__c
                                 from Pricebook2 Where Id = :pres[0].Pricebook2Id];                 
        System.debug(pres.size());
        System.debug(pr);
        System.assertEquals(1, pres.size());
        System.debug(pres[0].KEY__c);
        System.assertEquals(pres[0].KEY__c,'BS_Taxation_direct_Machine_testSBG004_RMB');
        System.assertEquals(pr[0].ProductSegment__c,'BS');
        System.assertEquals(pr[0].TradeType__c,'Taxation');
        System.assertEquals(pr[0].SalesChannel__c,'direct');
        System.assertEquals(pr[0].MachineParts__c,'Machine');
        
    
    }



    @isTest
    static void testSBG004_delete0() {
        Product2 prd = testSBG004Init();
        prd.EffectiveDateTo__c = date.newinstance(2012, 12, 1);
        update prd;

        SBG004Rest.GeData GeData = new SBG004Rest.GeData();
        SBG004Rest.GeDatas GeDatas = new SBG004Rest.GeDatas();

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


        GeDatas.GeData = new SBG004Rest.GeData[] { GeData };
        GeDatas.Monitoring.MessageGroupNumber = nowStr + '32';
        GeData.ProductCode  = 'testSBG004';
        GeData.Currency_x         = 'USD';
        GeData.EffectiveDateFrom  = '20131203';
        GeData.EffectiveDateTo    = '20191204';
        GeData.PurposeOfAdvice    = '2';
        GeData.ProductSegment     = 'BS';
        GeData.MachineParts       = 'Machine';
        GeData.SalesChannel       = 'direct';
        GeData.TradeType          = 'Taxation';
        GeData.CostPrice          = 100;




        List<Product2> rslts1 = [select Id, ProductCode, Product_ECCode__c,
                                     EffectiveDateTo__c,
                                     ProductModels__c,
                                     ProductStatus__c
                                from Product2];
        System.debug(rslts1);




        Pricebook2 p2 = [Select Id,Name From Pricebook2 Where SalesChannel__c = 'direct'];
        PricebookEntry pbe = new PricebookEntry();
        pbe.Pricebook2Id = p2.Id;
        pbe.Product2Id      = rslts1[0].Id;
        pbe.UnitPrice       = 0;
        pbe.CurrencyIsoCode = 'CNY';
        pbe.IsActive        = true;
        pbe.KEY__c = 'BS_Taxation_direct_Machine_testSBG004_USD';
        pbe.UseStandardPrice = false;






        insert pbe;



        System.Test.startTest();
        // SBG004Rest.SBG004(GeDatas);
        //GeData.Currency_x         = 'RMB';
        BatchIF_Log__c rowData = NFMUtil.saveRowData(GeDatas.Monitoring, 'SBG004', GeDatas.GeData);
        SBG004Rest.main(rowData.Id);
        //SBG004Rest.SBG004(GeDatas);
        //GeData.EffectiveDateFrom  = '20131202';
        //GeData.EffectiveDateTo    = '20131202';
        //SBG004Rest.SBG004(GeDatas);
        //GeData.EffectiveDateFrom  = '20141203';
        //GeData.EffectiveDateTo    = '29121204';
        //SBG004Rest.SBG004(GeDatas);

        System.Test.stopTest();


         List<BatchIF_Log__c> log = [Select ErrorLog__c,Id,Name,MessageGroupNumber__c,Log__c From BatchIF_Log__c];
        System.debug(log);

        List<Product2> rslts = [select Id, ProductCode, Product_ECCode__c,
                                     EffectiveDateTo__c,
                                     ProductModels__c,
                                     ProductStatus__c
                                from Product2
                                where Product_ECCode__c = :GeData.ProductCode];
        // deleteの場合、EffectiveDateTo が前日
        System.assertEquals(1, rslts.size());
        System.assertEquals(date.newinstance(2012, 12, 01), rslts[0].EffectiveDateTo__c);
        String key1 = GeData.ProductSegment + '_' + GeData.TradeType + '_' + GeData.SalesChannel + '_' + GeData.MachineParts + '_' + GeData.ProductCode;
        System.debug(key1);


        List<PricebookEntry>  pres = [Select Id,Name,Pricebook2Id,Product2Id,KEY__c,EffectiveDateFrom1__c,EffectiveDateFrom2__c,
                                 EffectiveDateTo1__c,EffectiveDateTo2__c,CostPrice1__c,CostPrice2__c,SalesPrice1__c,SalesPrice2__c
                                 from PricebookEntry Where KEY__c = 'BS_Taxation_direct_Machine_testSBG004_USD'];
        List<Pricebook2> pr =   [Select Id,Name,ProductSegment__c,TradeType__c,SalesChannel__c,MachineParts__c
                                 from Pricebook2 Where Id = :pres[0].Pricebook2Id];                 
        System.debug(pres.size());
        System.debug(pr);
        System.assertEquals(1, pres.size());
        System.debug(pres[0].KEY__c);
        System.assertEquals(pres[0].KEY__c,'BS_Taxation_direct_Machine_testSBG004_USD');
        System.assertEquals(pr[0].ProductSegment__c,'BS');
        System.assertEquals(pr[0].TradeType__c,'Taxation');
        System.assertEquals(pr[0].SalesChannel__c,'direct');
        System.assertEquals(pr[0].MachineParts__c,'Machine');
        
    
    }

   
    @isTest
    static void testSBG004_delete1() {
        Product2 prd = testSBG004Init();
        prd.EffectiveDateTo__c = date.newinstance(2012, 12, 1);
        update prd;

        SBG004Rest.GeData GeData = new SBG004Rest.GeData();
        SBG004Rest.GeDatas GeDatas = new SBG004Rest.GeDatas();

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


        GeDatas.GeData = new SBG004Rest.GeData[] { GeData };
        GeDatas.Monitoring.MessageGroupNumber = nowStr + '32';
        GeData.ProductCode  = 'testSBG004';
        GeData.Currency_x         = 'USD';
        GeData.EffectiveDateFrom  = '20131203';
        GeData.EffectiveDateTo    = '20191204';
        GeData.PurposeOfAdvice    = '2';
        GeData.ProductSegment     = 'BS';
        GeData.MachineParts       = 'Machine';
        GeData.SalesChannel       = 'direct';
        GeData.TradeType          = 'Taxation';
        GeData.CostPrice          = 100;




        List<Product2> rslts1 = [select Id, ProductCode, Product_ECCode__c,
                                     EffectiveDateTo__c,
                                     ProductModels__c,
                                     ProductStatus__c
                                from Product2];
        System.debug(rslts1);




        Pricebook2 p2 = [Select Id,Name From Pricebook2 Where SalesChannel__c = 'direct'];
        PricebookEntry pbe = new PricebookEntry();
        pbe.Pricebook2Id = p2.Id;
        pbe.Product2Id      = rslts1[0].Id;
        pbe.UnitPrice       = 0;
        pbe.CurrencyIsoCode = 'CNY';
        pbe.IsActive        = true;
        pbe.KEY__c = 'BS_Taxation_direct_Machine_testSBG004_USD';
        Date dateFrom = NFMUtil.parseStr2Date('20131201', false);
        Date dateTo = NFMUtil.parseStr2Date('20191204', true);
        Date dateFrom2 = NFMUtil.parseStr2Date('20131202', false);
        Date dateTo2 = NFMUtil.parseStr2Date('20191204', true);
        pbe.EffectiveDateFrom1__c = dateFrom;
        pbe.EffectiveDateTo1__c = dateTo;
        pbe.EffectiveDateFrom2__c = dateFrom2;
        pbe.EffectiveDateTo2__c = dateTo2;
        pbe.UseStandardPrice = false;






        insert pbe;



        System.Test.startTest();
        // SBG004Rest.SBG004(GeDatas);
        BatchIF_Log__c rowData = NFMUtil.saveRowData(GeDatas.Monitoring, 'SBG004', GeDatas.GeData);
        SBG004Rest.main(rowData.Id);
        //GeData.Currency_x         = 'RMB';
        //SBG004Rest.SBG004(GeDatas);
        //GeData.EffectiveDateFrom  = '20131202';
        //GeData.EffectiveDateTo    = '20131202';
        //SBG004Rest.SBG004(GeDatas);
        //GeData.EffectiveDateFrom  = '20141203';
        //GeData.EffectiveDateTo    = '29121204';
        //SBG004Rest.SBG004(GeDatas);

        System.Test.stopTest();


         List<BatchIF_Log__c> log = [Select ErrorLog__c,Id,Name,MessageGroupNumber__c,Log__c From BatchIF_Log__c];
        System.debug(log);

        List<Product2> rslts = [select Id, ProductCode, Product_ECCode__c,
                                     EffectiveDateTo__c,
                                     ProductModels__c,
                                     ProductStatus__c
                                from Product2
                                where Product_ECCode__c = :GeData.ProductCode];
        // deleteの場合、EffectiveDateTo が前日
        System.assertEquals(1, rslts.size());
        System.assertEquals(date.newinstance(2012, 12, 01), rslts[0].EffectiveDateTo__c);
        String key1 = GeData.ProductSegment + '_' + GeData.TradeType + '_' + GeData.SalesChannel + '_' + GeData.MachineParts + '_' + GeData.ProductCode;
        System.debug(key1);


        List<PricebookEntry>  pres = [Select Id,Name,Pricebook2Id,Product2Id,KEY__c,EffectiveDateFrom1__c,EffectiveDateFrom2__c,
                                 EffectiveDateTo1__c,EffectiveDateTo2__c,CostPrice1__c,CostPrice2__c,SalesPrice1__c,SalesPrice2__c
                                 from PricebookEntry Where KEY__c = 'BS_Taxation_direct_Machine_testSBG004_USD'];
        List<Pricebook2> pr =   [Select Id,Name,ProductSegment__c,TradeType__c,SalesChannel__c,MachineParts__c
                                 from Pricebook2 Where Id = :pres[0].Pricebook2Id];                 
        System.debug(pres.size());
        System.debug(pr);
        System.assertEquals(1, pres.size());
        System.debug(pres[0].KEY__c);
        System.assertEquals(pres[0].KEY__c,'BS_Taxation_direct_Machine_testSBG004_USD');
        System.assertEquals(pr[0].ProductSegment__c,'BS');
        System.assertEquals(pr[0].TradeType__c,'Taxation');
        System.assertEquals(pr[0].SalesChannel__c,'direct');
        System.assertEquals(pr[0].MachineParts__c,'Machine');
        
    
    }


    @isTest
    static void testSBG004_delete2() {
        Product2 prd = testSBG004Init();
        prd.EffectiveDateTo__c = date.newinstance(2012, 12, 1);
        update prd;

        SBG004Rest.GeData GeData = new SBG004Rest.GeData();
        SBG004Rest.GeDatas GeDatas = new SBG004Rest.GeDatas();

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


        GeDatas.GeData = new SBG004Rest.GeData[] { GeData };
        GeDatas.Monitoring.MessageGroupNumber = nowStr + '32';
        GeData.ProductCode  = 'testSBG004';
        GeData.Currency_x         = 'USD';
        GeData.EffectiveDateFrom  = '20131202';
        GeData.EffectiveDateTo    = '20191204';
        GeData.PurposeOfAdvice    = '2';
        GeData.ProductSegment     = 'BS';
        GeData.MachineParts       = 'Machine';
        GeData.SalesChannel       = 'direct';
        GeData.TradeType          = 'Taxation';
        GeData.CostPrice          = 100;




        List<Product2> rslts1 = [select Id, ProductCode, Product_ECCode__c,
                                     EffectiveDateTo__c,
                                     ProductModels__c,
                                     ProductStatus__c
                                from Product2];
        System.debug(rslts1);




        Pricebook2 p2 = [Select Id,Name From Pricebook2 Where SalesChannel__c = 'direct'];
        PricebookEntry pbe = new PricebookEntry();
        pbe.Pricebook2Id = p2.Id;
        pbe.Product2Id      = rslts1[0].Id;
        pbe.UnitPrice       = 0;
        pbe.CurrencyIsoCode = 'CNY';
        pbe.IsActive        = true;
        pbe.KEY__c = 'BS_Taxation_direct_Machine_testSBG004_USD';
        Date dateFrom = NFMUtil.parseStr2Date('20131201', false);
        Date dateTo = NFMUtil.parseStr2Date('20191204', true);
        pbe.EffectiveDateFrom1__c = dateFrom;
        pbe.EffectiveDateTo1__c = dateTo;
        pbe.UseStandardPrice = false;






        insert pbe;



        System.Test.startTest();
        // SBG004Rest.SBG004(GeDatas);
        BatchIF_Log__c rowData = NFMUtil.saveRowData(GeDatas.Monitoring, 'SBG004', GeDatas.GeData);
        SBG004Rest.main(rowData.Id);
        //GeData.Currency_x         = 'RMB';
        //SBG004Rest.SBG004(GeDatas);
        //GeData.EffectiveDateFrom  = '20131202';
        //GeData.EffectiveDateTo    = '20131202';
        //SBG004Rest.SBG004(GeDatas);
        //GeData.EffectiveDateFrom  = '20141203';
        //GeData.EffectiveDateTo    = '29121204';
        //SBG004Rest.SBG004(GeDatas);

        System.Test.stopTest();


         List<BatchIF_Log__c> log = [Select ErrorLog__c,Id,Name,MessageGroupNumber__c,Log__c From BatchIF_Log__c];
        System.debug(log);

        List<Product2> rslts = [select Id, ProductCode, Product_ECCode__c,
                                     EffectiveDateTo__c,
                                     ProductModels__c,
                                     ProductStatus__c
                                from Product2
                                where Product_ECCode__c = :GeData.ProductCode];
        // deleteの場合、EffectiveDateTo が前日
        System.assertEquals(1, rslts.size());
        System.assertEquals(date.newinstance(2012, 12, 01), rslts[0].EffectiveDateTo__c);
        String key1 = GeData.ProductSegment + '_' + GeData.TradeType + '_' + GeData.SalesChannel + '_' + GeData.MachineParts + '_' + GeData.ProductCode;
        System.debug(key1);


        List<PricebookEntry>  pres = [Select Id,Name,Pricebook2Id,Product2Id,KEY__c,EffectiveDateFrom1__c,EffectiveDateFrom2__c,
                                 EffectiveDateTo1__c,EffectiveDateTo2__c,CostPrice1__c,CostPrice2__c,SalesPrice1__c,SalesPrice2__c
                                 from PricebookEntry Where KEY__c = 'BS_Taxation_direct_Machine_testSBG004_USD'];
        List<Pricebook2> pr =   [Select Id,Name,ProductSegment__c,TradeType__c,SalesChannel__c,MachineParts__c
                                 from Pricebook2 Where Id = :pres[0].Pricebook2Id];                 
        System.debug(pres.size());
        System.debug(pr);
        System.assertEquals(1, pres.size());
        System.debug(pres[0].KEY__c);
        System.assertEquals(pres[0].KEY__c,'BS_Taxation_direct_Machine_testSBG004_USD');
        System.assertEquals(pr[0].ProductSegment__c,'BS');
        System.assertEquals(pr[0].TradeType__c,'Taxation');
        System.assertEquals(pr[0].SalesChannel__c,'direct');
        System.assertEquals(pr[0].MachineParts__c,'Machine');
        
    
    }

    @isTest
    static void testSBG004_resend() {
        Product2 prd = testSBG004Init();
        prd.EffectiveDateTo__c = date.newinstance(2012, 12, 1);
        update prd;

        SBG004Rest.GeData GeData = new SBG004Rest.GeData();
        SBG004Rest.GeDatas GeDatas = new SBG004Rest.GeDatas();

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


        GeDatas.GeData = new SBG004Rest.GeData[] { GeData };
        GeDatas.Monitoring.MessageGroupNumber = nowStr + '32';
        GeData.ProductCode  = 'testSBG004';
        GeData.Currency_x         = 'USD';
        GeData.EffectiveDateFrom  = '20121201';
        GeData.EffectiveDateTo    = '29121204';
        GeData.PurposeOfAdvice    = '2';
        GeData.ProductSegment     = 'BS';
        GeData.MachineParts       = 'Machine';
        GeData.SalesChannel       = '99';
        GeData.TradeType          = 'Taxation';
        GeData.CostPrice          = 100;

        System.Test.startTest();
        // SBG004Rest.SBG004(GeDatas);
        BatchIF_Log__c rowData = NFMUtil.saveRowData(GeDatas.Monitoring, 'SBG004', GeDatas.GeData);
        SBG004Rest.main(rowData.Id);
        System.Test.stopTest();

        List<Product2> rslts = [select Id, ProductCode, Product_ECCode__c,
                                     EffectiveDateTo__c,
                                     ProductModels__c,
                                     ProductStatus__c
                                from Product2
                                where Product_ECCode__c = :GeData.ProductCode];
        // deleteの場合、EffectiveDateTo が前日
        System.assertEquals(1, rslts.size());
        System.assertEquals(date.newinstance(2012, 12, 01), rslts[0].EffectiveDateTo__c);

        List<BatchIF_Log__c> rowbl = [Select Id, Log__c,
                                            ErrorLog__c
                                        from BatchIF_Log__c
                                        where RowDataFlg__c = true
                                        and Type__c = 'SBG004'
                                        order by CreatedDate desc];
        System.assertEquals(1, rowbl.size());
        rowbl[0].retry_cnt__c = 1;
        update rowbl;

        SBGITMRest.executefuture(rowbl[0].id);

        List<BatchIF_Log__c> bl = [Select Id, Is_Error__c,
                Type__c, Log__c, ErrorLog__c,retry_cnt__c
                from BatchIF_Log__c
                where Id = :rowbl[0].id];
        System.assertEquals(1, bl.size());
        // System.assertEquals(0, bl[0].retry_cnt__c);
    }

    @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": [{"TradeType": "Taxation"}]}}';
    req.requestURI = 'services/apexrest/SBG004/execute';
    req.httpMethod = 'POST';
    req.requestBody = Blob.valueof(JsonMsg);
    RestContext.request = req;
    RestContext.response= res;

    SBG004Rest.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"}]}');
}
}