diff options
author | 2018-03-20 11:50:44 -0400 | |
---|---|---|
committer | 2018-03-20 11:50:44 -0400 | |
commit | 996036b832bca89a197fe496c666057835ce043c (patch) | |
tree | 525804169287b7bc177e6d2be0060a1695282dcf /ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/xmlobj | |
parent | 50125440c5371ae710674fec2b8d8f817aa1b4e4 (diff) |
Added Junits
Issue-ID: PORTAL-136
Includes JUNITS
Change-Id: I1a0109649d32c3031ce441a873dbfdda2d6cc011
Change-Id: I1a0109649d32c3031ce441a873dbfdda2d6cc011
Signed-off-by: Kishore Reddy, Gujja (kg811t) <kg811t@research.att.com>
Diffstat (limited to 'ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/xmlobj')
-rw-r--r-- | ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/xmlobj/ActionHandlerTest.java | 547 |
1 files changed, 547 insertions, 0 deletions
diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/xmlobj/ActionHandlerTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/xmlobj/ActionHandlerTest.java new file mode 100644 index 00000000..dae5a90d --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/xmlobj/ActionHandlerTest.java @@ -0,0 +1,547 @@ +/* + * ============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.xmlobj; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; +import static org.powermock.api.mockito.PowerMockito.whenNew; + +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.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Vector; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.junit.Before; +import org.junit.Ignore; +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.controller.ActionHandler; +import org.onap.portalsdk.analytics.model.ReportLoader; +import org.onap.portalsdk.analytics.model.SearchHandler; +import org.onap.portalsdk.analytics.model.base.ReportWrapper; +import org.onap.portalsdk.analytics.model.definition.ReportDefinition; +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.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.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 }) +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(); + + + @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 reportRunRaptorReportExceptionTest() 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("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 = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><CustomReportType xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xsi:type=\"xs:string\"><reportName>name</reportName><reportDescr>desc</reportDescr><chartType>type</chartType><showChartTitle>false</showChartTitle><public>false</public><createId>id</createId><pageNav>false</pageNav></CustomReportType>"; + 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<DataSourceType> list = new ArrayList<>(); + DataSourceType dataSourceType = new DataSourceType(); + dataSourceType.setTableName("test"); + dataSourceType.setRefTableId("1"); + dataSourceType.setTableId("1"); + List<DataColumnType> 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<String> enums; + Vector<String> attrs = new Vector<String>(); + attrs.add("ff_test"); + enums = attrs.elements(); + when(rr.getParamKeys()).thenReturn(enums); + assertEquals(actionHandler.reportRun(mockedRequest, "test").getClass(), String.class); + } + + + @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); + } + + 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<DataColumnType> 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(ESAPI.class); + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + when(AppUtils.getImgFolderURL()).thenReturn("test"); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_F_REPORT_ID)).thenReturn("test"); + when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_F_REPORT_NAME)).thenReturn("test"); + when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_SORT_ORDER)).thenReturn("f_owner_id"); + when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_LIST_CATEGORY)).thenReturn("test"); + when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_USER_REPORTS)).thenReturn(true); + when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_PUBLIC_REPORTS)).thenReturn(true); + when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_FAVORITE_REPORTS)).thenReturn(true); + when(AppUtils.nvl(Matchers.anyString())).thenReturn("te"); + when(Globals.getLoadReportSearchResult()).thenReturn("test"); + when(Globals.getLoadReportSearchRepIdSql()).thenReturn("test"); + when(Globals.getLoadReportSearchInstr()).thenReturn("test"); + when(Globals.getLoadReportSearchResultUser()).thenReturn("test"); + when(Globals.getLoadReportSearchResultPublic()).thenReturn("test"); + when(Globals.getLoadReportSearchResultFav()).thenReturn("test"); + when(Globals.getLoadReportSearchResultSort()).thenReturn("test"); + when(AppUtils.getRequestNvlValue(mockedRequest, "r_page")).thenReturn("10"); + Vector<String> vc = new Vector<>(); + vc.add("test"); + vc.add("test2"); + when(AppUtils.getUserRoles(mockedRequest)).thenReturn(vc); + when(AppUtils.isSuperUser(mockedRequest)).thenReturn(false); + DataSet set = Mockito.mock(DataSet.class); + when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(set); + Enumeration<String> enums; + Vector<String> attrs = new Vector<String>(); + attrs.add("parent_test"); + attrs.add("child_test"); + enums = attrs.elements(); + when(mockedRequest.getSession().getAttributeNames()).thenReturn(enums); + when(mockedRequest.getParameter("rep_id")).thenReturn("test"); + when(mockedRequest.getParameter("rep_id_options")).thenReturn("test"); + when(mockedRequest.getParameter("rep_name_options")).thenReturn("test"); + when(mockedRequest.getParameter("rep_name")).thenReturn("test"); + SearchHandler sh = Mockito.mock(SearchHandler.class); + whenNew(SearchHandler.class).withNoArguments().thenReturn(sh); + actionHandler.reportSearch(mockedRequest, "10"); + } + + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Test(expected = NullPointerException.class) + public void reportChartRunTest() throws Exception { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.mockStatic(ReportWrapper.class); + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(ReportDefinition.class); + PowerMockito.mockStatic(ESAPI.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + PowerMockito.mockStatic(UserUtils.class); + when(UserUtils.getUserId(mockedRequest)).thenReturn(1); + when(AppUtils.isAdminUser(mockedRequest)).thenReturn(true); + when(AppUtils.isSuperUser(mockedRequest)).thenReturn(true); + Map roles = new HashMap<>(); + roles.put("role1", "test1"); + roles.put("role2", "test2"); + when(UserUtils.getRoles(mockedRequest)).thenReturn(roles); + when(mockedRequest.getParameter(AppConstants.RI_ACTION)).thenReturn("chart.data.json"); + ChartWebRuntime cwr = Mockito.mock(ChartWebRuntime.class); + whenNew(ChartWebRuntime.class).withNoArguments().thenReturn(cwr); + when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_REPORT_ID)).thenReturn("test"); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(DbUtils.getConnection()).thenReturn(connection); + when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_REPORT_ID)).thenReturn("1"); + 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 = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><CustomReportType xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xsi:type=\"xs:string\"><reportType>Hive</reportType><reportName>name</reportName><reportDescr>desc</reportDescr><chartType>type</chartType><showChartTitle>false</showChartTitle><public>false</public><createId>id</createId><pageNav>false</pageNav></CustomReportType>"; + 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.getRequestNvlValue(mockedRequest, "pdfAttachmentKey")).thenReturn("test"); + when(AppUtils.nvl(rr.getLegendLabelAngle())).thenReturn("standard"); + when(AppUtils.getRequestNvlValue(Matchers.any(), Matchers.anyString())).thenReturn("test"); + 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); + PowerMockito.mockStatic(ReportDefinition.class); + 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]"); + DataSet set = PowerMockito.mock(DataSet.class); + when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(set); + when(set.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); + whenNew(ReportRuntime.class).withArguments(Matchers.any(CustomReportType.class), Matchers.anyString(), + Matchers.any(HttpServletRequest.class), Matchers.anyString(), Matchers.anyString(), + Matchers.anyString(), Matchers.anyString(), Matchers.anyString(), Matchers.anyString(), + Matchers.anyBoolean()).thenReturn(rr); + DataSourceList dsl = Mockito.mock(DataSourceList.class); + List<DataSourceType> list = new ArrayList<>(); + DataSourceType sr1 = new DataSourceType(); + sr1.setComment("test"); + sr1.setRefDefinition("test"); + sr1.setDataColumnList(new DataColumnList()); + sr1.setTableId("test"); + sr1.setTableName("test"); + list.add(sr1); + when(crType.getDataSourceList()).thenReturn(dsl); + when(dsl.getDataSource()).thenReturn(list); + DashboardReports rps = Mockito.mock(DashboardReports.class); + List<Reports> reportList = new ArrayList<>(); + Reports rp = new Reports(); + rp.setBgcolor("white"); + rp.setReportId("1"); + reportList.add(rp); + when(rdf.getDashBoardReports()).thenReturn(rps); + when(rps.getReportsList()).thenReturn(reportList); + when(ReportLoader.loadCustomReportXML("1")).thenReturn(str); + actionHandler.reportChartRun(mockedRequest, "10"); + } +} |