2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
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
26 * https://creativecommons.org/licenses/by/4.0/
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.
34 * ============LICENSE_END============================================
38 package org.onap.portalsdk.analytics.model.runtime;
40 import static org.junit.Assert.assertEquals;
42 import java.io.OutputStreamWriter;
43 import java.io.PrintWriter;
44 import java.io.StringWriter;
45 import java.sql.ResultSet;
46 import java.sql.ResultSetMetaData;
47 import java.util.ArrayList;
48 import java.util.List;
49 import java.util.Vector;
51 import javax.servlet.ServletContext;
52 import javax.servlet.ServletOutputStream;
53 import javax.servlet.http.HttpServletRequest;
54 import javax.servlet.http.HttpServletResponse;
56 import org.junit.Before;
57 import org.junit.Ignore;
58 import org.junit.Test;
59 import org.junit.runner.RunWith;
60 import org.mockito.InjectMocks;
61 import org.mockito.Matchers;
62 import org.mockito.Mock;
63 import org.mockito.Mockito;
64 import org.mockito.MockitoAnnotations;
65 import org.onap.portalsdk.analytics.controller.Action;
66 import org.onap.portalsdk.analytics.controller.ActionMapping;
67 import org.onap.portalsdk.analytics.controller.ErrorHandler;
68 import org.onap.portalsdk.analytics.error.RaptorException;
69 import org.onap.portalsdk.analytics.model.DataCache;
70 import org.onap.portalsdk.analytics.model.ReportHandler;
71 import org.onap.portalsdk.analytics.model.ReportLoader;
72 import org.onap.portalsdk.analytics.model.base.IdNameValue;
73 import org.onap.portalsdk.analytics.model.base.ReportWrapper;
74 import org.onap.portalsdk.analytics.model.definition.ReportDefinition;
75 import org.onap.portalsdk.analytics.model.definition.wizard.ColumnJSON;
76 import org.onap.portalsdk.analytics.model.definition.wizard.DefinitionJSON;
77 import org.onap.portalsdk.analytics.model.definition.wizard.ImportJSON;
78 import org.onap.portalsdk.analytics.model.definition.wizard.MessageJSON;
79 import org.onap.portalsdk.analytics.model.definition.wizard.QueryJSON;
80 import org.onap.portalsdk.analytics.system.AppUtils;
81 import org.onap.portalsdk.analytics.system.ConnectionUtils;
82 import org.onap.portalsdk.analytics.system.DbUtils;
83 import org.onap.portalsdk.analytics.system.Globals;
84 import org.onap.portalsdk.analytics.system.fusion.web.RaptorControllerAsync;
85 import org.onap.portalsdk.analytics.util.AppConstants;
86 import org.onap.portalsdk.analytics.util.DataSet;
87 import org.onap.portalsdk.analytics.util.Utils;
88 import org.onap.portalsdk.analytics.util.XSSFilter;
89 import org.onap.portalsdk.analytics.view.ReportData;
90 import org.onap.portalsdk.analytics.xmlobj.ChartAdditionalOptions;
91 import org.onap.portalsdk.analytics.xmlobj.CustomReportType;
92 import org.onap.portalsdk.analytics.xmlobj.DataColumnList;
93 import org.onap.portalsdk.analytics.xmlobj.DataColumnType;
94 import org.onap.portalsdk.analytics.xmlobj.DataSourceList;
95 import org.onap.portalsdk.analytics.xmlobj.DataSourceType;
96 import org.onap.portalsdk.analytics.xmlobj.FormFieldList;
97 import org.onap.portalsdk.analytics.xmlobj.FormFieldType;
98 import org.onap.portalsdk.analytics.xmlobj.MockRunTimeReport;
99 import org.onap.portalsdk.analytics.xmlobj.MockitoTestSuite;
100 import org.onap.portalsdk.core.domain.User;
101 import org.onap.portalsdk.core.service.DataAccessService;
102 import org.onap.portalsdk.core.util.SecurityCodecUtil;
103 import org.onap.portalsdk.core.web.support.UserUtils;
104 import org.owasp.esapi.ESAPI;
105 import org.owasp.esapi.Encoder;
106 import org.owasp.esapi.codecs.Codec;
107 import org.powermock.api.mockito.PowerMockito;
108 import org.powermock.core.classloader.annotations.PrepareForTest;
109 import org.powermock.modules.junit4.PowerMockRunner;
110 import org.powermock.reflect.exceptions.MethodInvocationException;
112 @RunWith(PowerMockRunner.class)
113 @PrepareForTest({ AppConstants.class, Globals.class, AppUtils.class, ReportWrapper.class, DataCache.class,
114 DbUtils.class, DataSet.class , ReportLoader.class ,ReportRuntime.class, Utils.class, ESAPI.class,
115 Codec.class,SecurityCodecUtil.class , ConnectionUtils.class, XSSFilter.class})
116 public class RaptorControllerAsyncTest {
119 RaptorControllerAsync raptorControllerAsync = new RaptorControllerAsync();
122 public void setup() {
123 MockitoAnnotations.initMocks(this);
127 DataAccessService dataAccessService;
130 AppConstants appConstants;
135 Action action = new Action("test", "RaptorControllerAsync", "test", "test");
137 ActionMapping actionMapping = new ActionMapping();
139 ReportDefinition reportDefinition ;
142 ReportHandler reportHandler = new ReportHandler();
144 MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
145 HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
146 HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
147 NullPointerException nullPointerException = new NullPointerException();
149 MockRunTimeReport mockRunTimeReport = new MockRunTimeReport();
152 public void RaptorSearchToDownloadexcel2007Test() throws Exception {
153 Mockito.when(mockedRequest.getParameter(AppConstants.RI_ACTION))
154 .thenReturn("report.download.excel2007.session");
155 Mockito.when(mockedRequest.getParameter("action")).thenReturn("report.download.excel2007.session");
156 User user = new User();
157 user.setOrgUserId("test12");
158 Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
159 ServletContext servletContext = PowerMockito.mock(ServletContext.class);
160 Mockito.when(mockedRequest.getSession().getServletContext()).thenReturn(servletContext);
161 Mockito.when(mockedRequest.getParameter("parent")).thenReturn("parent_test");
162 PowerMockito.mockStatic(Globals.class);
163 PowerMockito.mockStatic(AppUtils.class);
164 Mockito.when(Globals.isSystemInitialized()).thenReturn(true);
165 Mockito.when(AppUtils.getUserID(mockedRequest)).thenReturn("test12");
166 ReportRuntime reportRuntime = mockRunTimeReport.mockReportRuntime();
167 ReportData reportData = PowerMockito.mock(ReportData.class);
168 Mockito.when(mockedRequest.getSession().getAttribute("parent_test" + "_rr")).thenReturn(reportRuntime);
169 Mockito.when(mockedRequest.getSession().getAttribute("parent_test" + "_rd")).thenReturn(reportData);
170 OutputStreamWriter outputStreamWriter = PowerMockito.mock(OutputStreamWriter.class);
171 ServletOutputStream ServletOutputStream = PowerMockito.mock(ServletOutputStream.class);
172 Mockito.when(mockedResponse.getOutputStream()).thenReturn(ServletOutputStream);
173 Mockito.doNothing().when(reportHandler).createExcel2007FileContent(Matchers.any(OutputStreamWriter.class), Matchers.any(ReportData.class),
174 Matchers.any(ReportRuntime.class), Matchers.any(HttpServletRequest.class), Matchers.any(HttpServletResponse.class), Matchers.any(String.class), Matchers.anyInt());
176 reportRuntime = PowerMockito.mock(ReportRuntime.class);
177 Mockito.when(reportRuntime.getReportDataSQL("test12", 500, mockedRequest)).thenReturn("test");
178 StringWriter sw = new StringWriter();
179 PrintWriter writer = new PrintWriter(sw);
180 Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
181 Mockito.when(Globals.getGenerateSubsetSql()).thenReturn("test");
182 Mockito.when(Globals.getReportSqlOnlyFirstPart()).thenReturn("test");
183 raptorControllerAsync.RaptorSearch(mockedRequest, mockedResponse);
186 @Test(expected = java.lang.NullPointerException.class)
187 public void RaptorSearchNullActionKeyTest() throws Exception {
188 User user = new User();
189 user.setOrgUserId("test12");
190 Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
191 ServletContext servletContext = PowerMockito.mock(ServletContext.class);
192 Mockito.when(mockedRequest.getSession().getServletContext()).thenReturn(servletContext);
193 PowerMockito.mockStatic(Globals.class);
194 Mockito.when(Globals.isSystemInitialized()).thenReturn(true);
195 Mockito.when(Globals.getRaptorActionMapping()).thenReturn(actionMapping);
196 Action action1 = new Action("test",
197 "org.onap.portalsdk.analytics.system.fusion.service.RaptorControllerAsyncTest", "test", "test");
198 Mockito.when(actionMapping.getAction(Matchers.anyString())).thenReturn(action1);
199 StringWriter sw = new StringWriter();
200 PrintWriter writer = new PrintWriter(sw);
201 Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
202 raptorControllerAsync.RaptorSearch(mockedRequest, mockedResponse);
205 public String test(HttpServletRequest request, String str) {
209 @Test(expected = java.lang.NullPointerException.class)
210 public void RaptorSearchClassNotFoundExceptionTest() throws Exception {
211 User user = new User();
212 user.setOrgUserId("test12");
213 Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
214 ServletContext servletContext = PowerMockito.mock(ServletContext.class);
215 Mockito.when(mockedRequest.getSession().getServletContext()).thenReturn(servletContext);
216 PowerMockito.mockStatic(Globals.class);
217 Mockito.when(Globals.isSystemInitialized()).thenReturn(true);
218 Mockito.when(Globals.getRaptorActionMapping()).thenReturn(actionMapping);
219 Action action1 = new Action("test", "RaptorControllerAsyncTest", "test", "test");
220 Mockito.when(actionMapping.getAction(Matchers.anyString())).thenReturn(action1);
221 StringWriter sw = new StringWriter();
222 PrintWriter writer = new PrintWriter(sw);
223 Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
224 raptorControllerAsync.RaptorSearch(mockedRequest, mockedResponse);
227 @Test(expected = java.lang.NullPointerException.class)
228 public void RaptorSearchMethodNotFoundExceptionTest() throws Exception {
229 User user = new User();
230 user.setOrgUserId("test12");
231 Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
232 ServletContext servletContext = PowerMockito.mock(ServletContext.class);
233 Mockito.when(mockedRequest.getSession().getServletContext()).thenReturn(servletContext);
234 PowerMockito.mockStatic(Globals.class);
235 Mockito.when(Globals.isSystemInitialized()).thenReturn(true);
236 Mockito.when(Globals.getRaptorActionMapping()).thenReturn(actionMapping);
237 Action action1 = new Action("test",
238 "org.onap.portalsdk.analytics.system.fusion.service.RaptorControllerAsyncTest", "newtest", "test");
239 Mockito.when(actionMapping.getAction(Matchers.anyString())).thenReturn(action1);
240 StringWriter sw = new StringWriter();
241 PrintWriter writer = new PrintWriter(sw);
242 Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
243 raptorControllerAsync.RaptorSearch(mockedRequest, mockedResponse);
246 public void test1(HttpServletRequest request, String str) {
247 throw new MethodInvocationException("test");
250 @Test(expected = java.lang.NullPointerException.class)
251 public void RaptorSearchMethodInvocationFoundExceptionTest() throws Exception {
252 User user = new User();
253 user.setOrgUserId("test12");
254 Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
255 ServletContext servletContext = PowerMockito.mock(ServletContext.class);
256 Mockito.when(mockedRequest.getSession().getServletContext()).thenReturn(servletContext);
257 PowerMockito.mockStatic(Globals.class);
258 Mockito.when(Globals.isSystemInitialized()).thenReturn(true);
259 Mockito.when(Globals.getRaptorActionMapping()).thenReturn(actionMapping);
260 Action action1 = new Action("test",
261 "org.onap.portalsdk.analytics.system.fusion.service.RaptorControllerAsyncTest", "test1", null);
262 Mockito.when(actionMapping.getAction(Matchers.anyString())).thenReturn(action1);
263 StringWriter sw = new StringWriter();
264 PrintWriter writer = new PrintWriter(sw);
265 Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
266 raptorControllerAsync.RaptorSearch(mockedRequest, mockedResponse);
269 @Test(expected = java.lang.NullPointerException.class)
270 public void RaptorSearchRaptorExceptionTest() throws Exception {
271 User user = new User();
272 user.setOrgUserId("test12");
273 Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
274 ServletContext servletContext = PowerMockito.mock(ServletContext.class);
275 Mockito.when(mockedRequest.getSession().getServletContext()).thenReturn(servletContext);
276 PowerMockito.mockStatic(Globals.class);
277 Mockito.when(Globals.isSystemInitialized()).thenReturn(true);
278 Mockito.when(Globals.getRaptorActionMapping()).thenReturn(actionMapping);
279 Mockito.when(actionMapping.getAction(Matchers.anyString())).thenReturn(null);
280 StringWriter sw = new StringWriter();
281 PrintWriter writer = new PrintWriter(sw);
282 Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
283 raptorControllerAsync.RaptorSearch(mockedRequest, mockedResponse);
287 public void RaptorSearchNoUserTest() throws Exception {
289 Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(null);
290 ServletContext servletContext = PowerMockito.mock(ServletContext.class);
291 Mockito.when(mockedRequest.getSession().getServletContext()).thenReturn(servletContext);
292 PowerMockito.mockStatic(Globals.class);
293 Mockito.when(Globals.isSystemInitialized()).thenReturn(true);
294 Mockito.when(Globals.getRaptorActionMapping()).thenReturn(actionMapping);
295 Action action1 = new Action("test",
296 "org.onap.portalsdk.analytics.system.fusion.service.RaptorControllerAsyncTest", "test1", null);
297 Mockito.when(actionMapping.getAction(Matchers.anyString())).thenReturn(action1);
298 StringWriter sw = new StringWriter();
299 PrintWriter writer = new PrintWriter(sw);
300 Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
301 raptorControllerAsync.RaptorSearch(mockedRequest, mockedResponse);
304 @Test(expected = java.lang.NullPointerException.class)
305 public void RaptorSearchGlobalyTest() throws Exception {
306 User user = new User();
307 user.setOrgUserId("test12");
308 Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
309 ServletContext servletContext = PowerMockito.mock(ServletContext.class);
310 Mockito.when(mockedRequest.getSession().getServletContext()).thenReturn(servletContext);
311 PowerMockito.mockStatic(Globals.class);
312 Mockito.when(Globals.isSystemInitialized()).thenReturn(false);
313 Mockito.when(Globals.getRaptorActionMapping()).thenReturn(actionMapping);
314 Action action1 = new Action("test",
315 "org.onap.portalsdk.analytics.system.fusion.service.RaptorControllerAsyncTest", "test", "test");
316 Mockito.when(actionMapping.getAction(Matchers.anyString())).thenReturn(action1);
317 StringWriter sw = new StringWriter();
318 PrintWriter writer = new PrintWriter(sw);
319 Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
320 ErrorHandler errorHandler = PowerMockito.mock(ErrorHandler.class);
321 Mockito.when(errorHandler.processFatalErrorJSON(Matchers.any(HttpServletRequest.class), Matchers.any(RaptorException.class))).thenReturn("test");
324 raptorControllerAsync.setViewName("test");
325 raptorControllerAsync.RaptorSearch(mockedRequest, mockedResponse);
329 public void listColumnsTest() throws Exception {
330 List<DataColumnType> reportColumnList = new ArrayList<>();
331 DataColumnType dataColumnType = new DataColumnType();
332 dataColumnType.setColId("test");
333 dataColumnType.setColName("testname");
334 reportColumnList.add(dataColumnType);
335 ReportDefinition reportDefinition = PowerMockito.mock(ReportDefinition.class);
336 reportDefinition.setReportName("test");
337 Mockito.when(reportDefinition.getAllColumns()).thenReturn(reportColumnList);
338 Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION))
339 .thenReturn(reportDefinition);
340 ArrayList<ColumnJSON> listJSON = new ArrayList<ColumnJSON>();
341 ColumnJSON columnJSON = new ColumnJSON();
342 columnJSON.setId("test");
343 columnJSON.setName("testname");
344 listJSON.add(columnJSON);
345 assertEquals(listJSON.get(0).getId(),
346 raptorControllerAsync.listColumns(mockedRequest, mockedResponse).get(0).getId());
350 public void list_drilldown_reports() throws Exception {
351 PowerMockito.mockStatic(Globals.class);
352 PowerMockito.mockStatic(DbUtils.class);
354 Mockito.when(Globals.getReportUserAccess()).thenReturn("test");
355 ResultSet rs = PowerMockito.mock(ResultSet.class);
356 ResultSetMetaData rsmd = PowerMockito.mock(ResultSetMetaData.class);
357 Mockito.when(rsmd.getColumnCount()).thenReturn(1);
358 Mockito.when(rs.getMetaData()).thenReturn(rsmd);
359 DataSet datset = PowerMockito.mock(DataSet.class);
360 Mockito.when(datset.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn(null);
361 Mockito.when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(datset);
362 Mockito.when(Globals.getNewScheduleData()).thenReturn("test");
363 CustomReportType customReportType = new CustomReportType();
364 customReportType.setReportType("test");
365 ReportWrapper reportWrapper = new ReportWrapper(customReportType, "-1", "test", "testId", "test", "test", "1",
367 ReportDefinition reportDefinition = PowerMockito.mock(ReportDefinition.class);
368 Mockito.doNothing().when(reportDefinition).generateWizardSequence(null);
369 reportDefinition = new ReportDefinition(reportWrapper, mockedRequest);
370 PowerMockito.mockStatic(DataCache.class);
371 PowerMockito.mockStatic(AppUtils.class);
372 Vector<IdNameValue> reportnames = new Vector<>();
373 IdNameValue idNameValue = new IdNameValue();
374 idNameValue.setId("1");
375 reportnames.add(idNameValue);
376 Mockito.when(DataCache.getPublicReportIdNames()).thenReturn(reportnames);
377 reportDefinition.setReportName("test");
378 Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION))
379 .thenReturn(reportDefinition);
380 Mockito.when(AppUtils.getUserID(mockedRequest)).thenReturn("test12");
381 Vector userRoles = new Vector<>();
382 userRoles.add(idNameValue);
383 Mockito.when(AppUtils.getUserRoles(mockedRequest)).thenReturn(userRoles);
385 Vector groupReportIdNames = new Vector<>();
386 groupReportIdNames.add(idNameValue);
387 Mockito.when(DataCache.getGroupAccessibleReportIdNames("test12", userRoles)).thenReturn(groupReportIdNames);
388 Mockito.when(DataCache.getPrivateAccessibleReportIdNames("test12", userRoles)).thenReturn(groupReportIdNames);
389 ServletContext servletContext = PowerMockito.mock(ServletContext.class);
390 Mockito.when(mockedRequest.getSession().getServletContext()).thenReturn(servletContext);
391 Mockito.when(Globals.isSystemInitialized()).thenReturn(true);
392 assertEquals(3, raptorControllerAsync.list_drilldown_reports(mockedRequest, mockedResponse).size());
396 public void list_drilldown_reportsNull() throws Exception {
397 PowerMockito.mockStatic(Globals.class);
398 PowerMockito.mockStatic(DbUtils.class);
400 Mockito.when(Globals.getReportUserAccess()).thenReturn("test");
401 ResultSet rs = PowerMockito.mock(ResultSet.class);
402 ResultSetMetaData rsmd = PowerMockito.mock(ResultSetMetaData.class);
403 Mockito.when(rsmd.getColumnCount()).thenReturn(1);
404 Mockito.when(rs.getMetaData()).thenReturn(rsmd);
405 DataSet datset = PowerMockito.mock(DataSet.class);
406 // datset = new DataSet(rs);
407 Mockito.when(datset.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn(null);
408 Mockito.when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(datset);
409 Mockito.when(Globals.getNewScheduleData()).thenReturn("test");
410 CustomReportType customReportType = new CustomReportType();
411 customReportType.setReportType("test");
412 ReportWrapper reportWrapper = new ReportWrapper(customReportType, "-1", "test", "testId", "test", "test", "1",
414 ReportDefinition reportDefinition = PowerMockito.mock(ReportDefinition.class);
415 Mockito.doNothing().when(reportDefinition).generateWizardSequence(null);
416 reportDefinition = new ReportDefinition(reportWrapper, mockedRequest);
417 PowerMockito.mockStatic(DataCache.class);
418 PowerMockito.mockStatic(AppUtils.class);
419 Vector<IdNameValue> reportnames = new Vector<>();
420 IdNameValue idNameValue = new IdNameValue();
421 idNameValue.setId("-1");
422 reportnames.add(idNameValue);
423 Mockito.when(DataCache.getPublicReportIdNames()).thenReturn(reportnames);
424 reportDefinition.setReportName("test");
425 Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION))
426 .thenReturn(reportDefinition);
427 Mockito.when(AppUtils.getUserID(mockedRequest)).thenReturn("test12");
428 Vector userRoles = new Vector<>();
429 userRoles.add(idNameValue);
430 Mockito.when(AppUtils.getUserRoles(mockedRequest)).thenReturn(userRoles);
432 Vector groupReportIdNames = new Vector<>();
433 groupReportIdNames.add(idNameValue);
434 Mockito.when(DataCache.getGroupAccessibleReportIdNames("test12", userRoles)).thenReturn(groupReportIdNames);
435 Mockito.when(DataCache.getPrivateAccessibleReportIdNames("test12", userRoles)).thenReturn(groupReportIdNames);
436 ServletContext servletContext = PowerMockito.mock(ServletContext.class);
437 Mockito.when(mockedRequest.getSession().getServletContext()).thenReturn(servletContext);
438 Mockito.when(Globals.isSystemInitialized()).thenReturn(true);
439 assertEquals(0, raptorControllerAsync.list_drilldown_reports(mockedRequest, mockedResponse).size());
443 public void listFormFields() throws Exception
445 PowerMockito.mockStatic(Globals.class);
446 PowerMockito.mockStatic(DbUtils.class);
448 Mockito.when(Globals.getReportUserAccess()).thenReturn("test");
449 ResultSet rs = PowerMockito.mock(ResultSet.class);
450 ResultSetMetaData rsmd = PowerMockito.mock(ResultSetMetaData.class);
451 Mockito.when(rsmd.getColumnCount()).thenReturn(1);
452 Mockito.when(rs.getMetaData()).thenReturn(rsmd);
453 DataSet datset = PowerMockito.mock(DataSet.class);
454 // datset = new DataSet(rs);
455 Mockito.when(datset.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn(null);
456 Mockito.when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(datset);
457 Mockito.when(Globals.getNewScheduleData()).thenReturn("test");
458 CustomReportType customReportType = new CustomReportType();
459 customReportType.setReportType("test");
460 FormFieldList formFieldList= new FormFieldList();
461 formFieldList.setComment("test");
462 customReportType.setFormFieldList(formFieldList);
463 ReportWrapper reportWrapper = new ReportWrapper(customReportType, "-1", "test", "testId", "test", "test", "1",
465 ReportDefinition reportDefinition = PowerMockito.mock(ReportDefinition.class);
466 Mockito.doNothing().when(reportDefinition).generateWizardSequence(null);
467 reportDefinition = new ReportDefinition(reportWrapper, mockedRequest);
469 Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION)).thenReturn(reportDefinition);
471 assertEquals(raptorControllerAsync.listFormFields(mockedRequest, mockedResponse).size(), 0);
475 public void listFormFieldsTest() throws Exception
477 PowerMockito.mockStatic(Globals.class);
478 PowerMockito.mockStatic(DbUtils.class);
480 Mockito.when(Globals.getReportUserAccess()).thenReturn("test");
481 ResultSet rs = PowerMockito.mock(ResultSet.class);
482 ResultSetMetaData rsmd = PowerMockito.mock(ResultSetMetaData.class);
483 Mockito.when(rsmd.getColumnCount()).thenReturn(1);
484 Mockito.when(rs.getMetaData()).thenReturn(rsmd);
485 DataSet datset = PowerMockito.mock(DataSet.class);
486 // datset = new DataSet(rs);
487 Mockito.when(datset.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn(null);
488 Mockito.when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(datset);
489 Mockito.when(Globals.getNewScheduleData()).thenReturn("test");
490 CustomReportType customReportType = new CustomReportType();
491 customReportType.setReportType("test");
492 FormFieldList formFieldList= PowerMockito.mock(FormFieldList.class);
493 formFieldList.setComment("test");
494 customReportType.setFormFieldList(formFieldList);
495 ReportWrapper reportWrapper = new ReportWrapper(customReportType, "-1", "test", "testId", "test", "test", "1",
497 ReportDefinition reportDefinition = PowerMockito.mock(ReportDefinition.class);
498 Mockito.doNothing().when(reportDefinition).generateWizardSequence(null);
499 reportDefinition = new ReportDefinition(reportWrapper, mockedRequest);
500 List<FormFieldType> formField = new ArrayList<>();
501 FormFieldType formFieldType = new FormFieldType();
502 formFieldType.setFieldId("id");
503 formField.add(formFieldType);
504 Mockito.when(formFieldList.getFormField()).thenReturn(formField);
505 Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION)).thenReturn(reportDefinition);
506 assertEquals(raptorControllerAsync.listFormFields(mockedRequest, mockedResponse).size(), 1);
510 public void listFormFieldsNullTest() throws Exception
512 PowerMockito.mockStatic(Globals.class);
513 PowerMockito.mockStatic(DbUtils.class);
515 Mockito.when(Globals.getReportUserAccess()).thenReturn("test");
516 ResultSet rs = PowerMockito.mock(ResultSet.class);
517 ResultSetMetaData rsmd = PowerMockito.mock(ResultSetMetaData.class);
518 Mockito.when(rsmd.getColumnCount()).thenReturn(1);
519 Mockito.when(rs.getMetaData()).thenReturn(rsmd);
520 DataSet datset = PowerMockito.mock(DataSet.class);
521 // datset = new DataSet(rs);
522 Mockito.when(datset.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn(null);
523 Mockito.when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(datset);
524 Mockito.when(Globals.getNewScheduleData()).thenReturn("test");
525 CustomReportType customReportType = new CustomReportType();
526 customReportType.setReportType("test");
527 ReportWrapper reportWrapper = new ReportWrapper(customReportType, "-1", "test", "testId", "test", "test", "1",
529 ReportDefinition reportDefinition = PowerMockito.mock(ReportDefinition.class);
530 Mockito.doNothing().when(reportDefinition).generateWizardSequence(null);
531 reportDefinition = new ReportDefinition(reportWrapper, mockedRequest);
532 Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION)).thenReturn(reportDefinition);
533 assertEquals(raptorControllerAsync.listFormFields(mockedRequest, mockedResponse).size(),0);
536 @Test(expected = java.lang.NullPointerException.class)
537 public void saveDefTabWiseDataIfIdInSessionTest() throws Exception
539 DefinitionJSON definitionJSON = new DefinitionJSON();
540 definitionJSON.setTabId("1");
541 PowerMockito.mockStatic(ReportLoader.class);
542 Mockito.when(ReportLoader.loadCustomReportXML("1")).thenReturn("test");
543 ReportRuntime rr = PowerMockito.mock(ReportRuntime.class);
544 PowerMockito.mockStatic(Globals.class);
545 PowerMockito.mockStatic(DbUtils.class);
547 Mockito.when(Globals.getReportUserAccess()).thenReturn("test");
548 ResultSet rs = PowerMockito.mock(ResultSet.class);
549 ResultSetMetaData rsmd = PowerMockito.mock(ResultSetMetaData.class);
550 Mockito.when(rsmd.getColumnCount()).thenReturn(1);
551 Mockito.when(rs.getMetaData()).thenReturn(rsmd);
552 DataSet datset = PowerMockito.mock(DataSet.class);
553 Mockito.when(datset.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn(null);
554 Mockito.when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(datset);
555 Mockito.when(Globals.getNewScheduleData()).thenReturn("test");
556 CustomReportType customReportType = new CustomReportType();
557 customReportType.setReportType("test");
558 DataSourceList list = new DataSourceList();
559 customReportType.setDataSourceList(list);
560 ReportWrapper reportWrapper = new ReportWrapper(customReportType, "-1", "test", "testId", "test", "test", "1",
562 rr = new ReportRuntime(reportWrapper);
563 Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(null);
564 Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr);
565 raptorControllerAsync.saveDefTabWiseData("test", definitionJSON, mockedRequest, mockedResponse);
570 public void reportChartReceiveTest() throws Exception
573 PowerMockito.mockStatic(ReportLoader.class);
574 Mockito.when(ReportLoader.loadCustomReportXML("1")).thenReturn("test");
575 ReportRuntime rr = mockRunTimeReport.mockReportRuntime();
576 PowerMockito.mockStatic(Globals.class);
577 PowerMockito.mockStatic(DbUtils.class);
578 Mockito.when(Globals.getReportUserAccess()).thenReturn("test");
579 ResultSet rs = PowerMockito.mock(ResultSet.class);
580 ResultSetMetaData rsmd = PowerMockito.mock(ResultSetMetaData.class);
581 Mockito.when(rsmd.getColumnCount()).thenReturn(1);
582 Mockito.when(rs.getMetaData()).thenReturn(rsmd);
583 DataSet datset = PowerMockito.mock(DataSet.class);
584 Mockito.when(datset.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn(null);
585 Mockito.when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(datset);
586 Mockito.when(Globals.getNewScheduleData()).thenReturn("test");
587 CustomReportType customReportType = new CustomReportType();
588 customReportType.setReportType("test");
589 DataSourceList list = new DataSourceList();
590 customReportType.setDataSourceList(list);
591 ReportWrapper reportWrapper = new ReportWrapper(customReportType, "-1", "test", "testId", "test", "test", "1",
593 Mockito.when( mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr);
594 ChartJSON chartJSON = mockChartJSON();
595 raptorControllerAsync.reportChartReceive(chartJSON, mockedRequest, mockedResponse);
600 public ChartJSON mockChartJSON()
602 ChartJSON chartJSON = new ChartJSON();
603 chartJSON.setAnimation(false);
604 chartJSON.setWidth("width");
605 chartJSON.setHeight("height");
606 chartJSON.setShowTitle(true);
607 BarChartOptions barChartOptions= new BarChartOptions();
608 chartJSON.setBarChartOptions(barChartOptions);
609 DomainAxisJSON domainAxisJSON= new DomainAxisJSON();
610 domainAxisJSON.setValue("test");
611 chartJSON.setDomainAxisJSON(domainAxisJSON);
612 ArrayList<RangeAxisJSON> rangeAxisJSONList = new ArrayList<>();
613 RangeAxisJSON rangeAxisJSON = new RangeAxisJSON();
614 rangeAxisJSONList.add(rangeAxisJSON);
615 chartJSON.setRangeAxisRemoveList(rangeAxisJSONList);
616 ChartTypeJSON chartTypeJSON = new ChartTypeJSON();
617 chartTypeJSON.setValue("BarChart3D");
618 chartJSON.setChartTypeJSON(chartTypeJSON);
619 chartJSON.setRangeAxisList(rangeAxisJSONList);
620 CommonChartOptions commonChartOptions = new CommonChartOptions();
621 commonChartOptions.setLegendLabelAngle("test");
622 commonChartOptions.setLegendPosition("legendPosition");
623 commonChartOptions.setHideLegend(false);
624 chartJSON.setCommonChartOptions(commonChartOptions);