2c9a30b08b0b69f249d9bacc160e64d75d2678f3
[portal/sdk.git] /
1 /*
2  * ============LICENSE_START==========================================
3  * ONAP Portal SDK
4  * ===================================================================
5  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
8  * Unless otherwise specified, all software contained herein is licensed
9  * under the Apache License, Version 2.0 (the "License");
10  * you may not use this software except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  * Unless otherwise specified, all documentation contained herein is licensed
22  * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23  * you may not use this documentation except in compliance with the License.
24  * You may obtain a copy of the License at
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
28  * Unless required by applicable law or agreed to in writing, documentation
29  * distributed under the License is distributed on an "AS IS" BASIS,
30  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31  * See the License for the specific language governing permissions and
32  * limitations under the License.
33  *
34  * ============LICENSE_END============================================
35  *
36  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
37  */
38 package org.onap.portalsdk.analytics.controller;
39
40 import static org.junit.Assert.assertEquals;
41 import static org.mockito.Mockito.when;
42 import static org.powermock.api.mockito.PowerMockito.whenNew;
43
44 import java.io.InputStream;
45 import java.sql.Connection;
46 import java.sql.PreparedStatement;
47 import java.sql.ResultSet;
48 import java.sql.ResultSetMetaData;
49 import java.util.ArrayList;
50 import java.util.Enumeration;
51 import java.util.HashMap;
52 import java.util.List;
53 import java.util.Map;
54 import java.util.Vector;
55
56 import javax.servlet.http.HttpServletRequest;
57 import javax.servlet.http.HttpServletResponse;
58 import javax.servlet.http.HttpSession;
59
60 import org.junit.Before;
61 import org.junit.Test;
62 import org.junit.runner.RunWith;
63 import org.mockito.InjectMocks;
64 import org.mockito.Matchers;
65 import org.mockito.Mock;
66 import org.mockito.Mockito;
67 import org.mockito.MockitoAnnotations;
68 import org.onap.portalsdk.analytics.model.ReportLoader;
69 import org.onap.portalsdk.analytics.model.SearchHandler;
70 import org.onap.portalsdk.analytics.model.base.ReportWrapper;
71 import org.onap.portalsdk.analytics.model.definition.ReportDefinition;
72 import org.onap.portalsdk.analytics.model.runtime.ChartWebRuntime;
73 import org.onap.portalsdk.analytics.model.runtime.ReportRuntime;
74 import org.onap.portalsdk.analytics.system.AppUtils;
75 import org.onap.portalsdk.analytics.system.DbUtils;
76 import org.onap.portalsdk.analytics.system.Globals;
77 import org.onap.portalsdk.analytics.util.AppConstants;
78 import org.onap.portalsdk.analytics.util.DataSet;
79 import org.onap.portalsdk.analytics.xmlobj.ChartAdditionalOptions;
80 import org.onap.portalsdk.analytics.xmlobj.CustomReportType;
81 import org.onap.portalsdk.analytics.xmlobj.DashboardReports;
82 import org.onap.portalsdk.analytics.xmlobj.DataColumnList;
83 import org.onap.portalsdk.analytics.xmlobj.DataColumnType;
84 import org.onap.portalsdk.analytics.xmlobj.DataSourceList;
85 import org.onap.portalsdk.analytics.xmlobj.DataSourceType;
86 import org.onap.portalsdk.analytics.xmlobj.MockitoTestSuite;
87 import org.onap.portalsdk.analytics.xmlobj.Reports;
88 import org.onap.portalsdk.core.logging.format.AlarmSeverityEnum;
89 import org.onap.portalsdk.core.util.SecurityCodecUtil;
90 import org.onap.portalsdk.core.web.support.UserUtils;
91 import org.owasp.esapi.ESAPI;
92 import org.owasp.esapi.Encoder;
93 import org.owasp.esapi.codecs.Codec;
94 import org.powermock.api.mockito.PowerMockito;
95 import org.powermock.core.classloader.annotations.PrepareForTest;
96 import org.powermock.modules.junit4.PowerMockRunner;
97
98 @RunWith(PowerMockRunner.class)
99 @PrepareForTest({ AppUtils.class, UserUtils.class, ESAPI.class, AppConstants.class, AlarmSeverityEnum.class, ReportWrapper.class,
100                 ReportDefinition.class, SecurityCodecUtil.class, Globals.class, DbUtils.class, ReportLoader.class })
101 public class ActionHandlerTest {
102
103         @InjectMocks
104         ActionHandler actionHandler = new ActionHandler();
105
106         @Mock
107         Connection connection;
108         @Mock
109         PreparedStatement stmt;
110         @Mock
111         ResultSet rs;
112         @Mock
113         java.sql.Clob clob;
114         @Mock
115         InputStream in;
116
117         @Before
118         public void setup() {
119                 MockitoAnnotations.initMocks(this);
120         }
121
122         MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
123         HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
124         HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
125
126         @Test
127         public void reportRunExceptionTest() {
128                 when(mockedRequest.getParameter("action")).thenReturn("test");
129                 PowerMockito.mockStatic(AppUtils.class);
130                 when(AppUtils.getRequestFlag(mockedRequest, "fromDashboard")).thenReturn(true);
131                 assertEquals(actionHandler.reportRun(mockedRequest, "test").getClass(), String.class);
132         }
133
134         @Test
135         public void reportRunRaptorReportExceptionTest() throws Exception {
136                 PowerMockito.mockStatic(Globals.class);
137                 PowerMockito.mockStatic(DbUtils.class);
138                 PowerMockito.mockStatic(ReportLoader.class);
139                 PowerMockito.mockStatic(ReportWrapper.class);
140                 PowerMockito.mockStatic(AppUtils.class);
141                 PowerMockito.mockStatic(ReportDefinition.class);
142                 PowerMockito.mockStatic(ESAPI.class);
143                 PowerMockito.mockStatic(SecurityCodecUtil.class);
144                 when(mockedRequest.getParameter("action")).thenReturn("test");
145                 when(AppUtils.getRequestFlag(mockedRequest, "fromDashboard")).thenReturn(false);
146                 when(AppUtils.getRequestNvlValue(mockedRequest, "pdfAttachmentKey")).thenReturn("test");
147                 ReportRuntime rr = PowerMockito.mock(ReportRuntime.class);
148                 when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr);
149                 Encoder encoder = PowerMockito.mock(Encoder.class);
150                 when(ESAPI.encoder()).thenReturn(encoder);
151                 Codec codec = PowerMockito.mock(Codec.class);
152                 when(SecurityCodecUtil.getCodec()).thenReturn(codec);
153                 when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *");
154                 when(Globals.getDownloadAllEmailSent()).thenReturn("test");
155                 DataSet set = Mockito.mock(DataSet.class);
156                 when(DbUtils.executeQuery(Matchers.anyString(), Matchers.anyInt())).thenReturn(set);
157                 when(DbUtils.getConnection()).thenReturn(connection);
158                 when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_REPORT_ID)).thenReturn("test2");
159                 when(rr.getReportID()).thenReturn("test");
160                 when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_SHOW_BACK_BTN)).thenReturn(true);
161                 when(Globals.getLoadCustomReportXml()).thenReturn("java.lang.String");
162                 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>";
163                 when(connection.prepareStatement("1")).thenReturn(stmt);
164                 when(stmt.executeQuery()).thenReturn(rs);
165                 when(Globals.isWeblogicServer()).thenReturn(true);
166                 when(rs.getClob(1)).thenReturn(clob);
167                 when(rs.next()).thenReturn(true);
168                 when(clob.getAsciiStream()).thenReturn(in);
169                 when(in.read(Matchers.any())).thenReturn(1);
170                 when(AppUtils.getRequestNvlValue(mockedRequest, "pdfAttachmentKey")).thenReturn("test");
171                 when(AppUtils.nvl(rr.getLegendLabelAngle())).thenReturn("standard");
172                 when(AppUtils.getRequestNvlValue(Matchers.any(), Matchers.anyString())).thenReturn("test");
173                 when(AppUtils.nvl("Y")).thenReturn("Y");
174                 when(AppUtils.nvl("bottom")).thenReturn("Y");
175                 when(AppUtils.nvl("test")).thenReturn("test|");
176                 when(AppUtils.getRequestValue(mockedRequest, "c_dashboard")).thenReturn("1");
177                 when(ReportLoader.isDashboardType("-1")).thenReturn(false);
178                 ReportDefinition rdf = PowerMockito.mock(ReportDefinition.class);
179                 whenNew(ReportDefinition.class)
180                                 .withArguments(Matchers.any(ReportWrapper.class), Matchers.any(HttpServletRequest.class))
181                                 .thenReturn(rdf);
182                 when(ReportDefinition.unmarshal(Mockito.anyString(), Mockito.anyString(), Mockito.anyObject())).thenReturn(rdf);
183                 CustomReportType crType = Mockito.mock(CustomReportType.class);
184                 when(ReportWrapper.unmarshalCR(Matchers.anyString())).thenReturn(crType);
185                 when(Globals.getReportWrapperFormat()).thenReturn("[Globals.getTimeFormat()]");
186                 when(Globals.getTimeFormat()).thenReturn("[reportID]");
187                 when(Globals.getReportUserAccess()).thenReturn("[reportID]");
188                 when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(set);
189                 when(set.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test");
190                 whenNew(ReportRuntime.class).withArguments(Matchers.any(CustomReportType.class), Matchers.anyString(),
191                                 Matchers.any(HttpServletRequest.class), Matchers.anyString(), Matchers.anyString(),
192                                 Matchers.anyString(), Matchers.anyString(), Matchers.anyString(), Matchers.anyString(),
193                                 Matchers.anyBoolean()).thenReturn(rr);
194                 when(ReportLoader.loadCustomReportXML("test2")).thenReturn(str);
195
196                 assertEquals(actionHandler.reportRun(mockedRequest, "test").getClass(), String.class);
197         }
198
199         @Test
200         public void reportRunForCSVDownloadTest() throws Exception {
201                 when(mockedRequest.getParameter("action")).thenReturn("test");
202                 when(mockedRequest.getParameter("r_action")).thenReturn("report.csv.download");
203                 PowerMockito.mockStatic(AppUtils.class);
204                 PowerMockito.mockStatic(Globals.class);
205                 PowerMockito.mockStatic(DbUtils.class);
206
207                 when(AppUtils.getRequestFlag(mockedRequest, "fromDashboard")).thenReturn(false);
208                 when(AppUtils.getRequestNvlValue(mockedRequest, "pdfAttachmentKey")).thenReturn("");
209                 ReportRuntime rr = PowerMockito.mock(ReportRuntime.class);
210                 when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr);
211                 when(AppUtils.getUserID(mockedRequest)).thenReturn("test");
212                 when(AppUtils.getRequestFlag(mockedRequest, "fromReportLog")).thenReturn(true);
213                 when(rr.getReportType()).thenReturn(AppConstants.RT_LINEAR);
214                 when(rr.getReportDataSQL(Matchers.anyString(), Matchers.anyInt(), Matchers.any())).thenReturn("test");
215                 PowerMockito.mockStatic(ESAPI.class);
216                 Encoder encoder = PowerMockito.mock(Encoder.class);
217                 when(ESAPI.encoder()).thenReturn(encoder);
218                 Codec codec = PowerMockito.mock(Codec.class);
219                 PowerMockito.mockStatic(SecurityCodecUtil.class);
220                 when(SecurityCodecUtil.getCodec()).thenReturn(codec);
221                 when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *");
222                 when(Globals.getDownloadAllEmailSent()).thenReturn("test");
223                 DataSet set = new DataSet();
224                 when(DbUtils.executeQuery(Matchers.anyString(), Matchers.anyInt())).thenReturn(set);
225                 assertEquals(actionHandler.reportRun(mockedRequest, "test").getClass(), String.class);
226         }
227
228         public ReportRuntime mockReportRunTime1() throws Exception {
229                 PowerMockito.mockStatic(Globals.class);
230                 PowerMockito.mockStatic(DbUtils.class);
231                 when(Globals.getReportUserAccess()).thenReturn("test");
232                 ResultSet rs = PowerMockito.mock(ResultSet.class);
233                 ResultSetMetaData rsmd = PowerMockito.mock(ResultSetMetaData.class);
234                 when(rsmd.getColumnCount()).thenReturn(1);
235                 when(rs.getMetaData()).thenReturn(rsmd);
236                 DataSet datset = PowerMockito.mock(DataSet.class);
237                 // datset = new DataSet(rs);
238                 when(datset.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn(null);
239                 when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(datset);
240                 when(Globals.getNewScheduleData()).thenReturn("test");
241                 CustomReportType customReportType = new CustomReportType();
242                 DataSourceList dataSourceList = new DataSourceList();
243                 DataSourceType dataSourceType = new DataSourceType();
244                 dataSourceType.setTableName("test");
245                 dataSourceType.setRefTableId("1");
246                 dataSourceType.setTableId("1");
247                 List<DataColumnType> dataColumnTypeList = new ArrayList<>();
248                 DataColumnType dataColumnType = new DataColumnType();
249                 dataColumnType.setChartGroup("test");
250                 dataColumnType.setYAxis("test");
251                 dataColumnType.setColName("[test");
252                 dataColumnType.setColOnChart("LEGEND");
253                 dataColumnType.setDisplayName("chart_total");
254                 dataColumnType.setColId("1");
255                 dataColumnType.setTableId("1");
256                 dataColumnType.setColType("DATE");
257                 dataColumnTypeList.add(dataColumnType);
258                 customReportType.setReportType("test");
259                 customReportType.setReportTitle("test");
260                 customReportType.setDataSourceList(dataSourceList);
261                 ChartAdditionalOptions chartAdditionalOptions = new ChartAdditionalOptions();
262                 chartAdditionalOptions.setLabelAngle("test");
263                 chartAdditionalOptions.setTimeSeriesRender("test");
264                 chartAdditionalOptions.setMultiSeries(false);
265                 customReportType.setChartAdditionalOptions(chartAdditionalOptions);
266                 ReportWrapper reportWrapper = new ReportWrapper(customReportType, "-1", "test", "testId", "test", "test", "1",
267                                 "1", true);
268                 PowerMockito.mockStatic(UserUtils.class);
269                 when(Globals.getRequestParams()).thenReturn("test");
270                 when(Globals.getSessionParams()).thenReturn("test");
271                 when(Globals.getSessionParamsForScheduling()).thenReturn("test");
272                 PowerMockito.mockStatic(AppUtils.class);
273                 when(AppUtils.getUserID(mockedRequest)).thenReturn("test12");
274                 ReportRuntime rr = new ReportRuntime(reportWrapper, mockedRequest);
275                 rr.setLegendLabelAngle("test");
276                 rr.setMultiSeries(false);
277                 rr.setChartType("test");
278                 return rr;
279         }
280
281         @Test
282         public void reportRunTestCase1() throws Exception {
283                 when(mockedRequest.getParameter("action")).thenReturn("test");
284                 PowerMockito.mockStatic(AppUtils.class);
285                 PowerMockito.mockStatic(Globals.class);
286                 PowerMockito.mockStatic(DbUtils.class);
287
288                 when(AppUtils.getRequestFlag(mockedRequest, "fromDashboard")).thenReturn(false);
289                 when(AppUtils.getRequestNvlValue(mockedRequest, "pdfAttachmentKey")).thenReturn("test");
290                 ReportRuntime rr = PowerMockito.mock(ReportRuntime.class);
291                 when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr);
292
293                 PowerMockito.mockStatic(ESAPI.class);
294                 Encoder encoder = PowerMockito.mock(Encoder.class);
295                 when(ESAPI.encoder()).thenReturn(encoder);
296                 Codec codec = PowerMockito.mock(Codec.class);
297                 PowerMockito.mockStatic(SecurityCodecUtil.class);
298                 when(SecurityCodecUtil.getCodec()).thenReturn(codec);
299                 when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *");
300                 when(Globals.getDownloadAllEmailSent()).thenReturn("test");
301                 DataSet set = PowerMockito.mock(DataSet.class);
302                 when(set.isEmpty()).thenReturn(false);
303                 when(DbUtils.executeQuery(Matchers.anyString(), Matchers.anyInt())).thenReturn(set);
304                 when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_REPORT_ID)).thenReturn(null);
305                 PowerMockito.mockStatic(ReportLoader.class);
306                 when(ReportLoader.loadCustomReportXML(Matchers.anyString())).thenReturn("test");
307                 assertEquals(actionHandler.reportRun(mockedRequest, "test").getClass(), String.class);
308         }
309
310         @Test
311         public void reportDeleteTest() throws Exception {
312                 PowerMockito.mockStatic(ESAPI.class);
313                 PowerMockito.mockStatic(AppUtils.class);
314                 PowerMockito.mockStatic(Globals.class);
315                 PowerMockito.mockStatic(DbUtils.class);
316                 PowerMockito.mockStatic(AlarmSeverityEnum.class);
317                 DataSet set = Mockito.mock(DataSet.class);
318                 Encoder encoder = PowerMockito.mock(Encoder.class);
319                 ReportRuntime rr = PowerMockito.mock(ReportRuntime.class);
320                 ReportDefinition rd = PowerMockito.mock(ReportDefinition.class);
321                 when(ESAPI.encoder()).thenReturn(encoder);
322                 Codec codec = PowerMockito.mock(Codec.class);
323                 PowerMockito.mockStatic(SecurityCodecUtil.class);
324                 when(SecurityCodecUtil.getCodec()).thenReturn(codec);
325                 when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_REPORT_ID)).thenReturn("1");
326                 when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("1");
327                 when(AppUtils.getUserID(mockedRequest)).thenReturn("test");
328                 when(Globals.getReportSecurity()).thenReturn("[rw.getReportID()]");
329                 when(Globals.getReportUserAccess()).thenReturn("[reportID]");
330                 when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(set);
331                 when(Globals.getDeleteOnlyByOwner()).thenReturn(true);
332                 when(Globals.getLogVariablesInSession()).thenReturn("test");
333                 HttpSession session = Mockito.mock(HttpSession.class);
334                 when(session.getAttribute(Matchers.anyString())).thenReturn(rr);
335                 when(session.getAttribute(Matchers.anyString())).thenReturn(rd);
336                 assertEquals(actionHandler.reportDelete(mockedRequest, "10").getClass(), String.class);
337         }
338
339         @Test
340         public void reportSearchTest() throws Exception {
341                 PowerMockito.mockStatic(ESAPI.class);
342                 PowerMockito.mockStatic(AppUtils.class);
343                 PowerMockito.mockStatic(Globals.class);
344                 PowerMockito.mockStatic(DbUtils.class);
345                 when(AppUtils.getImgFolderURL()).thenReturn("test");
346                 when(AppUtils.getUserID(mockedRequest)).thenReturn("test");
347                 when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_F_REPORT_ID)).thenReturn("test");
348                 when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_F_REPORT_NAME)).thenReturn("test");
349                 when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_SORT_ORDER)).thenReturn("f_owner_id");
350                 when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_LIST_CATEGORY)).thenReturn("test");
351                 when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_USER_REPORTS)).thenReturn(true);
352                 when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_PUBLIC_REPORTS)).thenReturn(true);
353                 when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_FAVORITE_REPORTS)).thenReturn(true);
354                 when(AppUtils.nvl(Matchers.anyString())).thenReturn("te");
355                 when(Globals.getLoadReportSearchResult()).thenReturn("test");
356                 when(Globals.getLoadReportSearchRepIdSql()).thenReturn("test");
357                 when(Globals.getLoadReportSearchInstr()).thenReturn("test");
358                 when(Globals.getLoadReportSearchResultUser()).thenReturn("test");
359                 when(Globals.getLoadReportSearchResultPublic()).thenReturn("test");
360                 when(Globals.getLoadReportSearchResultFav()).thenReturn("test");
361                 when(Globals.getLoadReportSearchResultSort()).thenReturn("test");
362                 when(AppUtils.getRequestNvlValue(mockedRequest, "r_page")).thenReturn("10");
363                 Vector<String> vc = new Vector<>();
364                 vc.add("test");
365                 vc.add("test2");
366                 when(AppUtils.getUserRoles(mockedRequest)).thenReturn(vc);
367                 when(AppUtils.isSuperUser(mockedRequest)).thenReturn(false);
368                 DataSet set = Mockito.mock(DataSet.class);
369                 when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(set);
370                 Enumeration<String> enums;
371                 Vector<String> attrs = new Vector<String>();
372                 attrs.add("parent_test");
373                 attrs.add("child_test");
374                 enums = attrs.elements();
375                 when(mockedRequest.getSession().getAttributeNames()).thenReturn(enums);
376                 when(mockedRequest.getParameter("rep_id")).thenReturn("test");
377                 when(mockedRequest.getParameter("rep_id_options")).thenReturn("test");
378                 when(mockedRequest.getParameter("rep_name_options")).thenReturn("test");
379                 when(mockedRequest.getParameter("rep_name")).thenReturn("test");
380                 SearchHandler sh = Mockito.mock(SearchHandler.class);
381                 whenNew(SearchHandler.class).withNoArguments().thenReturn(sh);
382                 actionHandler.reportSearch(mockedRequest, "10");
383         }
384         
385         @SuppressWarnings({ "rawtypes", "unchecked" })
386         @Test(expected = NullPointerException.class)
387         public void reportChartRunTest() throws Exception {
388                 PowerMockito.mockStatic(Globals.class);
389                 PowerMockito.mockStatic(DbUtils.class);
390                 PowerMockito.mockStatic(ReportLoader.class);
391                 PowerMockito.mockStatic(ReportWrapper.class);
392                 PowerMockito.mockStatic(AppUtils.class);
393                 PowerMockito.mockStatic(ReportDefinition.class);
394                 PowerMockito.mockStatic(ESAPI.class);
395                 PowerMockito.mockStatic(SecurityCodecUtil.class);
396                 PowerMockito.mockStatic(UserUtils.class);
397                 when(UserUtils.getUserId(mockedRequest)).thenReturn(1);
398                 when(AppUtils.isAdminUser(mockedRequest)).thenReturn(true);
399                 when(AppUtils.isSuperUser(mockedRequest)).thenReturn(true);
400                 Map roles = new HashMap<>();
401                 roles.put("role1", "test1");
402                 roles.put("role2", "test2");
403                 when(UserUtils.getRoles(mockedRequest)).thenReturn(roles);
404                 when(mockedRequest.getParameter(AppConstants.RI_ACTION)).thenReturn("chart.data.json");
405                 ChartWebRuntime cwr = Mockito.mock(ChartWebRuntime.class);
406                 whenNew(ChartWebRuntime.class).withNoArguments().thenReturn(cwr);
407                 when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_REPORT_ID)).thenReturn("test");
408                 ReportRuntime rr = PowerMockito.mock(ReportRuntime.class);
409                 when(DbUtils.getConnection()).thenReturn(connection);
410                 when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_REPORT_ID)).thenReturn("1");
411                 when(rr.getReportID()).thenReturn("test");
412                 when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_SHOW_BACK_BTN)).thenReturn(true);
413                 when(Globals.getLoadCustomReportXml()).thenReturn("java.lang.String");
414                 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>";
415                 when(connection.prepareStatement("1")).thenReturn(stmt);
416                 when(stmt.executeQuery()).thenReturn(rs);
417                 when(Globals.isWeblogicServer()).thenReturn(true);
418                 when(rs.getClob(1)).thenReturn(clob);
419                 when(rs.next()).thenReturn(true);
420                 when(clob.getAsciiStream()).thenReturn(in);
421                 when(in.read(Matchers.any())).thenReturn(1);
422                 when(AppUtils.getRequestNvlValue(mockedRequest, "pdfAttachmentKey")).thenReturn("test");
423                 when(AppUtils.nvl(rr.getLegendLabelAngle())).thenReturn("standard");
424                 when(AppUtils.getRequestNvlValue(Matchers.any(), Matchers.anyString())).thenReturn("test");
425                 when(AppUtils.nvl("Y")).thenReturn("Y");
426                 when(AppUtils.nvl("bottom")).thenReturn("Y");
427                 when(AppUtils.nvl("test")).thenReturn("test|");
428                 when(AppUtils.getRequestValue(mockedRequest, "c_dashboard")).thenReturn("1");
429                 when(ReportLoader.isDashboardType("-1")).thenReturn(false);
430                 ReportDefinition rdf = PowerMockito.mock(ReportDefinition.class);
431                 whenNew(ReportDefinition.class)
432                                 .withArguments(Matchers.any(ReportWrapper.class), Matchers.any(HttpServletRequest.class))
433                                 .thenReturn(rdf);
434                 PowerMockito.mockStatic(ReportDefinition.class);
435                 when(ReportDefinition.unmarshal(Mockito.anyString(), Mockito.anyString(), Mockito.anyObject())).thenReturn(rdf);
436                 CustomReportType crType = Mockito.mock(CustomReportType.class);
437                 when(ReportWrapper.unmarshalCR(Matchers.anyString())).thenReturn(crType);
438                 when(Globals.getReportWrapperFormat()).thenReturn("[Globals.getTimeFormat()]");
439                 when(Globals.getTimeFormat()).thenReturn("[reportID]");
440                 when(Globals.getReportUserAccess()).thenReturn("[reportID]");
441                 DataSet set = PowerMockito.mock(DataSet.class);
442                 when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(set);
443                 when(set.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test");
444                 whenNew(ReportRuntime.class).withArguments(Matchers.any(CustomReportType.class), Matchers.anyString(),
445                                 Matchers.any(HttpServletRequest.class), Matchers.anyString(), Matchers.anyString(),
446                                 Matchers.anyString(), Matchers.anyString(), Matchers.anyString(), Matchers.anyString(),
447                                 Matchers.anyBoolean()).thenReturn(rr);
448                 DataSourceList dsl = Mockito.mock(DataSourceList.class);
449                 List<DataSourceType> list = new ArrayList<>();
450                 DataSourceType sr1 = new DataSourceType();
451                 sr1.setComment("test");
452                 sr1.setRefDefinition("test");
453                 sr1.setDataColumnList(new DataColumnList());
454                 sr1.setTableId("test");
455                 sr1.setTableName("test");
456                 list.add(sr1);
457                 when(crType.getDataSourceList()).thenReturn(dsl);
458                 when(dsl.getDataSource()).thenReturn(list);
459                 DashboardReports rps = Mockito.mock(DashboardReports.class);
460                 List<Reports> reportList = new ArrayList<>();
461                 Reports rp = new Reports();
462                 rp.setBgcolor("white");
463                 rp.setReportId("1");
464                 reportList.add(rp);
465                 when(rdf.getDashBoardReports()).thenReturn(rps);
466                 when(rps.getReportsList()).thenReturn(reportList);
467                 when(ReportLoader.loadCustomReportXML("1")).thenReturn(str);
468                 actionHandler.reportChartRun(mockedRequest, "10");
469         }
470 }