2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2018 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 java.util.ArrayList;
42 import javax.servlet.http.HttpServletRequest;
44 import org.junit.Before;
45 import org.junit.Test;
46 import org.junit.runner.RunWith;
47 import org.mockito.Matchers;
48 import org.mockito.Mockito;
49 import org.onap.portalsdk.analytics.error.RaptorException;
50 import org.onap.portalsdk.analytics.model.base.ReportWrapper;
51 import org.onap.portalsdk.analytics.system.AppUtils;
52 import org.onap.portalsdk.analytics.util.AppConstants;
53 import org.onap.portalsdk.analytics.xmlobj.MockitoTestSuite;
54 import org.onap.portalsdk.core.web.support.UserUtils;
55 import org.powermock.api.mockito.PowerMockito;
56 import org.powermock.core.classloader.annotations.PrepareForTest;
57 import org.powermock.modules.junit4.PowerMockRunner;
59 @RunWith(PowerMockRunner.class)
60 @PrepareForTest({ UserUtils.class, AppUtils.class})
61 public class ChartWebRuntimeTest {
62 ChartWebRuntime chartWebRuntime;
64 MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
65 HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
69 chartWebRuntime = new ChartWebRuntime();
70 ArrayList chartList = new ArrayList<>();
71 chartList.add("test");
72 ArrayList infoList = new ArrayList<>();
74 chartWebRuntime.setChartList(chartList);
75 chartWebRuntime.setInfoList(infoList);
76 chartWebRuntime.setTotalSql("select * from test");
80 public void testBarChartOptionsProperties() throws RaptorException {
81 PowerMockito.mockStatic(UserUtils.class);
82 PowerMockito.mockStatic(AppUtils.class);
83 Mockito.when(mockedRequest.getParameter("action")).thenReturn("test");
84 Mockito.when(UserUtils.getUserId(mockedRequest)).thenReturn(10);
85 Mockito.when(AppUtils.isAdminUser(mockedRequest)).thenReturn(true);
86 Mockito.when(AppUtils.nvl(Mockito.anyString())).thenReturn("test");
87 Mockito.when(mockedRequest.getParameter("refresh")).thenReturn("N");
88 Mockito.when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_REPORT_ID)).thenReturn("1");
89 Mockito.when(AppUtils.getRequestNvlValue(Mockito.any(HttpServletRequest.class), Mockito.anyString())).thenReturn("test");
90 ReportRuntime rr = PowerMockito.mock(ReportRuntime.class);
91 Mockito.when(rr.getReportID()).thenReturn("1");
92 Mockito.when(rr.getReportType()).thenReturn("Hive");
93 Mockito.when(rr.getReportSQL()).thenReturn("select * from test");
94 Mockito.when(rr.getLegendLabelAngle()).thenReturn("standard");
95 Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr);
96 ReportWrapper rw = PowerMockito.mock(ReportWrapper.class);
97 ReportFormFields reportFormFields = new ReportFormFields(rw, mockedRequest);
98 FormField formField = new FormField("test", "fieldDisplayName", "TEXTAREA", "validationType", false,
99 "defaultValue", "helpText", new ArrayList(), true, "dependsOn", null, null, "rangeStartDateSQL",
100 "rangeEndDateSQL", "multiSelectListSize");
101 FormField formField1 = new FormField("test", "fieldDisplayName", "TEXTAREA", "validationType", false,
102 "defaultValue", "helpText", new ArrayList(), false, "dependsOn", null, null, "rangeStartDateSQL",
103 "rangeEndDateSQL", "multiSelectListSize");
104 FormField formField2 = new FormField("test", "fieldDisplayName", "TEXTAREA", "validationType", false,
105 "defaultValue", "helpText", new ArrayList(), false, "dependsOn", null, null, "rangeStartDateSQL",
106 "rangeEndDateSQL", "multiSelectListSize");
108 reportFormFields.add(formField);
109 reportFormFields.add(formField1);
110 reportFormFields.add(formField2);
111 Mockito.when(rr.getReportFormFields()).thenReturn(reportFormFields);
112 Mockito.when(rr.getReportDefType()).thenReturn(AppConstants.RD_SQL_BASED);
113 Mockito.when(rr.getReportTitle()).thenReturn("test");
114 Mockito.when(mockedRequest.getParameterValues(Matchers.anyString())).thenReturn(new String[] { "test" });
115 chartWebRuntime.generateChart(mockedRequest);