summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/ReportScheduleTest.java
blob: 40ab05deb0b21451975037eae785d72dcaa09e0a (plain)
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
/*
 * ============LICENSE_START==========================================
 * ONAP Portal SDK
 * ===================================================================
 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
 * ===================================================================
 *
 * Unless otherwise specified, all software contained herein is licensed
 * under the Apache License, Version 2.0 (the "License");
 * you may not use this software except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *             http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Unless otherwise specified, all documentation contained herein is licensed
 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
 * you may not use this documentation except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *             https://creativecommons.org/licenses/by/4.0/
 *
 * Unless required by applicable law or agreed to in writing, documentation
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * ============LICENSE_END============================================
 *
 * 
 */
package org.onap.portalsdk.analytics.model.definition;

import java.io.FileInputStream;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.commons.io.IOUtils;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.onap.portalsdk.analytics.error.RaptorException;
import org.onap.portalsdk.analytics.error.ReportSQLException;
import org.onap.portalsdk.analytics.model.runtime.ReportRuntime;
import org.onap.portalsdk.analytics.system.AppUtils;
import org.onap.portalsdk.analytics.system.DbUtils;
import org.onap.portalsdk.analytics.system.Globals;
import org.onap.portalsdk.analytics.util.AppConstants;
import org.onap.portalsdk.analytics.util.DataSet;
import org.owasp.esapi.ESAPI;
import org.owasp.esapi.Encoder;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

@RunWith(PowerMockRunner.class)
@PrepareForTest({ AppUtils.class, Globals.class, DbUtils.class, AppUtils.class, ESAPI.class})

public class ReportScheduleTest {

	ReportSchedule reportSchedule;
	
	private String REPORT_ID="1000";
	private String USER_ID="USER#1";
	
	@Mock
	HttpServletRequest httpServletRequest;
	
	@Mock
	HttpSession httpSession;
	
	@Mock
	ReportRuntime reportRuntime;
	
	@Mock
	ReportDefinition reportDefinition;

	@Mock
	Encoder encoder;
	
	@Mock
	DataSet dataSet1;
	
	@Mock
	Connection connection;
	
	@Mock
	PreparedStatement preparedStatement;
	
	@Mock
	ResultSet resultSet;
	
	@Mock
	java.sql.Clob clob;
	
	@Mock
	FileInputStream fileInputStream;
	
	@Before
	public void setUp() throws Exception {		
		
		PowerMockito.mockStatic(Globals.class);
		PowerMockito.mockStatic(AppUtils.class);
		PowerMockito.mockStatic(DbUtils.class);
		PowerMockito.mockStatic(AppUtils.class);
		PowerMockito.mockStatic(ESAPI.class);
						
		MockitoAnnotations.initMocks(this);
		
		Mockito.when(httpSession.getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(reportRuntime);
		Mockito.when(httpServletRequest.getSession()).thenReturn(httpSession);

		Mockito.when(reportRuntime.getReportID()).thenReturn(REPORT_ID);
		Mockito.when(AppUtils.getUserID(httpServletRequest)).thenReturn("USER1");
		
		PowerMockito.when(ESAPI.encoder()).thenReturn(encoder);
		
		createInstanceOfReportSchedule_case1();
		createInstanceOfReportSchedule_case2();

	}

	private void createInstanceOfReportSchedule_case1() throws Exception {
		String load_schedule_data = "SELECT rs.enabled_yn, DATE_FORMAT(rs.start_date, '%m/%d/%Y') start_date, DATE_FORMAT(rs.end_date, '%m/%d/%Y') end_date, DATE_FORMAT(rs.run_date, '%m/%d/%Y') run_date, coalesce(DATE_FORMAT(rs.run_date, '%h'), '12') run_hour, coalesce(DATE_FORMAT(rs.run_date, '%i'), '00') run_min, coalesce(DATE_FORMAT(rs.run_date, '%p'), 'AM') run_ampm, rs.recurrence, rs.conditional_yn, rs.notify_type, rs.max_row, rs.initial_formfields, rs.schedule_id, coalesce(DATE_FORMAT(rs.end_date, '%h'), '11') end_hour, coalesce(DATE_FORMAT(rs.end_date, '%i'), '45') end_min, coalesce(DATE_FORMAT(rs.end_date, '%p'), 'PM') end_ampm, encrypt_yn, attachment_yn FROM cr_report_schedule rs WHERE rs.rep_id = [reportID]";
		String load_schedule_getid = "SELECT rsu.user_id, concat(fuser.last_name,', ',fuser.first_name), fuser.login_id FROM cr_report_schedule_users rsu, fn_user fuser WHERE rsu.rep_id = [reportID]  AND rsu.schedule_id = [getScheduleID()] and rsu.user_id IS NOT NULL and rsu.user_id = fuser.user_id";
		String load_schedule_users = "SELECT rsu.role_id FROM cr_report_schedule_users rsu WHERE rsu.rep_id = [reportID] AND rsu.schedule_id = [getScheduleID()] AND rsu.role_id IS NOT NULL";
				
		PowerMockito.when(Globals.getLoadScheduleData()).thenReturn(load_schedule_data);
		PowerMockito.when(Globals.getLoadScheduleGetId()).thenReturn(load_schedule_getid);
		PowerMockito.when(Globals.getLoadScheduleUsers()).thenReturn(load_schedule_users);
		PowerMockito.when(AppUtils.isAdminUser(httpServletRequest)).thenReturn(true);
		PowerMockito.when(Globals.isWeblogicServer()).thenReturn(true);

		//reportSchedule = new ReportSchedule(REPORT_ID, USER_ID, false, httpServletRequest);
		//String dataArray[] = {"Y", "10/10/2018", "10/10/2999", "01/11/2018", "9", "10", "AM", "Y", "Y", "0", "512","", "2000", "10", "30", "PM," };		
		
		PowerMockito.when(DbUtils.getConnection()).thenReturn(connection);
		
		Mockito.when(connection.prepareStatement(Mockito.anyString())).thenReturn(preparedStatement);
		Mockito.when(preparedStatement.executeQuery()).thenReturn(resultSet);
		Mockito.when(resultSet.next()).thenReturn(true);
		Mockito.when(resultSet.getClob(Mockito.anyInt())).thenReturn(clob);

		String source = "This is the source of my input stream";
		InputStream inputStream = IOUtils.toInputStream(source, "UTF-8");
		
		Mockito.when(clob.getAsciiStream()).thenReturn(inputStream);

		//SI_REPORT_RUNTIME
		PowerMockito.when(DbUtils.executeQuery(Mockito.anyString())).thenReturn(dataSet1);
		Mockito.when(dataSet1.getRowCount()).thenReturn(1);
		
		Mockito.when(dataSet1.getString(Mockito.anyInt(), Mockito.anyInt())).thenReturn("Some Value1");
		Mockito.when(dataSet1.getString(Mockito.anyInt(), Mockito.anyString())).thenReturn("Some Value2");

		reportSchedule = new ReportSchedule(REPORT_ID, USER_ID, true, httpServletRequest);

		
		/*
		Mockito.when(dataSet1.getString(Mockito.anyInt(), Mockito.anyObject())).thenAnswer(new Answer<String>() {

			@Override
			public String answer(InvocationOnMock invocation) throws Throwable {
				Object args[] = invocation.getArguments();
				int columnIndex= 0;
				
				try {
					columnIndex = Integer.parseInt((String)args[1]);
				} catch (Exception e) {
					if ("encrypt_yn".equals((String)args[1]))
				}
				
				
				return null;
			}
		});
		*/
	}
	
	private void createInstanceOfReportSchedule_case2() throws Exception {
		String load_schedule_data = "SELECT rs.enabled_yn, DATE_FORMAT(rs.start_date, '%m/%d/%Y') start_date, DATE_FORMAT(rs.end_date, '%m/%d/%Y') end_date, DATE_FORMAT(rs.run_date, '%m/%d/%Y') run_date, coalesce(DATE_FORMAT(rs.run_date, '%h'), '12') run_hour, coalesce(DATE_FORMAT(rs.run_date, '%i'), '00') run_min, coalesce(DATE_FORMAT(rs.run_date, '%p'), 'AM') run_ampm, rs.recurrence, rs.conditional_yn, rs.notify_type, rs.max_row, rs.initial_formfields, rs.schedule_id, coalesce(DATE_FORMAT(rs.end_date, '%h'), '11') end_hour, coalesce(DATE_FORMAT(rs.end_date, '%i'), '45') end_min, coalesce(DATE_FORMAT(rs.end_date, '%p'), 'PM') end_ampm, encrypt_yn, attachment_yn FROM cr_report_schedule rs WHERE rs.rep_id = [reportID]";
		String load_schedule_getid = "SELECT rsu.user_id, concat(fuser.last_name,', ',fuser.first_name), fuser.login_id FROM cr_report_schedule_users rsu, fn_user fuser WHERE rsu.rep_id = [reportID]  AND rsu.schedule_id = [getScheduleID()] and rsu.user_id IS NOT NULL and rsu.user_id = fuser.user_id";
		String load_schedule_users = "SELECT rsu.role_id FROM cr_report_schedule_users rsu WHERE rsu.rep_id = [reportID] AND rsu.schedule_id = [getScheduleID()] AND rsu.role_id IS NOT NULL";
				
		String new_schedule_data = "select coalesce(max(schedule_id),0)+1  AS sequence from cr_report_schedule";
				
		PowerMockito.when(Globals.getLoadScheduleData()).thenReturn(load_schedule_data);
		PowerMockito.when(Globals.getLoadScheduleGetId()).thenReturn(load_schedule_getid);
		PowerMockito.when(Globals.getLoadScheduleUsers()).thenReturn(load_schedule_users);
		PowerMockito.when(AppUtils.isAdminUser(httpServletRequest)).thenReturn(false);
		PowerMockito.when(Globals.isWeblogicServer()).thenReturn(false);
		PowerMockito.when(Globals.getNewScheduleData()).thenReturn(new_schedule_data);
		PowerMockito.when(Globals.isPostgreSQL()).thenReturn(false);
		
		PowerMockito.when(Globals.getUseLoginIdInSchedYN()).thenReturn("Y");
				
		//reportSchedule = new ReportSchedule(REPORT_ID, USER_ID, false, httpServletRequest);
		//String dataArray[] = {"Y", "10/10/2018", "10/10/2999", "01/11/2018", "9", "10", "AM", "Y", "Y", "0", "512","", "2000", "10", "30", "PM," };		
		
		PowerMockito.when(DbUtils.getConnection()).thenReturn(connection);
		
		Mockito.when(connection.prepareStatement(Mockito.anyString())).thenReturn(preparedStatement);
		Mockito.when(preparedStatement.executeQuery()).thenReturn(resultSet);
		Mockito.when(resultSet.next()).thenReturn(true);
		Mockito.when(resultSet.getClob(Mockito.anyInt())).thenReturn(clob);

		String source = "This is the source of my input stream";
		InputStream inputStream = IOUtils.toInputStream(source, "UTF-8");
		
		Mockito.when(clob.getAsciiStream()).thenReturn(inputStream);

		//SI_REPORT_RUNTIME
		PowerMockito.when(DbUtils.executeQuery(Mockito.anyString())).thenReturn(dataSet1);
		Mockito.when(dataSet1.getRowCount()).thenReturn(0);
		
		Mockito.when(dataSet1.getString(Mockito.anyInt(), Mockito.anyInt())).thenReturn("Some Value1");
		Mockito.when(dataSet1.getString(Mockito.anyInt(), Mockito.anyString())).thenReturn("Some Value2");

		reportSchedule = new ReportSchedule(REPORT_ID, "SCHDULE_ID", USER_ID, httpServletRequest);

		/*
		Mockito.when(dataSet1.getString(Mockito.anyInt(), Mockito.anyObject())).thenAnswer(new Answer<String>() {

			@Override
			public String answer(InvocationOnMock invocation) throws Throwable {
				Object args[] = invocation.getArguments();
				int columnIndex= 0;
				
				try {
					columnIndex = Integer.parseInt((String)args[1]);
				} catch (Exception e) {
					if ("encrypt_yn".equals((String)args[1]))
				}
				
				
				return null;
			}
		});
		*/
	}

	
	
	@Test
	public void testAddEmailToUser() {		
		reportSchedule.addEmailToUser("UserID1", "UserName1");
		reportSchedule.addEmailToUser("UserID2", "UserName2");
		reportSchedule.addEmailToUser("UserID2", "UserName2");

	}
	
	@Test
	public void testPersistScheduleData_case1() throws Exception {
		reportSchedule.persistScheduleData(connection, httpServletRequest);
	}
	
	@Test
	public void testPersistScheduleData_RowCount_case1() throws Exception {
		String execute_update = "DELETE FROM cr_report_schedule_users WHERE rep_id = [reportID] and schedule_id = [getScheduleID()]";		
		String execute_update_users = "INSERT INTO cr_report_schedule_users (schedule_id, rep_id, user_id, role_id, order_no) VALUES([getScheduleID()], [reportID], [emailToUsers.get(i)).getId()], NULL, [(i + 1)])";
		String execute_update_roles = "INSERT INTO cr_report_schedule_users (schedule_id, rep_id, user_id, role_id, order_no) VALUES([getScheduleID()], [reportID], NULL, [emailToRoles.get(i)).getId()], [((emailToUsers.size() + i + 1)])";
		String execute_update_activity = "INSERT into cr_schedule_activity_log (schedule_id, notes, run_time) values ([getScheduleID()],'Submitted:Schedule',TO_DATE('[getRunDate()] [getRunHour()]:[getRunMin()] [getRunAMPM()]', 'MM/DD/YYYY HH:MI AM'))";
		String persist_cond_sql_update = "update cr_report_schedule set condition_large_sql = '' where  schedule_id = [scheduleId]";
		
		PowerMockito.when(DbUtils.executeQuery(Mockito.anyObject(), Mockito.anyString())).thenReturn(dataSet1);
		PowerMockito.when(Globals.getExecuteUpdate()).thenReturn(execute_update);
		PowerMockito.when(Globals.getExecuteUpdateUsers()).thenReturn(execute_update_users);
		PowerMockito.when(Globals.getExecuteUpdateRoles()).thenReturn(execute_update_roles);
		PowerMockito.when(Globals.getExecuteUpdateActivity()).thenReturn(execute_update_activity);
		PowerMockito.when(Globals.getPersistCondSqlUpdate()).thenReturn(persist_cond_sql_update);
		PowerMockito.when(Globals.isPostgreSQL()).thenReturn(true);
		
		PowerMockito.when(Globals.getRequestParams()).thenReturn("1, 2, 3");
		PowerMockito.when(Globals.getSessionParams()).thenReturn("1, 2, 3");
		PowerMockito.when(Globals.getSessionParamsForScheduling()).thenReturn("login_id");
							
		Mockito.when(reportRuntime.getDBInfo()).thenReturn(AppConstants.DB_LOCAL);
		
		Mockito.when(connection.prepareStatement(Mockito.anyString())).thenReturn(preparedStatement);
		Mockito.when(preparedStatement.executeQuery()).thenReturn(resultSet);
		Mockito.when(resultSet.next()).thenReturn(true);
		
		Mockito.when(dataSet1.getRowCount()).thenReturn(1);
		
		reportSchedule.setDownloadLimit("1000");
		reportSchedule.setSchedEnabled("N");
		reportSchedule.setFormFields("Field1");
		reportSchedule.setNotify_type("1");
		reportSchedule.setStartDate("10/10/2018");
		reportSchedule.setEndDate("10/10/2019");
		reportSchedule.setRunDate("10/10/2019");
		reportSchedule.setRunHour("10");
		reportSchedule.setRunMin("10");
		reportSchedule.setRunAMPM("PM");
		reportSchedule.setRecurrence("Y");
		reportSchedule.setAttachmentMode("N");		
		reportSchedule.setConditionSQL("SELECT coalesce(cr.owner_id, cr.create_id) owner_id, cr.create_id, DATE_FORMAT(cr.create_date, '[Globals.getTimeFormat()]') create_date, maint_id, DATE_FORMAT(cr.maint_date, '[Globals.getTimeFormat()]') update_date, cr.menu_id, cr.menu_approved_yn FROM cr_report cr WHERE cr.rep_id= [reportID]");
		
		reportSchedule.persistScheduleData(connection, httpServletRequest);
	}
	
	@Test
	public void testPersistScheduleData_RowCount_case2() throws Exception {
		String execute_update = "DELETE FROM cr_report_schedule_users WHERE rep_id = [reportID] and schedule_id = [getScheduleID()]";		
		String execute_update_users = "INSERT INTO cr_report_schedule_users (schedule_id, rep_id, user_id, role_id, order_no) VALUES([getScheduleID()], [reportID], [emailToUsers.get(i)).getId()], NULL, [(i + 1)])";
		String execute_update_roles = "INSERT INTO cr_report_schedule_users (schedule_id, rep_id, user_id, role_id, order_no) VALUES([getScheduleID()], [reportID], NULL, [emailToRoles.get(i)).getId()], [((emailToUsers.size() + i + 1)])";
		String execute_update_activity = "INSERT into cr_schedule_activity_log (schedule_id, notes, run_time) values ([getScheduleID()],'Submitted:Schedule',TO_DATE('[getRunDate()] [getRunHour()]:[getRunMin()] [getRunAMPM()]', 'MM/DD/YYYY HH:MI AM'))";
		String persist_cond_sql_update = "update cr_report_schedule set condition_large_sql = '' where  schedule_id = [scheduleId]";
		
		PowerMockito.when(DbUtils.executeQuery(Mockito.anyObject(), Mockito.anyString())).thenReturn(dataSet1);
		PowerMockito.when(Globals.getExecuteUpdate()).thenReturn(execute_update);
		PowerMockito.when(Globals.getExecuteUpdateUsers()).thenReturn(execute_update_users);
		PowerMockito.when(Globals.getExecuteUpdateRoles()).thenReturn(execute_update_roles);
		PowerMockito.when(Globals.getExecuteUpdateActivity()).thenReturn(execute_update_activity);
		PowerMockito.when(Globals.getPersistCondSqlUpdate()).thenReturn(persist_cond_sql_update);
		PowerMockito.when(Globals.isPostgreSQL()).thenReturn(true);
		
		PowerMockito.when(Globals.getRequestParams()).thenReturn("1, 2, 3");
		PowerMockito.when(Globals.getSessionParams()).thenReturn("1, 2, 3");
		PowerMockito.when(Globals.getSessionParamsForScheduling()).thenReturn("login_id");
							
		Mockito.when(reportRuntime.getDBInfo()).thenReturn(AppConstants.DB_DEV);
		
		Mockito.when(connection.prepareStatement(Mockito.anyString())).thenReturn(preparedStatement);
		Mockito.when(preparedStatement.executeQuery()).thenReturn(resultSet);
		Mockito.when(resultSet.next()).thenReturn(true);
		
		Mockito.when(dataSet1.getRowCount()).thenReturn(0);
		
		reportSchedule.setSchedEnabled("N");
		reportSchedule.setConditionSQL("SELECT coalesce(cr.owner_id, cr.create_id) owner_id, cr.create_id, DATE_FORMAT(cr.create_date, '[Globals.getTimeFormat()]') create_date, maint_id, DATE_FORMAT(cr.maint_date, '[Globals.getTimeFormat()]') update_date, cr.menu_id, cr.menu_approved_yn FROM cr_report cr WHERE cr.rep_id= [reportID]");
		
		reportSchedule.persistScheduleData(connection, httpServletRequest);
	}
	
	
	@Test
	public void testDeleteScheduleData_case1() throws RaptorException {
		String delete_schedule_data = "SELECT 1 FROM cr_report_schedule WHERE rep_id = [reportID] and sched_user_id = [getScheduleUserID()] and schedule_id = [getScheduleID()]";
		String delete_schedule_data_users = "DELETE FROM cr_report_schedule_users WHERE rep_id = [reportID]  and schedule_id = [getScheduleID()]";
		String delete_schedule_data_id = "DELETE FROM cr_report_schedule where rep_id = [reportID] and sched_user_id = [getScheduleUserID()] and schedule_id = [getScheduleID()]";
				
		PowerMockito.when(Globals.getDeleteScheduleData()).thenReturn(delete_schedule_data);
		PowerMockito.when(Globals.getDeleteScheduleDataUsers()).thenReturn(delete_schedule_data_users);
		PowerMockito.when(DbUtils.executeQuery(Mockito.anyObject(), Mockito.anyString())).thenReturn(dataSet1);
		PowerMockito.when(Globals.getDeleteScheduleDataId()).thenReturn(delete_schedule_data_id);
		
		Mockito.when(dataSet1.getRowCount()).thenReturn(1);
	
		reportSchedule.deleteScheduleData(connection);
	}

	@Test
	public void testDeleteScheduleData_case2() throws RaptorException {
		String delete_schedule_data = "SELECT 1 FROM cr_report_schedule WHERE rep_id = [reportID] and sched_user_id = [getScheduleUserID()] and schedule_id = [getScheduleID()]";
		String delete_schedule_data_users = "DELETE FROM cr_report_schedule_users WHERE rep_id = [reportID]  and schedule_id = [getScheduleID()]";
		String delete_schedule_data_id = "DELETE FROM cr_report_schedule where rep_id = [reportID] and sched_user_id = [getScheduleUserID()] and schedule_id = [getScheduleID()]";
				
		PowerMockito.when(Globals.getDeleteScheduleData()).thenReturn(delete_schedule_data);
		PowerMockito.when(Globals.getDeleteScheduleDataUsers()).thenReturn(delete_schedule_data_users);
		PowerMockito.when(DbUtils.executeQuery(Mockito.anyObject(), Mockito.anyString())).thenReturn(dataSet1);
		PowerMockito.when(Globals.getDeleteScheduleDataId()).thenReturn(delete_schedule_data_id);
		
		Mockito.when(dataSet1.getRowCount()).thenReturn(0);
	
		reportSchedule.deleteScheduleData(connection);
	}
	
	@Test(expected=RaptorException.class)
	public void testDeleteScheduleData_case3() throws RaptorException {
		String delete_schedule_data = "SELECT 1 FROM cr_report_schedule WHERE rep_id = [reportID] and sched_user_id = [getScheduleUserID()] and schedule_id = [getScheduleID()]";
				
		PowerMockito.when(Globals.getDeleteScheduleData()).thenReturn(delete_schedule_data);
		PowerMockito.when(DbUtils.startTransaction()).thenReturn(null);
		PowerMockito.when(DbUtils.executeQuery(Mockito.anyObject(), Mockito.anyString())).thenReturn(dataSet1);

		PowerMockito.doThrow(new ReportSQLException("Failed to save data...")).when(DbUtils.class);
		DbUtils.commitTransaction(Mockito.anyObject());
		
		Mockito.when(dataSet1.getRowCount()).thenReturn(0);
		
		reportSchedule.deleteScheduleData(null);
	}
	
	@Test
	public void testDeleteScheduleData_case4() throws RaptorException {
		reportSchedule.setReportID("-1");		
		reportSchedule.deleteScheduleData(null);
	}
			
	
	@Test(expected=RuntimeException.class)
	public void testLoadConditionalSQL_Error_case1() throws Exception {
		String load_cond_sql = "SELECT condition_large_sql FROM cr_report_schedule WHERE schedule_id=?";
				
		Mockito.when(DbUtils.getConnection()).thenReturn(connection);
		Mockito.when(connection.prepareStatement(Mockito.anyString())).thenReturn(preparedStatement);
		Mockito.when(preparedStatement.executeQuery()).thenReturn(resultSet);
		PowerMockito.when(Globals.isWeblogicServer()).thenReturn(true);
		Mockito.when(resultSet.next()).thenReturn(false);
		
		PowerMockito.when(Globals.getLoadCondSql()).thenReturn(load_cond_sql);
		
		ReportSchedule.loadConditionalSQL("scheduleId#123");
	}
	
	/*
	@Test
	public void testLoadConditionalSQL_Error_case2() throws Exception {
	
		String load_cond_sql = "SELECT condition_large_sql FROM cr_report_schedule WHERE schedule_id=?";
		Mockito.when(DbUtils.getConnection()).thenReturn(connection);
		Mockito.when(connection.prepareStatement(Mockito.anyString())).thenReturn(preparedStatement);
		Mockito.when(preparedStatement.executeQuery()).thenReturn(resultSet);
		Mockito.when(Globals.isWeblogicServer()).thenReturn(false);
		Mockito.when(Globals.isPostgreSQL()).thenReturn(false);
		Mockito.when(Globals.isMySQL()).thenReturn(true);
		
		Mockito.when(resultSet.next()).thenReturn(false);
		
		PowerMockito.when(Globals.getLoadCondSql()).thenReturn(load_cond_sql);
		
		ReportSchedule.loadConditionalSQL("scheduleId#123");
	}*/
	
	
	/*

	@Test
	public void testAddEmailArrayToUser() {
		fail("Not yet implemented");
	}

	@Test
	public void testRemoveEmailToUser() {
		fail("Not yet implemented");
	}

	@Test
	public void testAddEmailToRole() {
		fail("Not yet implemented");
	}

	@Test
	public void testAddEmailArrayToRole() {
		fail("Not yet implemented");
	}

	@Test
	public void testRemoveEmailToRole() {
		fail("Not yet implemented");
	}

	@Test
	public void testPersistScheduleData() {
		fail("Not yet implemented");
	}

	@Test
	public void testDeleteScheduleData() {
		fail("Not yet implemented");
	}

	@Test
	public void testLoadConditionalSQL() {
		fail("Not yet implemented");
	}
	*/

}