@isTest
|
private class OPDQuarterPlanPhotographBatchTest {
|
|
static Date thismonth_Lastday ;
|
static Date lastmonth_Lastday ;
|
|
static void basicData() {
|
// カスタム設定を定義
|
SS_BatchColumnMapping__c opdMapping = new SS_BatchColumnMapping__c(Name = 'OPDPlan__c', SS_TableName__c='SS_OPDPlan__c');
|
opdMapping.From_Column_001__c = 'Id';
|
opdMapping.SS_Column_001__c = 'OPDPlan__c.Name';
|
opdMapping.From_Column_002__c = 'Name';
|
opdMapping.SS_Column_002__c = 'Name';
|
insert new SS_BatchColumnMapping__c[] {opdMapping};
|
Date toDate = Date.today();
|
//本月的第一天
|
Date mon1stDate = Date.newInstance(toDate.year(), toDate.month(), 1);
|
//本月的最后一天
|
thismonth_Lastday = Date.toDay().addMonths(1).toStartOfMonth().addDays(-1);
|
System.debug('thismonth_Lastday6666' + thismonth_Lastday);
|
//上月的第一天
|
Date lastmonth_firstday = Date.toDay().addMonths(-1).toStartOfMonth();
|
//上月的最后一天
|
lastmonth_Lastday = Date.newInstance(toDate.year(), toDate.month(), 1).addDays(-1);
|
System.debug('lastmonth_Lastday1234' + lastmonth_Lastday);
|
//下月的第一天
|
Date nextmonth_firstday = Date.toDay().addMonths(1).toStartOfMonth();
|
//下月的最后一天
|
Date nextmonth_Lastday = Date.toDay().addMonths(2).toStartOfMonth().addDays(-1);
|
|
OPDPlan__c oPDPlan0 = new OPDPlan__c();
|
oPDPlan0.Status__c = '计划中';
|
oPDPlan0.OPDPlan_ImplementDate__c = nextmonth_firstday;
|
oPDPlan0.NoOpp_Reason__c = '无询价查阅权限';
|
insert oPDPlan0;
|
|
OPDPlan__c oPDPlan1 = new OPDPlan__c();
|
oPDPlan1.Status__c = '计划中';
|
oPDPlan1.OPDPlan_ImplementDate__c = nextmonth_firstday;
|
oPDPlan1.NoOpp_Reason__c = '无询价查阅权限';
|
insert oPDPlan1;
|
|
OPDPlan__c oPDPlan2 = new OPDPlan__c();
|
oPDPlan2.Status__c = '计划中';
|
oPDPlan2.OPDPlan_ImplementDate__c = nextmonth_firstday;
|
oPDPlan2.NoOpp_Reason__c = '无询价查阅权限';
|
insert oPDPlan2;
|
|
OPDPlan__c oPDPlan3 = new OPDPlan__c();
|
oPDPlan3.Status__c = '计划中';
|
oPDPlan3.OPDPlan_ImplementDate__c = nextmonth_firstday;
|
oPDPlan3.NoOpp_Reason__c = '无询价查阅权限';
|
insert oPDPlan3;
|
OPDPlan__c oPDPlan4 = new OPDPlan__c();
|
oPDPlan4.Status__c = '计划中';
|
oPDPlan4.NoOpp_Reason__c = '无询价查阅权限';
|
oPDPlan4.OPDPlan_ImplementDate__c = nextmonth_firstday;
|
insert oPDPlan4;
|
|
OPDPlan__c oPDPlan5 = new OPDPlan__c();
|
oPDPlan5.Status__c = '计划中';
|
oPDPlan5.NoOpp_Reason__c = '无询价查阅权限';
|
oPDPlan5.OPDPlan_ImplementDate__c = nextmonth_firstday;
|
insert oPDPlan5;
|
}
|
//正常执行
|
@isTest
|
static void test_method_one() {
|
|
basicData();
|
Id execBTId = null;
|
System.Test.StartTest();
|
List<OPDPlan__c> oPDPlans = [Select Id,Name,Status__c,lastMonth_Plan__c,ThisMonthPlan__c,If_ThisMonth_Plan__c
|
from OPDPlan__c
|
Where (( lastMonth_Plan__c != 0 and ThisMonthPlan__c = 0) or
|
( lastMonth_Plan__c = 0 and ThisMonthPlan__c != 0) or
|
( ThisMonthPlan__c = 0 and If_ThisMonth_Plan__c != 0) or
|
( ThisMonthPlan__c != 0 and If_ThisMonth_Plan__c = 0))
|
and OPDPlan_ImplementDate__c <= :thismonth_Lastday];
|
// System.assertEquals(4, oPDPlans.size());
|
execBTId = Database.executeBatch(new OPDQuarterPlanPhotographBatch());
|
|
System.Test.StopTest();
|
|
}
|
////指定日期执行
|
//@isTest
|
//static void test_method_two() {
|
// basicData();
|
// Id execBTId = null;
|
// List<OPDPlan__c> oPDPlans = [Select Id,Name,Status__c,lastMonth_Plan__c,ThisMonthPlan__c,If_ThisMonth_Plan__c
|
// from OPDPlan__c
|
// Where (( lastMonth_Plan__c != 0 and ThisMonthPlan__c = 0) or
|
// ( lastMonth_Plan__c = 0 and ThisMonthPlan__c != 0) or
|
// ( ThisMonthPlan__c = 0 and If_ThisMonth_Plan__c != 0) or
|
// ( ThisMonthPlan__c != 0 and If_ThisMonth_Plan__c = 0) or
|
// ( lastMonth_Execute__c = 0 and ThisMonthExecute__c != 0) or
|
// ( lastMonth_Execute__c != 0 and ThisMonthExecute__c = 0))
|
// and OPDPlan_ImplementDate__c <= :lastmonth_Lastday];
|
// System.assertEquals(2, oPDPlans.size());
|
// System.Test.StartTest();
|
// execBTId = Database.executeBatch(new OPDPlanMarkBatch(String.valueOf(lastmonth_Lastday)));
|
// System.Test.StopTest();
|
//}
|
//指定"OPD计划"的Id执行
|
@isTest
|
static void test_method_three() {
|
basicData();
|
List<String> oPDPlanIds = new List<String>();
|
List<OPDPlan__c> oDPlans = [ select Id,Name from OPDPlan__c];
|
System.assertEquals(6, oDPlans.size());
|
for (OPDPlan__c opdPlan : oDPlans) {
|
oPDPlanIds.add(opdPlan.Id);
|
}
|
Id execBTId = null;
|
System.Test.StartTest();
|
execBTId = Database.executeBatch(new OPDQuarterPlanPhotographBatch(oPDPlanIds));
|
System.Test.StopTest();
|
}
|
}
|