@isTest
private class OpportunityUpdateSendEmailBatchTest {
    static testMethod void testMethod1() {
    	Date dateToday = Date.today();
        List<RecordType> rectNDT = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer NDT'];
        Account accNDT = new Account(
            Name = '*',
            RecordTypeId = rectNDT[0].Id,
            OwnerId = UserInfo.getUserId(),
            DivisionName__c='Customer NDT',
            FacilityName__c='abc',
            Province__c = '内蒙古',
            PostCode__c = '123456'
        );
        insert accNDT; 
           
        List<RecordType> rectOpp = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity'];
        Opportunity opp1 = new Opportunity(
            Name = 'test opp',
            AccountId = accNDT.Id,
            RecordTypeId = rectOpp[0].Id,
            OwnerId = UserInfo.getUserId(),
            StageName = 'Prospect Created',
            CancelReason__c = 'Inquiry repeat',
            Cancel_reason_D__c = 'Inquiry repeat',
            CurrencyIsoCode = 'CNY',
            ProductSegment__c = 'NDT',
            CloseDate = Date.today(),
            NewInquiryDate__c = Date.today().addDays(-2),
            ExpectedOrderDate__c = Date.today().addDays(2),
            TradeType__c = 'Taxation',
            SalesChannel__c = 'direct',
            Machine_Parts__c = 'Machine',
            IsSendEmail__c=true,
            IsUpdate__c = true,
            OppUpdateDate__c = dateToday.addDays(-1)
        );
        insert opp1;
        Opportunity opp2 = new Opportunity(
            Name = 'test opp',
            AccountId = accNDT.Id,
            RecordTypeId = rectOpp[0].Id,
            OwnerId = UserInfo.getUserId(),
            StageName = 'Prospect Created',
            CancelReason__c = 'Inquiry repeat',
            Cancel_reason_D__c = 'Inquiry repeat',
            CurrencyIsoCode = 'CNY',
            ProductSegment__c = 'NDT',
            CloseDate = Date.today(),
            NewInquiryDate__c = Date.today().addDays(-2),
            ExpectedOrderDate__c = Date.today().addDays(2),
            TradeType__c = 'Taxation',
            SalesChannel__c = 'direct',
            Machine_Parts__c = 'Machine',
            IsSendEmail__c=true,
            ThreeMonths__c = false,
            OppUpdateDate__c = dateToday.addMonths(-4)
        );
        insert opp2;
        Opportunity opp3 = new Opportunity(
            Name = 'test opp',
            AccountId = accNDT.Id,
            RecordTypeId = rectOpp[0].Id,
            OwnerId = UserInfo.getUserId(),
            StageName = 'Prospect Created',
            CancelReason__c = 'Inquiry repeat',
            Cancel_reason_D__c = 'Inquiry repeat',
            CurrencyIsoCode = 'CNY',
            ProductSegment__c = 'NDT',
            CloseDate = Date.today(),
            NewInquiryDate__c = Date.today().addDays(-2),
            ExpectedOrderDate__c = Date.today().addDays(2),
            TradeType__c = 'Taxation',
            SalesChannel__c = 'direct',
            Machine_Parts__c = 'Machine',
            IsSendEmail__c=true,
            SixMonths__c = false,
            OppUpdateDate__c = dateToday.addMonths(-7)
        );
        insert opp3;
        Opportunity opp4 = new Opportunity(
            Name = 'test opp',
            AccountId = accNDT.Id,
            RecordTypeId = rectOpp[0].Id,
            OwnerId = UserInfo.getUserId(),
            StageName = 'Prospect Created',
            CancelReason__c = 'Inquiry repeat',
            Cancel_reason_D__c = 'Inquiry repeat',
            CurrencyIsoCode = 'CNY',
            ProductSegment__c = 'NDT',
            CloseDate = Date.today(),
            NewInquiryDate__c = Date.today().addDays(-2),
            ExpectedOrderDate__c = Date.today().addDays(2),
            TradeType__c = 'Taxation',
            SalesChannel__c = 'direct',
            Machine_Parts__c = 'Machine',
            IsSendEmail__c=true,
            NineMonths__c = false,
            OppUpdateDate__c = dateToday.addMonths(-10)
        );
        insert opp4;
        List<String> oppList = new List<String>();
        oppList.add(opp1.Id);
        oppList.add(opp2.Id);
        oppList.add(opp3.Id);
        oppList.add(opp4.Id);
        Database.executeBatch(new OpportunityUpdateSendEmailBatch(), 10);
    }
    static testMethod void testMethod2() {
    	Date dateToday = Date.today();
        List<RecordType> rectANI = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer ANI'];
        Account accANI = new Account(
            Name = '*',
            RecordTypeId = rectANI[0].Id,
            OwnerId = UserInfo.getUserId(),
            DivisionName__c='Customer ANI',
            FacilityName__c='abc',
            Province__c = '辽宁',
            PostCode__c = '123456'
        );
        insert accANI; 
           
        List<RecordType> rectOpp = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity'];
        Opportunity opp1 = new Opportunity(
            Name = 'test opp',
            AccountId = accANI.Id,
            RecordTypeId = rectOpp[0].Id,
            OwnerId = UserInfo.getUserId(),
            StageName = 'Prospect Created',
            CancelReason__c = 'Inquiry repeat',
            Cancel_reason_D__c = 'Inquiry repeat',
            CurrencyIsoCode = 'CNY',
            ProductSegment__c = 'ANI',
            CloseDate = Date.today(),
            NewInquiryDate__c = Date.today().addDays(-2),
            ExpectedOrderDate__c = Date.today().addDays(2),
            TradeType__c = 'Taxation',
            SalesChannel__c = 'direct',
            Machine_Parts__c = 'Machine',
            IsSendEmail__c=true,
            IsUpdate__c = true,
            OppUpdateDate__c = dateToday.addMonths(-2)
        );
        insert opp1;
        Opportunity opp2 = new Opportunity(
            Name = 'test opp',
            AccountId = accANI.Id,
            RecordTypeId = rectOpp[0].Id,
            OwnerId = UserInfo.getUserId(),
            StageName = 'Prospect Created',
            CancelReason__c = 'Inquiry repeat',
            Cancel_reason_D__c = 'Inquiry repeat',
            CurrencyIsoCode = 'CNY',
            ProductSegment__c = 'ANI',
            CloseDate = Date.today(),
            NewInquiryDate__c = Date.today().addDays(-2),
            ExpectedOrderDate__c = Date.today().addDays(2),
            TradeType__c = 'Taxation',
            SalesChannel__c = 'direct',
            Machine_Parts__c = 'Machine',
            IsSendEmail__c=true,
            ThreeMonths__c = false,
            OppUpdateDate__c = dateToday.addMonths(-4)
        );
        insert opp2;
        Opportunity opp3 = new Opportunity(
            Name = 'test opp',
            AccountId = accANI.Id,
            RecordTypeId = rectOpp[0].Id,
            OwnerId = UserInfo.getUserId(),
            StageName = 'Prospect Created',
            CancelReason__c = 'Inquiry repeat',
            Cancel_reason_D__c = 'Inquiry repeat',
            CurrencyIsoCode = 'CNY',
            ProductSegment__c = 'ANI',
            CloseDate = Date.today(),
            NewInquiryDate__c = Date.today().addDays(-2),
            ExpectedOrderDate__c = Date.today().addDays(2),
            TradeType__c = 'Taxation',
            SalesChannel__c = 'direct',
            Machine_Parts__c = 'Machine',
            IsSendEmail__c=true,
            SixMonths__c = false,
            OppUpdateDate__c = dateToday.addMonths(-7)
        );
        insert opp3;
        Opportunity opp4 = new Opportunity(
            Name = 'test opp',
            AccountId = accANI.Id,
            RecordTypeId = rectOpp[0].Id,
            OwnerId = UserInfo.getUserId(),
            StageName = 'Prospect Created',
            CancelReason__c = 'Inquiry repeat',
            Cancel_reason_D__c = 'Inquiry repeat',
            CurrencyIsoCode = 'CNY',
            ProductSegment__c = 'ANIANI',
            CloseDate = Date.today(),
            NewInquiryDate__c = Date.today().addDays(-2),
            ExpectedOrderDate__c = Date.today().addDays(2),
            TradeType__c = 'Taxation',
            SalesChannel__c = 'direct',
            Machine_Parts__c = 'Machine',
            IsSendEmail__c=true,
            NineMonths__c = false,
            OppUpdateDate__c = dateToday.addMonths(-10)
        );
        insert opp4;
        List<String> oppList = new List<String>();
        oppList.add(opp1.Id);
        oppList.add(opp2.Id);
        oppList.add(opp3.Id);
        oppList.add(opp4.Id);
        Database.executeBatch(new OpportunityUpdateSendEmailBatch(oppList), 10);
    }
}