-
Notifications
You must be signed in to change notification settings - Fork 2
/
TimeSpent_TEST
199 lines (139 loc) · 6.8 KB
/
TimeSpent_TEST
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
@isTest
public class TimeSpent_TEST {
private static final String SERVICEDESKCLIENT = 'ServiceDesk Client';
private static final String TESTCATEGORY = 'Test Category';
private static final String TIMESPENT = 'Time Spent';
private static final Integer batchSize = 200;
private static User clientUser = null;
private static BMCServiceDesk__Category__c category = null;
static{
generateCategoryData();
generateActionData();
generateStatuses();
}
private static testMethod void TimeSpent_NoSettings(){
//don't add custom setting value
Integer timeSpentValue = 20;
disableTimeTracking();
List<BMCServiceDesk__Incident__c> incList = getIncident(batchSize);
for(BMCServiceDesk__Incident__c i: incList){
i.BMCServiceDesk__timeSpent__c = timeSpentValue;
}
insert incList;
for(BMCServiceDesk__Incident__c i: [Select BMCServiceDesk__timeSpent__c from BMCServiceDesk__Incident__c]){
System.assertEquals(i.BMCServiceDesk__timeSpent__c,timeSpentValue);
}
List<BMCServiceDesk__IncidentHistory__c> historyList = new List<BMCServiceDesk__IncidentHistory__c>();
historyList = [Select id from BMCServiceDesk__IncidentHistory__c];
Integer historySize = historyList.size();
System.assertEquals(historySize,0);
}
private static testMethod void TimeSpent_Enabled(){
enableTimeTracking();
List<BMCServiceDesk__Incident__c> incList = getIncident(batchSize);
for(BMCServiceDesk__Incident__c i: incList){
i.BMCServiceDesk__timeSpent__c = 20;
}
insert incList;
for(BMCServiceDesk__Incident__c i: [Select BMCServiceDesk__timeSpent__c from BMCServiceDesk__Incident__c]){
System.assertEquals(i.BMCServiceDesk__timeSpent__c,null);
}
List<BMCServiceDesk__IncidentHistory__c> historyList = new List<BMCServiceDesk__IncidentHistory__c>();
historyList = [Select id from BMCServiceDesk__IncidentHistory__c];
Integer historySize = historyList.size();
System.assertEquals(historySize,batchSize);
}
private static testMethod void TimeSpent_Disabled(){
Integer timeSpentValue = 20;
disableTimeTracking();
List<BMCServiceDesk__Incident__c> incList = getIncident(batchSize);
for(BMCServiceDesk__Incident__c i: incList){
i.BMCServiceDesk__timeSpent__c = timeSpentValue;
}
insert incList;
for(BMCServiceDesk__Incident__c i: [Select BMCServiceDesk__timeSpent__c from BMCServiceDesk__Incident__c]){
System.assertEquals(i.BMCServiceDesk__timeSpent__c,timeSpentValue);
}
List<BMCServiceDesk__IncidentHistory__c> historyList = new List<BMCServiceDesk__IncidentHistory__c>();
historyList = [Select id from BMCServiceDesk__IncidentHistory__c];
Integer historySize = historyList.size();
System.assertEquals(historySize,0);
}
private static testMethod void TimeSpent_Close(){
enableTimeTracking();
List<BMCServiceDesk__Incident__c> incList = getIncident(batchSize);
String statusId = [Select Id from BMCServiceDesk__Status__c limit 1].Id;
for(BMCServiceDesk__Incident__c i: incList){
i.BMCServiceDesk__timeSpent__c = 20;
i.BMCServiceDesk__FKStatus__c = statusId;
}
insert incList;
for(BMCServiceDesk__Incident__c i: [Select BMCServiceDesk__timeSpent__c from BMCServiceDesk__Incident__c]){
System.assertEquals(i.BMCServiceDesk__timeSpent__c,null);
}
List<BMCServiceDesk__IncidentHistory__c> historyList = new List<BMCServiceDesk__IncidentHistory__c>();
historyList = [Select id from BMCServiceDesk__IncidentHistory__c];
Integer historySize = historyList.size();
System.assertEquals(historySize,batchSize);
}
private static void enableTimeTracking(){
Map<String,String> customSettingsMap = new Map<String,String>();
customSettingsMap.put('Enabled','true');
insertSettings(customSettingsMap);
}
private static void disableTimeTracking(){
Map<String,String> customSettingsMap = new Map<String,String>();
customSettingsMap.put('Enabled','false');
insertSettings(customSettingsMap);
}
private static void insertSettings(Map<String,String> valueList){
for(String s: valueList.keySet()){
Time_Spent__c setting = new Time_Spent__c();
setting.Name = s;
setting.Value__c = valueList.get(s);
insert setting;
}
}
/*
*
*
*
*/
private static void generateStatuses(){
List<BMCServiceDesk__Status__c> statusList = new List<BMCServiceDesk__Status__c>();
statusList.add(new BMCServiceDesk__Status__c(Name = 'CLOSED', BMCServiceDesk__state__c=false,BMCServiceDesk__appliesToIncident__c=true));
insert statusList;
}
private static void generateCategoryData() {
List<BMCServiceDesk__Category__c> catList = new List<BMCServiceDesk__Category__c>();
catList.add(new BMCServiceDesk__Category__c(Name = TESTCATEGORY, BMCServiceDesk__AvailableForIncidents__c=true));
insert catList;
}
private static void generateActionData(){
List<BMCServiceDesk__Action__c> actionList = new List<BMCServiceDesk__Action__c>();
actionList.add(new BMCServiceDesk__Action__c(Name=TIMESPENT, BMCServiceDesk__appliesToIncident__c=true));
insert actionList;
}
private static User getClientUser() {
if(clientUser == null){
clientUser = [Select Id from User where Profile.Name = :SERVICEDESKCLIENT AND isActive = true limit 1];
}
return clientUser;
}
private static BMCServiceDesk__Category__c getCategory(String catName){
if(category == null){
category = [select id from BMCServiceDesk__Category__c where Name = :catName limit 1];
}
return category;
}
private static List<BMCServiceDesk__Incident__c> getIncident(Integer num){
List<BMCServiceDesk__Incident__c> incList = new List<BMCServiceDesk__Incident__c>();
for(Integer i = 0; i<num; i++){
BMCServiceDesk__Incident__c inc = new BMCServiceDesk__Incident__c();
inc.BMCServiceDesk__FKClient__c = getClientUser().Id;
inc.BMCServiceDesk__FKCategory__c = getCategory(TESTCATEGORY).Id;
incList.add(inc);
}
return incList;
}
}