@isTest
private class LogAutoSendBatchTest {

    @isTest
    static void test_LogAutoSendBatch_SBGITM() {
        Id pricebookId = ControllerUtil.getStandardPricebook().Id;
        SBGITMRest.GeData GeData = new SBGITMRest.GeData();
        SBGITMRest.GeDatas GeDatas = new SBGITMRest.GeDatas();
        GeDatas.GeData = new SBGITMRest.GeData[] { GeData };

        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        GeDatas.Monitoring = new NFMUtil.Monitoring();
        GeDatas.Monitoring.MessageGroupNumber = nowStr + '01';
        GeData.EffectiveDateTo                            = '29121103';
        GeData.ProductCode                = 'SBGITMTst1';
        // SBGITMRest.SBGITM(GeDatas);
        //
        BatchIF_Log__c rowData = NFMUtil.saveRowData(GeDatas.Monitoring, 'SBGITM', GeDatas.GeData);
        SBGITMRest.main(rowData.Id);
        BatchIF_Log__c[] logs = [Select Id,
                                 Name,
                                 Log__c,
                                 ErrorLog__c,
                                 Log2__c,
                                 Log3__c,
                                 Log4__c,
                                 Log5__c,
                                 Log6__c,
                                 Log7__c,
                                 Log8__c,
                                 Log9__c,
                                 Log10__c,
                                 Log11__c,
                                 Log12__c,
                                 MessageGroupNumber__c,
                                 retry_cnt__c
                                 from BatchIF_Log__c
                                 where RowDataFlg__c = true
                                         and Type__c = 'SBGITM'
                                                 order by CreatedDate desc ];

        logs[0].retry_cnt__c = 1;
        update logs;
        Id execBTId = Database.executeBatch(new LogAutoSendBatch(), 1);

    }
    @isTest
    static void test_LogAutoSendBatch_SBG010() {
        Id pricebookId = ControllerUtil.getStandardPricebook().Id;
        SBGITMRest.GeData GeData = new SBGITMRest.GeData();
        SBGITMRest.GeDatas GeDatas = new SBGITMRest.GeDatas();
        GeDatas.GeData = new SBGITMRest.GeData[] { GeData };

        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        GeDatas.Monitoring = new NFMUtil.Monitoring();
        GeDatas.Monitoring.MessageGroupNumber = nowStr + '01';
        GeData.EffectiveDateTo                            = '29121103';
        GeData.ProductCode                = 'SBGITMTst1';
        // SBGITMRest.SBGITM(GeDatas);
        //
        BatchIF_Log__c rowData = NFMUtil.saveRowData(GeDatas.Monitoring, 'SBG010', GeDatas.GeData);
        SBG010WebService.execute(rowData.Id);
        BatchIF_Log__c[] logs = [Select Id,
                                 Name,
                                 Log__c,
                                 ErrorLog__c,
                                 Log2__c,
                                 Log3__c,
                                 Log4__c,
                                 Log5__c,
                                 Log6__c,
                                 Log7__c,
                                 Log8__c,
                                 Log9__c,
                                 Log10__c,
                                 Log11__c,
                                 Log12__c,
                                 MessageGroupNumber__c,
                                 retry_cnt__c
                                 from BatchIF_Log__c
                                 where RowDataFlg__c = true
                                         and Type__c = 'SBG010'
                                                 order by CreatedDate desc ];

        logs[0].retry_cnt__c = 1;
        update logs;
        Id execBTId = Database.executeBatch(new LogAutoSendBatch(), 1);

    }

    @isTest
    static void test_LogAutoSendBatch_SBG017() {
        Id pricebookId = ControllerUtil.getStandardPricebook().Id;
        SBGITMRest.GeData GeData = new SBGITMRest.GeData();
        SBGITMRest.GeDatas GeDatas = new SBGITMRest.GeDatas();
        GeDatas.GeData = new SBGITMRest.GeData[] { GeData };

        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        GeDatas.Monitoring = new NFMUtil.Monitoring();
        GeDatas.Monitoring.MessageGroupNumber = nowStr + '01';
        GeData.EffectiveDateTo                            = '29121103';
        GeData.ProductCode                = 'SBGITMTst1';
        // SBGITMRest.SBGITM(GeDatas);
        //
        BatchIF_Log__c rowData = NFMUtil.saveRowData(GeDatas.Monitoring, 'SBG017', GeDatas.GeData);
        SBG017Rest.main(rowData.Id);
        BatchIF_Log__c[] logs = [Select Id,
                                 Name,
                                 Log__c,
                                 ErrorLog__c,
                                 Log2__c,
                                 Log3__c,
                                 Log4__c,
                                 Log5__c,
                                 Log6__c,
                                 Log7__c,
                                 Log8__c,
                                 Log9__c,
                                 Log10__c,
                                 Log11__c,
                                 Log12__c,
                                 MessageGroupNumber__c,
                                 retry_cnt__c
                                 from BatchIF_Log__c
                                 where RowDataFlg__c = true
                                         and Type__c = 'SBG017'
                                                 order by CreatedDate desc ];

        logs[0].retry_cnt__c = 1;
        update logs;
        Id execBTId = Database.executeBatch(new LogAutoSendBatch(), 1);

    }

    @isTest
    static void test_LogAutoSendBatch_SBG203() {
        Id pricebookId = ControllerUtil.getStandardPricebook().Id;
        SBGITMRest.GeData GeData = new SBGITMRest.GeData();
        SBGITMRest.GeDatas GeDatas = new SBGITMRest.GeDatas();
        GeDatas.GeData = new SBGITMRest.GeData[] { GeData };

        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        GeDatas.Monitoring = new NFMUtil.Monitoring();
        GeDatas.Monitoring.MessageGroupNumber = nowStr + '01';
        GeData.EffectiveDateTo                            = '29121103';
        GeData.ProductCode                = 'SBGITMTst1';
        // SBGITMRest.SBGITM(GeDatas);
        //
        BatchIF_Log__c rowData = NFMUtil.saveRowData(GeDatas.Monitoring, 'SBG203', GeDatas.GeData);
        SBG203Rest.main(rowData.Id);
        BatchIF_Log__c[] logs = [Select Id,
                                 Name,
                                 Log__c,
                                 ErrorLog__c,
                                 Log2__c,
                                 Log3__c,
                                 Log4__c,
                                 Log5__c,
                                 Log6__c,
                                 Log7__c,
                                 Log8__c,
                                 Log9__c,
                                 Log10__c,
                                 Log11__c,
                                 Log12__c,
                                 MessageGroupNumber__c,
                                 retry_cnt__c
                                 from BatchIF_Log__c
                                 where RowDataFlg__c = true
                                         and Type__c = 'SBG203'
                                                 order by CreatedDate desc ];

        logs[0].retry_cnt__c = 1;
        update logs;
        Id execBTId = Database.executeBatch(new LogAutoSendBatch(), 1);

    }

    @isTest
    static void test_LogAutoSendBatch_SBG204() {
        Id pricebookId = ControllerUtil.getStandardPricebook().Id;
        SBGITMRest.GeData GeData = new SBGITMRest.GeData();
        SBGITMRest.GeDatas GeDatas = new SBGITMRest.GeDatas();
        GeDatas.GeData = new SBGITMRest.GeData[] { GeData };

        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        GeDatas.Monitoring = new NFMUtil.Monitoring();
        GeDatas.Monitoring.MessageGroupNumber = nowStr + '01';
        GeData.EffectiveDateTo                            = '29121103';
        GeData.ProductCode                = 'SBGITMTst1';
        // SBGITMRest.SBGITM(GeDatas);
        //
        BatchIF_Log__c rowData = NFMUtil.saveRowData(GeDatas.Monitoring, 'SBG204', GeDatas.GeData);
        SBG204Rest.main(rowData.Id);
        BatchIF_Log__c[] logs = [Select Id,
                                 Name,
                                 Log__c,
                                 ErrorLog__c,
                                 Log2__c,
                                 Log3__c,
                                 Log4__c,
                                 Log5__c,
                                 Log6__c,
                                 Log7__c,
                                 Log8__c,
                                 Log9__c,
                                 Log10__c,
                                 Log11__c,
                                 Log12__c,
                                 MessageGroupNumber__c,
                                 retry_cnt__c
                                 from BatchIF_Log__c
                                 where RowDataFlg__c = true
                                         and Type__c = 'SBG204'
                                                 order by CreatedDate desc ];

        logs[0].retry_cnt__c = 1;
        update logs;
        Id execBTId = Database.executeBatch(new LogAutoSendBatch(), 1);

    }

    @isTest
    static void test_LogAutoSendBatch_SBG018() {
        SBG018Rest.GeData GeData = new SBG018Rest.GeData();
        SBG018Rest.GeDatas GeDatas = new SBG018Rest.GeDatas();
        GeDatas.GeData = new SBG018Rest.GeData[] { GeData };
        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        GeDatas.Monitoring = new NFMUtil.Monitoring();
        GeDatas.Monitoring.MessageGroupNumber = nowStr + '01';
        SBG018Rest.GeDataDetails GeDataDetail01 = new  SBG018Rest.GeDataDetails();
        SBG018Rest.GeDataDetails GeDataDetail02 = new  SBG018Rest.GeDataDetails();
        GeData.GeDataDetails = new  SBG018Rest.GeDataDetails[] {GeDataDetail01, GeDataDetail02};
        GeData.Status = 'Z5';
        GeData.TransforDate = String.valueOf(Date.today());//'20210113';
        GeDataDetail01.ProductCode = 'testSBG018';
        GeDataDetail01.Plant = 'CCTV';
        GeDataDetail01.Department = 'LS';
        GeDataDetail01.FGSP = 'SP';
        GeDataDetail01.Qty = '11';
        GeDataDetail01.TradeType = 'Taxation';
        GeDataDetail02.ProductCode = 'testSBG018';
        // 用于触发异常 进入Catch
        GeDataDetail02.Plant = 'CC31';

        GeDataDetail02.Department = 'LS';
        GeDataDetail02.FGSP = 'FG';
        GeDataDetail02.Qty = '11';
        GeDataDetail02.TradeType = 'Taxation';
        System.Test.startTest();
        BatchIF_Log__c rowData = NFMUtil.saveRowData(GeDatas.Monitoring, 'SBG018', GeDatas.GeData);
        SBG018Rest.main(rowData.Id);
        
        BatchIF_Log__c[] logs =[Select Id,
                                    Name,
                                    Log__c,
                                    Type__c,
                                    ErrorLog__c,
                                    Log2__c,
                                    Log3__c,
                                    Log4__c,
                                    Log5__c,
                                    Log6__c,
                                    Log7__c,
                                    Log8__c,
                                    Log9__c,
                                    Log10__c,
                                    Log11__c,
                                    Log12__c,
                                    MessageGroupNumber__c,
                                    CreatedDate,
                                    retry_cnt__c
                                from BatchIF_Log__c
                                where RowDataFlg__c = true
                                and Type__c = 'SBG018'
                                order by CreatedDate desc ];

        logs[0].retry_cnt__c=1;
        update logs;
        Id execBTId = Database.executeBatch(new LogAutoSendBatch(), 5);
        Database.executeBatch(new LogAutoSendBatch(logs[0].Type__c,logs[0].MessageGroupNumber__c,logs[0].CreatedDate), 1);


    }





}