@isTest
private class LogAutoSendBatchProductTest {
	 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 test_LogAutoSendBatchProduct_SBG004() {
		testSBG004Init();

        SBG004Rest.GeData GeData = new SBG004Rest.GeData();
        SBG004Rest.GeDatas GeDatas = new SBG004Rest.GeDatas();
        GeDatas.GeData = new SBG004Rest.GeData[] { GeData };
        
        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        GeDatas.Monitoring = new NFMUtil.Monitoring();
        GeDatas.Monitoring.MessageGroupNumber = nowStr + '01';
        GeDatas.Monitoring.MessageGroupNumber = nowStr + '02';
        GeData.ProductCode  = 'testSBG004X';
        BatchIF_Log__c rowData = NFMUtil.saveRowData(GeDatas.Monitoring, 'SBG004', GeDatas.GeData);
        //System.Test.startTest();
        SBG004Rest.main(rowData.Id);
        
        //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 = 'SBG004'
                                order by CreatedDate desc ];

        logs[0].retry_cnt__c=1;
        update logs;
        Id execBTId = Database.executeBatch(new LogAutoSendBatchProduct(), 1);
	    //System.Test.stopTest();
    }
    @isTest 
    static void test_LogAutoSendBatchProduct_SBG005() {
        testSBG004Init();

        SBG005Rest.GeData GeData = new SBG005Rest.GeData();
        SBG005Rest.GeDatas GeDatas = new SBG005Rest.GeDatas();
        GeDatas.GeData = new SBG005Rest.GeData[] { GeData };
        
        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        GeDatas.Monitoring = new NFMUtil.Monitoring();
        GeDatas.Monitoring.MessageGroupNumber = nowStr + '01';
        GeDatas.Monitoring.MessageGroupNumber = nowStr + '02';
        GeData.ProductCode  = 'testSBG005X';
         BatchIF_Log__c rowData = NFMUtil.saveRowData(GeDatas.Monitoring, 'SBG005', GeDatas.GeData);
        //System.Test.startTest();
        SBG005Rest.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 = 'SBG005'
                        order by CreatedDate desc ];

        logs[0].retry_cnt__c=1;
        update logs;
        Id execBTId = Database.executeBatch(new LogAutoSendBatchProduct(), 1);
        //System.Test.stopTest();
    }
}