From f51a3e2b128f0b96bc9ed67dfc3081f4b41d1303 Mon Sep 17 00:00:00 2001 From: "Kishore Reddy, Gujja (kg811t)" Date: Fri, 8 Jun 2018 16:40:16 -0400 Subject: Junit Test Cases & Raptors Issue-ID: PORTAL-273. PORTAL-301 Covered JUNITS for sdk modules and RAPTOR reports fixes Change-Id: Ifaf3bf06f0ec123051a791cc8e7f10662f97a525 Signed-off-by: Kishore Reddy, Gujja (kg811t) --- .../analytics/controller/ActionHandlerTest.java | 1259 ++++++++++++++++++++ 1 file changed, 1259 insertions(+) create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/ActionHandlerTest.java (limited to 'ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/ActionHandlerTest.java') diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/ActionHandlerTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/ActionHandlerTest.java new file mode 100644 index 00000000..71d3a1b5 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/ActionHandlerTest.java @@ -0,0 +1,1259 @@ +package org.onap.portalsdk.analytics.controller; +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ + + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; +import static org.powermock.api.mockito.PowerMockito.whenNew; + +import java.io.IOException; +import java.io.InputStream; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.List; +import java.util.Vector; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.apache.commons.io.FilenameUtils; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Matchers; +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.DataCache; +import org.onap.portalsdk.analytics.model.ReportHandler; +import org.onap.portalsdk.analytics.model.ReportLoader; +import org.onap.portalsdk.analytics.model.SearchHandler; +import org.onap.portalsdk.analytics.model.base.IdNameColLookup; +import org.onap.portalsdk.analytics.model.base.IdNameList; +import org.onap.portalsdk.analytics.model.base.ReportWrapper; +import org.onap.portalsdk.analytics.model.definition.ReportDefinition; +import org.onap.portalsdk.analytics.model.definition.ReportSchedule; +import org.onap.portalsdk.analytics.model.runtime.ChartWebRuntime; +import org.onap.portalsdk.analytics.model.runtime.FormField; +import org.onap.portalsdk.analytics.model.runtime.ReportFormFields; +import org.onap.portalsdk.analytics.model.runtime.ReportJSONRuntime; +import org.onap.portalsdk.analytics.model.runtime.ReportRuntime; +import org.onap.portalsdk.analytics.model.runtime.VisualManager; +import org.onap.portalsdk.analytics.model.search.ReportSearchResultJSON; +import org.onap.portalsdk.analytics.system.AppUtils; +import org.onap.portalsdk.analytics.system.ConnectionUtils; +import org.onap.portalsdk.analytics.system.DbUtils; +import org.onap.portalsdk.analytics.system.Globals; +import org.onap.portalsdk.analytics.system.IAppUtils; +import org.onap.portalsdk.analytics.system.fusion.domain.QuickLink; +import org.onap.portalsdk.analytics.util.AppConstants; +import org.onap.portalsdk.analytics.util.DataSet; +import org.onap.portalsdk.analytics.util.Utils; +import org.onap.portalsdk.analytics.view.ReportData; +import org.onap.portalsdk.analytics.xmlobj.ChartAdditionalOptions; +import org.onap.portalsdk.analytics.xmlobj.CustomReportType; +import org.onap.portalsdk.analytics.xmlobj.DashboardReports; +import org.onap.portalsdk.analytics.xmlobj.DataColumnList; +import org.onap.portalsdk.analytics.xmlobj.DataColumnType; +import org.onap.portalsdk.analytics.xmlobj.DataSourceList; +import org.onap.portalsdk.analytics.xmlobj.DataSourceType; +import org.onap.portalsdk.analytics.xmlobj.FormFieldList; +import org.onap.portalsdk.analytics.xmlobj.FormFieldType; +import org.onap.portalsdk.analytics.xmlobj.FormatList; +import org.onap.portalsdk.analytics.xmlobj.FormatType; +import org.onap.portalsdk.analytics.xmlobj.MockitoTestSuite; +import org.onap.portalsdk.analytics.xmlobj.Reports; +import org.onap.portalsdk.analytics.xmlobj.SemaphoreType; +import org.onap.portalsdk.core.logging.format.AlarmSeverityEnum; +import org.onap.portalsdk.core.util.SecurityCodecUtil; +import org.onap.portalsdk.core.web.support.UserUtils; +import org.owasp.esapi.ESAPI; +import org.owasp.esapi.Encoder; +import org.owasp.esapi.codecs.Codec; +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, UserUtils.class, ESAPI.class, AppConstants.class, AlarmSeverityEnum.class, ReportWrapper.class, + ReportDefinition.class, SecurityCodecUtil.class, Globals.class, DbUtils.class, ReportLoader.class, ConnectionUtils.class, FilenameUtils.class, Utils.class, ReportRuntime.class, DataCache.class, ActionHandler.class}) +public class ActionHandlerTest { + + @InjectMocks + ActionHandler actionHandler = new ActionHandler(); + + @Mock + Connection connection; + @Mock + PreparedStatement stmt; + @Mock + ResultSet rs; + @Mock + java.sql.Clob clob; + @Mock + InputStream in; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + + + @SuppressWarnings("unchecked") + @Test + public void reportRunTest_WhenReportTypeIsNotEqualToDashboard() throws Exception { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.mockStatic(ReportWrapper.class); + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mock(AppConstants.class); + PowerMockito.mockStatic(ReportDefinition.class); + PowerMockito.mockStatic(ESAPI.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + when(mockedRequest.getParameter("action")).thenReturn("test"); + when(AppUtils.getRequestFlag(mockedRequest, "fromDashboard")).thenReturn(false); + when(AppUtils.getRequestNvlValue(mockedRequest, "pdfAttachmentKey")).thenReturn("testxyz"); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + when(mockedRequest.getSession().getAttribute("FirstDashReport")).thenReturn(rr); + when(mockedRequest.getParameter(AppConstants.RI_ACTION)).thenReturn("report.download"); + Encoder encoder = PowerMockito.mock(Encoder.class); + when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + when(SecurityCodecUtil.getCodec()).thenReturn(codec); + when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); + when(Globals.getDownloadAllEmailSent()).thenReturn("test"); + DataSet set = Mockito.mock(DataSet.class); + when(DbUtils.executeQuery(Matchers.anyString(), Matchers.anyInt())).thenReturn(set); + when(DbUtils.getConnection()).thenReturn(connection); + when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_REPORT_ID)).thenReturn(null); + when(rr.getReportID()).thenReturn("test"); + when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_SHOW_BACK_BTN)).thenReturn(true); + when(Globals.getLoadCustomReportXml()).thenReturn("java.lang.String"); + String str = "namedesctypefalsefalseidfalse"; + when(connection.prepareStatement("1")).thenReturn(stmt); + when(stmt.executeQuery()).thenReturn(rs); + when(Globals.isWeblogicServer()).thenReturn(true); + when(rs.getClob(1)).thenReturn(clob); + when(rs.next()).thenReturn(true); + when(clob.getAsciiStream()).thenReturn(in); + when(in.read(Matchers.any())).thenReturn(1); + when(AppUtils.nvl(rr.getLegendLabelAngle())).thenReturn("standard"); + when(AppUtils.nvl("Y")).thenReturn("Y"); + when(AppUtils.nvl("bottom")).thenReturn("Y"); + when(AppUtils.nvl("test")).thenReturn("test|"); + when(AppUtils.getRequestValue(mockedRequest, "c_dashboard")).thenReturn("1"); + when(ReportLoader.isDashboardType("-1")).thenReturn(false); + ReportDefinition rdf = PowerMockito.mock(ReportDefinition.class); + whenNew(ReportDefinition.class) + .withArguments(Matchers.any(ReportWrapper.class), Matchers.any(HttpServletRequest.class)) + .thenReturn(rdf); + when(ReportDefinition.unmarshal(Mockito.anyString(), Mockito.anyString(), Mockito.anyObject())).thenReturn(rdf); + CustomReportType crType = Mockito.mock(CustomReportType.class); + when(ReportWrapper.unmarshalCR(Matchers.anyString())).thenReturn(crType); + when(Globals.getReportWrapperFormat()).thenReturn("[Globals.getTimeFormat()]"); + when(Globals.getTimeFormat()).thenReturn("[reportID]"); + when(Globals.getReportUserAccess()).thenReturn("[reportID]"); + when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(set); + when(set.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); + when(set.getString(Matchers.anyInt(), Matchers.any(String.class))).thenReturn("test"); + when(ReportLoader.loadCustomReportXML("test2")).thenReturn(str); + FormFieldType formFieldType = new FormFieldType(); + formFieldType.setFieldId("test"); + formFieldType.setColId("1"); + formFieldType.setFieldName("test"); + formFieldType.setFieldType("type"); + formFieldType.setValidationType("validation"); + formFieldType.setMandatory("Y"); + formFieldType.setDefaultValue("test"); + formFieldType.setGroupFormField(true); + List formFieldTypeList = new ArrayList<>(); + formFieldTypeList.add(formFieldType); + FormFieldList formFieldList = PowerMockito.mock(FormFieldList.class); + when(formFieldList.getFormField()).thenReturn(formFieldTypeList); + Mockito.when(crType.getFormFieldList()).thenReturn(formFieldList); + when(Globals.getRequestParams()).thenReturn("test,case"); + when( Globals.getSessionParams()).thenReturn("test,abc"); + when(Globals.getSessionParamsForScheduling()).thenReturn("test"); + + DataSourceList dataSourceList = new DataSourceList(); + List list = new ArrayList<>(); + DataSourceType dataSourceType = new DataSourceType(); + dataSourceType.setTableName("test"); + dataSourceType.setRefTableId("1"); + dataSourceType.setTableId("1"); + List dataColumnTypeList = new ArrayList<>(); + DataColumnType dataColumnType = new DataColumnType(); + dataColumnType.setChartGroup("test"); + dataColumnType.setYAxis("test"); + dataColumnType.setColName("[test"); + dataColumnType.setColOnChart("LEGEND"); + dataColumnType.setDisplayName("chart_total"); + dataColumnType.setColId("1"); + dataColumnType.setTableId("1"); + dataColumnType.setColType("DATE"); + dataColumnType.setCrossTabValue("ROW"); + dataColumnType.setPdfDisplayWidthInPxls("0.0"); + dataColumnType.setVisible(true); + dataColumnType.setCalculated(true); + dataColumnTypeList.add(dataColumnType); + DataColumnType dataColumnType1 = new DataColumnType(); + dataColumnType1.setCrossTabValue("COLUMN"); + dataColumnType1.setColId("1"); + dataColumnType1.setVisible(true); + dataColumnType1.setPdfDisplayWidthInPxls("1.0"); + dataColumnTypeList.add(dataColumnType1); + + DataColumnList dataColumnList = new DataColumnList(); + //dataColumnList.dataColumn = dataColumnTypeList; + dataSourceType.setDataColumnList(dataColumnList); + list.add(dataSourceType); + //dataSourceList.dataSource = list; + when(crType.getDataSourceList()).thenReturn(dataSourceList); + + List predefinedValues = new ArrayList<>(); + ReportWrapper rw = PowerMockito.mock(ReportWrapper.class); + ReportFormFields reportFormFields = new ReportFormFields(rw, mockedRequest); + FormField formField = new FormField("test", "fieldDisplayName", FormField.FFT_COMBO_BOX, "validationType", false, + "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + FormField formField1 = new FormField("test", "fieldDisplayName", FormField.FFT_LIST_MULTI, "validationType", false, + "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + FormField formField2 = new FormField("test", "fieldDisplayName", FormField.FFT_BLANK, "validationType", false, + "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + + reportFormFields.add(formField); + reportFormFields.add(formField1); + reportFormFields.add(formField2); + rr.setReportFormFields(null); + rr.setReportFormFields(reportFormFields); + when(rr.getReportFormFields()).thenReturn(reportFormFields); + when(mockedRequest.getSession().getAttribute("remoteDB")).thenReturn("test"); + Enumeration enums; + Vector attrs = new Vector(); + attrs.add("ff_test"); + enums = attrs.elements(); + when(rr.getParamKeys()).thenReturn(enums); + + DashboardReports daashBoard = Mockito.mock(DashboardReports.class); + when(rdf.getDashBoardReports()).thenReturn(daashBoard); + when(daashBoard.getReportsList()).thenReturn(new ArrayList()); + String testHTML = "
[Report#123][Report#124]
[Report#125][Report#126]
"; + when(rr.getDashboardLayoutHTML()).thenReturn(testHTML); + when(rr.getReportType()).thenReturn("test"); + when(mockedRequest.getParameter("refresh")).thenReturn("N"); + when(rr.getDisplayContent()).thenReturn(true); + + when(AppUtils.getRequestNvlValue(mockedRequest,AppConstants.RI_VISUAL_ACTION)).thenReturn("test"); + when(AppUtils.getRequestNvlValue(mockedRequest,AppConstants.RI_DETAIL_ID)).thenReturn("test"); + when(AppUtils.getRequestNvlValue(mockedRequest,AppConstants.RI_DETAIL_ID)).thenReturn("test"); + when(rr.isDisplayOptionHideMap()).thenReturn(true); + when(mockedRequest.getSession().getAttribute("isEmbedded")).thenReturn(true); + when(rr.isDrillDownURLInPopupPresent()).thenReturn(true); + ArrayList aL = new ArrayList<>(); + ReportRuntime rr1 = PowerMockito.mock(ReportRuntime.class); + when(rr1.getReportID()).thenReturn("test1"); + when(rr1.getReportType()).thenReturn("test"); + aL.add(rr1); + when(mockedRequest.getSession().getAttribute(AppConstants.DRILLDOWN_REPORTS_LIST)).thenReturn(aL); + when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_RESET_PARAMS)).thenReturn(true); + when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_RESET_ACTION)).thenReturn(false); + when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_GO_BACK)).thenReturn(true); + + assertEquals(actionHandler.reportRun(mockedRequest, "test").getClass(), String.class); + } + + @Test + public void reportRunExceptionTest() { + when(mockedRequest.getParameter("action")).thenReturn("test"); + PowerMockito.mockStatic(AppUtils.class); + when(AppUtils.getRequestFlag(mockedRequest, "fromDashboard")).thenReturn(true); + assertEquals(actionHandler.reportRun(mockedRequest, "test").getClass(), String.class); + } + + @SuppressWarnings("unchecked") + @Test + public void reportRunTest() throws Exception { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.mockStatic(ReportWrapper.class); + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mock(AppConstants.class); + PowerMockito.mockStatic(ReportDefinition.class); + PowerMockito.mockStatic(ESAPI.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + when(mockedRequest.getParameter("action")).thenReturn("test"); + when(AppUtils.getRequestFlag(mockedRequest, "fromDashboard")).thenReturn(false); + when(AppUtils.getRequestNvlValue(mockedRequest, "pdfAttachmentKey")).thenReturn("testxyz"); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + when(mockedRequest.getSession().getAttribute("FirstDashReport")).thenReturn(rr); + when(mockedRequest.getParameter(AppConstants.RI_ACTION)).thenReturn("report.download"); + Encoder encoder = PowerMockito.mock(Encoder.class); + when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + when(SecurityCodecUtil.getCodec()).thenReturn(codec); + when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); + when(Globals.getDownloadAllEmailSent()).thenReturn("test"); + DataSet set = Mockito.mock(DataSet.class); + when(DbUtils.executeQuery(Matchers.anyString(), Matchers.anyInt())).thenReturn(set); + when(DbUtils.getConnection()).thenReturn(connection); + when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_REPORT_ID)).thenReturn(AppConstants.RT_DASHBOARD); + when(rr.getReportID()).thenReturn(AppConstants.RT_DASHBOARD); + when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_SHOW_BACK_BTN)).thenReturn(true); + when(Globals.getLoadCustomReportXml()).thenReturn("java.lang.String"); + String str = "namedesctypefalsefalseidfalse"; + when(connection.prepareStatement("1")).thenReturn(stmt); + when(stmt.executeQuery()).thenReturn(rs); + when(Globals.isWeblogicServer()).thenReturn(true); + when(rs.getClob(1)).thenReturn(clob); + when(rs.next()).thenReturn(true); + when(clob.getAsciiStream()).thenReturn(in); + when(in.read(Matchers.any())).thenReturn(1); + when(AppUtils.nvl(rr.getLegendLabelAngle())).thenReturn("standard"); + when(AppUtils.nvl("Y")).thenReturn("Y"); + when(AppUtils.nvl("bottom")).thenReturn("Y"); + when(AppUtils.nvl("test")).thenReturn("test|"); + when(AppUtils.getRequestValue(mockedRequest, "c_dashboard")).thenReturn("1"); + when(ReportLoader.isDashboardType("-1")).thenReturn(false); + ReportDefinition rdf = PowerMockito.mock(ReportDefinition.class); + whenNew(ReportDefinition.class) + .withArguments(Matchers.any(ReportWrapper.class), Matchers.any(HttpServletRequest.class)) + .thenReturn(rdf); + when(ReportDefinition.unmarshal(Mockito.anyString(), Mockito.anyString(), Mockito.anyObject())).thenReturn(rdf); + CustomReportType crType = Mockito.mock(CustomReportType.class); + when(ReportWrapper.unmarshalCR(Matchers.anyString())).thenReturn(crType); + when(Globals.getReportWrapperFormat()).thenReturn("[Globals.getTimeFormat()]"); + when(Globals.getTimeFormat()).thenReturn("[reportID]"); + when(Globals.getReportUserAccess()).thenReturn("[reportID]"); + when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(set); + when(set.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); + when(ReportLoader.loadCustomReportXML("test2")).thenReturn(str); + FormFieldType formFieldType = new FormFieldType(); + formFieldType.setFieldId("test"); + formFieldType.setColId("1"); + formFieldType.setFieldName("test"); + formFieldType.setFieldType("type"); + formFieldType.setValidationType("validation"); + formFieldType.setMandatory("Y"); + formFieldType.setDefaultValue("test"); + formFieldType.setGroupFormField(true); + List formFieldTypeList = new ArrayList<>(); + formFieldTypeList.add(formFieldType); + FormFieldList formFieldList = PowerMockito.mock(FormFieldList.class); + when(formFieldList.getFormField()).thenReturn(formFieldTypeList); + Mockito.when(crType.getFormFieldList()).thenReturn(formFieldList); + when(Globals.getRequestParams()).thenReturn("test,case"); + when( Globals.getSessionParams()).thenReturn("test,abc"); + when(Globals.getSessionParamsForScheduling()).thenReturn("test"); + + DataSourceList dataSourceList = new DataSourceList(); + List list = new ArrayList<>(); + DataSourceType dataSourceType = new DataSourceType(); + dataSourceType.setTableName("test"); + dataSourceType.setRefTableId("1"); + dataSourceType.setTableId("1"); + List dataColumnTypeList = new ArrayList<>(); + DataColumnType dataColumnType = new DataColumnType(); + dataColumnType.setChartGroup("test"); + dataColumnType.setYAxis("test"); + dataColumnType.setColName("[test"); + dataColumnType.setColOnChart("LEGEND"); + dataColumnType.setDisplayName("chart_total"); + dataColumnType.setColId("1"); + dataColumnType.setTableId("1"); + dataColumnType.setColType("DATE"); + dataColumnType.setCrossTabValue("ROW"); + dataColumnType.setPdfDisplayWidthInPxls("0.0"); + dataColumnType.setVisible(true); + dataColumnType.setCalculated(true); + dataColumnTypeList.add(dataColumnType); + DataColumnType dataColumnType1 = new DataColumnType(); + dataColumnType1.setCrossTabValue("COLUMN"); + dataColumnType1.setColId("1"); + dataColumnType1.setVisible(true); + dataColumnType1.setPdfDisplayWidthInPxls("1.0"); + dataColumnTypeList.add(dataColumnType1); + + DataColumnList dataColumnList = new DataColumnList(); + //dataColumnList.dataColumn = dataColumnTypeList; + dataSourceType.setDataColumnList(dataColumnList); + list.add(dataSourceType); + //dataSourceList.dataSource = list; + when(crType.getDataSourceList()).thenReturn(dataSourceList); + + List predefinedValues = new ArrayList<>(); + ReportWrapper rw = PowerMockito.mock(ReportWrapper.class); + ReportFormFields reportFormFields = new ReportFormFields(rw, mockedRequest); + FormField formField = new FormField("test", "fieldDisplayName", FormField.FFT_COMBO_BOX, "validationType", false, + "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + FormField formField1 = new FormField("test", "fieldDisplayName", FormField.FFT_LIST_MULTI, "validationType", false, + "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + FormField formField2 = new FormField("test", "fieldDisplayName", FormField.FFT_BLANK, "validationType", false, + "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + + reportFormFields.add(formField); + reportFormFields.add(formField1); + reportFormFields.add(formField2); + rr.setReportFormFields(null); + rr.setReportFormFields(reportFormFields); + when(rr.getReportFormFields()).thenReturn(reportFormFields); + when(mockedRequest.getSession().getAttribute("remoteDB")).thenReturn("test"); + Enumeration enums; + Vector attrs = new Vector(); + attrs.add("ff_test"); + enums = attrs.elements(); + when(rr.getParamKeys()).thenReturn(enums); + + DashboardReports daashBoard = Mockito.mock(DashboardReports.class); + when(rdf.getDashBoardReports()).thenReturn(daashBoard); + when(daashBoard.getReportsList()).thenReturn(new ArrayList()); + String testHTML = "
[Report#123][Report#124]
[Report#125][Report#126]
"; + when(rr.getDashboardLayoutHTML()).thenReturn(testHTML); + when(rr.getReportType()).thenReturn(AppConstants.RT_DASHBOARD); + when(mockedRequest.getParameter("refresh")).thenReturn("N"); + when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_DISPLAY_CONTENT)).thenReturn(true); + assertEquals(actionHandler.reportRun(mockedRequest, "test").getClass(), String.class); + } + + + + @SuppressWarnings("unchecked") + @Test + public void reportRunRaptorReportExceptionTest() throws Exception { + try { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.mockStatic(ReportWrapper.class); + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mock(AppConstants.class); + PowerMockito.mockStatic(ReportDefinition.class); + PowerMockito.mockStatic(ESAPI.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + when(mockedRequest.getParameter("action")).thenReturn("test"); + when(AppUtils.getRequestFlag(mockedRequest, "fromDashboard")).thenReturn(false); + when(AppUtils.getRequestNvlValue(mockedRequest, "pdfAttachmentKey")).thenReturn("testxyz"); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + when(mockedRequest.getSession().getAttribute("FirstDashReport")).thenReturn(rr); + when(mockedRequest.getParameter(AppConstants.RI_ACTION)).thenReturn("report.download"); + Encoder encoder = PowerMockito.mock(Encoder.class); + when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + when(SecurityCodecUtil.getCodec()).thenReturn(codec); + when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); + when(Globals.getDownloadAllEmailSent()).thenReturn("test"); + DataSet set = Mockito.mock(DataSet.class); + when(DbUtils.executeQuery(Matchers.anyString(), Matchers.anyInt())).thenReturn(set); + when(DbUtils.getConnection()).thenReturn(connection); + when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_REPORT_ID)).thenReturn("test2"); + when(rr.getReportID()).thenReturn("test"); + when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_SHOW_BACK_BTN)).thenReturn(true); + when(Globals.getLoadCustomReportXml()).thenReturn("java.lang.String"); + String str = "namedesctypefalsefalseidfalse"; + when(connection.prepareStatement("1")).thenReturn(stmt); + when(stmt.executeQuery()).thenReturn(rs); + when(Globals.isWeblogicServer()).thenReturn(true); + when(rs.getClob(1)).thenReturn(clob); + when(rs.next()).thenReturn(true); + when(clob.getAsciiStream()).thenReturn(in); + when(in.read(Matchers.any())).thenReturn(1); + when(AppUtils.nvl(rr.getLegendLabelAngle())).thenReturn("standard"); + when(AppUtils.nvl("Y")).thenReturn("Y"); + when(AppUtils.nvl("bottom")).thenReturn("Y"); + when(AppUtils.nvl("test")).thenReturn("test|"); + when(AppUtils.getRequestValue(mockedRequest, "c_dashboard")).thenReturn("1"); + when(ReportLoader.isDashboardType("-1")).thenReturn(false); + ReportDefinition rdf = PowerMockito.mock(ReportDefinition.class); + whenNew(ReportDefinition.class) + .withArguments(Matchers.any(ReportWrapper.class), Matchers.any(HttpServletRequest.class)) + .thenReturn(rdf); + when(ReportDefinition.unmarshal(Mockito.anyString(), Mockito.anyString(), Mockito.anyObject())).thenReturn(rdf); + CustomReportType crType = Mockito.mock(CustomReportType.class); + when(ReportWrapper.unmarshalCR(Matchers.anyString())).thenReturn(crType); + when(Globals.getReportWrapperFormat()).thenReturn("[Globals.getTimeFormat()]"); + when(Globals.getTimeFormat()).thenReturn("[reportID]"); + when(Globals.getReportUserAccess()).thenReturn("[reportID]"); + when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(set); + when(set.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); + when(ReportLoader.loadCustomReportXML("test2")).thenReturn(str); + FormFieldType formFieldType = new FormFieldType(); + formFieldType.setFieldId("test"); + formFieldType.setColId("1"); + formFieldType.setFieldName("test"); + formFieldType.setFieldType("type"); + formFieldType.setValidationType("validation"); + formFieldType.setMandatory("Y"); + formFieldType.setDefaultValue("test"); + formFieldType.setGroupFormField(true); + List formFieldTypeList = new ArrayList<>(); + formFieldTypeList.add(formFieldType); + FormFieldList formFieldList = PowerMockito.mock(FormFieldList.class); + when(formFieldList.getFormField()).thenReturn(formFieldTypeList); + Mockito.when(crType.getFormFieldList()).thenReturn(formFieldList); + when(Globals.getRequestParams()).thenReturn("test,case"); + when( Globals.getSessionParams()).thenReturn("test,abc"); + when(Globals.getSessionParamsForScheduling()).thenReturn("test"); + + DataSourceList dataSourceList = new DataSourceList(); + List list = new ArrayList<>(); + DataSourceType dataSourceType = new DataSourceType(); + dataSourceType.setTableName("test"); + dataSourceType.setRefTableId("1"); + dataSourceType.setTableId("1"); + List dataColumnTypeList = new ArrayList<>(); + DataColumnType dataColumnType = new DataColumnType(); + dataColumnType.setChartGroup("test"); + dataColumnType.setYAxis("test"); + dataColumnType.setColName("[test"); + dataColumnType.setColOnChart("LEGEND"); + dataColumnType.setDisplayName("chart_total"); + dataColumnType.setColId("1"); + dataColumnType.setTableId("1"); + dataColumnType.setColType("DATE"); + dataColumnType.setCrossTabValue("ROW"); + dataColumnType.setPdfDisplayWidthInPxls("0.0"); + dataColumnType.setVisible(true); + dataColumnType.setCalculated(true); + dataColumnTypeList.add(dataColumnType); + DataColumnType dataColumnType1 = new DataColumnType(); + dataColumnType1.setCrossTabValue("COLUMN"); + dataColumnType1.setColId("1"); + dataColumnType1.setVisible(true); + dataColumnType1.setPdfDisplayWidthInPxls("1.0"); + dataColumnTypeList.add(dataColumnType1); + + DataColumnList dataColumnList = new DataColumnList(); + //dataColumnList.dataColumn = dataColumnTypeList; + dataSourceType.setDataColumnList(dataColumnList); + list.add(dataSourceType); + //dataSourceList.dataSource = list; + when(crType.getDataSourceList()).thenReturn(dataSourceList); + when(rr.getReportType()).thenReturn(AppConstants.RT_DASHBOARD); + + List predefinedValues = new ArrayList<>(); + ReportWrapper rw = PowerMockito.mock(ReportWrapper.class); + ReportFormFields reportFormFields = new ReportFormFields(rw, mockedRequest); + FormField formField = new FormField("test", "fieldDisplayName", FormField.FFT_COMBO_BOX, "validationType", false, + "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + FormField formField1 = new FormField("test", "fieldDisplayName", FormField.FFT_LIST_MULTI, "validationType", false, + "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + FormField formField2 = new FormField("test", "fieldDisplayName", FormField.FFT_BLANK, "validationType", false, + "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + + reportFormFields.add(formField); + reportFormFields.add(formField1); + reportFormFields.add(formField2); + rr.setReportFormFields(null); + rr.setReportFormFields(reportFormFields); + when(rr.getReportFormFields()).thenReturn(reportFormFields); + when(mockedRequest.getSession().getAttribute("remoteDB")).thenReturn("test"); + Enumeration enums; + Vector attrs = new Vector(); + attrs.add("ff_test"); + enums = attrs.elements(); + when(rr.getParamKeys()).thenReturn(enums); + assertEquals(actionHandler.reportRun(mockedRequest, "test").getClass(), String.class); + }catch(Exception e) { + e.printStackTrace(); + } + } + + + @Test + public void reportRunForCSVDownloadTest() throws Exception { + when(mockedRequest.getParameter("action")).thenReturn("test"); + when(mockedRequest.getParameter("r_action")).thenReturn("report.csv.download"); + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + + when(AppUtils.getRequestFlag(mockedRequest, "fromDashboard")).thenReturn(false); + when(AppUtils.getRequestNvlValue(mockedRequest, "pdfAttachmentKey")).thenReturn(""); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + when(AppUtils.getRequestFlag(mockedRequest, "fromReportLog")).thenReturn(true); + when(rr.getReportType()).thenReturn(AppConstants.RT_LINEAR); + when(rr.getReportDataSQL(Matchers.anyString(), Matchers.anyInt(), Matchers.any())).thenReturn("test"); + PowerMockito.mockStatic(ESAPI.class); + Encoder encoder = PowerMockito.mock(Encoder.class); + when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + when(SecurityCodecUtil.getCodec()).thenReturn(codec); + when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); + when(Globals.getDownloadAllEmailSent()).thenReturn("test"); + DataSet set = new DataSet(); + when(DbUtils.executeQuery(Matchers.anyString(), Matchers.anyInt())).thenReturn(set); + assertEquals(actionHandler.reportRun(mockedRequest, "test").getClass(), String.class); + } + + @Test + public void reportRunForExcelDownloadTest() throws Exception { + when(mockedRequest.getParameter("action")).thenReturn("test"); + when(mockedRequest.getParameter("r_action")).thenReturn("report.download.excel2007"); + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + + when(AppUtils.getRequestFlag(mockedRequest, "fromDashboard")).thenReturn(false); + when(AppUtils.getRequestNvlValue(mockedRequest, "pdfAttachmentKey")).thenReturn(""); + when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_REFRESH)).thenReturn(true); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + when(AppUtils.getRequestFlag(mockedRequest, "fromReportLog")).thenReturn(false); + when(rr.getReportType()).thenReturn(AppConstants.RT_LINEAR); + when(rr.getReportDataSQL(Matchers.anyString(), Matchers.anyInt(), Matchers.any())).thenReturn("test"); + PowerMockito.mockStatic(ESAPI.class); + Encoder encoder = PowerMockito.mock(Encoder.class); + when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + when(SecurityCodecUtil.getCodec()).thenReturn(codec); + when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); + when(Globals.getDownloadAllEmailSent()).thenReturn("test"); + DataSet set = new DataSet(); + when(DbUtils.executeQuery(Matchers.anyString(), Matchers.anyInt())).thenReturn(set); + Enumeration enum1 = Mockito.mock(Enumeration.class); + HttpSession session = mockedRequest.getSession(); + when(session.getAttributeNames()).thenReturn(enum1); + assertEquals(actionHandler.reportRun(mockedRequest, "test").getClass(), String.class); + } + + + public ReportRuntime mockReportRunTime1() throws Exception { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + when(Globals.getReportUserAccess()).thenReturn("test"); + ResultSet rs = PowerMockito.mock(ResultSet.class); + ResultSetMetaData rsmd = PowerMockito.mock(ResultSetMetaData.class); + when(rsmd.getColumnCount()).thenReturn(1); + when(rs.getMetaData()).thenReturn(rsmd); + DataSet datset = PowerMockito.mock(DataSet.class); + // datset = new DataSet(rs); + when(datset.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn(null); + when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(datset); + when(Globals.getNewScheduleData()).thenReturn("test"); + CustomReportType customReportType = new CustomReportType(); + DataSourceList dataSourceList = new DataSourceList(); + DataSourceType dataSourceType = new DataSourceType(); + dataSourceType.setTableName("test"); + dataSourceType.setRefTableId("1"); + dataSourceType.setTableId("1"); + List dataColumnTypeList = new ArrayList<>(); + DataColumnType dataColumnType = new DataColumnType(); + dataColumnType.setChartGroup("test"); + dataColumnType.setYAxis("test"); + dataColumnType.setColName("[test"); + dataColumnType.setColOnChart("LEGEND"); + dataColumnType.setDisplayName("chart_total"); + dataColumnType.setColId("1"); + dataColumnType.setTableId("1"); + dataColumnType.setColType("DATE"); + dataColumnTypeList.add(dataColumnType); + customReportType.setReportType("test"); + customReportType.setReportTitle("test"); + customReportType.setDataSourceList(dataSourceList); + ChartAdditionalOptions chartAdditionalOptions = new ChartAdditionalOptions(); + chartAdditionalOptions.setLabelAngle("test"); + chartAdditionalOptions.setTimeSeriesRender("test"); + chartAdditionalOptions.setMultiSeries(false); + customReportType.setChartAdditionalOptions(chartAdditionalOptions); + ReportWrapper reportWrapper = new ReportWrapper(customReportType, "-1", "test", "testId", "test", "test", "1", + "1", true); + PowerMockito.mockStatic(UserUtils.class); + when(Globals.getRequestParams()).thenReturn("test"); + when(Globals.getSessionParams()).thenReturn("test"); + when(Globals.getSessionParamsForScheduling()).thenReturn("test"); + PowerMockito.mockStatic(AppUtils.class); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test12"); + ReportRuntime rr = new ReportRuntime(reportWrapper, mockedRequest); + rr.setLegendLabelAngle("test"); + rr.setMultiSeries(false); + rr.setChartType("test"); + return rr; + } + + + @Test + public void reportRunTestCase1() throws Exception { + when(mockedRequest.getParameter("action")).thenReturn("test"); + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + + when(AppUtils.getRequestFlag(mockedRequest, "fromDashboard")).thenReturn(false); + when(AppUtils.getRequestNvlValue(mockedRequest, "pdfAttachmentKey")).thenReturn("test"); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + + PowerMockito.mockStatic(ESAPI.class); + Encoder encoder = PowerMockito.mock(Encoder.class); + when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + when(SecurityCodecUtil.getCodec()).thenReturn(codec); + when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); + when(Globals.getDownloadAllEmailSent()).thenReturn("test"); + DataSet set = PowerMockito.mock(DataSet.class); + when(set.isEmpty()).thenReturn(false); + when(DbUtils.executeQuery(Matchers.anyString(), Matchers.anyInt())).thenReturn(set); + when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_REPORT_ID)).thenReturn(null); + PowerMockito.mockStatic(ReportLoader.class); + when(ReportLoader.loadCustomReportXML(Matchers.anyString())).thenReturn("test"); + assertEquals(actionHandler.reportRun(mockedRequest, "test").getClass(), String.class); + } + + + @Test + public void reportDeleteTest() throws Exception { + PowerMockito.mockStatic(ESAPI.class); + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + PowerMockito.mockStatic(AlarmSeverityEnum.class); + DataSet set = Mockito.mock(DataSet.class); + Encoder encoder = PowerMockito.mock(Encoder.class); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + ReportDefinition rd = PowerMockito.mock(ReportDefinition.class); + when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + when(SecurityCodecUtil.getCodec()).thenReturn(codec); + when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_REPORT_ID)).thenReturn("1"); + when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("1"); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + when(Globals.getReportSecurity()).thenReturn("[rw.getReportID()]"); + when(Globals.getReportUserAccess()).thenReturn("[reportID]"); + when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(set); + when(Globals.getDeleteOnlyByOwner()).thenReturn(true); + when(Globals.getLogVariablesInSession()).thenReturn("test"); + HttpSession session = Mockito.mock(HttpSession.class); + when(session.getAttribute(Matchers.anyString())).thenReturn(rr); + when(session.getAttribute(Matchers.anyString())).thenReturn(rd); + assertEquals(actionHandler.reportDelete(mockedRequest, "10").getClass(), String.class); + } + + + @Test + public void reportSearchTest() throws Exception { + PowerMockito.mockStatic(AppUtils.class); + when(AppUtils.getImgFolderURL()).thenReturn("test"); + SearchHandler sh = Mockito.mock(SearchHandler.class); + whenNew(SearchHandler.class).withNoArguments().thenReturn(sh); + ReportSearchResultJSON rsrj = Mockito.mock(ReportSearchResultJSON.class); + when(sh.loadReportSearchResult(mockedRequest)).thenReturn(rsrj); + when(rsrj.getJSONString()).thenReturn("test"); + Enumeration enum1 = Mockito.mock(Enumeration.class); + HttpSession session = mockedRequest.getSession(); + when(session.getAttributeNames()).thenReturn(enum1); + actionHandler.reportSearch(mockedRequest, "10"); + } + + + @Test + public void reportChartRunTest() throws Exception { + ChartWebRuntime cwr = PowerMockito.mock(ChartWebRuntime.class); + whenNew(ChartWebRuntime.class).withNoArguments().thenReturn(cwr); + when(cwr.generateChart(mockedRequest,false)).thenReturn("testReport"); + assertEquals("testReport", actionHandler.reportChartRun(mockedRequest, "10")); + } + + @Test + public void reportSearchUserTest() throws Exception { + PowerMockito.mockStatic(AppUtils.class); + when(AppUtils.getImgFolderURL()).thenReturn("test"); + SearchHandler sh = Mockito.mock(SearchHandler.class); + whenNew(SearchHandler.class).withNoArguments().thenReturn(sh); + ReportSearchResultJSON rsrj = Mockito.mock(ReportSearchResultJSON.class); + when(sh.loadReportSearchResult(mockedRequest)).thenReturn(rsrj); + when(rsrj.getJSONString()).thenReturn("test"); + Enumeration enum1 = Mockito.mock(Enumeration.class); + HttpSession session = mockedRequest.getSession(); + when(session.getAttributeNames()).thenReturn(enum1); + assertEquals("test", actionHandler.reportSearchUser(mockedRequest, "10")); + } + + @Test + public void reportSearchPublicTest() throws Exception { + PowerMockito.mockStatic(AppUtils.class); + when(AppUtils.getImgFolderURL()).thenReturn("test"); + SearchHandler sh = Mockito.mock(SearchHandler.class); + whenNew(SearchHandler.class).withNoArguments().thenReturn(sh); + ReportSearchResultJSON rsrj = Mockito.mock(ReportSearchResultJSON.class); + when(sh.loadReportSearchResult(mockedRequest)).thenReturn(rsrj); + when(rsrj.getJSONString()).thenReturn("test"); + Enumeration enum1 = Mockito.mock(Enumeration.class); + HttpSession session = mockedRequest.getSession(); + when(session.getAttributeNames()).thenReturn(enum1); + assertEquals("test", actionHandler.reportSearchPublic(mockedRequest, "10")); + } + + @Test + public void reportSearchFavoritesTest() throws Exception { + PowerMockito.mockStatic(AppUtils.class); + when(AppUtils.getImgFolderURL()).thenReturn("test"); + SearchHandler sh = Mockito.mock(SearchHandler.class); + whenNew(SearchHandler.class).withNoArguments().thenReturn(sh); + ReportSearchResultJSON rsrj = Mockito.mock(ReportSearchResultJSON.class); + when(sh.loadReportSearchResult(mockedRequest)).thenReturn(rsrj); + when(rsrj.getJSONString()).thenReturn("test"); + Enumeration enum1 = Mockito.mock(Enumeration.class); + HttpSession session = mockedRequest.getSession(); + when(session.getAttributeNames()).thenReturn(enum1); + assertEquals("test", actionHandler.reportSearchFavorites(mockedRequest, "10")); + } + + @Test + public void reportChartDataRunTest() throws Exception { + ChartWebRuntime cwr = Mockito.mock(ChartWebRuntime.class); + whenNew(ChartWebRuntime.class).withNoArguments().thenReturn(cwr); + when(cwr.generateChart(mockedRequest)).thenReturn("testReport"); + assertEquals("testReport", actionHandler.reportChartDataRun(mockedRequest, "10")); + } + + + @Test + public void processScheduleDeleteTest() throws Exception { + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(DbUtils.class); + PowerMockito.mockStatic(Globals.class); + when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_SCHEDULE_ID)).thenReturn("test"); + when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_REPORT_ID)).thenReturn("test2"); + ReportHandler rh = Mockito.mock(ReportHandler.class); + ReportDefinition rdef = Mockito.mock(ReportDefinition.class); + whenNew(ReportHandler.class).withNoArguments().thenReturn(rh); + when(rh.loadReportDefinition(mockedRequest, "test2")).thenReturn(rdef); + when(AppUtils.getRequestNvlValue(mockedRequest, "myScheduleRepId")).thenReturn("test3"); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + ReportSchedule rs = Mockito.mock(ReportSchedule.class); + whenNew(ReportSchedule.class).withArguments(Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class)).thenReturn(rs); + Connection con = Mockito.mock(Connection.class); + when(DbUtils.startTransaction()).thenReturn(con); + PowerMockito.doNothing().when(rs).deleteScheduleData(con); + PowerMockito.doNothing().when(DbUtils.class, "commitTransaction", new Object[]{con}); + PowerMockito.doNothing().when(DbUtils.class, "clearConnection", new Object[]{con}); + when(mockedRequest.getParameter("action")).thenReturn("report.download.excel2007"); + + when(AppUtils.getRequestFlag(mockedRequest, "fromDashboard")).thenReturn(false); + when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_REFRESH)).thenReturn(true); + when(AppUtils.getRequestFlag(mockedRequest, "fromReportLog")).thenReturn(false); + when(AppUtils.getRequestNvlValue(mockedRequest, "pdfAttachmentKey")).thenReturn("test"); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + + PowerMockito.mockStatic(ESAPI.class); + Encoder encoder = PowerMockito.mock(Encoder.class); + when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + when(SecurityCodecUtil.getCodec()).thenReturn(codec); + when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); + when(Globals.getDownloadAllEmailSent()).thenReturn("test"); + DataSet set = PowerMockito.mock(DataSet.class); + when(set.isEmpty()).thenReturn(false); + when(DbUtils.executeQuery(Matchers.anyString(), Matchers.anyInt())).thenReturn(set); + when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_REPORT_ID)).thenReturn(null); + PowerMockito.mockStatic(ReportLoader.class); + when(ReportLoader.loadCustomReportXML(Matchers.anyString())).thenReturn("test"); + PowerMockito.doNothing().when(rr).logReportExecutionTime(Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class)); + assertEquals(String.class, actionHandler.processScheduleDelete(mockedRequest, "10").getClass()); + } + + @Test + public void testFormFieldRun() { + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + ReportJSONRuntime rjr = Mockito.mock(ReportJSONRuntime.class); + when(rr.createFormFieldJSONRuntime(mockedRequest)).thenReturn(rjr); + assertEquals(String.class, actionHandler.formFieldRun(mockedRequest, "10").getClass()); + } + + @Test + public void testGetReportData() throws RaptorException { + PowerMockito.mockStatic(ConnectionUtils.class); + PowerMockito.mockStatic(AppUtils.class); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + ReportFormFields rff = PowerMockito.mock(ReportFormFields.class); + FormField ff = PowerMockito.mock(FormField.class); + SemaphoreType st = PowerMockito.mock(SemaphoreType.class); + FormatList fl = PowerMockito.mock(FormatList.class); + FormatType ft = PowerMockito.mock(FormatType.class); + VisualManager visualManager = PowerMockito.mock(VisualManager.class); + List ftList = new ArrayList<>(); + ftList.add(ft); + List dctList= new ArrayList<>(); + DataColumnType dct = new DataColumnType(); + dct.setColId("1"); + dct.setDisplayName("testData"); + dct.setColType("DATE"); + dct.setDependsOnFormField("[testFieldDisplayName]"); + dct.setSemaphoreId("testSemaphoreId"); + dct.setColFormat("testColFormat"); + dct.setDrillDownURL("testDrillDownUrl"); + dct.setVisible(true); + dct.setDisplayWidthInPxls("testDisplayWidthInPxls"); + dct.setDisplayHeaderAlignment("testDisplayHeaderAlignment"); + dctList.add(dct); + when(rr.getAllColumns()).thenReturn(dctList); + when(rr.getReportFormFields()).thenReturn(rff); + when(rr.getDBInfo()).thenReturn("testDB"); + when(rr.getReportDefType()).thenReturn(AppConstants.RD_SQL_BASED); + when(rr.getSemaphoreById(Mockito.any())).thenReturn(st); + when(rr.getChildReportFormFields(Mockito.any(HttpServletRequest.class), Mockito.any(String.class))).thenReturn(rff); + when(rr.getVisualManager()).thenReturn(visualManager); + DataSet ds = PowerMockito.mock(DataSet.class); + when(ConnectionUtils.getDataSet(Mockito.any(String.class), Mockito.any(String.class))).thenReturn(ds); + when(ds.getRowCount()).thenReturn(1); + when(ds.getString(Mockito.any(Integer.class),Mockito.any(Integer.class))).thenReturn("testDataValue"); + when(rff.size()).thenReturn(1); + when(rff.getFormField(Mockito.any(Integer.class))).thenReturn(ff); + when(ff.getFieldDisplayName()).thenReturn("testFieldDisplayName"); + when(ff.getFieldName()).thenReturn("testFieldName"); + when(mockedRequest.getParameter("testFieldName")).thenReturn("testFieldValue"); + when(st.getFormatList()).thenReturn(fl); + when(st.getSemaphoreType()).thenReturn(AppConstants.ST_ROW); + when(fl.getFormat()).thenReturn(ftList); + when(ft.getLessThanValue()).thenReturn("10"); + when(visualManager.isColumnVisible(Mockito.any(String.class))).thenReturn(true); + when(visualManager.getSortByColId()).thenReturn("1"); + assertEquals(ReportData.class, actionHandler.getReportData(rr, mockedRequest, "test", 10).getClass()); + } + + @Test(expected = IOException.class) + public void testDownloadAll() throws InterruptedException, IOException, Exception { + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + PowerMockito.mockStatic(FilenameUtils.class); + PowerMockito.mockStatic(Utils.class); + PowerMockito.mockStatic(ReportRuntime.class); + when(AppUtils.getRequestValue(mockedRequest, "pdfAttachmentKey")).thenReturn("test"); + when(AppUtils.getUserEmail(mockedRequest)).thenReturn("test@mail.com"); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + when(AppUtils.getRequestValue(mockedRequest, "log_id")).thenReturn("testLogID"); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + when(Globals.getDownloadAllEmailSent()).thenReturn("testEmailSentQuery"); + when(Globals.getDownloadAllGenKey()).thenReturn("testGenerateKeyQuery"); + when(Globals.getShellScriptDir()).thenReturn("./"); + DataSet ds = PowerMockito.mock(DataSet.class); + when(DbUtils.executeQuery(Mockito.any(String.class), Mockito.eq(1))).thenReturn(ds); + when(DbUtils.executeQuery(Mockito.any(String.class))).thenReturn(ds); + when(ds.isEmpty()).thenReturn(false); + when(ds.getString(0,"user_id")).thenReturn("testUserID"); + when(ds.getString(0,"rep_id")).thenReturn("testReportID"); + when(ds.getRowCount()).thenReturn(1); + when(ds.getString(0,0)).thenReturn("testScheduleId"); + when(FilenameUtils.normalize(Mockito.any(String.class))).thenReturn("testFile.txt"); + when(Utils.isDownloadFileExists(Mockito.any(String.class))).thenReturn(true); + when(Utils.getLatestDownloadableFile(Mockito.any(String.class))).thenReturn("testLastDownloadedFile.txt"); + List dctList= new ArrayList<>(); + DataColumnType dct = new DataColumnType(); + dct.setDisplayName("testData"); + dctList.add(dct); + when(rr.getAllColumns()).thenReturn(dctList); + when(mockedRequest.getParameter("refresh")).thenReturn("N"); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + when(rr.getReportID()).thenReturn("testReportID"); + actionHandler.downloadAll(mockedRequest, "10"); + } + + @Test + public void testRunSQLPopup() throws ReportSQLException { + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(Utils.class); + PowerMockito.mockStatic(ConnectionUtils.class); + when(AppUtils.getRequestNvlValue(mockedRequest, AppConstants.RI_FORMATTED_SQL)).thenReturn("SELECT * FROM TEST"); + when(AppUtils.getRequestNvlValue(mockedRequest,AppConstants.RI_CHK_FIELD_SQL)).thenReturn("N"); + ReportDefinition rdef = PowerMockito.mock(ReportDefinition.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION)).thenReturn(rdef); + FormFieldType formFieldType = new FormFieldType(); + formFieldType.setFieldId("test"); + formFieldType.setColId("1"); + formFieldType.setFieldName("test"); + formFieldType.setFieldType("type"); + formFieldType.setValidationType("validation"); + formFieldType.setMandatory("Y"); + formFieldType.setDefaultValue("test"); + formFieldType.setGroupFormField(true); + FormFieldList formFieldList = PowerMockito.mock(FormFieldList.class); + formFieldList.getFormField().add(formFieldType); + when(rdef.getFormFieldList()).thenReturn(formFieldList); + when(rdef.getFormFieldDisplayName(formFieldType)).thenReturn("testField"); + when(mockedRequest.getParameter("remoteDbPrefix")).thenReturn("testDB"); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + when(Utils.replaceInString(Mockito.any(String.class),Mockito.any(String.class),Mockito.any(String.class))).thenReturn("testString"); + when(Globals.getRequestParams()).thenReturn("test"); + when(Globals.getSessionParams()).thenReturn("test"); + DataSet ds = PowerMockito.mock(DataSet.class); + when(ConnectionUtils.getDataSet(Mockito.any(String.class), Mockito.any(String.class), Mockito.eq(true))).thenReturn(ds); + when(ds.getRowCount()).thenReturn(1); + when(ds.getString(Mockito.any(Integer.class),Mockito.any(Integer.class))).thenReturn("testDataValue"); + PowerMockito.mockStatic(ESAPI.class); + Encoder encoder = PowerMockito.mock(Encoder.class); + when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + when(SecurityCodecUtil.getCodec()).thenReturn(codec); + when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); + actionHandler.testRunSQLPopup(mockedRequest, "10"); + } + + @Test + public void testSchedCondPopup() throws RaptorException { + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(ConnectionUtils.class); + ReportDefinition rdef = PowerMockito.mock(ReportDefinition.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION)).thenReturn(rdef); + when(AppUtils.getRequestNvlValue(mockedRequest, AppConstants.RI_FORMATTED_SQL)).thenReturn("testSQL"); + when(Globals.getTestSchedCondPopup()).thenReturn("testQuery"); + when(mockedRequest.getParameter("remoteDbPrefix")).thenReturn("testDB"); + DataSet ds = PowerMockito.mock(DataSet.class); + when(ConnectionUtils.getDataSet(Mockito.any(String.class), Mockito.any(String.class))).thenReturn(ds); + when(ds.getRowCount()).thenReturn(1); + actionHandler.testSchedCondPopup(mockedRequest, "10"); + } + + @Test + public void testReportShowSQLPopup() throws RaptorException { + PowerMockito.mockStatic(AppUtils.class); + ReportDefinition rdef = PowerMockito.mock(ReportDefinition.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION)).thenReturn(rdef); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + when(rdef.generateSQL(Mockito.any(String.class),Mockito.any(HttpServletRequest.class))).thenReturn("testReportSQL"); + actionHandler.reportShowSQLPopup(mockedRequest, "10"); + } + + + @Test + public void testReportFilterDataPopup() throws RaptorException { + PowerMockito.mockStatic(AppUtils.class); + ReportDefinition rdef = PowerMockito.mock(ReportDefinition.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION)).thenReturn(rdef); + when(AppUtils.getRequestNvlValue(mockedRequest, AppConstants.RI_COLUMN_ID)).thenReturn("testColID"); + when(rdef.getDBInfo()).thenReturn(null); + when(mockedRequest.getSession().getAttribute("remoteDB")).thenReturn("testDB"); + when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_RESET_PARAMS)).thenReturn(false); + IdNameColLookup lookUp = Mockito.mock(IdNameColLookup.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_COLUMN_LOOKUP)).thenReturn(lookUp); + when(lookUp.getColId()).thenReturn("testColID"); + when(AppUtils.getRequestNvlValue(mockedRequest, AppConstants.RI_SEARCH_STRING)).thenReturn("testSearchStr"); + when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_CONTAIN_FLAG)).thenReturn(true); + actionHandler.reportFilterDataPopup(mockedRequest, "10"); + } + + @Test + public void testReportImportSave() throws Exception { + PowerMockito.mockStatic(AppUtils.class); + String str = "namedesctypefalsefalseidfalse"; + when(AppUtils.getRequestValue(mockedRequest, "reportXML")).thenReturn(str); + ReportHandler rh = Mockito.mock(ReportHandler.class); + ReportDefinition rdef = Mockito.mock(ReportDefinition.class); + whenNew(ReportHandler.class).withNoArguments().thenReturn(rh); + when(rh.createReportDefinition(mockedRequest, "-1", str)).thenReturn(rdef); + PowerMockito.doNothing().when(rdef).updateReportDefType(); + PowerMockito.doNothing().when(rdef).generateWizardSequence(mockedRequest); + when(rdef.getReportName()).thenReturn("test"); + PowerMockito.doNothing().when(rdef).setReportName("Import: test"); + PowerMockito.doNothing().when(rdef).clearAllDrillDowns(); + actionHandler.reportImportSave(mockedRequest, "10"); + } + + @Test + public void testProcessSchedule() throws RaptorException { + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.mockStatic(DbUtils.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_SCHEDULE)).thenReturn("test"); + when(AppUtils.getRequestNvlValue(mockedRequest, AppConstants.RI_ACTION)).thenReturn("test"); + when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_SCHEDULE_ID)).thenReturn(""); + ReportSchedule rs = Mockito.mock(ReportSchedule.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_SCHEDULE)).thenReturn(rs); + when(rs.getScheduleID()).thenReturn("testSchecduleID"); + when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_REPORT_ID)).thenReturn("testReportID"); + when(AppUtils.isAdminUser(mockedRequest)).thenReturn(true); + when(ReportLoader.doesUserCanScheduleReport(Mockito.any(HttpServletRequest.class), Mockito.any(String.class))).thenReturn(true); + when(rs.getFormFields()).thenReturn("testField"); + when(Globals.getSessionParamsForScheduling()).thenReturn("test"); + Connection con = Mockito.mock(Connection.class); + when(DbUtils.startTransaction()).thenReturn(con); + actionHandler.processSchedule(mockedRequest, "10"); + } + + @Test(expected=RuntimeException.class) + public void testProcessSchedule_WhenReportScheduleIsNull() throws RaptorException { + PowerMockito.mockStatic(AppUtils.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_SCHEDULE)).thenReturn(null); + when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_REPORT_ID)).thenReturn(""); + ReportDefinition rdef = PowerMockito.mock(ReportDefinition.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION)).thenReturn(rdef); + actionHandler.processSchedule(mockedRequest, "10"); + } + + @Test + public void testReportValuesMapDefPopup() throws RaptorException { + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(ConnectionUtils.class); + ReportDefinition rdef = PowerMockito.mock(ReportDefinition.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION)).thenReturn(rdef); + when(AppUtils.getRequestNvlValue(mockedRequest, "colName")).thenReturn("testCol"); + when(AppUtils.getRequestNvlValue(mockedRequest, "displayName")).thenReturn("testDisplayName"); + when(AppUtils.getRequestNvlValue(mockedRequest, "displayFormat")).thenReturn("testDisplayFormat"); + when(AppUtils.getRequestNvlValue(mockedRequest, "tableId")).thenReturn("testTableId"); + when(mockedRequest.getSession().getAttribute("remoteDB")).thenReturn("testDB"); + when(Globals.getReportValuesMapDefA()).thenReturn("testA"); + when(Globals.getReportValuesMapDefB()).thenReturn("testB"); + when(Globals.getReportValuesMapDefC()).thenReturn("testC"); + when(Globals.getReportValuesMapDefD()).thenReturn("testD"); + when(Globals.getDefaultPageSize()).thenReturn(10); + DataSourceType ds = Mockito.mock(DataSourceType.class); + when(ds.getTableName()).thenReturn("testTable"); + when(rdef.getTableById(Mockito.any(String.class))).thenReturn(ds); + DataSet data = Mockito.mock(DataSet.class); + when(ConnectionUtils.getDataSet(Mockito.any(String.class), Mockito.any(String.class))).thenReturn(data); + actionHandler.reportValuesMapDefPopup(mockedRequest, "10"); + } + + @Test + public void testReportFormFieldPopup() { + PowerMockito.mockStatic(AppUtils.class); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + FormField formField = new FormField("test", "fieldDisplayName", FormField.FFT_COMBO_BOX, "validationType", false, + "defaultValue", "helpText", new ArrayList<>(), false, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + when(rr.getFormField(Mockito.any(String.class))).thenReturn(formField); + ReportFormFields rff = PowerMockito.mock(ReportFormFields.class); + when(rr.getReportFormFields()).thenReturn(rff); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + IdNameList lookup = Mockito.mock(IdNameList.class); + when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_TEXTFIELD_POP)).thenReturn(true); + actionHandler.reportFormFieldPopup(mockedRequest, "10"); + } + + @Test + public void testReportCreate() throws Exception { + PowerMockito.mockStatic(ReportDefinition.class); + PowerMockito.mockStatic(DataCache.class); + Enumeration enum1 = Mockito.mock(Enumeration.class); + HttpSession session = mockedRequest.getSession(); + when(session.getAttributeNames()).thenReturn(enum1); + ReportDefinition rdef = PowerMockito.mock(ReportDefinition.class); + when(ReportDefinition.createBlank(mockedRequest)).thenReturn(rdef); + PowerMockito.doNothing().when(DataCache.class, "refreshReportTableSources", new Object[]{}); + actionHandler.reportCreate(mockedRequest, "10"); + } + + @Test + public void testRefreshCache() throws Exception { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DataCache.class); + Enumeration enum1 = Mockito.mock(Enumeration.class); + HttpSession session = mockedRequest.getSession(); + when(session.getAttributeNames()).thenReturn(enum1); + PowerMockito.doNothing().when(DataCache.class, "refreshAll", new Object[]{}); + IAppUtils iau = Mockito.mock(IAppUtils.class); + when(Globals.getAppUtils()).thenReturn(iau); + PowerMockito.doNothing().when(iau).resetUserCache(); + actionHandler.refreshCache(mockedRequest, "10"); + } + + @Test + public void testProcessScheduleReportListd() throws Exception { + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(ReportLoader.class); + when(AppUtils.getRequestNvlValue(mockedRequest, "schedule_reports")).thenReturn("reportID"); + when(AppUtils.isAdminUser(mockedRequest)).thenReturn(true); + when(ReportLoader.doesUserCanScheduleReport(mockedRequest, null)).thenReturn(true); + ReportDefinition rdef = PowerMockito.mock(ReportDefinition.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION)).thenReturn(rdef); + when(rdef.getReportID()).thenReturn("reportID"); + actionHandler.processScheduleReportList(mockedRequest, "10"); + } + + + @Test + public void testGetQuickLinksJSON() throws Exception { + PowerMockito.mockStatic(SecurityCodecUtil.class); + PowerMockito.mockStatic(ESAPI.class); + PowerMockito.mockStatic(ReportLoader.class); + Encoder encoder = PowerMockito.mock(Encoder.class); + when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + when(SecurityCodecUtil.getCodec()).thenReturn(codec); + when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); + ArrayList qList = new ArrayList(); + qList.add(new QuickLink()); + when(ReportLoader.getQuickLinksJSON(Mockito.any(HttpServletRequest.class), Mockito.any(String.class), Mockito.eq(true))).thenReturn(qList); + actionHandler.getQuickLinksJSON(mockedRequest, "10"); + } + +} -- cgit 1.2.3-korg