summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-analytics
diff options
context:
space:
mode:
authorMadheswaran, Saravanan <msaravanan@in.ibm.com>2018-03-22 15:05:25 -0400
committerMadheswaran, Saravanan <msaravanan@in.ibm.com>2018-03-22 15:05:25 -0400
commit17891f3aac1fa48f3cc1b2b858024d4edbd1f38c (patch)
tree656751b54f030b52c156fd0d88dec24b38d8945d /ecomp-sdk/epsdk-analytics
parent3303a979e1730e9b999a5090f769a6e6811224b3 (diff)
Added Junits
Issue-ID: PORTAL-136 Includes JUNITS, Analytics module Change-Id: I294bc657a2f0008a6ef889da2635525c77abc809 Change-Id: I294bc657a2f0008a6ef889da2635525c77abc809 Signed-off-by: Madheswaran, Saravanan <msaravanan@in.ibm.com>
Diffstat (limited to 'ecomp-sdk/epsdk-analytics')
-rw-r--r--ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/definition/ReportSchedule.java10
-rw-r--r--ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/ReportScheduleTest.java482
2 files changed, 487 insertions, 5 deletions
diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/definition/ReportSchedule.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/definition/ReportSchedule.java
index 5ffb1326..1cd9b918 100644
--- a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/definition/ReportSchedule.java
+++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/definition/ReportSchedule.java
@@ -1311,7 +1311,7 @@ public class ReportSchedule extends RaptorObject implements Serializable{
stmt = connection.prepareStatement(sql);
stmt.setString(1,scheduleId);
rs = stmt.executeQuery();
- Writer out = null;
+ //Writer out = null;
/*if(Globals.isWeblogicServer()) {
java.sql.Clob clob = null;
if (rs.next())
@@ -1345,9 +1345,9 @@ public class ReportSchedule extends RaptorObject implements Serializable{
throw new RaptorException("only maria db support for this ");
}
- out.write(conditional_sql);
- out.flush();
- out.close();
+ //out.write(conditional_sql);
+ //out.flush();
+ //out.close();
} catch (RaptorException ex) {
if(ex.getMessage().indexOf("invalid identifier")!= -1) {
try {
@@ -1377,7 +1377,7 @@ public class ReportSchedule extends RaptorObject implements Serializable{
} catch (SQLException ex2) {
throw new ReportSQLException (ex2.getMessage(), ex2.getCause());
}
- } catch (IOException ex) {
+ } catch (Exception ex) {
throw new RaptorRuntimeException (ex.getMessage(), ex.getCause());
} finally {
try {
diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/ReportScheduleTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/ReportScheduleTest.java
new file mode 100644
index 00000000..83c14bfa
--- /dev/null
+++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/ReportScheduleTest.java
@@ -0,0 +1,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============================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+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");
+ }
+ */
+
+}